From 60c67a9c96be75f842afbbdb30e2fe3b8fc4d9f5 Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Mon, 20 Apr 2026 14:19:22 +0200 Subject: [PATCH 01/10] fix(PolygonsAroundVertex): handling of non-orientable meshes --- src/geode/mesh/core/surface_mesh.cpp | 33 ++++++-- .../mesh/helpers/detail/surface_merger.cpp | 11 ++- .../helpers/repair_polygon_orientations.cpp | 7 ++ tests/data/moebius_strip.og_tsf3d | Bin 0 -> 7639 bytes tests/mesh/CMakeLists.txt | 6 ++ tests/mesh/test-moebius-strip.cpp | 76 ++++++++++++++++++ 6 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 tests/data/moebius_strip.og_tsf3d create mode 100644 tests/mesh/test-moebius-strip.cpp diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 275d6ab12..2ec2b6242 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -125,14 +125,14 @@ namespace constexpr geode::index_t MAX_SAFETY_COUNT{ 1000 }; geode::internal::PolygonsAroundVertexImpl result; auto cur_polygon_vertex = first_polygon; + bool non_orientable{ false }; do { - OPENGEODE_ASSERT( - mesh.polygon_vertex( cur_polygon_vertex.value() ) == vertex_id, - "[SurfaceMesh::polygons_around_vertex] Wrong polygon " - "around vertex ", - vertex_id, " / ", cur_polygon_vertex->string(), " ", - mesh.polygon_vertex( cur_polygon_vertex.value() ) ); + if( mesh.polygon_vertex( cur_polygon_vertex.value() ) != vertex_id ) + { + non_orientable = true; + break; + } result.polygons.push_back( cur_polygon_vertex.value() ); const auto prev_vertex = mesh.previous_polygon_vertex( cur_polygon_vertex.value() ); @@ -151,6 +151,27 @@ namespace } while( cur_polygon_vertex != first_polygon && safety_count < MAX_SAFETY_COUNT ); + if( non_orientable ) + { + result.polygons.clear(); + result.vertex_is_on_border = false; + // méthode bourrin à améliorer + for( const auto polygon_id : geode::Range{ mesh.nb_polygons() } ) + { + for( const auto local_vertex_id : + geode::LRange{ mesh.nb_polygon_vertices( polygon_id ) } ) + { + const geode::PolygonVertex polygon_vertex{ polygon_id, + local_vertex_id }; + if( mesh.polygon_vertex( polygon_vertex ) == vertex_id ) + { + result.polygons.push_back( polygon_vertex ); + } + } + } + return result; + } + result.vertex_is_on_border = cur_polygon_vertex != first_polygon; if( result.vertex_is_on_border ) { diff --git a/src/geode/mesh/helpers/detail/surface_merger.cpp b/src/geode/mesh/helpers/detail/surface_merger.cpp index 4af911c8a..062f9c343 100644 --- a/src/geode/mesh/helpers/detail/surface_merger.cpp +++ b/src/geode/mesh/helpers/detail/surface_merger.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -131,7 +132,15 @@ namespace geode void clean_surface( SurfaceMeshMerger< dimension >& merger ) { separate_surfaces( merger ); - repair_polygon_orientations( merger.mesh(), merger.builder() ); + try + { + repair_polygon_orientations( + merger.mesh(), merger.builder() ); + } + catch( const OpenGeodeException& e ) + { + Logger::warn( e.what() ); + } } void create_polygons( SurfaceMeshMerger< dimension >& merger ) diff --git a/src/geode/mesh/helpers/repair_polygon_orientations.cpp b/src/geode/mesh/helpers/repair_polygon_orientations.cpp index 8b30758a3..3e7bb3013 100644 --- a/src/geode/mesh/helpers/repair_polygon_orientations.cpp +++ b/src/geode/mesh/helpers/repair_polygon_orientations.cpp @@ -67,6 +67,13 @@ namespace } return get_bad_oriented_polygons(); } + catch( geode::OpenGeodeDataException& e ) + { + const auto msg = absl::StrCat( "Surface ", + mesh_.name().value_or( mesh_.id().string() ), ": ", + e.what() ); + throw geode::OpenGeodeDataException( msg ); + } catch( geode::OpenGeodeException& e ) { const auto msg = absl::StrCat( "Surface ", diff --git a/tests/data/moebius_strip.og_tsf3d b/tests/data/moebius_strip.og_tsf3d new file mode 100644 index 0000000000000000000000000000000000000000..ffe602ed43cd9ff0d080a944ea9f8115350c6116 GIT binary patch literal 7639 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 + +#include +#include + +#include +#include +#include +#include +#include + +void test_polygons_around_vertex() +{ + auto moebius_strip = geode::load_triangulated_surface< 3 >( + absl::StrCat( geode::DATA_PATH, "moebius_strip.og_tsf3d" ) ); + + geode::index_t vertex_id_border = 0; + auto polygons_around_border = + moebius_strip->polygons_around_vertex( vertex_id_border ); + + OPENGEODE_EXCEPTION( polygons_around.size() == 6, + "[Test] Wrong computation of polygons around vertex 1 : should be 6 " + "polygons , " + "get ", + polygons_around.size() ); + OPENGEODE_EXCEPTION( + polygons_around[0][0] == 0 && polygons_around[1][0] == 159, + "[TEST] Wrong polygons around vertex 0" ) + + geode::index_t vertex_id = 1; + auto polygons_around = moebius_strip->polygons_around_vertex( vertex_id ); + + OPENGEODE_EXCEPTION( polygons_around_border.size() == 2, + "[Test] Wrong computation of polygons around vertex 1 : should be 2 " + "polygons , " + "get ", + polygons_around_border.size() ); + OPENGEODE_EXCEPTION( polygons_around[0][0] == 0 + && polygons_around_border[1][0] == 1 + && polygons_around_border[2][0] == 2 + && polygons_around_border[3][0] == 157 + && polygons_around_border[4][0] == 158 + && polygons_around_border[5][0] == 159, + "[TEST] Wrong polygons around vertex 1" ) +} + +void test() +{ + geode::OpenGeodeMeshLibrary::initialize(); + geode::Logger::set_level( geode::Logger::LEVEL::debug ); + test_polygons_around_vertex(); +} + +OPENGEODE_TEST( "moebius-strip" ) \ No newline at end of file From 8e109363760649e8750a2e79ec24368e6178fd40 Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Mon, 20 Apr 2026 15:28:11 +0200 Subject: [PATCH 02/10] test --- tests/mesh/test-moebius-strip.cpp | 50 ++++++++++++++++++------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/tests/mesh/test-moebius-strip.cpp b/tests/mesh/test-moebius-strip.cpp index a0b5083bf..e1a33867f 100644 --- a/tests/mesh/test-moebius-strip.cpp +++ b/tests/mesh/test-moebius-strip.cpp @@ -25,11 +25,9 @@ #include #include -#include #include #include #include -#include void test_polygons_around_vertex() { @@ -39,31 +37,43 @@ void test_polygons_around_vertex() geode::index_t vertex_id_border = 0; auto polygons_around_border = moebius_strip->polygons_around_vertex( vertex_id_border ); - - OPENGEODE_EXCEPTION( polygons_around.size() == 6, - "[Test] Wrong computation of polygons around vertex 1 : should be 6 " + OPENGEODE_EXCEPTION( polygons_around_border.size() == 2, + "[Test] Wrong computation of polygons around vertex 0 : should be 2 " "polygons , " "get ", - polygons_around.size() ); - OPENGEODE_EXCEPTION( - polygons_around[0][0] == 0 && polygons_around[1][0] == 159, - "[TEST] Wrong polygons around vertex 0" ) + polygons_around_border.size() ); + OPENGEODE_EXCEPTION( polygons_around_border[0].polygon_id == 159 + && polygons_around_border[0].vertex_id == 2, + "[TEST] Wrong polygons around vertex 0" ); + OPENGEODE_EXCEPTION( polygons_around_border[1].polygon_id == 0 + && polygons_around_border[1].vertex_id == 2, + "[TEST] Wrong polygons around vertex 0" ); geode::index_t vertex_id = 1; auto polygons_around = moebius_strip->polygons_around_vertex( vertex_id ); - - OPENGEODE_EXCEPTION( polygons_around_border.size() == 2, - "[Test] Wrong computation of polygons around vertex 1 : should be 2 " + OPENGEODE_EXCEPTION( polygons_around.size() == 6, + "[Test] Wrong computation of polygons around vertex 1 : should be 6 " "polygons , " "get ", - polygons_around_border.size() ); - OPENGEODE_EXCEPTION( polygons_around[0][0] == 0 - && polygons_around_border[1][0] == 1 - && polygons_around_border[2][0] == 2 - && polygons_around_border[3][0] == 157 - && polygons_around_border[4][0] == 158 - && polygons_around_border[5][0] == 159, - "[TEST] Wrong polygons around vertex 1" ) + polygons_around.size() ); + OPENGEODE_EXCEPTION( polygons_around[0].polygon_id == 159 + && polygons_around[0].vertex_id == 1, + "[TEST] Wrong polygons around vertex 1" ); + OPENGEODE_EXCEPTION( polygons_around[1].polygon_id == 158 + && polygons_around[1].vertex_id == 1, + "[TEST] Wrong polygons around vertex 1" ); + OPENGEODE_EXCEPTION( polygons_around[2].polygon_id == 157 + && polygons_around[2].vertex_id == 2, + "[TEST] Wrong polygons around vertex 1" ); + OPENGEODE_EXCEPTION( + polygons_around[3].polygon_id == 2 && polygons_around[3].vertex_id == 2, + "[TEST] Wrong polygons around vertex 1" ); + OPENGEODE_EXCEPTION( + polygons_around[4].polygon_id == 1 && polygons_around[4].vertex_id == 2, + "[TEST] Wrong polygons around vertex 1" ); + OPENGEODE_EXCEPTION( + polygons_around[5].polygon_id == 0 && polygons_around[5].vertex_id == 1, + "[TEST] Wrong polygons around vertex 1" ); } void test() From b8fa52587597f7cdbf9b219dd38f1728c8904593 Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Mon, 20 Apr 2026 15:33:30 +0200 Subject: [PATCH 03/10] more efficient algo --- src/geode/mesh/core/surface_mesh.cpp | 80 ++++++++++++++++------------ 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 2ec2b6242..7f050b26b 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -125,22 +125,38 @@ namespace constexpr geode::index_t MAX_SAFETY_COUNT{ 1000 }; geode::internal::PolygonsAroundVertexImpl result; auto cur_polygon_vertex = first_polygon; - bool non_orientable{ false }; + bool reversed_orientation{ false }; do { - if( mesh.polygon_vertex( cur_polygon_vertex.value() ) != vertex_id ) - { - non_orientable = true; - break; - } + OPENGEODE_ASSERT( + mesh.polygon_vertex( cur_polygon_vertex.value() ) == vertex_id, + "[SurfaceMesh::polygons_around_vertex] Wrong polygon " + "around vertex ", + vertex_id, " / ", cur_polygon_vertex->string(), " ", + mesh.polygon_vertex( cur_polygon_vertex.value() ) ); result.polygons.push_back( cur_polygon_vertex.value() ); - const auto prev_vertex = - mesh.previous_polygon_vertex( cur_polygon_vertex.value() ); + const auto edge_vertex = + reversed_orientation + ? mesh.next_polygon_vertex( cur_polygon_vertex.value() ) + : mesh.previous_polygon_vertex( + cur_polygon_vertex.value() ); auto adj_edge = - mesh.polygon_adjacent_edge( geode::PolygonEdge{ prev_vertex } ); + mesh.polygon_adjacent_edge( geode::PolygonEdge{ edge_vertex } ); safety_count++; if( adj_edge ) { + const auto cur_edge_v0 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ edge_vertex }, 0 ); + const auto cur_edge_v1 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ edge_vertex }, 1 ); + const auto adj_edge_v0 = + mesh.polygon_edge_vertex( adj_edge.value(), 0 ); + const auto adj_edge_v1 = + mesh.polygon_edge_vertex( adj_edge.value(), 1 ); + if( cur_edge_v0 == adj_edge_v0 && cur_edge_v1 == adj_edge_v1 ) + { + reversed_orientation = !reversed_orientation; + } cur_polygon_vertex = geode::PolygonVertex{ adj_edge.value() }; } else @@ -151,27 +167,6 @@ namespace } while( cur_polygon_vertex != first_polygon && safety_count < MAX_SAFETY_COUNT ); - if( non_orientable ) - { - result.polygons.clear(); - result.vertex_is_on_border = false; - // méthode bourrin à améliorer - for( const auto polygon_id : geode::Range{ mesh.nb_polygons() } ) - { - for( const auto local_vertex_id : - geode::LRange{ mesh.nb_polygon_vertices( polygon_id ) } ) - { - const geode::PolygonVertex polygon_vertex{ polygon_id, - local_vertex_id }; - if( mesh.polygon_vertex( polygon_vertex ) == vertex_id ) - { - result.polygons.push_back( polygon_vertex ); - } - } - } - return result; - } - result.vertex_is_on_border = cur_polygon_vertex != first_polygon; if( result.vertex_is_on_border ) { @@ -187,16 +182,31 @@ namespace } while( cur_polygon_vertex && safety_count < MAX_SAFETY_COUNT ) { - const geode::PolygonVertex next_vertex{ mesh.next_polygon_edge( - geode::PolygonEdge{ cur_polygon_vertex.value() } ) }; + const geode::PolygonVertex edge_vertex = + reversed_orientation ? mesh.previous_polygon_vertex( + cur_polygon_vertex.value() ) + : mesh.next_polygon_vertex( + cur_polygon_vertex.value() ); + const auto cur_edge_v0 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ edge_vertex }, 0 ); + const auto cur_edge_v1 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ edge_vertex }, 1 ); + const auto adj_edge_v0 = + mesh.polygon_edge_vertex( adj_edge.value(), 0 ); + const auto adj_edge_v1 = + mesh.polygon_edge_vertex( adj_edge.value(), 1 ); + if( cur_edge_v0 == adj_edge_v0 && cur_edge_v1 == adj_edge_v1 ) + { + reversed_orientation = !reversed_orientation; + } OPENGEODE_ASSERT( - mesh.polygon_vertex( next_vertex ) == vertex_id, + mesh.polygon_vertex( edge_vertex ) == vertex_id, "[SurfaceMesh::polygons_around_vertex] Wrong polygon " "around vertex" ); - result.polygons.push_back( next_vertex ); + result.polygons.push_back( edge_vertex ); safety_count++; adj_edge = mesh.polygon_adjacent_edge( - geode::PolygonEdge{ next_vertex } ); + geode::PolygonEdge{ edge_vertex } ); if( adj_edge ) { cur_polygon_vertex = From c1bd775304bae1d9db21e67e708d7e49d0cd9ff3 Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Mon, 20 Apr 2026 15:52:00 +0200 Subject: [PATCH 04/10] fix --- src/geode/mesh/core/surface_mesh.cpp | 6 ------ tests/mesh/test-moebius-strip.cpp | 6 ++---- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 7f050b26b..160882fc4 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -128,12 +128,6 @@ namespace bool reversed_orientation{ false }; do { - OPENGEODE_ASSERT( - mesh.polygon_vertex( cur_polygon_vertex.value() ) == vertex_id, - "[SurfaceMesh::polygons_around_vertex] Wrong polygon " - "around vertex ", - vertex_id, " / ", cur_polygon_vertex->string(), " ", - mesh.polygon_vertex( cur_polygon_vertex.value() ) ); result.polygons.push_back( cur_polygon_vertex.value() ); const auto edge_vertex = reversed_orientation diff --git a/tests/mesh/test-moebius-strip.cpp b/tests/mesh/test-moebius-strip.cpp index e1a33867f..64c0e950d 100644 --- a/tests/mesh/test-moebius-strip.cpp +++ b/tests/mesh/test-moebius-strip.cpp @@ -39,8 +39,7 @@ void test_polygons_around_vertex() moebius_strip->polygons_around_vertex( vertex_id_border ); OPENGEODE_EXCEPTION( polygons_around_border.size() == 2, "[Test] Wrong computation of polygons around vertex 0 : should be 2 " - "polygons , " - "get ", + "polygons, get ", polygons_around_border.size() ); OPENGEODE_EXCEPTION( polygons_around_border[0].polygon_id == 159 && polygons_around_border[0].vertex_id == 2, @@ -53,8 +52,7 @@ void test_polygons_around_vertex() auto polygons_around = moebius_strip->polygons_around_vertex( vertex_id ); OPENGEODE_EXCEPTION( polygons_around.size() == 6, "[Test] Wrong computation of polygons around vertex 1 : should be 6 " - "polygons , " - "get ", + "polygons, get ", polygons_around.size() ); OPENGEODE_EXCEPTION( polygons_around[0].polygon_id == 159 && polygons_around[0].vertex_id == 1, From 12b2e8a35e1382ceab7d627e065797d70a82fddd Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Wed, 22 Apr 2026 14:48:22 +0200 Subject: [PATCH 05/10] more efficient algo (that works) --- src/geode/mesh/core/surface_mesh.cpp | 115 +++++++++++++++++---------- tests/mesh/test-moebius-strip.cpp | 74 +++++++++++------ 2 files changed, 121 insertions(+), 68 deletions(-) diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 160882fc4..21d088b26 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -125,33 +125,42 @@ namespace constexpr geode::index_t MAX_SAFETY_COUNT{ 1000 }; geode::internal::PolygonsAroundVertexImpl result; auto cur_polygon_vertex = first_polygon; - bool reversed_orientation{ false }; + bool vertex_is_next{ false }; do { + OPENGEODE_ASSERT( + mesh.polygon_vertex( cur_polygon_vertex.value() ) == vertex_id, + "[SurfaceMesh::polygons_around_vertex] Wrong polygon " + "around vertex ", + vertex_id, " / ", cur_polygon_vertex->string(), " ", + mesh.polygon_vertex( cur_polygon_vertex.value() ) ); result.polygons.push_back( cur_polygon_vertex.value() ); - const auto edge_vertex = - reversed_orientation - ? mesh.next_polygon_vertex( cur_polygon_vertex.value() ) - : mesh.previous_polygon_vertex( - cur_polygon_vertex.value() ); - auto adj_edge = - mesh.polygon_adjacent_edge( geode::PolygonEdge{ edge_vertex } ); safety_count++; + auto exit_vertex = vertex_is_next + ? cur_polygon_vertex.value() + : mesh.previous_polygon_vertex( + cur_polygon_vertex.value() ); + auto adj_edge = + mesh.polygon_adjacent_edge( geode::PolygonEdge{ exit_vertex } ); if( adj_edge ) { - const auto cur_edge_v0 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ edge_vertex }, 0 ); - const auto cur_edge_v1 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ edge_vertex }, 1 ); - const auto adj_edge_v0 = + const auto cur_v0 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ exit_vertex }, 0 ); + const auto cur_v1 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ exit_vertex }, 1 ); + const auto adj_v0 = mesh.polygon_edge_vertex( adj_edge.value(), 0 ); - const auto adj_edge_v1 = + const auto adj_v1 = mesh.polygon_edge_vertex( adj_edge.value(), 1 ); - if( cur_edge_v0 == adj_edge_v0 && cur_edge_v1 == adj_edge_v1 ) + if( cur_v0 == adj_v0 && cur_v1 == adj_v1 ) { - reversed_orientation = !reversed_orientation; + vertex_is_next = !vertex_is_next; } - cur_polygon_vertex = geode::PolygonVertex{ adj_edge.value() }; + cur_polygon_vertex = + vertex_is_next + ? geode::PolygonVertex{ mesh.next_polygon_vertex( + geode::PolygonVertex{ adj_edge.value() } ) } + : geode::PolygonVertex{ adj_edge.value() }; } else { @@ -164,11 +173,28 @@ namespace result.vertex_is_on_border = cur_polygon_vertex != first_polygon; if( result.vertex_is_on_border ) { + vertex_is_next = false; auto adj_edge = mesh.polygon_adjacent_edge( geode::PolygonEdge{ first_polygon.value() } ); if( adj_edge ) { - cur_polygon_vertex = geode::PolygonVertex{ adj_edge.value() }; + const auto cur_v0 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ first_polygon.value() }, 0 ); + const auto cur_v1 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ first_polygon.value() }, 1 ); + const auto adj_v0 = + mesh.polygon_edge_vertex( adj_edge.value(), 0 ); + const auto adj_v1 = + mesh.polygon_edge_vertex( adj_edge.value(), 1 ); + if( cur_v0 == adj_v0 && cur_v1 == adj_v1 ) + { + vertex_is_next = !vertex_is_next; + } + cur_polygon_vertex = + vertex_is_next + ? geode::PolygonVertex{ adj_edge.value() } + : geode::PolygonVertex{ mesh.next_polygon_vertex( + geode::PolygonVertex{ adj_edge.value() } ) }; } else { @@ -176,35 +202,38 @@ namespace } while( cur_polygon_vertex && safety_count < MAX_SAFETY_COUNT ) { - const geode::PolygonVertex edge_vertex = - reversed_orientation ? mesh.previous_polygon_vertex( - cur_polygon_vertex.value() ) - : mesh.next_polygon_vertex( - cur_polygon_vertex.value() ); - const auto cur_edge_v0 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ edge_vertex }, 0 ); - const auto cur_edge_v1 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ edge_vertex }, 1 ); - const auto adj_edge_v0 = - mesh.polygon_edge_vertex( adj_edge.value(), 0 ); - const auto adj_edge_v1 = - mesh.polygon_edge_vertex( adj_edge.value(), 1 ); - if( cur_edge_v0 == adj_edge_v0 && cur_edge_v1 == adj_edge_v1 ) - { - reversed_orientation = !reversed_orientation; - } OPENGEODE_ASSERT( - mesh.polygon_vertex( edge_vertex ) == vertex_id, + mesh.polygon_vertex( cur_polygon_vertex.value() ) + == vertex_id, "[SurfaceMesh::polygons_around_vertex] Wrong polygon " "around vertex" ); - result.polygons.push_back( edge_vertex ); + result.polygons.push_back( cur_polygon_vertex.value() ); safety_count++; + auto exit_vertex = vertex_is_next + ? mesh.previous_polygon_vertex( + cur_polygon_vertex.value() ) + : cur_polygon_vertex.value(); adj_edge = mesh.polygon_adjacent_edge( - geode::PolygonEdge{ edge_vertex } ); + geode::PolygonEdge{ exit_vertex } ); if( adj_edge ) { + const auto cur_v0 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ exit_vertex }, 0 ); + const auto cur_v1 = mesh.polygon_edge_vertex( + geode::PolygonEdge{ exit_vertex }, 1 ); + const auto adj_v0 = + mesh.polygon_edge_vertex( adj_edge.value(), 0 ); + const auto adj_v1 = + mesh.polygon_edge_vertex( adj_edge.value(), 1 ); + if( cur_v0 == adj_v0 && cur_v1 == adj_v1 ) + { + vertex_is_next = !vertex_is_next; + } cur_polygon_vertex = - geode::PolygonVertex{ adj_edge.value() }; + vertex_is_next + ? geode::PolygonVertex{ adj_edge.value() } + : geode::PolygonVertex{ mesh.next_polygon_vertex( + geode::PolygonVertex{ adj_edge.value() } ) }; continue; } cur_polygon_vertex = std::nullopt; @@ -977,8 +1006,8 @@ namespace geode for( const auto& polygon_vertex : polygons_around_vertex( from_vertex_id ) ) { - const auto next_vertex = next_polygon_vertex( polygon_vertex ); - if( this->polygon_vertex( next_vertex ) == to_vertex_id ) + const auto exit_vertex = next_polygon_vertex( polygon_vertex ); + if( this->polygon_vertex( exit_vertex ) == to_vertex_id ) { return std::optional< PolygonEdge >{ std::in_place, polygon_vertex }; @@ -1003,8 +1032,8 @@ namespace geode for( auto&& polygon_vertex : polygons_around_vertex( edge_vertices[0] ) ) { - const auto next_vertex = next_polygon_vertex( polygon_vertex ); - if( this->polygon_vertex( next_vertex ) == edge_vertices[1] ) + const auto exit_vertex = next_polygon_vertex( polygon_vertex ); + if( this->polygon_vertex( exit_vertex ) == edge_vertices[1] ) { polygons_around_edge.emplace_back( std::move( polygon_vertex ) ); diff --git a/tests/mesh/test-moebius-strip.cpp b/tests/mesh/test-moebius-strip.cpp index 64c0e950d..f6992969c 100644 --- a/tests/mesh/test-moebius-strip.cpp +++ b/tests/mesh/test-moebius-strip.cpp @@ -34,44 +34,68 @@ void test_polygons_around_vertex() auto moebius_strip = geode::load_triangulated_surface< 3 >( absl::StrCat( geode::DATA_PATH, "moebius_strip.og_tsf3d" ) ); - geode::index_t vertex_id_border = 0; - auto polygons_around_border = - moebius_strip->polygons_around_vertex( vertex_id_border ); - OPENGEODE_EXCEPTION( polygons_around_border.size() == 2, + geode::index_t vertex_id_0{ 0 }; + geode::Logger::debug( "TEST vertex id", vertex_id_0 ); + auto polygons_around_0 = + moebius_strip->polygons_around_vertex( vertex_id_0 ); + OPENGEODE_EXCEPTION( polygons_around_0.size() == 2, "[Test] Wrong computation of polygons around vertex 0 : should be 2 " "polygons, get ", - polygons_around_border.size() ); - OPENGEODE_EXCEPTION( polygons_around_border[0].polygon_id == 159 - && polygons_around_border[0].vertex_id == 2, + polygons_around_0.size() ); + OPENGEODE_EXCEPTION( polygons_around_0[0].polygon_id == 159 + && polygons_around_0[0].vertex_id == 2, "[TEST] Wrong polygons around vertex 0" ); - OPENGEODE_EXCEPTION( polygons_around_border[1].polygon_id == 0 - && polygons_around_border[1].vertex_id == 2, + OPENGEODE_EXCEPTION( polygons_around_0[1].polygon_id == 0 + && polygons_around_0[1].vertex_id == 0, "[TEST] Wrong polygons around vertex 0" ); - geode::index_t vertex_id = 1; - auto polygons_around = moebius_strip->polygons_around_vertex( vertex_id ); - OPENGEODE_EXCEPTION( polygons_around.size() == 6, + geode::index_t vertex_id_1{ 1 }; + geode::Logger::debug( "TEST vertex id", vertex_id_1 ); + auto polygons_around_1 = + moebius_strip->polygons_around_vertex( vertex_id_1 ); + OPENGEODE_EXCEPTION( polygons_around_1.size() == 6, "[Test] Wrong computation of polygons around vertex 1 : should be 6 " "polygons, get ", - polygons_around.size() ); - OPENGEODE_EXCEPTION( polygons_around[0].polygon_id == 159 - && polygons_around[0].vertex_id == 1, + polygons_around_1.size() ); + OPENGEODE_EXCEPTION( polygons_around_1[0].polygon_id == 159 + && polygons_around_1[0].vertex_id == 1, "[TEST] Wrong polygons around vertex 1" ); - OPENGEODE_EXCEPTION( polygons_around[1].polygon_id == 158 - && polygons_around[1].vertex_id == 1, + OPENGEODE_EXCEPTION( polygons_around_1[1].polygon_id == 158 + && polygons_around_1[1].vertex_id == 1, "[TEST] Wrong polygons around vertex 1" ); - OPENGEODE_EXCEPTION( polygons_around[2].polygon_id == 157 - && polygons_around[2].vertex_id == 2, + OPENGEODE_EXCEPTION( polygons_around_1[2].polygon_id == 157 + && polygons_around_1[2].vertex_id == 2, "[TEST] Wrong polygons around vertex 1" ); - OPENGEODE_EXCEPTION( - polygons_around[3].polygon_id == 2 && polygons_around[3].vertex_id == 2, + OPENGEODE_EXCEPTION( polygons_around_1[3].polygon_id == 2 + && polygons_around_1[3].vertex_id == 0, "[TEST] Wrong polygons around vertex 1" ); - OPENGEODE_EXCEPTION( - polygons_around[4].polygon_id == 1 && polygons_around[4].vertex_id == 2, + OPENGEODE_EXCEPTION( polygons_around_1[4].polygon_id == 1 + && polygons_around_1[4].vertex_id == 0, "[TEST] Wrong polygons around vertex 1" ); - OPENGEODE_EXCEPTION( - polygons_around[5].polygon_id == 0 && polygons_around[5].vertex_id == 1, + OPENGEODE_EXCEPTION( polygons_around_1[5].polygon_id == 0 + && polygons_around_1[5].vertex_id == 2, "[TEST] Wrong polygons around vertex 1" ); + + geode::index_t vertex_id_99{ 99 }; + geode::Logger::debug( "TEST vertex id", vertex_id_99 ); + auto polygons_around_99 = + moebius_strip->polygons_around_vertex( vertex_id_99 ); + OPENGEODE_EXCEPTION( polygons_around_99.size() == 4, + "[Test] Wrong computation of polygons around vertex 99 : should be 4 " + "polygons, get ", + polygons_around_99.size() ); + OPENGEODE_EXCEPTION( polygons_around_99[0].polygon_id == 153 + && polygons_around_99[0].vertex_id == 1, + "[TEST] Wrong polygons around vertex 99" ); + OPENGEODE_EXCEPTION( polygons_around_99[1].polygon_id == 152 + && polygons_around_99[1].vertex_id == 1, + "[TEST] Wrong polygons around vertex 99" ); + OPENGEODE_EXCEPTION( polygons_around_99[2].polygon_id == 6 + && polygons_around_99[2].vertex_id == 2, + "[TEST] Wrong polygons around vertex 99" ); + OPENGEODE_EXCEPTION( polygons_around_99[3].polygon_id == 7 + && polygons_around_99[3].vertex_id == 0, + "[TEST] Wrong polygons around vertex 99" ); } void test() From 1fe4e38152ccc06b3220f3bdcd0f357716295355 Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Wed, 22 Apr 2026 15:08:44 +0200 Subject: [PATCH 06/10] remove debug --- tests/mesh/test-moebius-strip.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/mesh/test-moebius-strip.cpp b/tests/mesh/test-moebius-strip.cpp index f6992969c..653625a37 100644 --- a/tests/mesh/test-moebius-strip.cpp +++ b/tests/mesh/test-moebius-strip.cpp @@ -35,7 +35,6 @@ void test_polygons_around_vertex() absl::StrCat( geode::DATA_PATH, "moebius_strip.og_tsf3d" ) ); geode::index_t vertex_id_0{ 0 }; - geode::Logger::debug( "TEST vertex id", vertex_id_0 ); auto polygons_around_0 = moebius_strip->polygons_around_vertex( vertex_id_0 ); OPENGEODE_EXCEPTION( polygons_around_0.size() == 2, @@ -50,7 +49,6 @@ void test_polygons_around_vertex() "[TEST] Wrong polygons around vertex 0" ); geode::index_t vertex_id_1{ 1 }; - geode::Logger::debug( "TEST vertex id", vertex_id_1 ); auto polygons_around_1 = moebius_strip->polygons_around_vertex( vertex_id_1 ); OPENGEODE_EXCEPTION( polygons_around_1.size() == 6, @@ -77,7 +75,6 @@ void test_polygons_around_vertex() "[TEST] Wrong polygons around vertex 1" ); geode::index_t vertex_id_99{ 99 }; - geode::Logger::debug( "TEST vertex id", vertex_id_99 ); auto polygons_around_99 = moebius_strip->polygons_around_vertex( vertex_id_99 ); OPENGEODE_EXCEPTION( polygons_around_99.size() == 4, From c8c6e18c6edc134bba2ffa970cc419dbae4624c0 Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Wed, 22 Apr 2026 16:42:45 +0200 Subject: [PATCH 07/10] correct synthax and refactor the test orientation modification --- src/geode/mesh/core/surface_mesh.cpp | 70 ++++++++++++---------------- tests/mesh/test-moebius-strip.cpp | 16 +++---- 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 21d088b26..7821968ab 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -107,6 +107,18 @@ namespace "edge" ); } + template < geode::index_t dimension > + bool orientation_has_changed( const geode::SurfaceMesh< dimension >& mesh, + const geode::PolygonEdge& current_edge, + const geode::PolygonEdge& adj_edge ) + { + const auto cur_v0 = mesh.polygon_edge_vertex( current_edge, 0 ); + const auto cur_v1 = mesh.polygon_edge_vertex( current_edge, 1 ); + const auto adj_v0 = mesh.polygon_edge_vertex( adj_edge, 0 ); + const auto adj_v1 = mesh.polygon_edge_vertex( adj_edge, 1 ); + return cur_v0 == adj_v0 && cur_v1 == adj_v1; + } + template < geode::index_t dimension > geode::internal::PolygonsAroundVertexImpl compute_polygons_around_vertex( const geode::SurfaceMesh< dimension >& mesh, @@ -136,23 +148,16 @@ namespace mesh.polygon_vertex( cur_polygon_vertex.value() ) ); result.polygons.push_back( cur_polygon_vertex.value() ); safety_count++; - auto exit_vertex = vertex_is_next - ? cur_polygon_vertex.value() - : mesh.previous_polygon_vertex( - cur_polygon_vertex.value() ); - auto adj_edge = - mesh.polygon_adjacent_edge( geode::PolygonEdge{ exit_vertex } ); + const auto exit_vertex = vertex_is_next + ? cur_polygon_vertex.value() + : mesh.previous_polygon_vertex( + cur_polygon_vertex.value() ); + const auto exit_edge = geode::PolygonEdge{ exit_vertex }; + const auto adj_edge = mesh.polygon_adjacent_edge( exit_edge ); if( adj_edge ) { - const auto cur_v0 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ exit_vertex }, 0 ); - const auto cur_v1 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ exit_vertex }, 1 ); - const auto adj_v0 = - mesh.polygon_edge_vertex( adj_edge.value(), 0 ); - const auto adj_v1 = - mesh.polygon_edge_vertex( adj_edge.value(), 1 ); - if( cur_v0 == adj_v0 && cur_v1 == adj_v1 ) + if( orientation_has_changed( + mesh, exit_edge, adj_edge.value() ) ) { vertex_is_next = !vertex_is_next; } @@ -178,15 +183,9 @@ namespace geode::PolygonEdge{ first_polygon.value() } ); if( adj_edge ) { - const auto cur_v0 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ first_polygon.value() }, 0 ); - const auto cur_v1 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ first_polygon.value() }, 1 ); - const auto adj_v0 = - mesh.polygon_edge_vertex( adj_edge.value(), 0 ); - const auto adj_v1 = - mesh.polygon_edge_vertex( adj_edge.value(), 1 ); - if( cur_v0 == adj_v0 && cur_v1 == adj_v1 ) + if( orientation_has_changed( mesh, + geode::PolygonEdge{ first_polygon.value() }, + adj_edge.value() ) ) { vertex_is_next = !vertex_is_next; } @@ -209,23 +208,16 @@ namespace "around vertex" ); result.polygons.push_back( cur_polygon_vertex.value() ); safety_count++; - auto exit_vertex = vertex_is_next - ? mesh.previous_polygon_vertex( - cur_polygon_vertex.value() ) - : cur_polygon_vertex.value(); - adj_edge = mesh.polygon_adjacent_edge( - geode::PolygonEdge{ exit_vertex } ); + const auto exit_vertex = vertex_is_next + ? mesh.previous_polygon_vertex( + cur_polygon_vertex.value() ) + : cur_polygon_vertex.value(); + const auto exit_edge = geode::PolygonEdge{ exit_vertex }; + adj_edge = mesh.polygon_adjacent_edge( exit_edge ); if( adj_edge ) { - const auto cur_v0 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ exit_vertex }, 0 ); - const auto cur_v1 = mesh.polygon_edge_vertex( - geode::PolygonEdge{ exit_vertex }, 1 ); - const auto adj_v0 = - mesh.polygon_edge_vertex( adj_edge.value(), 0 ); - const auto adj_v1 = - mesh.polygon_edge_vertex( adj_edge.value(), 1 ); - if( cur_v0 == adj_v0 && cur_v1 == adj_v1 ) + if( orientation_has_changed( + mesh, exit_edge, adj_edge.value() ) ) { vertex_is_next = !vertex_is_next; } diff --git a/tests/mesh/test-moebius-strip.cpp b/tests/mesh/test-moebius-strip.cpp index 653625a37..3754220fa 100644 --- a/tests/mesh/test-moebius-strip.cpp +++ b/tests/mesh/test-moebius-strip.cpp @@ -31,11 +31,11 @@ void test_polygons_around_vertex() { - auto moebius_strip = geode::load_triangulated_surface< 3 >( + const auto moebius_strip = geode::load_triangulated_surface< 3 >( absl::StrCat( geode::DATA_PATH, "moebius_strip.og_tsf3d" ) ); - geode::index_t vertex_id_0{ 0 }; - auto polygons_around_0 = + const geode::index_t vertex_id_0{ 0 }; + const auto polygons_around_0 = moebius_strip->polygons_around_vertex( vertex_id_0 ); OPENGEODE_EXCEPTION( polygons_around_0.size() == 2, "[Test] Wrong computation of polygons around vertex 0 : should be 2 " @@ -48,8 +48,8 @@ void test_polygons_around_vertex() && polygons_around_0[1].vertex_id == 0, "[TEST] Wrong polygons around vertex 0" ); - geode::index_t vertex_id_1{ 1 }; - auto polygons_around_1 = + const geode::index_t vertex_id_1{ 1 }; + const auto polygons_around_1 = moebius_strip->polygons_around_vertex( vertex_id_1 ); OPENGEODE_EXCEPTION( polygons_around_1.size() == 6, "[Test] Wrong computation of polygons around vertex 1 : should be 6 " @@ -74,8 +74,8 @@ void test_polygons_around_vertex() && polygons_around_1[5].vertex_id == 2, "[TEST] Wrong polygons around vertex 1" ); - geode::index_t vertex_id_99{ 99 }; - auto polygons_around_99 = + const geode::index_t vertex_id_99{ 99 }; + const auto polygons_around_99 = moebius_strip->polygons_around_vertex( vertex_id_99 ); OPENGEODE_EXCEPTION( polygons_around_99.size() == 4, "[Test] Wrong computation of polygons around vertex 99 : should be 4 " @@ -98,7 +98,7 @@ void test_polygons_around_vertex() void test() { geode::OpenGeodeMeshLibrary::initialize(); - geode::Logger::set_level( geode::Logger::LEVEL::debug ); + geode::Logger::set_level( geode::Logger::LEVEL::info ); test_polygons_around_vertex(); } From cb569f755c77db8b66a47c4545a28ee6d29cb458 Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Thu, 23 Apr 2026 10:08:48 +0200 Subject: [PATCH 08/10] refacto --- src/geode/mesh/core/surface_mesh.cpp | 120 +++++++++++---------------- 1 file changed, 48 insertions(+), 72 deletions(-) diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 7821968ab..8c99bef38 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -108,7 +108,7 @@ namespace } template < geode::index_t dimension > - bool orientation_has_changed( const geode::SurfaceMesh< dimension >& mesh, + bool not_same_orientation( const geode::SurfaceMesh< dimension >& mesh, const geode::PolygonEdge& current_edge, const geode::PolygonEdge& adj_edge ) { @@ -119,6 +119,30 @@ namespace return cur_v0 == adj_v0 && cur_v1 == adj_v1; } + template < geode::index_t dimension > + std::optional< geode::PolygonVertex > next_polygon_vertex_around( + const geode::SurfaceMesh< dimension >& mesh, + const geode::PolygonVertex& cur_polygon_vertex, + bool& vertex_is_next ) + { + const auto exit_vertex = + vertex_is_next ? cur_polygon_vertex + : mesh.previous_polygon_vertex( cur_polygon_vertex ); + const geode::PolygonEdge exit_edge{ exit_vertex }; + const auto adj_edge = mesh.polygon_adjacent_edge( exit_edge ); + if( !adj_edge ) + { + return std::nullopt; + } + if( not_same_orientation( mesh, exit_edge, adj_edge.value() ) ) + { + vertex_is_next = !vertex_is_next; + } + return vertex_is_next ? geode::PolygonVertex{ mesh.next_polygon_vertex( + geode::PolygonVertex{ adj_edge.value() } ) } + : geode::PolygonVertex{ adj_edge.value() }; + } + template < geode::index_t dimension > geode::internal::PolygonsAroundVertexImpl compute_polygons_around_vertex( const geode::SurfaceMesh< dimension >& mesh, @@ -148,28 +172,10 @@ namespace mesh.polygon_vertex( cur_polygon_vertex.value() ) ); result.polygons.push_back( cur_polygon_vertex.value() ); safety_count++; - const auto exit_vertex = vertex_is_next - ? cur_polygon_vertex.value() - : mesh.previous_polygon_vertex( - cur_polygon_vertex.value() ); - const auto exit_edge = geode::PolygonEdge{ exit_vertex }; - const auto adj_edge = mesh.polygon_adjacent_edge( exit_edge ); - if( adj_edge ) + cur_polygon_vertex = next_polygon_vertex_around( + mesh, cur_polygon_vertex.value(), vertex_is_next ); + if( !cur_polygon_vertex ) { - if( orientation_has_changed( - mesh, exit_edge, adj_edge.value() ) ) - { - vertex_is_next = !vertex_is_next; - } - cur_polygon_vertex = - vertex_is_next - ? geode::PolygonVertex{ mesh.next_polygon_vertex( - geode::PolygonVertex{ adj_edge.value() } ) } - : geode::PolygonVertex{ adj_edge.value() }; - } - else - { - cur_polygon_vertex = std::nullopt; break; } } while( cur_polygon_vertex != first_polygon @@ -178,57 +184,27 @@ namespace result.vertex_is_on_border = cur_polygon_vertex != first_polygon; if( result.vertex_is_on_border ) { - vertex_is_next = false; - auto adj_edge = mesh.polygon_adjacent_edge( - geode::PolygonEdge{ first_polygon.value() } ); - if( adj_edge ) - { - if( orientation_has_changed( mesh, - geode::PolygonEdge{ first_polygon.value() }, - adj_edge.value() ) ) - { - vertex_is_next = !vertex_is_next; - } - cur_polygon_vertex = - vertex_is_next - ? geode::PolygonVertex{ adj_edge.value() } - : geode::PolygonVertex{ mesh.next_polygon_vertex( - geode::PolygonVertex{ adj_edge.value() } ) }; - } - else - { - cur_polygon_vertex = std::nullopt; - } - while( cur_polygon_vertex && safety_count < MAX_SAFETY_COUNT ) + vertex_is_next = true; + cur_polygon_vertex = next_polygon_vertex_around( + mesh, first_polygon.value(), vertex_is_next ); + } + else + { + cur_polygon_vertex = std::nullopt; + } + while( cur_polygon_vertex && safety_count < MAX_SAFETY_COUNT ) + { + OPENGEODE_ASSERT( + mesh.polygon_vertex( cur_polygon_vertex.value() ) == vertex_id, + "[SurfaceMesh::polygons_around_vertex] Wrong polygon " + "around vertex" ); + result.polygons.push_back( cur_polygon_vertex.value() ); + safety_count++; + cur_polygon_vertex = next_polygon_vertex_around( + mesh, cur_polygon_vertex.value(), vertex_is_next ); + if( !cur_polygon_vertex ) { - OPENGEODE_ASSERT( - mesh.polygon_vertex( cur_polygon_vertex.value() ) - == vertex_id, - "[SurfaceMesh::polygons_around_vertex] Wrong polygon " - "around vertex" ); - result.polygons.push_back( cur_polygon_vertex.value() ); - safety_count++; - const auto exit_vertex = vertex_is_next - ? mesh.previous_polygon_vertex( - cur_polygon_vertex.value() ) - : cur_polygon_vertex.value(); - const auto exit_edge = geode::PolygonEdge{ exit_vertex }; - adj_edge = mesh.polygon_adjacent_edge( exit_edge ); - if( adj_edge ) - { - if( orientation_has_changed( - mesh, exit_edge, adj_edge.value() ) ) - { - vertex_is_next = !vertex_is_next; - } - cur_polygon_vertex = - vertex_is_next - ? geode::PolygonVertex{ adj_edge.value() } - : geode::PolygonVertex{ mesh.next_polygon_vertex( - geode::PolygonVertex{ adj_edge.value() } ) }; - continue; - } - cur_polygon_vertex = std::nullopt; + break; } } OPENGEODE_EXCEPTION( safety_count < MAX_SAFETY_COUNT, From 3fca99f1af5584131374b86499c59747c684b0e4 Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Thu, 23 Apr 2026 10:18:54 +0200 Subject: [PATCH 09/10] fix replace by mistake --- src/geode/mesh/core/surface_mesh.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 8c99bef38..299bb61c6 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -974,8 +974,8 @@ namespace geode for( const auto& polygon_vertex : polygons_around_vertex( from_vertex_id ) ) { - const auto exit_vertex = next_polygon_vertex( polygon_vertex ); - if( this->polygon_vertex( exit_vertex ) == to_vertex_id ) + const auto next_vertex = next_polygon_vertex( polygon_vertex ); + if( this->polygon_vertex( next_vertex ) == to_vertex_id ) { return std::optional< PolygonEdge >{ std::in_place, polygon_vertex }; @@ -1000,8 +1000,8 @@ namespace geode for( auto&& polygon_vertex : polygons_around_vertex( edge_vertices[0] ) ) { - const auto exit_vertex = next_polygon_vertex( polygon_vertex ); - if( this->polygon_vertex( exit_vertex ) == edge_vertices[1] ) + const auto next_vertex = next_polygon_vertex( polygon_vertex ); + if( this->polygon_vertex( next_vertex ) == edge_vertices[1] ) { polygons_around_edge.emplace_back( std::move( polygon_vertex ) ); From e0fb655b15f5e8a7a14419a0de992b92a2d6442e Mon Sep 17 00:00:00 2001 From: MarieENSG Date: Mon, 27 Apr 2026 10:47:58 +0200 Subject: [PATCH 10/10] review --- tests/mesh/test-moebius-strip.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/mesh/test-moebius-strip.cpp b/tests/mesh/test-moebius-strip.cpp index 3754220fa..85817b726 100644 --- a/tests/mesh/test-moebius-strip.cpp +++ b/tests/mesh/test-moebius-strip.cpp @@ -98,7 +98,6 @@ void test_polygons_around_vertex() void test() { geode::OpenGeodeMeshLibrary::initialize(); - geode::Logger::set_level( geode::Logger::LEVEL::info ); test_polygons_around_vertex(); }