Skip to content

Commit bce3ab7

Browse files
committed
better
1 parent 5ab29ff commit bce3ab7

File tree

3 files changed

+83
-32
lines changed

3 files changed

+83
-32
lines changed

include/geode/model/representation/core/internal/helpers.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,20 @@ namespace geode
5757
}
5858

5959
template < index_t dimension, typename MeshComponentRange >
60-
[[nodiscard]] BoundingBox< dimension > meshes_bounding_box(
61-
MeshComponentRange range )
60+
[[nodiscard]] std::optional< BoundingBox< dimension > >
61+
meshes_bounding_box( MeshComponentRange range )
6262
{
6363
BoundingBox< dimension > box;
64+
bool computed{ false };
6465
for( const auto& component : range )
6566
{
67+
computed = true;
6668
box.add_box( component.mesh().bounding_box() );
6769
}
70+
if( !computed )
71+
{
72+
return std::nullopt;
73+
}
6874
return box;
6975
}
7076
} // namespace internal

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

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -890,13 +890,26 @@ namespace geode
890890

891891
BoundingBox3D BRep::bounding_box() const
892892
{
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() ) );
893+
geode::BoundingBox3D bbox;
894+
if( const auto box = internal::meshes_bounding_box< 3 >( surfaces() ) )
895+
{
896+
bbox.add_box( box.value() );
897+
}
898+
if( const auto box = internal::meshes_bounding_box< 3 >( lines() ) )
899+
{
900+
bbox.add_box( box.value() );
901+
}
902+
if( const auto box = internal::meshes_bounding_box< 3 >( corners() ) )
903+
{
904+
bbox.add_box( box.value() );
905+
}
897906
try
898907
{
899-
box.add_box( internal::meshes_bounding_box< 3 >( blocks() ) );
908+
if( const auto box =
909+
internal::meshes_bounding_box< 3 >( blocks() ) )
910+
{
911+
bbox.add_box( box.value() );
912+
}
900913
}
901914
catch( const OpenGeodeException& )
902915
{
@@ -906,35 +919,53 @@ namespace geode
906919
"with not meshes Blocks and no Corners, no Lines and no "
907920
"Surfaces." );
908921
}
909-
OPENGEODE_EXCEPTION( box.min() <= box.max(),
922+
OPENGEODE_EXCEPTION( bbox.min() <= bbox.max(),
910923
"[BRep::bounding_box] Cannot return the "
911924
"bounding_box of an empty BRep." );
912-
return box;
925+
return bbox;
913926
}
914927

915928
BoundingBox3D BRep::active_components_bounding_box() const
916929
{
917-
geode::BoundingBox3D box;
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() ) );
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() ) )
938+
{
939+
bbox.add_box( box.value() );
940+
}
941+
if( const auto box =
942+
internal::meshes_bounding_box< 3 >( active_corners() ) )
943+
{
944+
bbox.add_box( box.value() );
945+
}
921946
try
922947
{
923-
box.add_box(
924-
internal::meshes_bounding_box< 3 >( active_blocks() ) );
948+
if( const auto box =
949+
internal::meshes_bounding_box< 3 >( active_blocks() ) )
950+
{
951+
bbox.add_box( box.value() );
952+
}
925953
}
926954
catch( const OpenGeodeException& )
927955
{
928956
for( const auto& block : active_blocks() )
929957
{
930-
box.add_box(
931-
internal::meshes_bounding_box< 3 >( boundaries( block ) ) );
958+
if( const auto box = internal::meshes_bounding_box< 3 >(
959+
boundaries( block ) ) )
960+
{
961+
bbox.add_box( box.value() );
962+
}
932963
}
933964
}
934-
OPENGEODE_EXCEPTION( box.min() <= box.max(),
965+
OPENGEODE_EXCEPTION( bbox.min() <= bbox.max(),
935966
"[BRep::bounding_box] Cannot return the "
936967
"bounding_box of a full inactive BRep." );
937-
return box;
968+
return bbox;
938969
}
939970

940971
} // namespace geode

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

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -590,32 +590,46 @@ namespace geode
590590

591591
BoundingBox2D Section::bounding_box() const
592592
{
593-
if( nb_lines() > 0 )
593+
geode::BoundingBox2D bbox;
594+
if( const auto box = internal::meshes_bounding_box< 2 >( surfaces() ) )
594595
{
595-
return internal::meshes_bounding_box< 2 >( lines() );
596+
bbox.add_box( box.value() );
596597
}
597-
if( nb_surfaces() > 0 )
598+
if( const auto box = internal::meshes_bounding_box< 2 >( lines() ) )
598599
{
599-
return internal::meshes_bounding_box< 2 >( surfaces() );
600+
bbox.add_box( box.value() );
600601
}
601-
return internal::meshes_bounding_box< 2 >( corners() );
602+
if( const auto box = internal::meshes_bounding_box< 2 >( corners() ) )
603+
{
604+
bbox.add_box( box.value() );
605+
}
606+
OPENGEODE_EXCEPTION( bbox.min() <= bbox.max(),
607+
"[Section::bounding_box] Cannot return the "
608+
"bounding_box of an empty Section." );
609+
return bbox;
602610
}
603611

604612
BoundingBox2D Section::active_components_bounding_box() const
605613
{
606-
geode::BoundingBox2D box;
607-
for( const auto& corner : active_corners() )
614+
geode::BoundingBox2D bbox;
615+
if( const auto box =
616+
internal::meshes_bounding_box< 2 >( active_surfaces() ) )
608617
{
609-
box.add_box( corner.mesh().bounding_box() );
618+
bbox.add_box( box.value() );
610619
}
611-
for( const auto& line : active_lines() )
620+
if( const auto box =
621+
internal::meshes_bounding_box< 2 >( active_lines() ) )
612622
{
613-
box.add_box( line.mesh().bounding_box() );
623+
bbox.add_box( box.value() );
614624
}
615-
for( const auto& surface : active_surfaces() )
625+
if( const auto box =
626+
internal::meshes_bounding_box< 2 >( active_corners() ) )
616627
{
617-
box.add_box( surface.mesh().bounding_box() );
628+
bbox.add_box( box.value() );
618629
}
619-
return box;
630+
OPENGEODE_EXCEPTION( bbox.min() <= bbox.max(),
631+
"[Section::bounding_box] Cannot return the "
632+
"bounding_box of a full inactive Section." );
633+
return bbox;
620634
}
621635
} // namespace geode

0 commit comments

Comments
 (0)