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)

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

◆ 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

4898  : _ptS1(p1), _ptS2(p2)
4899  {
4900 #ifndef HOMOG2D_NOCHECKS
4901  if( p1 == p2 )
4902  HOMOG2D_THROW_ERROR_1( "cannot build a segment with two identical points: " << p1 << " and " << p2 );
4903 #endif
4904  if constexpr( std::is_same_v<SV,typ::IsSegment> )
4905  priv::fix_order( _ptS1, _ptS2 );
4906  }
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:3555
#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.

4911  : SegVec( Point2d_<FPT>(x1,y1), Point2d_<FPT>(x2,y2) )
4912  {
4917  }
SegVec()
Default constructor: initializes segment to (0,0)–(1,1)
Definition: homog2d.hpp:4889
#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.

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

◆ 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
4934  : _ptS1(other._ptS1), _ptS2(other._ptS2)
4935  {
4936  static_assert(
4937  ( std::is_same_v<SV,typ::IsSegment>
4938  ||
4939  ( std::is_same_v<SV,typ::IsOSeg> && std::is_same_v<SV2,typ::IsOSeg> ) ),
4940  "Cannot build a OSegment from a Segment"
4941  );
4942  if constexpr( std::is_same_v<SV2,typ::IsSegment> )
4943  priv::fix_order( _ptS1, _ptS2 );
4944  }
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:3555
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.

5055  {
5056  return 0.;
5057  }
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
5514 {
5515  auto ppts = getPts();
5516  auto x1 = static_cast<HOMOG2D_INUMTYPE>( ppts.first.getX() );
5517  auto y1 = static_cast<HOMOG2D_INUMTYPE>( ppts.first.getY() );
5518  auto x2 = static_cast<HOMOG2D_INUMTYPE>( ppts.second.getX() );
5519  auto y2 = static_cast<HOMOG2D_INUMTYPE>( ppts.second.getY() );
5520 
5521  auto A = static_cast<HOMOG2D_INUMTYPE>(pt.getX()) - x1;
5522  auto B = static_cast<HOMOG2D_INUMTYPE>(pt.getY()) - y1;
5523  auto C = x2 - x1;
5524  auto D = y2 - y1;
5525 
5526  auto dot = A * C + B * D;
5527  auto len_sq = C * C + D * D;
5528  auto param = dot / len_sq;
5529 
5530  HOMOG2D_INUMTYPE xx, yy;
5531 
5532  if( param < 0. )
5533  {
5534  if( segDistCase )
5535  *segDistCase = -1;
5536  xx = x1;
5537  yy = y1;
5538  }
5539  else
5540  {
5541  if( param > 1. )
5542  {
5543  if( segDistCase )
5544  *segDistCase = +1;
5545  xx = x2;
5546  yy = y2;
5547  }
5548  else
5549  {
5550  if( segDistCase )
5551  *segDistCase = 0;
5552  xx = x1 + param * C;
5553  yy = y1 + param * D;
5554  }
5555  }
5556 
5557  auto dx = pt.getX() - xx;
5558  auto dy = pt.getY() - yy;
5559  return homog2d_sqrt( dx * dx + dy * dy );
5560 }
#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:5198
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.

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

