homog2d library
Public Types | Public Member Functions | Friends | List of all members
h2d::base::SegVec< SV, FPT > Class Template Reference

A line segment, oriented (OSegment_) or not (Segment_). Holds the two points. More...

#include <homog2d.hpp>

Inheritance diagram for h2d::base::SegVec< SV, FPT >:
Inheritance graph
[legend]
Collaboration diagram for h2d::base::SegVec< SV, FPT >:
Collaboration graph
[legend]

Public Types

using FType = FPT
 
using SType = SV
 

Public Member Functions

void draw (img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const
 
void draw (img::Image< img::SvgImage > &, img::DrawParams dp=img::DrawParams()) const
 
template<typename T >
std::pair< SegVec< SV, FPT >, SegVec< SV, FPT > > getParallelSegs (T dist) const
 Returns two parallel segments to the current one in a pair. More...
 
template<typename T >
PointSide getPointSide (const Point2d_< T > &pt) const
 Return side of point pt relatively to the segment (Oriented only) More...
 
template<typename T >
std::pair< OSegment_< FPT >, OSegment_< FPT > > split (T dist) const
 Returns a pair of segments/vectors split by point at arbitrary distance. More...
 
Type type () const
 
Constructors
 SegVec ()
 Default constructor: initializes segment to (0,0)–(1,1) More...
 
template<typename FP1 , typename FP2 >
 SegVec (Point2d_< FP1 > p1, Point2d_< FP2 > p2)
 Constructor 2: build segment from two points, can hold different FP types. More...
 
template<typename FP1 , typename FP2 , typename FP3 , typename FP4 >
 SegVec (FP1 x1, FP2 y1, FP3 x2, FP4 y2)
 Constructor 3: build segment from two points coordinates, calls constructor 2. More...
 
template<typename FP1 , typename FP2 >
 SegVec (const PointPair2_< FP1, FP2 > &ppts)
 Constructor 4: build segment from pair of points. More...
 
template<typename SV2 , typename FPT2 >
 SegVec (const SegVec< SV2, FPT2 > &other)
 Copy-Constructor, behavior depends on concrete types. More...
 
Modifying functions
SegVec< SV, FPT > operator- ()
 Reverse oriented segment. More...
 
template<typename FP1 , typename FP2 >
void set (const Point2d_< FP1 > &p1, const Point2d_< FP2 > &p2)
 Setter. More...
 
template<typename FP1 , typename FP2 >
void set (const PointPair2_< FP1, FP2 > &ppts)
 Setter from a std::pair. More...
 
template<typename FP1 , typename FP2 , typename FP3 , typename FP4 >
void set (FP1 x1, FP2 y1, FP3 x2, FP4 y2)
 Setter from 4 raw point coordinates. More...
 
template<typename T1 , typename T2 >
void translate (T1 dx, T2 dy)
 Translate Segment. More...
 
template<typename T1 , typename T2 >
void translate (const std::pair< T1, T2 > &pa)
 Translate Segment, using pair of values. More...
 
template<typename TX , typename TY >
void moveTo (TX x, TY y)
 Move Segment to other location. More...
 
template<typename T1 >
void moveTo (const Point2d_< T1 > &pt)
 Move Segment to other location, given by pt. More...
 
Attributes access
FRect_< HOMOG2D_INUMTYPEgetBB () const
 Get Bounding Box of segment, always throws but needed so the function getBB(T1,T2) builds, whatever the types and because of variant (. More...
 
constexpr size_t size () const
 Returns 2. More...
 
HOMOG2D_INUMTYPE length () const
 Get segment length. More...
 
constexpr HOMOG2D_INUMTYPE area () const
 A segment always has a null area. More...
 
std::pair< HOMOG2D_INUMTYPE, HOMOG2D_INUMTYPEgetVector () const
 Get vector of Oriented segment as a pair of values. More...
 
template<typename SV2 , typename FPT2 >
HOMOG2D_INUMTYPE getAngle (const SegVec< SV2, FPT2 > &other) const
 Get angle between segment and other segment. More...
 
template<typename LP , typename FPT2 >
HOMOG2D_INUMTYPE getAngle (const base::LPBase< LP, FPT2 > &other) const
 Get angle between segment and line. More...
 
Operators
bool operator== (const SegVec &s2) const
 
bool operator!= (const SegVec &s2) const
 
bool operator< (const SegVec &other) const
 
Enclosing functions
template<typename FPT2 >
bool isInside (const Circle_< FPT2 > &shape) const
 Segment is inside Circle. More...
 
template<typename FPT2 >
bool isInside (const FRect_< FPT2 > &shape) const
 Segment is inside FRect. More...
 
template<typename FPT2 >
bool isInside (const Ellipse_< FPT2 > &shape) const
 Segment is inside Ellipse. More...
 
template<typename FPT2 >
constexpr bool isInside (const OPolyline_< FPT2 > &) const
 Segment is inside OPolyline_. More...
 
template<typename FPT2 >
bool isInside (const CPolyline_< FPT2 > &cpoly) const
 Segment is inside CPolyline_. More...
 
Intersection functions
template<typename SV2 , typename FPT2 >
detail::Intersect< detail::Inters_1, FPT > intersects (const SegVec< SV2, FPT2 > &) const
 Segment/Segment intersection. More...
 
template<typename FPT2 >
detail::Intersect< detail::Inters_1, FPT > intersects (const Line2d_< FPT2 > &) const
 Segment/Line intersection. More...
 
template<typename FPT2 >
detail::IntersectM< FPT > intersects (const Circle_< FPT2 > &) const
 Segment/Circle intersection. More...
 
template<typename FPT2 >
detail::IntersectM< FPT > intersects (const FRect_< FPT2 > &r) const
 Segment/FRect intersection. More...
 
template<typename PLT , typename FPT2 >
detail::IntersectM< FPT > intersects (const base::PolylineBase< PLT, FPT2 > &other) const
 Segment/Polyline intersection. More...
 
- Public Member Functions inherited from h2d::detail::Common< FPT >
std::pair< int, int > dsize () const
 Get data size expressed as number of bits for, respectively, mantissa and exponent. More...
 
Dtype dtype () const
 Get numerical data type as a Dtype value, can be stringified with h2d::getString(Dtype) More...
 
template<typename T >
constexpr bool isInside (const Common< T > &) const
 This function is a fallback for all sub-classes that do not provide such a method. More...
 
size_t size () const
 
- Public Member Functions inherited from h2d::rtp::Root
virtual ~Root ()
 

Friends

template<typename U , typename V >
std::ostream & operator<< (std::ostream &, const SegVec< U, V > &)
 
template<typename T1 , typename T2 >
class SegVec
 

Other const functions

PointPair_< FPT > getPts () const
 Returns the points of segment as a std::pair. More...
 
template<typename T >
std::pair< SegVec, SegVecgetParallelSegs (T dist) const
 
template<typename FPT2 >
Point2d_< HOMOG2D_INUMTYPEgetPointAt (FPT2 dist) const
 Returns the point at a distance dist from starting point of oriented vector. More...
 
std::array< Point2d_< FPT >, 4 > getOrthogPts () const
 Returns the 4 points orthogonal to the segment/vector. More...
 
std::array< Segment_< FPT >, 4 > getOrthogSegs () const
 Returns the 4 segments/vectors orthogonal to the segment. More...
 
auto getLine () const
 Returns supporting line. More...
 
template<typename FPT2 >
PointSide getPointSide (const Point2d_< FPT2 > &pt) const
 
std::pair< SegVec< SV, FPT >, SegVec< SV, FPT > > split () const
 Returns a pair of segments/vectors split by the middle. More...
 
template<typename T >
std::pair< SegVec< typ::IsOSeg, FPT >, SegVec< typ::IsOSeg, FPT > > split (T dist) const
 
template<typename FPT2 >
HOMOG2D_INUMTYPE distTo (const Point2d_< FPT2 > &, int *segDistCase=0) const
 Distance from point to segment. More...
 
template<typename T >
constexpr bool isParallelTo (const T &other) const
 
auto getCenter () const
 Returns point at middle distance between p1 and p2. More...
 
SegVec< SV, FPT > getExtended () const
 Returns a segment with same support line but tripled length. More...
 
auto getBisector () const
 Returns the bisector line of the segment. More...
 

Detailed Description

template<typename SV, typename FPT>
class h2d::base::SegVec< SV, FPT >

A line segment, oriented (OSegment_) or not (Segment_). Holds the two points.

This will get instanciated as Segment_ or OSegment_

The difference between theses two types is that with Segment_, the "smallest" point is always stored as first element (see constructor).

Member Typedef Documentation

◆ FType

template<typename SV, typename FPT>
using h2d::base::SegVec< SV, FPT >::FType = FPT

◆ SType

template<typename SV, typename FPT>
using h2d::base::SegVec< SV, FPT >::SType = SV

Constructor & Destructor Documentation

◆ SegVec() [1/5]

template<typename SV, typename FPT>
h2d::base::SegVec< SV, FPT >::SegVec ( )
inline

Default constructor: initializes segment to (0,0)–(1,1)

4888  : _ptS2(1.,1.)
4889  {}

◆ SegVec() [2/5]

template<typename SV, typename FPT>
template<typename FP1 , typename FP2 >
h2d::base::SegVec< SV, FPT >::SegVec ( Point2d_< FP1 >  p1,
Point2d_< FP2 >  p2 
)
inline

Constructor 2: build segment from two points, can hold different FP types.

Please note that the source (points) floating-point type is lost

4897  : _ptS1(p1), _ptS2(p2)
4898  {
4899 #ifndef HOMOG2D_NOCHECKS
4900  if( p1 == p2 )
4901  HOMOG2D_THROW_ERROR_1( "cannot build a segment with two identical points: " << p1 << " and " << p2 );
4902 #endif
4903  if constexpr( std::is_same_v<SV,typ::IsSegment> )
4904  priv::fix_order( _ptS1, _ptS2 );
4905  }
void fix_order(Point2d_< FPT > &ptA, Point2d_< FPT > &ptB)
Private free function, swap the points so that ptA.x <= ptB.x, and if equal, sorts on y...
Definition: homog2d.hpp:3520
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
Here is the call graph for this function:

◆ SegVec() [3/5]

template<typename SV, typename FPT>
template<typename FP1 , typename FP2 , typename FP3 , typename FP4 >
h2d::base::SegVec< SV, FPT >::SegVec ( FP1  x1,
FP2  y1,
FP3  x2,
FP4  y2 
)
inline

Constructor 3: build segment from two points coordinates, calls constructor 2.

4910  : SegVec( Point2d_<FPT>(x1,y1), Point2d_<FPT>(x2,y2) )
4911  {
4916  }
SegVec()
Default constructor: initializes segment to (0,0)–(1,1)
Definition: homog2d.hpp:4888
#define HOMOG2D_CHECK_IS_NUMBER(T)
Definition: homog2d.hpp:144

◆ SegVec() [4/5]

template<typename SV, typename FPT>
template<typename FP1 , typename FP2 >
h2d::base::SegVec< SV, FPT >::SegVec ( const PointPair2_< FP1, FP2 > &  ppts)
inline

Constructor 4: build segment from pair of points.

4921  : SegVec(ppts.first, ppts.second)
4922  {}
SegVec()
Default constructor: initializes segment to (0,0)–(1,1)
Definition: homog2d.hpp:4888

◆ SegVec() [5/5]

template<typename SV, typename FPT>
template<typename SV2 , typename FPT2 >
h2d::base::SegVec< SV, FPT >::SegVec ( const SegVec< SV2, FPT2 > &  other)
inline

Copy-Constructor, behavior depends on concrete types.

  • OSegment(OSegment): OK
  • Segment(OSegment): OK, but loose orientation
  • Segment(Segment): OK
  • OSegment(Segment): No build, because orientation would be arbitrary
4933  : _ptS1(other._ptS1), _ptS2(other._ptS2)
4934  {
4935  static_assert(
4936  ( std::is_same_v<SV,typ::IsSegment>
4937  ||
4938  ( std::is_same_v<SV,typ::IsOSeg> && std::is_same_v<SV2,typ::IsOSeg> ) ),
4939  "Cannot build a OSegment from a Segment"
4940  );
4941  if constexpr( std::is_same_v<SV2,typ::IsSegment> )
4942  priv::fix_order( _ptS1, _ptS2 );
4943  }
void fix_order(Point2d_< FPT > &ptA, Point2d_< FPT > &ptB)
Private free function, swap the points so that ptA.x <= ptB.x, and if equal, sorts on y...
Definition: homog2d.hpp:3520
Here is the call graph for this function:

Member Function Documentation

◆ area()

template<typename SV, typename FPT>
constexpr HOMOG2D_INUMTYPE h2d::base::SegVec< SV, FPT >::area ( ) const
inlinevirtual

A segment always has a null area.

Implements h2d::rtp::Root.

5054  {
5055  return 0.;
5056  }
Here is the caller graph for this function:

◆ distTo()

template<typename SV , typename FPT >
template<typename FPT2 >
HOMOG2D_INUMTYPE h2d::base::SegVec< SV, FPT >::distTo ( const Point2d_< FPT2 > &  pt,
int *  segDistCase = 0 
) const

Distance from point to segment.

source: https://stackoverflow.com/a/6853926/193789

Temp implementation, until we get into this a bit more deeper

Todo:
20250219: pass an enum instead as an int, for segDistCase
Parameters
ptthe point
segDistCaseoptional, may be used to know if its the orthogonal distance or not
5513 {
5514  auto ppts = getPts();
5515  auto x1 = static_cast<HOMOG2D_INUMTYPE>( ppts.first.getX() );
5516  auto y1 = static_cast<HOMOG2D_INUMTYPE>( ppts.first.getY() );
5517  auto x2 = static_cast<HOMOG2D_INUMTYPE>( ppts.second.getX() );
5518  auto y2 = static_cast<HOMOG2D_INUMTYPE>( ppts.second.getY() );
5519 
5520  auto A = static_cast<HOMOG2D_INUMTYPE>(pt.getX()) - x1;
5521  auto B = static_cast<HOMOG2D_INUMTYPE>(pt.getY()) - y1;
5522  auto C = x2 - x1;
5523  auto D = y2 - y1;
5524 
5525  auto dot = A * C + B * D;
5526  auto len_sq = C * C + D * D;
5527  auto param = dot / len_sq;
5528 
5529  HOMOG2D_INUMTYPE xx, yy;
5530 
5531  if( param < 0. )
5532  {
5533  if( segDistCase )
5534  *segDistCase = -1;
5535  xx = x1;
5536  yy = y1;
5537  }
5538  else
5539  {
5540  if( param > 1. )
5541  {
5542  if( segDistCase )
5543  *segDistCase = +1;
5544  xx = x2;
5545  yy = y2;
5546  }
5547  else
5548  {
5549  if( segDistCase )
5550  *segDistCase = 0;
5551  xx = x1 + param * C;
5552  yy = y1 + param * D;
5553  }
5554  }
5555 
5556  auto dx = pt.getX() - xx;
5557  auto dy = pt.getY() - yy;
5558  return homog2d_sqrt( dx * dx + dy * dy );
5559 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
#define homog2d_sqrt
Definition: homog2d.hpp:75
PointPair_< FPT > getPts() const
Returns the points of segment as a std::pair.
Definition: homog2d.hpp:5197
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:
Here is the caller graph for this function:

◆ draw() [1/2]

template<typename SV , typename FPT >
void h2d::base::SegVec< SV, FPT >::draw ( img::Image< cv::Mat > &  im,
img::DrawParams  dp = img::DrawParams() 
) const
virtual

Implements h2d::rtp::Root.

11869 {
11870  cv::line(
11871  im.getReal(),
11872  _ptS1.getCvPtd(),
11873  _ptS2.getCvPtd(),
11874  dp.cvColor(),
11875  dp._dpValues._lineThickness,
11876  dp._dpValues._lineType==1?cv::LINE_AA:cv::LINE_8
11877  );
11878 
11879  if constexpr( std::is_same_v<SV,typ::IsOSeg> )
11880  {
11881  auto arrsegs = priv::getArrowSegments( *this );
11882  for( auto ppts: arrsegs )
11883  cv::line(
11884  im.getReal(),
11885  ppts.first.getCvPtd(),
11886  ppts.second.getCvPtd(),
11887  dp.cvColor(),
11888  dp._dpValues._lineThickness,
11889  dp._dpValues._lineType==1?cv::LINE_AA:cv::LINE_8
11890  );
11891  }
11892  else
11893  {
11894  if( dp._dpValues._showPoints )
11895  {
11896  _ptS1.draw( im, dp );
11897  _ptS2.draw( im, dp );
11898  }
11899  }
11900 }
std::array< PointPair_< double >, 3 > getArrowSegments(const base::SegVec< typ::IsOSeg, FPT > &vec)
Definition: homog2d.hpp:11805
img::Image< img::SvgImage > im(300, 400)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ draw() [2/2]

template<typename SV , typename FPT >
void h2d::base::SegVec< SV, FPT >::draw ( img::Image< img::SvgImage > &  im,
img::DrawParams  dp = img::DrawParams() 
) const
virtual

Implements h2d::rtp::Root.

12180 {
12181  auto group = false;
12182  if( dp._dpValues._showPoints || std::is_same_v<SV,typ::IsOSeg> )
12183  group = true;
12184 
12185  if( group )
12186  im.getReal()._svgString << "<g>";
12187 
12188  auto pts = getPts();
12189  priv::drawSvgSeg( im, pts, dp.getSvgRgbColor(), dp._dpValues._lineThickness, dp.getAttrString() );
12190 
12191  if constexpr( std::is_same_v<SV,typ::IsOSeg> )
12192  {
12193  auto arrsegs = priv::getArrowSegments( *this );
12194  for( auto ppts: arrsegs )
12195  priv::drawSvgSeg( im, ppts, dp.getSvgRgbColor(), dp._dpValues._lineThickness );
12196  }
12197  else
12198  {
12199  if( dp._dpValues._showPoints )
12200  {
12201  _ptS1.draw( im, dp );
12202  _ptS2.draw( im, dp );
12203  }
12204  }
12205 
12206  if( group )
12207  im.getReal()._svgString << "</g>\n";
12208 }
std::array< PointPair_< double >, 3 > getArrowSegments(const base::SegVec< typ::IsOSeg, FPT > &vec)
Definition: homog2d.hpp:11805
img::Image< img::SvgImage > im(300, 400)
PointPair_< FPT > getPts() const
Returns the points of segment as a std::pair.
Definition: homog2d.hpp:5197
void drawSvgSeg(img::Image< img::SvgImage > &im, const Point2d_< T > &pt1, const Point2d_< T > &pt2, std::string color, int thickness, std::string attribs=std::string())
Helper function to draw SVG segment.
Definition: homog2d.hpp:12137
Here is the call graph for this function:

◆ getAngle() [1/2]

template<typename SV, typename FPT>
template<typename SV2 , typename FPT2 >
HOMOG2D_INUMTYPE h2d::base::SegVec< SV, FPT >::getAngle ( const SegVec< SV2, FPT2 > &  other) const
inline

Get angle between segment and other segment.

  • if either the object or the argument is not oriented, then this will return the line angles, in the range [0:+PI]
  • if both are oriented, will return a value in the range [-PI:+PI]
5078  {
5079 // if one of the two is a (unoriented) segment, then we just return the lines angle
5080  if constexpr( std::is_same_v<SV,typ::IsSegment> || std::is_same_v<SV2,typ::IsSegment> )
5081  return other.getLine().getAngle( this->getLine() );
5082  else
5083  { // both are oriented segments
5084  auto v1 = this->getVector();
5085  auto v2 = other.getVector();
5086  auto dx1 = v1.first;
5087  auto dx2 = v2.first;
5088  auto dy1 = v1.second;
5089  auto dy2 = v2.second;
5090  return std::atan2(
5091  dx1 * dy2 - dy1 * dx2,
5092  dx1 * dx2 + dy1 * dy2
5093  );
5094  }
5095  }
std::pair< HOMOG2D_INUMTYPE, HOMOG2D_INUMTYPE > getVector() const
Get vector of Oriented segment as a pair of values.
Definition: homog2d.hpp:5060
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAngle() [2/2]

template<typename SV, typename FPT>
template<typename LP , typename FPT2 >
HOMOG2D_INUMTYPE h2d::base::SegVec< SV, FPT >::getAngle ( const base::LPBase< LP, FPT2 > &  other) const
inline

Get angle between segment and line.

5101  {
5102  static_assert( std::is_same_v<LP,typ::IsLine>, "cannot compute angle between segment and point" );
5103  return getLine().getAngle( other );
5104  }
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:

◆ getBB()

template<typename SV, typename FPT>
FRect_<HOMOG2D_INUMTYPE> h2d::base::SegVec< SV, FPT >::getBB ( ) const
inline

Get Bounding Box of segment, always throws but needed so the function getBB(T1,T2) builds, whatever the types and because of variant (.

See also
CommonType) (HOMOG2D_ENABLE_VRTP)
5035  {
5036  HOMOG2D_THROW_ERROR_1( "invalid call, Segment has no Bounding Box" );
5037  }
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181

◆ getBisector()

template<typename SV, typename FPT>
auto h2d::base::SegVec< SV, FPT >::getBisector ( ) const
inline

Returns the bisector line of the segment.

See also
free function h2d::getBisector()
5302  {
5303  SegVec<SV,HOMOG2D_INUMTYPE> seg2 = *this; // convert to (possibly) enhance precision
5304  return seg2.getLine().getOrthogLine( seg2.getCenter() );
5305  }
Here is the caller graph for this function:

◆ getCenter()

template<typename SV, typename FPT>
auto h2d::base::SegVec< SV, FPT >::getCenter ( ) const
inline

Returns point at middle distance between p1 and p2.

5289  {
5290  return Point2d_<HOMOG2D_INUMTYPE>(
5291  ( static_cast<HOMOG2D_INUMTYPE>(_ptS1.getX()) + _ptS2.getX() ) / 2.,
5292  ( static_cast<HOMOG2D_INUMTYPE>(_ptS1.getY()) + _ptS2.getY() ) / 2.
5293  );
5294  }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getExtended()

template<typename SV , typename FPT >
SegVec< SV, FPT > h2d::base::SegVec< SV, FPT >::getExtended ( ) const

Returns a segment with same support line but tripled length.

With (1,0)-(2,0) as input, will return the segment (0,0)-(3,0)

5477 {
5478  Segment_<HOMOG2D_INUMTYPE> seg(*this); // to get highest precision
5479  auto li = seg.getLine();
5480  auto rad1 = seg.length();
5481  auto c1 = Circle_<HOMOG2D_INUMTYPE>( _ptS1, rad1 );
5482  auto c2 = Circle_<HOMOG2D_INUMTYPE>( _ptS2, rad1 );
5483 
5484  auto int1 = li.intersects( c1 );
5485  auto int2 = li.intersects( c2 );
5486  assert( int1() );
5487  assert( int2() );
5488  auto ppt1 = int1.get();
5489  auto ppt2 = int2.get();
5490 
5491  return Segment_<FPT>(
5492  ppt1.first,
5493  ppt2.second
5494  );
5495 }
Segment seg
Definition: homog2d_test.cpp:4033
Line2d li
Definition: homog2d_test.cpp:4035
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLine()

template<typename SV, typename FPT>
auto h2d::base::SegVec< SV, FPT >::getLine ( ) const
inline

Returns supporting line.

5253  {
5254  Point2d_<HOMOG2D_INUMTYPE> pt1( _ptS1 );
5255  Point2d_<HOMOG2D_INUMTYPE> pt2( _ptS2 );
5256  auto li = pt1 * pt2;
5257  return Line2d_<HOMOG2D_INUMTYPE>(li);
5258  }
Line2d li
Definition: homog2d_test.cpp:4035
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOrthogPts()

template<typename SV, typename FPT>
std::array<Point2d_<FPT>,4> h2d::base::SegVec< SV, FPT >::getOrthogPts ( ) const
inline

Returns the 4 points orthogonal to the segment/vector.

5233  {
5234  return p_getOrthog();
5235  }
Here is the caller graph for this function:

◆ getOrthogSegs()

template<typename SV, typename FPT>
std::array<Segment_<FPT>,4> h2d::base::SegVec< SV, FPT >::getOrthogSegs ( ) const
inline

Returns the 4 segments/vectors orthogonal to the segment.

5240  {
5241  std::array<Segment_<FPT>,4> out;
5242  auto pts = p_getOrthog();
5243  out[0] = Segment_<FPT>( _ptS1, pts[0] );
5244  out[1] = Segment_<FPT>( _ptS1, pts[1] );
5245  out[2] = Segment_<FPT>( _ptS2, pts[2] );
5246  out[3] = Segment_<FPT>( _ptS2, pts[3] );
5247  return out;
5248  }
Here is the caller graph for this function:

◆ getParallelSegs() [1/2]

template<typename SV, typename FPT>
template<typename T >
std::pair<SegVec,SegVec> h2d::base::SegVec< SV, FPT >::getParallelSegs ( dist) const
Here is the caller graph for this function:

◆ getParallelSegs() [2/2]

template<typename SV, typename FPT>
template<typename T >
std::pair<SegVec<SV,FPT>,SegVec<SV,FPT> > h2d::base::SegVec< SV, FPT >::getParallelSegs ( dist) const

Returns two parallel segments to the current one in a pair.

Behavior differs depending on type of segment:

  • if oriented (OSegment_), the returned pair will hold as first the segment that is left of the original
  • if not oriented (Segment_), the order will be unpredictable
5439 {
5441 #ifndef HOMOG2D_NOCHECKS
5442  if( dist <= 0 )
5443  HOMOG2D_THROW_ERROR_1( "Invalid value for distance:" << dist );
5444 #endif
5445 
5446  auto plines = getLine().getParallelLines( dist );
5447  auto lo1 = getLine().getOrthogLine( _ptS1 );
5448  auto lo2 = getLine().getOrthogLine( _ptS2 );
5449 
5450  auto pA1 = lo1 * plines.first;
5451  auto pA2 = lo2 * plines.first;
5452  auto pB1 = lo1 * plines.second;
5453  auto pB2 = lo2 * plines.second;
5454 
5455  if constexpr( std::is_same_v<SV,typ::IsOSeg> )
5456  if( getPointSide(pB1) == PointSide::Left )
5457  {
5458  std::swap( pA1, pB1 );
5459  std::swap( pA2, pB2 );
5460  }
5461 
5462  return std::make_pair(
5463  SegVec( pA1, pA2 ),
5464  SegVec( pB1, pB2 )
5465  );
5466 }
PointSide getPointSide(const Point2d_< FPT2 > &pt) const
HOMOG2D_INUMTYPE dist(const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
Free function, distance between points.
Definition: homog2d.hpp:9847
SegVec()
Default constructor: initializes segment to (0,0)–(1,1)
Definition: homog2d.hpp:4888
#define HOMOG2D_CHECK_IS_NUMBER(T)
Definition: homog2d.hpp:144
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:

◆ getPointAt()

template<typename SV , typename FPT >
template<typename FPT2 >
Point2d_< HOMOG2D_INUMTYPE > h2d::base::SegVec< SV, FPT >::getPointAt ( FPT2  dist) const

Returns the point at a distance dist from starting point of oriented vector.

5412 {
5413  static_assert( std::is_same_v<SV,typ::IsOSeg>, "Cannot apply on non-oriented segment" );
5415 #ifndef HOMOG2D_NOCHECKS
5416  if( dist < 0 )
5417  HOMOG2D_THROW_ERROR_1( "distance value must be >0, current value=" << dist );
5418 #endif
5419 
5420  Line2d_<HOMOG2D_INUMTYPE> li = getLine();
5421  auto ppts = li.getPoints( _ptS1, dist );
5422  if( _ptS2.distTo( ppts.first ) < _ptS2.distTo( ppts.second ) )
5423  return ppts.first;
5424  else
5425  return ppts.second;
5426 }
Line2d li
Definition: homog2d_test.cpp:4035
HOMOG2D_INUMTYPE dist(const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
Free function, distance between points.
Definition: homog2d.hpp:9847
#define HOMOG2D_CHECK_IS_NUMBER(T)
Definition: homog2d.hpp:144
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPointSide() [1/2]

template<typename SV, typename FPT>
template<typename FPT2 >
PointSide h2d::base::SegVec< SV, FPT >::getPointSide ( const Point2d_< FPT2 > &  pt) const
Here is the caller graph for this function:

◆ getPointSide() [2/2]

template<typename SV, typename FPT>
template<typename T >
PointSide h2d::base::SegVec< SV, FPT >::getPointSide ( const Point2d_< T > &  pt) const

Return side of point pt relatively to the segment (Oriented only)

5387 {
5388  static_assert( std::is_same_v<SV,typ::IsOSeg>, "unable to get side of point related to Segment" );
5389 
5390  if( pt == _ptS1 || pt == _ptS2 )
5391  return PointSide::Neither;
5392 
5393  OSegment_<FPT> other( _ptS1, pt );
5394  HOMOG2D_INUMTYPE cp = detail::crossProductV( other, *this );
5395  PointSide out;
5396  switch ( priv::sign(cp) )
5397  {
5398  case 0: out = PointSide::Neither; break;
5399  case -1: out = PointSide::Left; break;
5400  case +1: out = PointSide::Right; break;
5401  default: assert(0);
5402  }
5403  return out;
5404 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
HOMOG2D_INUMTYPE crossProductV(const base::SegVec< typ::IsOSeg, FPT1 > &, const base::SegVec< typ::IsOSeg, FPT2 > &)
Cross product of two oriented segments, return a scalar.
Definition: homog2d.hpp:9076
int sign(T val)
Get sign of value.
Definition: homog2d.hpp:3529
PointSide
Point related to a OSegment.
Definition: homog2d.hpp:4825
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:

◆ getPts()

template<typename SV, typename FPT>
PointPair_<FPT> h2d::base::SegVec< SV, FPT >::getPts ( ) const
inline

Returns the points of segment as a std::pair.

If "Segment", then the one with smallest x coordinate will be returned as "first". If x-coordinate are equal, then the one with smallest y-coordinate will be returned first

5198  {
5199  return std::make_pair( _ptS1, _ptS2 );
5200  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getVector()

template<typename SV, typename FPT>
std::pair<HOMOG2D_INUMTYPE,HOMOG2D_INUMTYPE> h2d::base::SegVec< SV, FPT >::getVector ( ) const
inline

Get vector of Oriented segment as a pair of values.

5061  {
5062  static_assert( std::is_same_v<SV,typ::IsOSeg>, "cannot return vector of unoriented segment" );
5063  return std::make_pair(
5064  _ptS2.getX() - _ptS1.getX(),
5065  _ptS2.getY() - _ptS1.getY()
5066  );
5067  }
Here is the call graph for this function:

◆ intersects() [1/5]

template<typename SV , typename FPT >
template<typename SV2 , typename FPT2 >
detail::Intersect< detail::Inters_1, FPT > h2d::base::SegVec< SV, FPT >::intersects ( const SegVec< SV2, FPT2 > &  s2) const

Segment/Segment intersection.

Algorithm:

  • first compute the intersection point
  • then check if the intersection point lies in between the range of both segments, both on x and on y
8206 {
8207 // HOMOG2D_START;
8208  if( *this == s2 ) // same segment => no intersection
8209  return detail::Intersect<detail::Inters_1,FPT>();
8210 
8211  Line2d_<HOMOG2D_INUMTYPE> l1 = getLine();
8212  Line2d_<HOMOG2D_INUMTYPE> l2 = s2.getLine();
8213  if( l1.isParallelTo( l2 ) ) // if parallel,
8214  return detail::Intersect<detail::Inters_1,FPT>(); // then, no intersection
8215 
8216  const auto& ptA1 = getPts().first;
8217  const auto& ptA2 = getPts().second;
8218  const auto& ptB1 = s2.getPts().first;
8219  const auto& ptB2 = s2.getPts().second;
8220 
8221  auto ptInter = l1 * l2; // intersection point
8222 
8223  auto dA1 = ptA1.distTo( ptInter );
8224  auto dA2 = ptA2.distTo( ptInter );
8225  if( homog2d_abs(dA1+dA2 - length()) < thr::nullDistance() )
8226  {
8227  auto dB1 = ptB1.distTo( ptInter );
8228  auto dB2 = ptB2.distTo( ptInter );
8229  if( homog2d_abs(dB1+dB2 - s2.length()) < thr::nullDistance() )
8230  return detail::Intersect<detail::Inters_1,FPT>( ptInter );
8231  }
8232  return detail::Intersect<detail::Inters_1,FPT>(); // no intersection
8233 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1195
#define homog2d_abs
Definition: homog2d.hpp:69
HOMOG2D_INUMTYPE length() const
Get segment length.
Definition: homog2d.hpp:5047
PointPair_< FPT > getPts() const
Returns the points of segment as a std::pair.
Definition: homog2d.hpp:5197
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ intersects() [2/5]

template<typename SV , typename FPT >
template<typename FPT2 >
detail::Intersect< detail::Inters_1, FPT > h2d::base::SegVec< SV, FPT >::intersects ( const Line2d_< FPT2 > &  li1) const

Segment/Line intersection.

Algorithm:
We check if the intersection point lies in between the range of the segment, both on x and on y

8245 {
8246 // HOMOG2D_START;
8247 // HOMOG2D_LOG( "seg=" << *this << " line=" << li1 );
8248  detail::Intersect<detail::Inters_1,FPT> out;
8249  auto li2 = getLine();
8250 
8251  if( li1.isParallelTo( li2 ) ) // if parallel, no intersection
8252  return out;
8253 
8254  out._ptIntersect = li1 * li2; // intersection point
8255 
8256  const auto& pi = out._ptIntersect;
8257  const auto& pt1 = getPts().first;
8258  const auto& pt2 = getPts().second;
8259 
8260  auto d1 = pt1.distTo( pi );
8261  auto d2 = pt2.distTo( pi );
8262  if( homog2d_abs(d1+d2-length()) < thr::nullDistance() )
8263  out._doesIntersect = true;
8264 
8265  return out;
8266 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1195
#define homog2d_abs
Definition: homog2d.hpp:69
HOMOG2D_INUMTYPE length() const
Get segment length.
Definition: homog2d.hpp:5047
PointPair_< FPT > getPts() const
Returns the points of segment as a std::pair.
Definition: homog2d.hpp:5197
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:

◆ intersects() [3/5]

template<typename SV , typename FPT >
template<typename FPT2 >
detail::IntersectM< FPT > h2d::base::SegVec< SV, FPT >::intersects ( const Circle_< FPT2 > &  circle) const

Segment/Circle intersection.

For each point of the segment, we need to consider 3 different situations

  • point is inside (PI)
  • point is outside (PO)
  • point is on the edge (PE)

That makes 6 different situations to handle:

  • S1: PI-PI => no intersection
  • S2: PI-PO => 1 intersection
  • S3: PI-PE => 1 intersection
  • S4: PO-PO => depends on the support line:
    • S4A: if line does NOT intersects circle, no intersection pts
    • S4B: if line does intersects circle, and intersections point in segment area => 2 intersection pts
    • S4C: if line does intersects circle, and intersections point NOT in segment area => no intersection pts
  • S5: PO-PE => 1 intersection
  • S6: PE-PE => 2 intersections
8292 {
8293 // HOMOG2D_START;
8294  using detail::PtTag;
8295 
8296  auto tag_ptS1 = detail::getPtLabel( _ptS1, circle ); // get status of segment points related to circle (inside/outside/on-edge)
8297  auto tag_ptS2 = detail::getPtLabel( _ptS2, circle );
8298 
8299  if( tag_ptS1 == PtTag::Inside )
8300  if( tag_ptS2 == PtTag::Inside )
8301  return detail::IntersectM<FPT>();
8302 
8303  auto int_lc = getLine().intersects( circle );
8304  if( !int_lc() )
8305  return detail::IntersectM<FPT>();
8306 
8307  auto p_pts = int_lc.get(); // get the line intersection points
8308  const auto& p1 = p_pts.first;
8309  const auto& p2 = p_pts.second;
8310 
8311  if( // one inside, the other outside
8312  ( tag_ptS1 == PtTag::Inside && tag_ptS2 == PtTag::Outside )
8313  ||
8314  ( tag_ptS1 == PtTag::Outside && tag_ptS2 == PtTag::Inside )
8315  )
8316  {
8317  detail::IntersectM<FPT> out;
8318 
8319  auto d1 = _ptS1.distTo( p1 );
8320  auto d2 = _ptS2.distTo( p1 );
8321  if( homog2d_abs( d1+d2-length() ) < thr::nullDistance() )
8322  out.add( p1 ); // points is inside
8323  else
8324  out.add( p2 );
8325  return out;
8326  }
8327 
8328  detail::IntersectM<FPT> out;
8329  if( tag_ptS1 == PtTag::Outside && tag_ptS2 == PtTag::Outside ) // both outside
8330  {
8331  auto d1 = _ptS1.distTo( p1 );
8332  auto d2 = _ptS2.distTo( p1 );
8333  if( homog2d_abs( d1+d2-length() ) >= thr::nullDistance() ) // if sum of the two distances is higher than length
8334  return detail::IntersectM<FPT>();
8335 
8336  out.add( p1 );
8337  out.add( p2 );
8338  return out;
8339  }
8340 
8341  if( tag_ptS1 == PtTag::OnEdge )
8342  out.add( _ptS1 );
8343  if( tag_ptS2 == PtTag::OnEdge )
8344  out.add( _ptS2 );
8345 
8346  return out;
8347 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1195
PtTag
See getPtLabel( const Point2d_<FPT>& pt, const Circle_<FPT2>& circle )
Definition: homog2d.hpp:8159
#define homog2d_abs
Definition: homog2d.hpp:69
PtTag getPtLabel(const Point2d_< FPT > &pt, const Circle_< FPT2 > &circle)
Returns a label characterizing point pt, related to circle: inside, outside, or on edge of circle...
Definition: homog2d.hpp:8167
HOMOG2D_INUMTYPE length() const
Get segment length.
Definition: homog2d.hpp:5047
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:

◆ intersects() [4/5]

template<typename SV, typename FPT>
template<typename FPT2 >
detail::IntersectM<FPT> h2d::base::SegVec< SV, FPT >::intersects ( const FRect_< FPT2 > &  r) const
inline

Segment/FRect intersection.

5319  {
5320  return r.intersects( *this );
5321  }
Here is the call graph for this function:

◆ intersects() [5/5]

template<typename SV, typename FPT>
template<typename PLT , typename FPT2 >
detail::IntersectM<FPT> h2d::base::SegVec< SV, FPT >::intersects ( const base::PolylineBase< PLT, FPT2 > &  other) const
inline

Segment/Polyline intersection.

5326  {
5327  return other.intersects( *this );
5328  }
Here is the call graph for this function:

◆ isInside() [1/5]

template<typename SV, typename FPT>
template<typename FPT2 >
bool h2d::base::SegVec< SV, FPT >::isInside ( const Circle_< FPT2 > &  shape) const
inline

Segment is inside Circle.

5146  {
5147  return p_bothPtsAreInside( shape );
5148  }
Here is the caller graph for this function:

◆ isInside() [2/5]

template<typename SV, typename FPT>
template<typename FPT2 >
bool h2d::base::SegVec< SV, FPT >::isInside ( const FRect_< FPT2 > &  shape) const
inline

Segment is inside FRect.

5153  {
5154  return p_bothPtsAreInside( shape );
5155  }

◆ isInside() [3/5]

template<typename SV, typename FPT>
template<typename FPT2 >
bool h2d::base::SegVec< SV, FPT >::isInside ( const Ellipse_< FPT2 > &  shape) const
inline

Segment is inside Ellipse.

5160  {
5161  return p_bothPtsAreInside( shape );
5162  }

◆ isInside() [4/5]

template<typename SV, typename FPT>
template<typename FPT2 >
constexpr bool h2d::base::SegVec< SV, FPT >::isInside ( const OPolyline_< FPT2 > &  ) const
inline

Segment is inside OPolyline_.

5167  {
5168  return false;
5169  }

◆ isInside() [5/5]

template<typename SV, typename FPT>
template<typename FPT2 >
bool h2d::base::SegVec< SV, FPT >::isInside ( const CPolyline_< FPT2 > &  cpoly) const
inline

Segment is inside CPolyline_.

Requires both points inside AND no intersections

5177  {
5178  if( !p_bothPtsAreInside( cpoly ) )
5179  return false;
5180 
5181  for( auto poly_seg: cpoly.getSegs() )
5182  if( poly_seg.intersects( *this )() )
5183  return false;
5184  return true;
5185  }
Here is the call graph for this function:

◆ isParallelTo()

template<typename SV, typename FPT>
template<typename T >
constexpr bool h2d::base::SegVec< SV, FPT >::isParallelTo ( const T &  other) const
inline
5278  {
5279  static_assert(
5280  std::is_same<T,SegVec<SV,FPT>>::value ||
5281  std::is_same<T,Line2d_<FPT>>::value,
5282  "type needs to be a segment, a vector, or a line" );
5283  return getLine().isParallelTo( other );
5284  }
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ length()

template<typename SV, typename FPT>
HOMOG2D_INUMTYPE h2d::base::SegVec< SV, FPT >::length ( ) const
inlinevirtual

Get segment length.

Implements h2d::rtp::Root.

5048  {
5049  return _ptS1.distTo( _ptS2 );
5050  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveTo() [1/2]

template<typename SV, typename FPT>
template<typename TX , typename TY >
void h2d::base::SegVec< SV, FPT >::moveTo ( TX  x,
TY  y 
)
inline

Move Segment to other location.

5010  {
5013  moveTo( Point2d_<FPT>(x,y) );
5014  }
void moveTo(TX x, TY y)
Move Segment to other location.
Definition: homog2d.hpp:5009
#define HOMOG2D_CHECK_IS_NUMBER(T)
Definition: homog2d.hpp:144
Here is the call graph for this function:

◆ moveTo() [2/2]

template<typename SV, typename FPT>
template<typename T1 >
void h2d::base::SegVec< SV, FPT >::moveTo ( const Point2d_< T1 > &  pt)
inline

Move Segment to other location, given by pt.

5019  {
5020  auto w = _ptS2.getX() - _ptS1.getX();
5021  auto h = _ptS2.getY() - _ptS1.getY();
5022  _ptS1 = pt;
5023  _ptS2.set( _ptS1.getX() + w, _ptS1.getY() + h );
5024  }
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:

◆ operator!=()

template<typename SV, typename FPT>
bool h2d::base::SegVec< SV, FPT >::operator!= ( const SegVec< SV, FPT > &  s2) const
inline
5118  {
5119  return !(*this == s2);
5120  }

◆ operator-()

template<typename SV, typename FPT>
SegVec<SV,FPT> h2d::base::SegVec< SV, FPT >::operator- ( )
inline

Reverse oriented segment.

4952  {
4953  static_assert( !std::is_same_v<SV,typ::IsSegment>, "cannot reverse non-oriented segment" );
4954  std::swap( _ptS1, _ptS2 );
4955  return *this;
4956  }

◆ operator<()

template<typename SV, typename FPT>
bool h2d::base::SegVec< SV, FPT >::operator< ( const SegVec< SV, FPT > &  other) const
inline
5123  {
5124  return _ptS1 < other._ptS1;
5125  }
Here is the call graph for this function:

◆ operator==()

template<typename SV, typename FPT>
bool h2d::base::SegVec< SV, FPT >::operator== ( const SegVec< SV, FPT > &  s2) const
inline
5110  {
5111  if( _ptS1 != s2._ptS1 )
5112  return false;
5113  if( _ptS2 != s2._ptS2 )
5114  return false;
5115  return true;
5116  }

◆ set() [1/3]

template<typename SV, typename FPT>
template<typename FP1 , typename FP2 >
void h2d::base::SegVec< SV, FPT >::set ( const Point2d_< FP1 > &  p1,
const Point2d_< FP2 > &  p2 
)
inline

Setter.

4961  {
4962 #ifndef HOMOG2D_NOCHECKS
4963  if( p1 == p2 )
4964  HOMOG2D_THROW_ERROR_1( "cannot define a segment with two identical points" << p1 << " and " << p2 );
4965 #endif
4966  _ptS1 = p1;
4967  _ptS2 = p2;
4968  if constexpr( std::is_same_v<SV,typ::IsSegment> )
4969  priv::fix_order( _ptS1, _ptS2 );
4970  }
void fix_order(Point2d_< FPT > &ptA, Point2d_< FPT > &ptB)
Private free function, swap the points so that ptA.x <= ptB.x, and if equal, sorts on y...
Definition: homog2d.hpp:3520
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set() [2/3]

template<typename SV, typename FPT>
template<typename FP1 , typename FP2 >
void h2d::base::SegVec< SV, FPT >::set ( const PointPair2_< FP1, FP2 > &  ppts)
inline

Setter from a std::pair.

4975  {
4976  set( ppts.first, ppts.second );
4977  }

◆ set() [3/3]

template<typename SV, typename FPT>
template<typename FP1 , typename FP2 , typename FP3 , typename FP4 >
void h2d::base::SegVec< SV, FPT >::set ( FP1  x1,
FP2  y1,
FP3  x2,
FP4  y2 
)
inline

Setter from 4 raw point coordinates.

4982  {
4987  set( Point2d_<FPT>(x1,y1), Point2d_<FPT>(x2,y2) );
4988  }
#define HOMOG2D_CHECK_IS_NUMBER(T)
Definition: homog2d.hpp:144

◆ size()

template<typename SV, typename FPT>
constexpr size_t h2d::base::SegVec< SV, FPT >::size ( ) const
inlinevirtual

Returns 2.

Implements h2d::rtp::Root.

5042  {
5043  return 2;
5044  }

◆ split() [1/3]

template<typename SV , typename FPT >
std::pair< SegVec< SV, FPT >, SegVec< SV, FPT > > h2d::base::SegVec< SV, FPT >::split ( ) const

Returns a pair of segments/vectors split by the middle.

5347 {
5348  auto pt_mid = getCenter();
5349  return std::make_pair(
5350  SegVec<SV,FPT>( _ptS1, pt_mid ),
5351  SegVec<SV,FPT>( pt_mid, _ptS2 )
5352  );
5353 }
auto getCenter() const
Returns point at middle distance between p1 and p2.
Definition: homog2d.hpp:5288
Here is the call graph for this function:
Here is the caller graph for this function:

◆ split() [2/3]

template<typename SV, typename FPT>
template<typename T >
std::pair<SegVec<typ::IsOSeg,FPT>,SegVec<typ::IsOSeg,FPT> > h2d::base::SegVec< SV, FPT >::split ( dist) const

◆ split() [3/3]

template<typename SV, typename FPT>
template<typename T >
std::pair<OSegment_<FPT>,OSegment_<FPT> > h2d::base::SegVec< SV, FPT >::split ( dist) const

Returns a pair of segments/vectors split by point at arbitrary distance.

Note
: distance value must be >0 and less than segment length
5362 {
5363  static_assert( std::is_same_v<SV,typ::IsOSeg>, "cannot use this on non-oriented segments" );
5365 #ifndef HOMOG2D_NOCHECKS
5366  if( dist <= 0 )
5367  HOMOG2D_THROW_ERROR_1( "distance value must be >=0, current value=" << dist );
5368  if( dist >= length() )
5369  HOMOG2D_THROW_ERROR_1( "distance value must less than length, current value="
5370  << dist << " length=" << length() );
5371 #endif
5372 
5373  auto pt = getPointAt(dist);
5374  return std::make_pair(
5375  SegVec<SV,FPT>( _ptS1, pt ),
5376  SegVec<SV,FPT>( pt, _ptS2 )
5377  );
5378 }
Point2d_< HOMOG2D_INUMTYPE > getPointAt(FPT2 dist) const
Returns the point at a distance dist from starting point of oriented vector.
Definition: homog2d.hpp:5411
HOMOG2D_INUMTYPE dist(const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
Free function, distance between points.
Definition: homog2d.hpp:9847
HOMOG2D_INUMTYPE length() const
Get segment length.
Definition: homog2d.hpp:5047
#define HOMOG2D_CHECK_IS_NUMBER(T)
Definition: homog2d.hpp:144
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:

◆ translate() [1/2]

template<typename SV, typename FPT>
template<typename T1 , typename T2 >
void h2d::base::SegVec< SV, FPT >::translate ( T1  dx,
T2  dy 
)
inline

Translate Segment.

4993  {
4996  _ptS1.translate( dx, dy );
4997  _ptS2.translate( dx, dy );
4998  }
#define HOMOG2D_CHECK_IS_NUMBER(T)
Definition: homog2d.hpp:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ translate() [2/2]

template<typename SV, typename FPT>
template<typename T1 , typename T2 >
void h2d::base::SegVec< SV, FPT >::translate ( const std::pair< T1, T2 > &  pa)
inline

Translate Segment, using pair of values.

5003  {
5004  this->translate( pa.first, pa.second );
5005  }
void translate(T1 dx, T2 dy)
Translate Segment.
Definition: homog2d.hpp:4992
Here is the call graph for this function:

◆ type()

template<typename SV, typename FPT>
Type h2d::base::SegVec< SV, FPT >::type ( ) const
inlinevirtual
Todo:
20250127: if this works, then generalize to all the other base type() member functions

Implements h2d::rtp::Root.

4873  {
4874  if constexpr( std::is_same_v<SV,typ::IsSegment> )
4875  return Type::Segment;
4876  else
4877  return Type::OSegment;
4878  }

Friends And Related Function Documentation

◆ operator<<

template<typename SV, typename FPT>
template<typename U , typename V >
std::ostream& operator<< ( std::ostream &  ,
const SegVec< U, V > &   
)
friend

◆ SegVec

template<typename SV, typename FPT>
template<typename T1 , typename T2 >
friend class SegVec
friend

The documentation for this class was generated from the following file: