Skip to content

Commit

Permalink
LineModel: Rename connections() to edges()
Browse files Browse the repository at this point in the history
  • Loading branch information
AsnelChristian committed Jun 9, 2017
1 parent b6a73bb commit c959c83
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 149 deletions.
2 changes: 1 addition & 1 deletion CE3D2/doc/GettingStarted-LineModels.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main()

The line model contains additional information what vectors are connected
together with a line. This information is stored inside
`LineModel::connections()` using index pairs of the vectors in
`LineModel::edges()` using index pairs of the vectors in
`LineModel::vectors()`. The indices in the pairs refer to the (zero-based)
position inside `LineModel::vectors()`.

Expand Down
38 changes: 19 additions & 19 deletions CE3D2/models/LineModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace Models
{
LineModel::LineModel()
: Model()
, m_Connections()
, m_Edges()
{}

LineModel::LineModel(std::string name)
: Model(name)
, m_Connections()
, m_Edges()
{}

LineModel::LineModel(Model const& copy)
: Model(copy)
, m_Connections()
, m_Edges()
{}

LineModel::~LineModel()
Expand Down Expand Up @@ -47,7 +47,7 @@ namespace Models
LineModel::hypercube(Vector::size_type dimension)
{
using container_size_type = std::remove_reference<decltype(
std::declval<LineModel>().connections())>::type::size_type;
std::declval<LineModel>().edges())>::type::size_type;

// Precompute the size needed to store the index-pairs.
container_size_type index_count =
Expand All @@ -68,60 +68,60 @@ namespace Models
// The `dimension == 0` case is automatically covered from
// `Model::hypercube()`.
auto model = LineModel(Model::hypercube(dimension));
auto& connections = model.connections();
auto& edges = model.edges();

// The pre-size calculation formula below doesn't work for
// `dimension == 1` (because of the bitshift optimizations for 2^x
// exponential calculations).
if (dimension == 1)
{
connections.push_back(IndexPair(0, 1));
edges.push_back(IndexPair(0, 1));
return model;
}

connections.reserve(index_count);
edges.reserve(index_count);

// Since only `dimension == 2` reaches this code, we can already push
// back `IndexPair`s we are able to precalculate.
connections.push_back(IndexPair(0, 1));
connections.push_back(IndexPair(2, 3));
connections.push_back(IndexPair(0, 2));
connections.push_back(IndexPair(1, 3));
edges.push_back(IndexPair(0, 1));
edges.push_back(IndexPair(2, 3));
edges.push_back(IndexPair(0, 2));
edges.push_back(IndexPair(1, 3));

for (container_size_type i = 2; i < dimension; i++)
{
// Index duplication phase.
// Duplicates all existing index-pairs and offsets them by 2^i.
auto offset = static_cast<container_size_type>(2) << (i - 1);
auto current_size = connections.size();
auto current_size = edges.size();
for (container_size_type n = 0; n < current_size; n++)
{
auto const& indexpair = connections[n];
connections.push_back(IndexPair(indexpair.first + offset,
auto const& indexpair = edges[n];
edges.push_back(IndexPair(indexpair.first + offset,
indexpair.second + offset));
}

// Cross-link phase.
// Connect the previously created and duplicated index-pairs.
for (container_size_type j = 0; j < offset; j++)
{
connections.push_back(IndexPair(j, j + offset));
edges.push_back(IndexPair(j, j + offset));
}
}

return model;
}

StorageType<IndexPair> const&
LineModel::connections() const
LineModel::edges() const
{
return m_Connections;
return m_Edges;
}

StorageType<IndexPair>&
LineModel::connections()
LineModel::edges()
{
return m_Connections;
return m_Edges;
}
}
}
6 changes: 3 additions & 3 deletions CE3D2/models/LineModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ namespace Models
/// @returns A reference to the `StorageType` containing the
/// connection-index-pairs.
StorageType<IndexPair>&
connections();
edges();

/// Returns a read-only `StorageType` that contains the pairs that
/// define the line-connections of the model between the vectors.
///
/// @returns A `const` reference to the `StorageType` containing the
/// connection-index-pairs.
StorageType<IndexPair> const&
connections() const;
edges() const;

private:
StorageType<IndexPair> m_Connections;
StorageType<IndexPair> m_Edges;
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion CE3D2/render/TextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace Render
{
if (model->is_visible())
{
for (auto const& indexpair: model->connections())
for (auto const& indexpair: model->edges())
{
auto const& v1 = model->vectors()[indexpair.first];
auto const& v2 = model->vectors()[indexpair.second];
Expand Down
Loading

0 comments on commit c959c83

Please sign in to comment.