diff --git a/homog2d.hpp b/homog2d.hpp index f5f5ee0..012e7c5 100644 --- a/homog2d.hpp +++ b/homog2d.hpp @@ -1250,6 +1250,8 @@ product( Matrix_&, const Matrix_&, const Matrix_& ); //------------------------------------------------------------------ +/// Returns true if one of the points share a common coordinate +/// (thus making them unable to define a bounding box) template bool shareCommonCoord( const Point2d_& p1, const Point2d_& p2 ) @@ -1262,6 +1264,16 @@ shareCommonCoord( const Point2d_& p1, const Point2d_& p2 ) return false; } +//------------------------------------------------------------------ +/// Returns true if one of the points share a common coordinate +/// (thus making them unable to define a bounding box) +template +bool +shareCommonCoord( const std::pair,Point2d_>& ppts ) +{ + return shareCommonCoord( ppts.first , ppts.second ); +} + //------------------------------------------------------------------ /// Private free function, get top-left and bottom-right points from two arbitrary points /** Throws if one of the coordinates is equal to the other (x1=x2 or y1=y2)*/ @@ -3223,16 +3235,19 @@ We need Sfinae because there is another 3-args constructor (x, y, radius as floa return 1; } +/// Area of circle HOMOG2D_INUMTYPE area() const { return static_cast(_radius) * _radius * M_PI; } + +/// Perimeter of circle HOMOG2D_INUMTYPE length() const { return static_cast(_radius) * M_PI * 2.0; } -/// Returns Bounding Box +/// Returns Bounding Box of circle FRect_ getBB() const { return FRect_( @@ -4164,14 +4179,14 @@ Thus, we need the second one. impl_moveTo( pt, detail::BaseHelper() ); } -//#ifdef HOMOG2D_ENABLE_VRTP +#ifdef HOMOG2D_ENABLE_VRTP /// Needed so the function getBB(T1,T2) builds, whatever the types /// and because of variant (\sa CommonType) FRect_ getBB() const { HOMOG2D_THROW_ERROR_1( "invalid call, Point/Line has no Bounding Box" ); } -//#endif +#endif private: template @@ -5092,24 +5107,26 @@ class SegVec: public detail::Common /// \name Attributes access ///@{ -/// Needed so the function getBB(T1,T2) builds, whatever the types +#if 0 +/// Get Bounding Box of segment, always throws but needed so the function getBB(T1,T2) builds, whatever the types /// and because of variant (\sa CommonType) FRect_ getBB() const { HOMOG2D_THROW_ERROR_1( "invalid call, Segment has no Bounding Box" ); } +#endif constexpr size_t size() const { return 2; } -/// Get segment/vector length - +/// Get segment length HOMOG2D_INUMTYPE length() const { return _ptS1.distTo( _ptS2 ); } + /// A segment always has a null area constexpr HOMOG2D_INUMTYPE area() const { @@ -10402,15 +10419,23 @@ getBB( const T1& elem1, const T2& elem2 ) // because the underlying floating point might not be the same for the two arguments. if( isPoly_2 && siz_1==0 ) { -// std::cout << "isPoly_2 && isEmpty_1\n"; - out = getBB( elem2 ); - return out; + auto pp = ppair::getPointPair( elem2 ); + if( shareCommonCoord(pp) ) + { + HOMOG2D_THROW_ERROR_1( "Unable to build common Bounding Box of empty polyline and elem2:" << elem2 ); + } + else + return FRect_( pp ); } if( isPoly_1 && siz_2==0 ) { -// std::cout << "isPoly_1 && isEmpty_2\n"; - out = getBB( elem1 ); - return out; + auto pp = ppair::getPointPair( elem1 ); + if( shareCommonCoord(pp) ) + { + HOMOG2D_THROW_ERROR_1( "Unable to build common Bounding Box of empty polyline and elem1:" << elem1 ); + } + else + return FRect_( pp ); } try