Skip to content

Commit 7b00291

Browse files
committed
geometry
1 parent 8a4a359 commit 7b00291

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

src/geometry/graph/mst.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,39 @@ class WeightedEdge final
7272
}
7373
};
7474

75+
template <std::size_t N>
76+
std::array<int, 2> sorted_vertices(const std::array<int, N>& object, const std::size_t p1, const std::size_t p2)
77+
{
78+
const int v1 = object[p1];
79+
const int v2 = object[p2];
80+
81+
if (v1 < v2)
82+
{
83+
return {v1, v2};
84+
}
85+
86+
if (v2 < v1)
87+
{
88+
return {v2, v1};
89+
}
90+
91+
error("Double vertex in Delaunay " + to_string(object));
92+
}
93+
7594
template <std::size_t N>
7695
std::vector<Edge2> all_edges_from_delaunay_objects(const std::vector<std::array<int, N>>& delaunay_objects)
7796
{
7897
static_assert(N >= 3);
7998

8099
std::vector<Edge2> edges;
81100

82-
for (const std::array<int, N>& indices : delaunay_objects)
101+
for (const std::array<int, N>& object : delaunay_objects)
83102
{
84-
for (std::size_t p1 = 0; p1 < indices.size() - 1; ++p1)
103+
for (std::size_t p1 = 0; p1 < object.size() - 1; ++p1)
85104
{
86-
for (std::size_t p2 = p1 + 1; p2 < indices.size(); ++p2)
105+
for (std::size_t p2 = p1 + 1; p2 < object.size(); ++p2)
87106
{
88-
if (indices[p1] < indices[p2])
89-
{
90-
edges.emplace_back(std::array<int, 2>{indices[p1], indices[p2]});
91-
}
92-
else if (indices[p1] > indices[p2])
93-
{
94-
edges.emplace_back(std::array<int, 2>{indices[p2], indices[p1]});
95-
}
96-
else
97-
{
98-
error("Double vertex in Delaunay " + to_string(indices));
99-
}
107+
edges.emplace_back(sorted_vertices(object, p1, p2));
100108
}
101109
}
102110
}

0 commit comments

Comments
 (0)