diff --git a/src/geode/geometry/basic_objects/triangle.cpp b/src/geode/geometry/basic_objects/triangle.cpp index 261cac2cb..9c7c7a947 100644 --- a/src/geode/geometry/basic_objects/triangle.cpp +++ b/src/geode/geometry/basic_objects/triangle.cpp @@ -48,34 +48,35 @@ namespace std::optional< PivotNormalResult > simple_pivot_and_normal( const std::array< geode::RefPoint3D, 3 >& points ) { - try + std::optional< PivotNormalResult > result{ std::in_place }; + for( const auto pivot : geode::LRange{ 3 } ) { - std::optional< PivotNormalResult > result{ std::in_place }; - for( const auto pivot : geode::LRange{ 3 } ) + const auto next = pivot + 1 == 3 ? 0 : pivot + 1; + const geode::Vector3D edge{ points[pivot], points[next] }; + result->lengths[pivot] = edge.length(); + if( result->lengths[pivot] < geode::GLOBAL_EPSILON ) { - const auto next = pivot + 1 == 3 ? 0 : pivot + 1; - const geode::Vector3D edge{ points[pivot], points[next] }; - result->lengths[pivot] = edge.length(); - const auto edge0 = edge / result->lengths[pivot]; - const auto prev = pivot == 0 ? 2 : pivot - 1; - const auto edge1 = - geode::Vector3D{ points[pivot], points[prev] }.normalize(); - - const auto normal = edge0.cross( edge1 ); - const auto length = normal.length(); - if( length > geode::GLOBAL_ANGULAR_EPSILON ) - { - result->pivot = pivot; - result->normal = normal / length; - return result; - } + return std::nullopt; + } + const auto edge0 = edge / result->lengths[pivot]; + const auto prev = pivot == 0 ? 2 : pivot - 1; + auto edge1 = geode::Vector3D{ points[pivot], points[prev] }; + const auto length1 = edge1.length(); + if( length1 < geode::GLOBAL_EPSILON ) + { + return std::nullopt; + } + + const auto normal = edge0.cross( edge1 / length1 ); + const auto length = normal.length(); + if( length > geode::GLOBAL_ANGULAR_EPSILON ) + { + result->pivot = pivot; + result->normal = normal / length; + return result; } - return result; - } - catch( const geode::OpenGeodeException& /*unused*/ ) - { - return std::nullopt; } + return result; } } // namespace diff --git a/src/geode/mesh/core/solid_mesh.cpp b/src/geode/mesh/core/solid_mesh.cpp index f2bdbb446..e270b8db4 100644 --- a/src/geode/mesh/core/solid_mesh.cpp +++ b/src/geode/mesh/core/solid_mesh.cpp @@ -501,7 +501,7 @@ namespace geode { polyhedron_id, max_area_facet } ); if( !normal ) { - return true; + return 0.; } const auto facet_vertices = mesh.polyhedron_facet_vertices( { polyhedron_id, max_area_facet } ); @@ -967,9 +967,9 @@ namespace geode { if( nb_polyhedron_facet_vertices( polyhedron_facet ) < 3 ) { - return 0; + return 0.; } - double area{ 0 }; + double area{ 0. }; const auto direction = polyhedron_facet_normal( polyhedron_facet ) .value_or( Vector3D{ { 0, 0, 1 } } ); const auto vertices = polyhedron_facet_vertices( polyhedron_facet ); @@ -989,7 +989,7 @@ namespace geode { check_polyhedron_facet_id( *this, polyhedron_facet.polyhedron_id, polyhedron_facet.facet_id ); - Vector3D normal; + Vector3D normal{ { 0, 0, 0 } }; const auto facet_vertices = polyhedron_facet_vertices( polyhedron_facet ); const auto& p0 = this->point( facet_vertices[0] ); @@ -1007,7 +1007,7 @@ namespace geode { return normal.normalize(); } - catch( const OpenGeodeException& /*unused*/ ) + catch( ... ) { return std::nullopt; } diff --git a/src/geode/mesh/core/tetrahedral_solid.cpp b/src/geode/mesh/core/tetrahedral_solid.cpp index 3cd40bf5f..0ecc69752 100644 --- a/src/geode/mesh/core/tetrahedral_solid.cpp +++ b/src/geode/mesh/core/tetrahedral_solid.cpp @@ -343,31 +343,35 @@ namespace geode index_t first_polyhedron ) const { PolyhedraAroundEdge result{ first_polyhedron }; + const auto tet_vertices = this->polyhedron_vertices( first_polyhedron ); std::array< index_t, 2 > excluded_facets{ NO_ID, NO_ID }; local_index_t count{ 0 }; - const auto polyhedron_vertices = - this->polyhedron_vertices( first_polyhedron ); - for( const auto v : LRange{ 4 } ) + for( const auto v_id : LRange{ 4 } ) { - if( polyhedron_vertices[v] == vertices[0] - || polyhedron_vertices[v] == vertices[1] ) + if( tet_vertices.at( v_id ) == vertices.at( 0 ) + || tet_vertices.at( v_id ) == vertices.at( 1 ) ) { - excluded_facets[count++] = v; + excluded_facets[count] = v_id; + count++; + } + if( count == 2 ) + { + break; } } - for( const auto f : LRange{ 4 } ) + for( const auto f_id : LRange{ 4 } ) { - if( f == excluded_facets[0] || f == excluded_facets[1] ) + if( f_id == excluded_facets[0] || f_id == excluded_facets[1] ) { continue; } - const auto vertex_id = polyhedron_vertices[f]; + const auto vertex_id = tet_vertices[f_id]; if( vertex_id == vertices[0] || vertex_id == vertices[1] ) { continue; } const auto status = propagate_around_edge( - *this, { first_polyhedron, f }, vertices, result ); + *this, { first_polyhedron, f_id }, vertices, result ); if( !status.first ) { return polyhedra_around_edge( vertices );