12181 {
12182  auto group = false;
12183  if( dp._dpValues._showPoints || std::is_same_v<SV,typ::IsOSeg> )
12184  group = true;
12185 
12186  if( group )
12187  im.getReal()._svgString << "<g>";
12188 
12189  auto pts = getPts();
12190  priv::drawSvgSeg( im, pts, dp.getSvgRgbColor(), dp._dpValues._lineThickness, dp.getAttrString() );
12191 
12192  if constexpr( std::is_same_v<SV,typ::IsOSeg> )
12193  {
12194  auto arrsegs = priv::getArrowSegments( *this );
12195  for( auto ppts: arrsegs )
12196  priv::drawSvgSeg( im, ppts, dp.getSvgRgbColor(), dp._dpValues._lineThickness );
12197  }
12198  else
12199  {
12200  if( dp._dpValues._showPoints )
12201  {
12202  _ptS1.draw( im, dp );
12203  _ptS2.draw( im, dp );
12204  }
12205  }
12206 
12207  if( group )
12208  im.getReal()._svgString << "</g>\n";
12209 }
std::array< PointPair_< double >, 3 > getArrowSegments(const base::SegVec< typ::IsOSeg, FPT > &vec)
Definition: homog2d.hpp:11806
img::Image< img::SvgImage > im(300, 400)
PointPair_< FPT > getPts() const
Returns the points of segment as a std::pair.
Definition: homog2d.hpp:5198
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:12138
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]
5079  {
5080 // if one of the two is a (unoriented) segment, then we just return the lines angle
5081  if constexpr( std::is_same_v<SV,typ::IsSegment> || std::is_same_v<SV2,typ::IsSegment> )
5082  return other.getLine().getAngle( this->getLine() );
5083  else
5084  { // both are oriented segments
5085  auto v1 = this->getVector();
5086  auto v2 = other.getVector();
5087  auto dx1 = v1.first;
5088  auto dx2 = v2.first;
5089  auto dy1 = v1.second;
5090  auto dy2 = v2.second;
5091  return std::atan2(
5092  dx1 * dy2 - dy1 * dx2,
5093  dx1 * dx2 + dy1 * dy2
5094  );
5095  }
5096  }
std::pair< HOMOG2D_INUMTYPE, HOMOG2D_INUMTYPE > getVector() const
Get vector of Oriented segment as a pair of values.
Definition: homog2d.hpp:5061
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5253
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.

5102  {
5103  static_assert( std::is_same_v<LP,typ::IsLine>, "cannot compute angle between segment and point" );
5104  return getLine().getAngle( other );
5105  }
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5253
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)
5036  {
5037  HOMOG2D_THROW_ERROR_1( "invalid call, Segment has no Bounding Box" );
5038  }
#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()
5303  {
5304  SegVec<SV,HOMOG2D_INUMTYPE> seg2 = *this; // convert to (possibly) enhance precision
5305  return seg2.getLine().getOrthogLine( seg2.getCenter() );
5306  }
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.

5290  {
5291  return Point2d_<HOMOG2D_INUMTYPE>(
5292  ( static_cast<HOMOG2D_INUMTYPE>(_ptS1.getX()) + _ptS2.getX() ) / 2.,
5293  ( static_cast<HOMOG2D_INUMTYPE>(_ptS1.getY()) + _ptS2.getY() ) / 2.
5294  );
5295  }
#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)

5478 {
5479  Segment_<HOMOG2D_INUMTYPE> seg(*this); // to get highest precision
5480  auto li = seg.getLine();
5481  auto rad1 = seg.length();
5482  auto c1 = Circle_<HOMOG2D_INUMTYPE>( _ptS1, rad1 );
5483  auto c2 = Circle_<HOMOG2D_INUMTYPE>( _ptS2, rad1 );
5484 
5485  auto int1 = li.intersects( c1 );
5486  auto int2 = li.intersects( c2 );
5487  assert( int1() );
5488  assert( int2() );
5489  auto ppt1 = int1.get();
5490  auto ppt2 = int2.get();
5491 
5492  return Segment_<FPT>(
5493  ppt1.first,
5494  ppt2.second
5495  );
5496 }
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.

5254  {
5255  Point2d_<HOMOG2D_INUMTYPE> pt1( _ptS1 );
5256  Point2d_<HOMOG2D_INUMTYPE> pt2( _ptS2 );
5257  auto li = pt1 * pt2;
5258  return Line2d_<HOMOG2D_INUMTYPE>(li);
5259  }
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.

5234  {
5235  return p_getOrthog();
5236  }
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.

5241  {
5242  std::array<Segment_<FPT>,4> out;
5243  auto pts = p_getOrthog();
5244  out[0] = Segment_<FPT>( _ptS1, pts[0] );
5245  out[1] = Segment_<FPT>( _ptS1, pts[1] );
5246  out[2] = Segment_<FPT>( _ptS2, pts[2] );
5247  out[3] = Segment_<FPT>( _ptS2, pts[3] );
5248  return out;
5249  }
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
5440 {
5442 #ifndef HOMOG2D_NOCHECKS
5443  if( dist <= 0 )
5444  HOMOG2D_THROW_ERROR_1( "Invalid value for distance:" << dist );
5445 #endif
5446 
5447  auto plines = getLine().getParallelLines( dist );
5448  auto lo1 = getLine().getOrthogLine( _ptS1 );
5449  auto lo2 = getLine().getOrthogLine( _ptS2 );
5450 
5451  auto pA1 = lo1 * plines.first;
5452  auto pA2 = lo2 * plines.first;
5453  auto pB1 = lo1 * plines.second;
5454  auto pB2 = lo2 * plines.second;
5455 
5456  if constexpr( std::is_same_v<SV,typ::IsOSeg> )
5457  if( getPointSide(pB1) == PointSide::Left )
5458  {
5459  std::swap( pA1, pB1 );
5460  std::swap( pA2, pB2 );
5461  }
5462 
5463  return std::make_pair(
5464  SegVec( pA1, pA2 ),
5465  SegVec( pB1, pB2 )
5466  );
5467 }
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:9848
SegVec()
Default constructor: initializes segment to (0,0)–(1,1)
Definition: homog2d.hpp:4889
#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:5253
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.

5413 {
5414  static_assert( std::is_same_v<SV,typ::IsOSeg>, "Cannot apply on non-oriented segment" );
5416 #ifndef HOMOG2D_NOCHECKS
5417  if( dist < 0 )
5418  HOMOG2D_THROW_ERROR_1( "distance value must be >0, current value=" << dist );
5419 #endif
5420 
5421  Line2d_<HOMOG2D_INUMTYPE> li = getLine();
5422  auto ppts = li.getPoints( _ptS1, dist );
5423  if( _ptS2.distTo( ppts.first ) < _ptS2.distTo( ppts.second ) )
5424  return ppts.first;
5425  else
5426  return ppts.second;
5427 }
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:9848
#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:5253
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)

5388 {
5389  static_assert( std::is_same_v<SV,typ::IsOSeg>, "unable to get side of point related to Segment" );
5390 
5391  if( pt == _ptS1 || pt == _ptS2 )
5392  return PointSide::Neither;
5393 
5394  OSegment_<FPT> other( _ptS1, pt );
5395  HOMOG2D_INUMTYPE cp = detail::crossProductV( other, *this );
5396  PointSide out;
5397  switch ( priv::sign(cp) )
5398  {
5399  case 0: out = PointSide::Neither; break;
5400  case -1: out = PointSide::Left; break;
5401  case +1: out = PointSide::Right; break;
5402  default: assert(0);
5403  }
5404  return out;
5405 }
#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:9077
int sign(T val)
Get sign of value.
Definition: homog2d.hpp:3564
PointSide
Point related to a OSegment.
Definition: homog2d.hpp:4826
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

5199  {
5200  return std::make_pair( _ptS1, _ptS2 );
5201  }
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.

5062  {
5063  static_assert( std::is_same_v<SV,typ::IsOSeg>, "cannot return vector of unoriented segment" );
5064  return std::make_pair(
5065  _ptS2.getX() - _ptS1.getX(),
5066  _ptS2.getY() - _ptS1.getY()
5067  );
5068  }
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
8207 {
8208 // HOMOG2D_START;
8209  if( *this == s2 ) // same segment => no intersection
8210  return detail::Intersect<detail::Inters_1,FPT>();
8211 
8212  Line2d_<HOMOG2D_INUMTYPE> l1 = getLine();
8213  Line2d_<HOMOG2D_INUMTYPE> l2 = s2.getLine();
8214  if( l1.isParallelTo( l2 ) ) // if parallel,
8215  return detail::Intersect<detail::Inters_1,FPT>(); // then, no intersection
8216 
8217  const auto& ptA1 = getPts().first;
8218  const auto& ptA2 = getPts().second;
8219  const auto& ptB1 = s2.getPts().first;
8220  const auto& ptB2 = s2.getPts().second;
8221 
8222  auto ptInter = l1 * l2; // intersection point
8223 
8224  auto dA1 = ptA1.distTo( ptInter );
8225  auto dA2 = ptA2.distTo( ptInter );
8226  if( homog2d_abs(dA1+dA2 - length()) < thr::nullDistance() )
8227  {
8228  auto dB1 = ptB1.distTo( ptInter );
8229  auto dB2 = ptB2.distTo( ptInter );
8230  if( homog2d_abs(dB1+dB2 - s2.length()) < thr::nullDistance() )
8231  return detail::Intersect<detail::Inters_1,FPT>( ptInter );
8232  }
8233  return detail::Intersect<detail::Inters_1,FPT>(); // no intersection
8234 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1229
#define homog2d_abs
Definition: homog2d.hpp:69
HOMOG2D_INUMTYPE length() const
Get segment length.
Definition: homog2d.hpp:5048
PointPair_< FPT > getPts() const
Returns the points of segment as a std::pair.
Definition: homog2d.hpp:5198
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5253
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

8246 {
8247 // HOMOG2D_START;
8248 // HOMOG2D_LOG( "seg=" << *this << " line=" << li1 );
8249  detail::Intersect<detail::Inters_1,FPT> out;
8250  auto li2 = getLine();
8251 
8252  if( li1.isParallelTo( li2 ) ) // if parallel, no intersection
8253  return out;
8254 
8255  out._ptIntersect = li1 * li2; // intersection point
8256 
8257  const auto& pi = out._ptIntersect;
8258  const auto& pt1 = getPts().first;
8259  const auto& pt2 = getPts().second;
8260 
8261  auto d1 = pt1.distTo( pi );
8262  auto d2 = pt2.distTo( pi );
8263  if( homog2d_abs(d1+d2-length()) < thr::nullDistance() )
8264  out._doesIntersect = true;
8265 
8266  return out;
8267 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1229
#define homog2d_abs
Definition: homog2d.hpp:69
HOMOG2D_INUMTYPE length() const
Get segment length.
Definition: homog2d.hpp:5048
PointPair_< FPT > getPts() const
Returns the points of segment as a std::pair.
Definition: homog2d.hpp:5198
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5253
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
8293 {
8294 // HOMOG2D_START;
8295  using detail::PtTag;
8296 
8297  auto tag_ptS1 = detail::getPtLabel( _ptS1, circle ); // get status of segment points related to circle (inside/outside/on-edge)
8298  auto tag_ptS2 = detail::getPtLabel( _ptS2, circle );
8299 
8300  if( tag_ptS1 == PtTag::Inside )
8301  if( tag_ptS2 == PtTag::Inside )
8302  return detail::IntersectM<FPT>();
8303 
8304  auto int_lc = getLine().intersects( circle );
8305  if( !int_lc() )
8306  return detail::IntersectM<FPT>();
8307 
8308  auto p_pts = int_lc.get(); // get the line intersection points
8309  const auto& p1 = p_pts.first;
8310  const auto& p2 = p_pts.second;
8311 
8312  if( // one inside, the other outside
8313  ( tag_ptS1 == PtTag::Inside && tag_ptS2 == PtTag::Outside )
8314  ||
8315  ( tag_ptS1 == PtTag::Outside && tag_ptS2 == PtTag::Inside )
8316  )
8317  {
8318  detail::IntersectM<FPT> out;
8319 
8320  auto d1 = _ptS1.distTo( p1 );
8321  auto d2 = _ptS2.distTo( p1 );
8322  if( homog2d_abs( d1+d2-length() ) < thr::nullDistance() )
8323  out.add( p1 ); // points is inside
8324  else
8325  out.add( p2 );
8326  return out;
8327  }
8328 
8329  detail::IntersectM<FPT> out;
8330  if( tag_ptS1 == PtTag::Outside && tag_ptS2 == PtTag::Outside ) // both outside
8331  {
8332  auto d1 = _ptS1.distTo( p1 );
8333  auto d2 = _ptS2.distTo( p1 );
8334  if( homog2d_abs( d1+d2-length() ) >= thr::nullDistance() ) // if sum of the two distances is higher than length
8335  return detail::IntersectM<FPT>();
8336 
8337  out.add( p1 );
8338  out.add( p2 );
8339  return out;
8340  }
8341 
8342  if( tag_ptS1 == PtTag::OnEdge )
8343  out.add( _ptS1 );
8344  if( tag_ptS2 == PtTag::OnEdge )
8345  out.add( _ptS2 );
8346 
8347  return out;
8348 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1229
PtTag
See getPtLabel( const Point2d_<FPT>& pt, const Circle_<FPT2>& circle )
Definition: homog2d.hpp:8160
#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:8168
HOMOG2D_INUMTYPE length() const
Get segment length.
Definition: homog2d.hpp:5048
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5253
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.

5320  {
5321  return r.intersects( *this );
5322  }
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.

5327  {
5328  return other.intersects( *this );
5329  }
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.

5147  {
5148  return p_bothPtsAreInside( shape );
5149  }
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.

5154  {
5155  return p_bothPtsAreInside( shape );
5156  }

◆ 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.

5161  {
5162  return p_bothPtsAreInside( shape );
5163  }

◆ 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_.

5168  {
5169  return false;
5170  }

◆ 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

5178  {
5179  if( !p_bothPtsAreInside( cpoly ) )
5180  return false;
5181 
5182  for( auto poly_seg: cpoly.getSegs() )
5183  if( poly_seg.intersects( *this )() )
5184  return false;
5185  return true;
5186  }
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
5279  {
5280  static_assert(
5281  std::is_same<T,SegVec<SV,FPT>>::value ||
5282  std::is_same<T,Line2d_<FPT>>::value,
5283  "type needs to be a segment, a vector, or a line" );
5284  return getLine().isParallelTo( other );
5285  }
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5253
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.

5049  {
5050  return _ptS1.distTo( _ptS2 );
5051  }
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.

5011  {
5014  moveTo( Point2d_<FPT>(x,y) );
5015  }
void moveTo(TX x, TY y)
Move Segment to other location.
Definition: homog2d.hpp:5010
#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.

5020  {
5021  auto w = _ptS2.getX() - _ptS1.getX();
5022  auto h = _ptS2.getY() - _ptS1.getY();
5023  _ptS1 = pt;
5024  _ptS2.set( _ptS1.getX() + w, _ptS1.getY() + h );
5025  }
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
5119  {
5120  return !(*this == s2);
5121  }

◆ operator-()

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

Reverse oriented segment.

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

◆ operator<()

template<typename SV, typename FPT>
bool h2d::base::SegVec< SV, FPT >::operator< ( const SegVec< SV, FPT > &  other) const
inline
5124  {
5125  return _ptS1 < other._ptS1;
5126  }
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
5111  {
5112  if( _ptS1 != s2._ptS1 )
5113  return false;
5114  if( _ptS2 != s2._ptS2 )
5115  return false;
5116  return true;
5117  }

◆ 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.

4962  {
4963 #ifndef HOMOG2D_NOCHECKS
4964  if( p1 == p2 )
4965  HOMOG2D_THROW_ERROR_1( "cannot define a segment with two identical points" << p1 << " and " << p2 );
4966 #endif
4967  _ptS1 = p1;
4968  _ptS2 = p2;
4969  if constexpr( std::is_same_v<SV,typ::IsSegment> )
4970  priv::fix_order( _ptS1, _ptS2 );
4971  }
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:3555
#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.

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

◆ 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.

4983  {
4988  set( Point2d_<FPT>(x1,y1), Point2d_<FPT>(x2,y2) );
4989  }
#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.

5043  {
5044  return 2;
5045  }

◆ 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.

5348 {
5349  auto pt_mid = getCenter();
5350  return std::make_pair(
5351  SegVec<SV,FPT>( _ptS1, pt_mid ),
5352  SegVec<SV,FPT>( pt_mid, _ptS2 )
5353  );
5354 }
auto getCenter() const
Returns point at middle distance between p1 and p2.
Definition: homog2d.hpp:5289
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
5363 {
5364  static_assert( std::is_same_v<SV,typ::IsOSeg>, "cannot use this on non-oriented segments" );
5366 #ifndef HOMOG2D_NOCHECKS
5367  if( dist <= 0 )
5368  HOMOG2D_THROW_ERROR_1( "distance value must be >=0, current value=" << dist );
5369  if( dist >= length() )
5370  HOMOG2D_THROW_ERROR_1( "distance value must less than length, current value="
5371  << dist << " length=" << length() );
5372 #endif
5373 
5374  auto pt = getPointAt(dist);
5375  return std::make_pair(
5376  SegVec<SV,FPT>( _ptS1, pt ),
5377  SegVec<SV,FPT>( pt, _ptS2 )
5378  );
5379 }
Point2d_< HOMOG2D_INUMTYPE > getPointAt(FPT2 dist) const
Returns the point at a distance dist from starting point of oriented vector.
Definition: homog2d.hpp:5412
HOMOG2D_INUMTYPE dist(const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
Free function, distance between points.
Definition: homog2d.hpp:9848
HOMOG2D_INUMTYPE length() const
Get segment length.
Definition: homog2d.hpp:5048
#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.

4994  {
4997  _ptS1.translate( dx, dy );
4998  _ptS2.translate( dx, dy );
4999  }
#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.

5004  {
5005  this->translate( pa.first, pa.second );
5006  }
void translate(T1 dx, T2 dy)
Translate Segment.
Definition: homog2d.hpp:4993
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.

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

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: