@@ -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