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)

4892  : _ptS2(1.,1.)
4893  {}

◆ 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

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

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

4925  : SegVec(ppts.first, ppts.second)
4926  {}
SegVec()
Default constructor: initializes segment to (0,0)–(1,1)
Definition: homog2d.hpp:4892

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

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

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

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

5105  {
5106  static_assert( std::is_same_v<LP,typ::IsLine>, "cannot compute angle between segment and point" );
5107  return getLine().getAngle( other );
5108  }
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5256
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)
5039  {
5040  HOMOG2D_THROW_ERROR_1( "invalid call, Segment has no Bounding Box" );
5041  }
#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()
5306  {
5307  SegVec<SV,HOMOG2D_INUMTYPE> seg2 = *this; // convert to (possibly) enhance precision
5308  return seg2.getLine().getOrthogLine( seg2.getCenter() );
5309  }
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.

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

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

5257  {
5258  Point2d_<HOMOG2D_INUMTYPE> pt1( _ptS1 );
5259  Point2d_<HOMOG2D_INUMTYPE> pt2( _ptS2 );
5260  auto li = pt1 * pt2;
5261  return Line2d_<HOMOG2D_INUMTYPE>(li);
5262  }
Line2d li
Definition: homog2d_test.cpp:4053
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.

5237  {
5238  return p_getOrthog();
5239  }
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.

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

5416 {
5417  static_assert( std::is_same_v<SV,typ::IsOSeg>, "Cannot apply on non-oriented segment" );
5419 #ifndef HOMOG2D_NOCHECKS
5420  if( dist < 0 )
5421  HOMOG2D_THROW_ERROR_1( "distance value must be >0, current value=" << dist );
5422 #endif
5423 
5424  Line2d_<HOMOG2D_INUMTYPE> li = getLine();
5425  auto ppts = li.getPoints( _ptS1, dist );
5426  if( _ptS2.distTo( ppts.first ) < _ptS2.distTo( ppts.second ) )
5427  return ppts.first;
5428  else
5429  return ppts.second;
5430 }
Line2d li
Definition: homog2d_test.cpp:4053
HOMOG2D_INUMTYPE dist(const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
Free function, distance between points.
Definition: homog2d.hpp:9851
#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:5256
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)

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

5202  {
5203  return std::make_pair( _ptS1, _ptS2 );
5204  }
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.

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

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

5323  {
5324  return r.intersects( *this );
5325  }
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.

5330  {
5331  return other.intersects( *this );
5332  }
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.

5150  {
5151  return p_bothPtsAreInside( shape );
5152  }
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.

5157  {
5158  return p_bothPtsAreInside( shape );
5159  }

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

5164  {
5165  return p_bothPtsAreInside( shape );
5166  }

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

5171  {
5172  return false;
5173  }

◆ 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

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

5052  {
5053  return _ptS1.distTo( _ptS2 );
5054  }
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.

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

5023  {
5024  auto w = _ptS2.getX() - _ptS1.getX();
5025  auto h = _ptS2.getY() - _ptS1.getY();
5026  _ptS1 = pt;
5027  _ptS2.set( _ptS1.getX() + w, _ptS1.getY() + h );
5028  }
Point2d pt
Definition: homog2d_test.cpp:4052
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
5122  {
5123  return !(*this == s2);
5124  }

◆ operator-()

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

Reverse oriented segment.

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

◆ operator<()

template<typename SV, typename FPT>
bool h2d::base::SegVec< SV, FPT >::operator< ( const SegVec< SV, FPT > &  other) const
inline
5127  {
5128  return _ptS1 < other._ptS1;
5129  }
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
5114  {
5115  if( _ptS1 != s2._ptS1 )
5116  return false;
5117  if( _ptS2 != s2._ptS2 )
5118  return false;
5119  return true;
5120  }

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

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

4979  {
4980  set( ppts.first, ppts.second );
4981  }

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

4986  {
4991  set( Point2d_<FPT>(x1,y1), Point2d_<FPT>(x2,y2) );
4992  }
#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.

5046  {
5047  return 2;
5048  }

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

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

4997  {
5000  _ptS1.translate( dx, dy );
5001  _ptS2.translate( dx, dy );
5002  }
#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.

5007  {
5008  this->translate( pa.first, pa.second );
5009  }
void translate(T1 dx, T2 dy)
Translate Segment.
Definition: homog2d.hpp:4996
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.

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

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: