@@ -61,6 +61,7 @@ namespace geode
6161 [[nodiscard]] const std::array< PointType, 2 >& vertices () const ;
6262 [[nodiscard]] BoundingBox< dimension > bounding_box () const ;
6363 [[nodiscard]] bool is_degenerated () const ;
64+ [[nodiscard]] std::string string () const ;
6465
6566 private:
6667 std::array< PointType, 2 > vertices_;
@@ -102,4 +103,41 @@ namespace geode
102103 Segment< dimension >&& other ) noexcept ;
103104 };
104105 ALIAS_1D_AND_2D_AND_3D ( Segment );
106+
107+ template < index_t dimension >
108+ class OpenGeodeSegmentException : public OpenGeodeException
109+ {
110+ public:
111+ template < typename ... Args >
112+ explicit OpenGeodeSegmentException (
113+ Segment< dimension > segment_in, const Args&... message )
114+ : OpenGeodeException{ absl::StrCat (
115+ message..., " at " , segment_in.string () ) },
116+ segment{ std::move ( segment_in ) }
117+ {
118+ }
119+
120+ OwnerSegment< dimension > segment;
121+ };
122+ ALIAS_1D_AND_2D_AND_3D ( OpenGeodeSegmentException );
105123} // namespace geode
124+
125+ // NOLINTNEXTLINE
126+ #define OPENGEODE_SEGMENT_EXCEPTION ( dimension, condition, segment, ... ) \
127+ if ( ABSL_PREDICT_FALSE( !( condition ) ) ) \
128+ throw geode::OpenGeodeSegmentException< dimension > \
129+ { \
130+ segment, __VA_ARGS__ \
131+ }
132+
133+ // NOLINTNEXTLINE
134+ #define OPENGEODE_SEGMENT1D_EXCEPTION ( condition, segment, ... ) \
135+ OPENGEODE_SEGMENT_EXCEPTION ( 1 , condition, segment, __VA_ARGS__ )
136+
137+ // NOLINTNEXTLINE
138+ #define OPENGEODE_SEGMENT2D_EXCEPTION ( condition, segment, ... ) \
139+ OPENGEODE_SEGMENT_EXCEPTION ( 2 , condition, segment, __VA_ARGS__ )
140+
141+ // NOLINTNEXTLINE
142+ #define OPENGEODE_SEGMENT3D_EXCEPTION ( condition, segment, ... ) \
143+ OPENGEODE_SEGMENT_EXCEPTION ( 3 , condition, segment, __VA_ARGS__ )
0 commit comments