@@ -890,41 +890,82 @@ namespace geode
890890
891891    BoundingBox3D BRep::bounding_box () const 
892892    {
893-         if ( nb_surfaces () > 0  )
893+         geode::BoundingBox3D bbox;
894+         if ( const  auto  box = internal::meshes_bounding_box< 3  >( surfaces () ) )
894895        {
895-             return  internal::meshes_bounding_box<  3  >(  surfaces () );
896+             bbox. add_box ( box. value () );
896897        }
897-         if ( nb_blocks () >  0  )
898+         if ( const   auto  box = internal::meshes_bounding_box<  3  >(  lines () )  )
898899        {
899-             return  internal::meshes_bounding_box<  3  >(  blocks () );
900+             bbox. add_box ( box. value () );
900901        }
901-         if ( nb_lines () >  0  )
902+         if ( const   auto  box = internal::meshes_bounding_box<  3  >(  corners () )  )
902903        {
903-             return  internal::meshes_bounding_box<  3  >(  lines () );
904+             bbox. add_box ( box. value () );
904905        }
905-         return  internal::meshes_bounding_box< 3  >( corners () );
906+         try 
907+         {
908+             if ( const  auto  box =
909+                     internal::meshes_bounding_box< 3  >( blocks () ) )
910+             {
911+                 bbox.add_box ( box.value () );
912+             }
913+         }
914+         catch ( const  OpenGeodeException& )
915+         {
916+             OPENGEODE_EXCEPTION (
917+                 nb_corners () > 0  || nb_lines () > 0  || nb_surfaces () > 0 ,
918+                 " [BRep::bounding_box] Cannot return the bounding_box of a BRep " 
919+                 " with not meshes Blocks and no Corners, no Lines and no " 
920+                 " Surfaces."   );
921+         }
922+         OPENGEODE_EXCEPTION ( bbox.min () <= bbox.max (),
923+             " [BRep::bounding_box] Cannot return the " 
924+             " bounding_box of an empty BRep."   );
925+         return  bbox;
906926    }
907927
908928    BoundingBox3D BRep::active_components_bounding_box () const 
909929    {
910-         geode::BoundingBox3D box;
911-         for ( const  auto & corner : active_corners () )
930+         geode::BoundingBox3D bbox;
931+         if ( const  auto  box =
932+                 internal::meshes_bounding_box< 3  >( active_surfaces () ) )
933+         {
934+             bbox.add_box ( box.value () );
935+         }
936+         if ( const  auto  box =
937+                 internal::meshes_bounding_box< 3  >( active_lines () ) )
912938        {
913-             box .add_box ( corner. mesh (). bounding_box () );
939+             bbox .add_box ( box. value () );
914940        }
915-         for ( const  auto & line : active_lines () )
941+         if ( const  auto  box =
942+                 internal::meshes_bounding_box< 3  >( active_corners () ) )
916943        {
917-             box .add_box ( line. mesh (). bounding_box () );
944+             bbox .add_box ( box. value () );
918945        }
919-         for (  const   auto & surface :  active_surfaces () ) 
946+         try 
920947        {
921-             box.add_box ( surface.mesh ().bounding_box () );
948+             if ( const  auto  box =
949+                     internal::meshes_bounding_box< 3  >( active_blocks () ) )
950+             {
951+                 bbox.add_box ( box.value () );
952+             }
922953        }
923-         for ( const  auto & block :  active_blocks ()  )
954+         catch ( const  OpenGeodeException&  )
924955        {
925-             box.add_box ( block.mesh ().bounding_box () );
956+             for ( const  auto & block : active_blocks () )
957+             {
958+                 if ( const  auto  box = internal::meshes_bounding_box< 3  >(
959+                         boundaries ( block ) ) )
960+                 {
961+                     bbox.add_box ( box.value () );
962+                 }
963+             }
926964        }
927-         return  box;
965+         OPENGEODE_EXCEPTION ( bbox.min () <= bbox.max (),
966+             " [BRep::bounding_box] Cannot return the " 
967+             " bounding_box of a full inactive BRep."   );
968+         return  bbox;
928969    }
929970
930971} //  namespace geode
0 commit comments