@@ -1002,12 +1002,10 @@ namespace geode
10021002 }
10031003
10041004 template < index_t dimension >
1005- std::vector< std::array< index_t , 2 > >
1006- SolidMesh< dimension >::polyhedron_edges_vertices(
1007- index_t polyhedron ) const
1005+ PolyhedronEdgesVertices SolidMesh< dimension >::polyhedron_edges_vertices(
1006+ index_t polyhedron ) const
10081007 {
1009- std::vector< std::array< index_t , 2 > > edge_vertices;
1010- edge_vertices.reserve ( 3 * nb_polyhedron_facets ( polyhedron ) );
1008+ PolyhedronEdgesVertices edge_vertices;
10111009 for ( const auto f : LRange{ nb_polyhedron_facets ( polyhedron ) } )
10121010 {
10131011 const PolyhedronFacet facet{ polyhedron, f };
@@ -1025,18 +1023,25 @@ namespace geode
10251023 }
10261024
10271025 template < index_t dimension >
1028- std::vector< PolyhedronFacetVertices >
1029- SolidMesh< dimension >::polyhedron_facets_vertices(
1030- index_t polyhedron ) const
1026+ PolyhedronFacetsVertices SolidMesh< dimension >::polyhedron_facets_vertices(
1027+ index_t polyhedron ) const
10311028 {
1032- std::vector< PolyhedronFacetVertices > facet_vertices;
1033- facet_vertices.reserve ( 3 * nb_polyhedron_facets ( polyhedron ) );
1029+ PolyhedronFacetsVertices facets_vertices;
1030+ facets_vertices.reserve ( nb_polyhedron_facets ( polyhedron ) );
1031+ const auto vertices = polyhedron_vertices ( polyhedron );
10341032 for ( const auto f : LRange{ nb_polyhedron_facets ( polyhedron ) } )
10351033 {
1036- facet_vertices.emplace_back (
1037- polyhedron_facet_vertices ( { polyhedron, f } ) );
1034+ const PolyhedronFacet facet{ polyhedron, f };
1035+ auto & facet_vertices = facets_vertices.emplace_back ();
1036+ for ( const auto v :
1037+ LRange{ nb_polyhedron_facet_vertices ( facet ) } )
1038+ {
1039+ facet_vertices.push_back (
1040+ vertices[polyhedron_facet_vertex_id ( { facet, v } )
1041+ .vertex_id ] );
1042+ }
10381043 }
1039- return facet_vertices ;
1044+ return facets_vertices ;
10401045 }
10411046
10421047 template < index_t dimension >
@@ -1184,47 +1189,46 @@ namespace geode
11841189 SolidMesh< dimension >::polyhedron_adjacent_facet(
11851190 const PolyhedronFacet& polyhedron_facet ) const
11861191 {
1187- if ( !is_polyhedron_facet_on_border ( polyhedron_facet ) )
1192+ const auto opt_polyhedron_adj = polyhedron_adjacent ( polyhedron_facet );
1193+ if ( !opt_polyhedron_adj )
11881194 {
1189- absl::FixedArray< index_t > vertices (
1190- nb_polyhedron_facet_vertices ( polyhedron_facet ) );
1191- for ( const auto v : LIndices{ vertices } )
1195+ return absl::nullopt ;
1196+ }
1197+ absl::FixedArray< index_t > vertices (
1198+ nb_polyhedron_facet_vertices ( polyhedron_facet ) );
1199+ for ( const auto v : LIndices{ vertices } )
1200+ {
1201+ vertices[v] = polyhedron_facet_vertex ( { polyhedron_facet, v } );
1202+ }
1203+ const auto polyhedron_adj = opt_polyhedron_adj.value ();
1204+ for ( const auto f : LRange{ nb_polyhedron_facets ( polyhedron_adj ) } )
1205+ {
1206+ if ( polyhedron_adjacent ( { polyhedron_adj, f } )
1207+ != polyhedron_facet.polyhedron_id )
11921208 {
1193- vertices[v] =
1194- polyhedron_facet_vertex ( { polyhedron_facet, v } );
1209+ continue ;
11951210 }
1196- const auto polyhedron_adj =
1197- polyhedron_adjacent ( polyhedron_facet ).value ();
1198- for ( const auto f :
1199- LRange{ nb_polyhedron_facets ( polyhedron_adj ) } )
1211+ bool all_contained{ true };
1212+ for ( const auto v : LRange{
1213+ nb_polyhedron_facet_vertices ( { polyhedron_adj, f } ) } )
12001214 {
1201- const auto polyhedron =
1202- polyhedron_adjacent ( { polyhedron_adj, f } );
1203- if ( polyhedron == polyhedron_facet. polyhedron_id )
1215+ if ( absl::c_find ( vertices, polyhedron_facet_vertex (
1216+ { { polyhedron_adj, f }, v } ) )
1217+ == vertices. end () )
12041218 {
1205- bool all_contained{ true };
1206- for ( const auto v : LRange{ nb_polyhedron_facet_vertices (
1207- { polyhedron_adj, f } ) } )
1208- {
1209- if ( absl::c_find (
1210- vertices, polyhedron_facet_vertex (
1211- { { polyhedron_adj, f }, v } ) )
1212- == vertices.end () )
1213- {
1214- all_contained = false ;
1215- break ;
1216- }
1217- }
1218- if ( all_contained )
1219- {
1220- return PolyhedronFacet{ polyhedron_adj, f };
1221- }
1219+ all_contained = false ;
1220+ break ;
12221221 }
12231222 }
1224- throw OpenGeodeException{ " [SolidMesh::polyhedron_adjacent_"
1225- " facet] Wrong adjacency with polyhedra: " ,
1226- polyhedron_facet.polyhedron_id , " and " , polyhedron_adj };
1223+ if ( all_contained )
1224+ {
1225+ return absl::optional< PolyhedronFacet >{ absl::in_place,
1226+ polyhedron_adj, f };
1227+ }
12271228 }
1229+ throw OpenGeodeException{ " [SolidMesh::polyhedron_adjacent_"
1230+ " facet] Wrong adjacency with polyhedra: " ,
1231+ polyhedron_facet.polyhedron_id , " and " , polyhedron_adj };
12281232 return absl::nullopt ;
12291233 }
12301234
0 commit comments