Skip to content

Commit

Permalink
Use **Combinations** rather than **Permutations** when matching surfa…
Browse files Browse the repository at this point in the history
…ces/edges

Testbed / demo: https://godbolt.org/z/E7n88WP34
  • Loading branch information
jmarrec committed Oct 30, 2023
1 parent eaef513 commit f2c2537
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/utilities/geometry/Polyhedron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ std::ostream& operator<<(std::ostream& os, const Surface3dEdge& edge) {

Surface3d::Surface3d(std::vector<Point3d> t_vertices, std::string t_name, size_t t_surfNum)
: vertices(std::move(t_vertices)), name(std::move(t_name)), surfNum(t_surfNum) {

edges.reserve(vertices.size());
for (auto it = vertices.begin(); it != vertices.end(); ++it) {

auto itnext = std::next(it);
Expand Down Expand Up @@ -240,11 +242,9 @@ void Polyhedron::performEdgeMatching() {

m_hasAnySurfaceWithIncorrectOrientation = false;

for (size_t i = 0; i < m_surfaces.size(); ++i) {
for (size_t j = 0; j < m_surfaces.size(); ++j) {
if (i == j) {
continue;
}
// We use **Combinations** (rather than Permutations) to avoid traversing unnecessarily
for (size_t i = 0; i < m_surfaces.size() - 1; ++i) {
for (size_t j = i + 1; j < m_surfaces.size(); ++j) {
auto& surface1 = m_surfaces[i];
auto& surface2 = m_surfaces[j];
for (Surface3dEdge& edge1 : surface1.edges) {
Expand Down Expand Up @@ -273,11 +273,8 @@ void Polyhedron::performEdgeMatching() {
// we allow these edges to double count the first surface since they bound the same surface on two sides
for (auto& surface : m_surfaces) {
auto& edges = surface.edges;
for (size_t i = 0; i < edges.size(); ++i) {
for (size_t j = 0; j < edges.size(); ++j) {
if (i == j) {
continue;
}
for (size_t i = 0; i < edges.size() - 1; ++i) {
for (size_t j = i + 1; j < edges.size(); ++j) {
if ((edges[i].count() == 1) && (edges[j].count() == 1) && (edges[i] == edges[j]) && edges[i].reverseEqual(edges[j])) {
// appendSurface will allow use to check edge.count() later to check if count == 2.
// All edges must be count == 2 in an Enclosed Polyhedron
Expand Down

0 comments on commit f2c2537

Please sign in to comment.