Skip to content

Commit 5ab29ff

Browse files
committed
fix(BoundingBox): avoid to return invalid BoundingBox
1 parent 908ee60 commit 5ab29ff

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

src/geode/mesh/core/edged_curve.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ namespace geode
158158
template < index_t dimension >
159159
BoundingBox< dimension > EdgedCurve< dimension >::bounding_box() const
160160
{
161+
OPENGEODE_EXCEPTION( nb_vertices() != 0,
162+
"[EdgedCurve::bounding_box] Cannot return "
163+
"the bounding_box of an empty edged curve." );
161164
BoundingBox< dimension > box;
162165
for( const auto p : Range{ nb_vertices() } )
163166
{

src/geode/mesh/core/point_set.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ namespace geode
8686
template < index_t dimension >
8787
BoundingBox< dimension > PointSet< dimension >::bounding_box() const
8888
{
89+
OPENGEODE_EXCEPTION( nb_vertices() != 0,
90+
"[PointSet::bounding_box] Cannot return "
91+
"the bounding_box of an empty point set." );
8992
BoundingBox< dimension > box;
9093
for( const auto p : Range{ nb_vertices() } )
9194
{

src/geode/mesh/core/solid_mesh.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,9 @@ namespace geode
17311731
template < index_t dimension >
17321732
BoundingBox< dimension > SolidMesh< dimension >::bounding_box() const
17331733
{
1734+
OPENGEODE_EXCEPTION( nb_vertices() != 0,
1735+
"[SolidMesh::bounding_box] Cannot return "
1736+
"the bounding_box of an empty solid mesh." );
17341737
BoundingBox< dimension > box;
17351738
for( const auto p : Range{ nb_vertices() } )
17361739
{

src/geode/mesh/core/surface_mesh.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,9 @@ namespace geode
10641064
template < index_t dimension >
10651065
BoundingBox< dimension > SurfaceMesh< dimension >::bounding_box() const
10661066
{
1067+
OPENGEODE_EXCEPTION( nb_vertices() != 0,
1068+
"[SurfaceMesh::bounding_box] Cannot return "
1069+
"the bounding_box of an empty surface mesh." );
10671070
BoundingBox< dimension > box;
10681071
for( const auto p : Range{ nb_vertices() } )
10691072
{

src/geode/model/representation/core/brep.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -890,40 +890,50 @@ namespace geode
890890

891891
BoundingBox3D BRep::bounding_box() const
892892
{
893-
if( nb_surfaces() > 0 )
894-
{
895-
return internal::meshes_bounding_box< 3 >( surfaces() );
896-
}
897-
if( nb_blocks() > 0 )
893+
geode::BoundingBox3D box;
894+
box.add_box( internal::meshes_bounding_box< 3 >( surfaces() ) );
895+
box.add_box( internal::meshes_bounding_box< 3 >( lines() ) );
896+
box.add_box( internal::meshes_bounding_box< 3 >( corners() ) );
897+
try
898898
{
899-
return internal::meshes_bounding_box< 3 >( blocks() );
899+
box.add_box( internal::meshes_bounding_box< 3 >( blocks() ) );
900900
}
901-
if( nb_lines() > 0 )
901+
catch( const OpenGeodeException& )
902902
{
903-
return internal::meshes_bounding_box< 3 >( lines() );
903+
OPENGEODE_EXCEPTION(
904+
nb_corners() > 0 || nb_lines() > 0 || nb_surfaces() > 0,
905+
"[BRep::bounding_box] Cannot return the bounding_box of a BRep "
906+
"with not meshes Blocks and no Corners, no Lines and no "
907+
"Surfaces." );
904908
}
905-
return internal::meshes_bounding_box< 3 >( corners() );
909+
OPENGEODE_EXCEPTION( box.min() <= box.max(),
910+
"[BRep::bounding_box] Cannot return the "
911+
"bounding_box of an empty BRep." );
912+
return box;
906913
}
907914

908915
BoundingBox3D BRep::active_components_bounding_box() const
909916
{
910917
geode::BoundingBox3D box;
911-
for( const auto& corner : active_corners() )
912-
{
913-
box.add_box( corner.mesh().bounding_box() );
914-
}
915-
for( const auto& line : active_lines() )
916-
{
917-
box.add_box( line.mesh().bounding_box() );
918-
}
919-
for( const auto& surface : active_surfaces() )
918+
box.add_box( internal::meshes_bounding_box< 3 >( active_corners() ) );
919+
box.add_box( internal::meshes_bounding_box< 3 >( active_lines() ) );
920+
box.add_box( internal::meshes_bounding_box< 3 >( active_surfaces() ) );
921+
try
920922
{
921-
box.add_box( surface.mesh().bounding_box() );
923+
box.add_box(
924+
internal::meshes_bounding_box< 3 >( active_blocks() ) );
922925
}
923-
for( const auto& block : active_blocks() )
926+
catch( const OpenGeodeException& )
924927
{
925-
box.add_box( block.mesh().bounding_box() );
928+
for( const auto& block : active_blocks() )
929+
{
930+
box.add_box(
931+
internal::meshes_bounding_box< 3 >( boundaries( block ) ) );
932+
}
926933
}
934+
OPENGEODE_EXCEPTION( box.min() <= box.max(),
935+
"[BRep::bounding_box] Cannot return the "
936+
"bounding_box of a full inactive BRep." );
927937
return box;
928938
}
929939

0 commit comments

Comments
 (0)