homog2d library
Namespaces | Classes | Functions
h2d::priv Namespace Reference

Holds private stuff. More...

Namespaces

 chull
 Holds convex hull code.
 
 runion
 Common stuff for FRect_ union, see FRect_::unionArea()
 

Classes

class  ClosestPoints
 Used in getClosestPoints() More...
 
struct  F_MAX
 
struct  F_MIN
 used in findPoint() More...
 
struct  PolylineAttribs
 Holds attribute of a Polyline, allows storage of last computed value through the use of ValueFlag. More...
 
class  ValueFlag
 A POD value that needs some computing, associated with its flag. Used to be able to retain a value needing complex calculation. More...
 

Functions

template<typename Cont , typename std::enable_if< trait::IsArray< Cont >::value, Cont >::type * = nullptr>
Cont alloc (std::size_t)
 Allocation for std::array container. More...
 
template<typename T >
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. More...
 
template<typename T >
void drawSvgSeg (img::Image< img::SvgImage > &im, const std::pair< Point2d_< T >, Point2d_< T >> &ppts, std::string color, int thickness, std::string attribs=std::string())
 
template<typename FPT , typename CONT , typename S_WHAT >
size_t findPoint (const Point2d_< FPT > &qpt, const CONT &cont, const S_WHAT &)
 Private. Common function for searching nearest of farthest point. More...
 
template<typename FPT >
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. More...
 
template<typename FPT >
std::array< PointPair_< double >, 3 > getArrowSegments (const base::SegVec< typ::IsOSeg, FPT > &vec)
 
template<typename FPT >
auto getBB_CommonType (const std::vector< CommonType_< FPT >> &v_var)
 Get Bounding Box for a container holding variant objects. More...
 
template<typename FPT >
auto getBB_FRect (const std::vector< FRect_< FPT >> &v_rects)
 get BB for a set of FRect_ objects More...
 
template<typename T , typename std::enable_if< trait::IsContainer< T >::value, T >::type * = nullptr>
PointPair_< typename T::value_type::FType > getBB_Points (const T &vpts)
 Returns the bounding box of points in vector/list/array of points vpts (free function) More...
 
template<typename T , typename std::enable_if< trait::IsContainer< T >::value, T >::type * = nullptr>
FRect_< typename T::value_type::FType > getBB_Segments (const T &vsegs)
 Returns the bounding box of segments in vector/list/array of points vsegs. More...
 
template<typename T >
auto getBmPoint_helper (const T &t)
 Return iterator on Bottom-most point of container holding points. More...
 
template<typename PT >
std::array< PT, 3 > getLargestDistancePoints (PT pt1, PT pt2, PT pt3)
 Helper function, used to check for colinearity of three points. More...
 
template<typename T1 , typename T2 >
Line2d_< T1 > getOrthogonalLine_B2 (const Point2d_< T2 > &pt, const Line2d_< T1 > &li)
 Helper function for impl_getOrthogonalLine_A() and impl_getOrthogonalLine_B(), Compute orthogonal line to li at point pt (that must lie on the line) More...
 
template<typename FPT , typename FPT2 , typename FPT3 >
auto getPoints_B2 (const Point2d_< FPT > &pt, FPT2 dist, const Line2d_< FPT3 > &li)
 Helper function, factorized here for the two impl_getPoints_A() implementations. More...
 
template<typename IMG , typename FPT >
void impl_drawIndexes (img::Image< IMG > &img, size_t c, const img::DrawParams &dp, const Point2d_< FPT > &pt)
 Draw indexes for points. More...
 
template<typename IMG , typename FPT >
void impl_drawIndexes (img::Image< IMG > &img, size_t c, const img::DrawParams &dp, const Segment_< FPT > &seg)
 Draw indexes for segment. More...
 
template<typename IMG , typename DUMMY >
void impl_drawIndexes (img::Image< IMG > &, size_t, const img::DrawParams &, const DUMMY &)
 Default signature, will be instanciated if no other fits (and does nothing) More...
 
template<typename T >
std::pair< int, int > impl_dsize (const detail::DataFpType< T > &)
 Implementation of dsize(), returns nb of bits of mantissa and exponent (default implementation) More...
 
template<long unsigned int M, long unsigned int E>
std::pair< int, int > impl_dsize (const detail::DataFpType< ttmath::Big< M, E >> &)
 Implementation for ttmath types. More...
 
Dtype impl_dtype (const detail::DataFpType< float > &)
 
Dtype impl_dtype (const detail::DataFpType< double > &)
 
Dtype impl_dtype (const detail::DataFpType< long double > &)
 
template<typename T >
Dtype impl_dtype (const detail::DataFpType< T > &)
 
template<long unsigned int M, long unsigned int E>
Dtype impl_dtype (const detail::DataFpType< ttmath::Big< M, E >> &)
 Implementation for ttmath types. More...
 
template<typename FPT1 , typename PT >
bool is_valid_circle (const Circle_< FPT1 > &circ, const std::vector< PT > &pts)
 Free Function to check whether a circle encloses the given points. More...
 
template<typename ST , typename PLT , typename FPT >
std::vector< ST > p_getSegs (const base::PolylineBase< PLT, FPT > &pl, const ST &)
 Private helper function for base::PolylineBase::getSegs() and base::PolylineBase::getOSegs() More...
 
template<typename T , size_t N>
void printArray (const std::array< T, N > &v, std::string msg=std::string())
 
template<typename T >
void printVector (const std::vector< T > &v, std::string msg=std::string(), bool linefeed=false)
 
template<typename T >
void printVectorPairs (const std::vector< std::pair< T, T >> &v)
 
template<typename T >
int sign (T val)
 Get sign of value. More...
 
template<typename FPT1 , typename FPT2 >
HOMOG2D_INUMTYPE sqDist (const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
 Free function, squared distance between points (sqrt not needed for comparisons, and can save some time) More...
 

Detailed Description

Holds private stuff.

Helper function used by the draw(OSegment) function, returns the 3 segment corresponding to the "arrows" as 3 pairs of points.

Used both in the SVG and the Opencv backends

   /|\
    |
    |
    |
   ---

Function Documentation

◆ alloc()

template<typename Cont , typename std::enable_if< trait::IsArray< Cont >::value, Cont >::type * = nullptr>
Cont h2d::priv::alloc ( std::size_t  nb)

Allocation for std::array container.

Allocation for std::vector and std::list container.

See also
operator * ( const Hmatrix_&, const Cont& );
9779 {
9780  return Cont();
9781 }

◆ drawSvgSeg() [1/2]

template<typename T >
void h2d::priv::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.

12146 {
12147  im.getReal()._svgString << "<line x1=\""
12148  << pt1.getX()
12149  << "\" y1=\""
12150  << pt1.getY()
12151  << "\" x2=\""
12152  << pt2.getX()
12153  << "\" y2=\""
12154  << pt2.getY()
12155  << "\" stroke=\"" << color
12156  << "\" stroke-width=\"" << thickness << "\" "
12157  << attribs << "/>\n";
12158 }
img::Image< img::SvgImage > im(300, 400)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawSvgSeg() [2/2]

template<typename T >
void h2d::priv::drawSvgSeg ( img::Image< img::SvgImage > &  im,
const std::pair< Point2d_< T >, Point2d_< T >> &  ppts,
std::string  color,
int  thickness,
std::string  attribs = std::string() 
)
12168 {
12169  drawSvgSeg( im, ppts.first, ppts.second, color, thickness, attribs );
12170 }
void drawSvgSeg(img::Image< img::SvgImage > &im, const std::pair< Point2d_< T >, Point2d_< T >> &ppts, std::string color, int thickness, std::string attribs=std::string())
Definition: homog2d.hpp:12161
img::Image< img::SvgImage > im(300, 400)

◆ findPoint()

template<typename FPT , typename CONT , typename S_WHAT >
size_t h2d::priv::findPoint ( const Point2d_< FPT > &  qpt,
const CONT &  cont,
const S_WHAT &   
)

Private. Common function for searching nearest of farthest point.

Parameters
qptquery point
contcontainer
11091 {
11092  if( cont.size() < 2 )
11093  HOMOG2D_THROW_ERROR_1( "container holds " << cont.size() \
11094  << " points, minimum is 2" );
11095 
11096  decltype( priv::sqDist( qpt, qpt ) ) resDist;
11097  size_t startIdx = 1;
11098  size_t resIdx = 0;
11099 
11100 // if point is the first one of the container, then
11101 // initialize with the second one
11102  if( cont[0] == qpt )
11103  {
11104  startIdx++;
11105  resIdx++;
11106  resDist = priv::sqDist( qpt, cont[1] );
11107  }
11108  else // initialize with first point
11109  {
11110  resDist = priv::sqDist( qpt, cont[0] );
11111  }
11112 
11113  for( size_t i=startIdx; i<cont.size(); i++ )
11114  {
11115  if( qpt != cont[i] )
11116  {
11117  auto currentDist = priv::sqDist( qpt, cont[i] );
11118  if constexpr( std::is_same_v<S_WHAT, F_MIN> )
11119  {
11120  if( currentDist < resDist )
11121  {
11122  resIdx = i;
11123  resDist = currentDist;
11124  }
11125  }
11126  else
11127  {
11128  if( currentDist > resDist )
11129  {
11130  resIdx = i;
11131  resDist = currentDist;
11132  }
11133  }
11134  }
11135  }
11136  return resIdx;
11137 }
HOMOG2D_INUMTYPE sqDist(const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
Free function, squared distance between points (sqrt not needed for comparisons, and can save some ti...
Definition: homog2d.hpp:3574
#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:

◆ fix_order()

template<typename FPT >
void h2d::priv::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.

3556 {
3557  if( !(ptA < ptB) )
3558  std::swap( ptA, ptB );
3559 }
Here is the caller graph for this function:

◆ getArrowSegments()

template<typename FPT >
std::array<PointPair_<double>,3> h2d::priv::getArrowSegments ( const base::SegVec< typ::IsOSeg, FPT > &  vec)
11809 {
11810  std::array<std::pair<Point2d_<double>,Point2d_<double>>,3> out;
11811  auto ppts = vec.getPts();
11812  auto pt1 = ppts.first;
11813  auto pt2 = ppts.second;
11814 
11815  const int arSize = 8;
11816 
11817  Line2d_<double> liA = vec.getLine().getOrthogLine( pt1 );
11818  out[0] = liA.getPoints( pt1, arSize );
11819 
11820  auto ppts_B = vec.getLine().getPoints( pt2, arSize );
11821 
11822  Point2d_<double> p0 = ppts_B.first;
11823  if( dist( pt1, ppts_B.first) > dist(pt1, ppts_B.second) )
11824  p0 = ppts_B.second;
11825 
11826  Line2d_<double> liB = vec.getLine().getOrthogLine( p0 );
11827  auto ppts_C = liB.getPoints( p0, arSize );
11828 
11829  out[1] = std::make_pair(ppts_C.first, pt2);
11830  out[2] = std::make_pair(ppts_C.second, pt2);
11831 
11832  return out;
11833 }
HOMOG2D_INUMTYPE dist(const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
Free function, distance between points.
Definition: homog2d.hpp:9848
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBB_CommonType()

template<typename FPT >
auto h2d::priv::getBB_CommonType ( const std::vector< CommonType_< FPT >> &  v_var)

Get Bounding Box for a container holding variant objects.

Note
Here, we DO NOT preallocate the vector, because if the container holds lines, then no point pair will be added for these elements. If we would have preallocate with 2 x size of input vector, then some default-constructed points could sneak in, and introduce an error.
Todo:
20240513: At present, this is only implemented for std::vector. Let it handle std::list and std::array.
10278 {
10279  HOMOG2D_START;
10280  HOMOG2D_DEBUG_ASSERT( v_var.size(), "cannot compute bounding box of empty set of variant" );
10281 
10282  std::vector<Point2d_<FPT>> vpts;
10283  vpts.reserve( v_var.size()*2 );
10284  PointPair_<FPT> ppair;
10285  for( const auto& elem: v_var )
10286  {
10287  try
10288  {
10289  ppair = std::visit( fct::PtPairFunct{}, elem );
10290  }
10291  catch( const std::exception& err )
10292  {
10293  HOMOG2D_LOG_WARNING( "unable to compute point pair\n -msg=" << err.what() );
10294  }
10295  vpts.push_back( ppair.first );
10296  vpts.push_back( ppair.second );
10297  }
10298  return FRect_<FPT>( getBB_Points( vpts ) );
10299 }
PointPair_< typename T::value_type::FType > getBB_Points(const T &vpts)
Returns the bounding box of points in vector/list/array of points vpts (free function) ...
Definition: homog2d.hpp:5904
#define HOMOG2D_START
Definition: homog2d.hpp:106
#define HOMOG2D_LOG_WARNING(a)
Definition: homog2d.hpp:151
#define HOMOG2D_DEBUG_ASSERT(a, b)
Assert debug macro, used internally if HOMOG2D_DEBUGMODE is defined.
Definition: homog2d.hpp:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBB_FRect()

template<typename FPT >
auto h2d::priv::getBB_FRect ( const std::vector< FRect_< FPT >> &  v_rects)

get BB for a set of FRect_ objects

Todo:
same as getBB_Segments() ???
5979 {
5980  HOMOG2D_START;
5981  HOMOG2D_DEBUG_ASSERT( v_rects.size(), "cannot compute bounding box of empty set of rectangles" );
5982 
5983  std::vector<Point2d_<FPT>> vpts( v_rects.size()*2 );
5984  auto it = vpts.begin();
5985  for( const auto& seg: v_rects )
5986  {
5987  auto ppts = seg.getPts();
5988  *it++ = ppts.first;
5989  *it++ = ppts.second;
5990  }
5991  return FRect_<FPT>( getBB_Points( vpts ) );
5992 }
PointPair_< typename T::value_type::FType > getBB_Points(const T &vpts)
Returns the bounding box of points in vector/list/array of points vpts (free function) ...
Definition: homog2d.hpp:5904
Segment seg
Definition: homog2d_test.cpp:4033
#define HOMOG2D_START
Definition: homog2d.hpp:106
#define HOMOG2D_DEBUG_ASSERT(a, b)
Assert debug macro, used internally if HOMOG2D_DEBUGMODE is defined.
Definition: homog2d.hpp:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBB_Points()

template<typename T , typename std::enable_if< trait::IsContainer< T >::value, T >::type * = nullptr>
PointPair_<typename T::value_type::FType> h2d::priv::getBB_Points ( const T &  vpts)

Returns the bounding box of points in vector/list/array of points vpts (free function)

Todo:
This loops twice on the points. Maybe some improvement here.
5905 {
5906  HOMOG2D_START;
5907  using FPT = typename T::value_type::FType;
5908  HOMOG2D_DEBUG_ASSERT( static_cast<bool>(vpts.size()), "cannot run with no points" );
5909 
5910  auto mm_x = std::minmax_element(
5911  std::begin( vpts ),
5912  std::end( vpts ),
5913  [] // lambda
5914  ( const Point2d_<FPT>& pt1, const Point2d_<FPT>& pt2 )
5915  {
5916  return pt1.getX() < pt2.getX();
5917  }
5918  );
5919  auto mm_y = std::minmax_element(
5920  std::begin( vpts ),
5921  std::end( vpts ),
5922  [] // lambda
5923  ( const Point2d_<FPT>& pt1, const Point2d_<FPT>& pt2 )
5924  {
5925  return pt1.getY() < pt2.getY();
5926  }
5927  );
5928 
5929  auto p1 = Point2d_<HOMOG2D_INUMTYPE>( mm_x.first->getX(), mm_y.first->getY() );
5930  auto p2 = Point2d_<HOMOG2D_INUMTYPE>( mm_x.second->getX(), mm_y.second->getY() );
5931 
5932 #ifndef HOMOG2D_NOCHECKS
5933  if( p1.distTo( p2 ) < thr::nullDistance() )
5935  "unable to compute bounding box of set, identical points:\n -p1:"<< p1 << "\n -p2:" << p2
5936  );
5937  if( shareCommonCoord( p1, p2 ) )
5939  "unable to compute bounding box of set, points share common coordinate:\n -p1:"
5940  << p1 << "\n -p2:" << p2
5941  );
5942 #endif // HOMOG2D_NOCHECKS
5943 
5944  return std::make_pair( p1, p2 );
5945 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1229
#define HOMOG2D_START
Definition: homog2d.hpp:106
#define HOMOG2D_DEBUG_ASSERT(a, b)
Assert debug macro, used internally if HOMOG2D_DEBUGMODE is defined.
Definition: homog2d.hpp:126
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
bool shareCommonCoord(const std::pair< Point2d_< FPT1 >, Point2d_< FPT2 >> &ppts)
Returns true if one of the points share a common coordinate (thus making them unable to define a boun...
Definition: homog2d.hpp:1336
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBB_Segments()

template<typename T , typename std::enable_if< trait::IsContainer< T >::value, T >::type * = nullptr>
FRect_<typename T::value_type::FType> h2d::priv::getBB_Segments ( const T &  vsegs)

Returns the bounding box of segments in vector/list/array of points vsegs.

5958 {
5959  HOMOG2D_START;
5960  using FPT = typename T::value_type::FType;
5961 
5962  HOMOG2D_DEBUG_ASSERT( vsegs.size(), "cannot compute bounding box of empty set of segments" );
5963  std::vector<Point2d_<FPT>> vpts( vsegs.size()*2 );
5964  auto it = vpts.begin();
5965  for( const auto& seg: vsegs )
5966  {
5967  auto ppts = seg.getPts();
5968  *it++ = ppts.first;
5969  *it++ = ppts.second;
5970  }
5971  return FRect_<typename T::value_type::FType>( getBB_Points( vpts ) );
5972 }
PointPair_< typename T::value_type::FType > getBB_Points(const T &vpts)
Returns the bounding box of points in vector/list/array of points vpts (free function) ...
Definition: homog2d.hpp:5904
Segment seg
Definition: homog2d_test.cpp:4033
#define HOMOG2D_START
Definition: homog2d.hpp:106
#define HOMOG2D_DEBUG_ASSERT(a, b)
Assert debug macro, used internally if HOMOG2D_DEBUGMODE is defined.
Definition: homog2d.hpp:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBmPoint_helper()

template<typename T >
auto h2d::priv::getBmPoint_helper ( const T &  t)

Return iterator on Bottom-most point of container holding points.

Used by

6880 {
6881  using FPT = typename T::value_type::FType;
6882 #ifndef HOMOG2D_NOCHECKS
6883  if( t.size() == 0 )
6884  HOMOG2D_THROW_ERROR_1( "invalid call, container is empty" );
6885 #endif
6886 
6887  return std::min_element(
6888  std::begin(t),
6889  std::end(t),
6890  [] // lambda
6891  ( const Point2d_<FPT>& pt1, const Point2d_<FPT>& pt2 )
6892  {
6893  if( pt1.getY() < pt2.getY() )
6894  return true;
6895  if( pt1.getY() > pt2.getY() )
6896  return false;
6897  return( pt1.getX() < pt2.getX() );
6898  }
6899  );
6900 }
#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:

◆ getLargestDistancePoints()

template<typename PT >
std::array<PT,3> h2d::priv::getLargestDistancePoints ( PT  pt1,
PT  pt2,
PT  pt3 
)

Helper function, used to check for colinearity of three points.

This will return the same points as given in input but ordered as:

  • the pair that has the largest distance in [0] and [1]
  • the third point in [2]
  • the point closest to the third point in [1], the farthest in [0]
See also
bool areCollinear()
Todo:
20220520: needs some optimization, once it has been extensively tested

We have theses 6 situations described on below diagrams A through F, with the desired output order:

 1 +                       1 +
   |    A => 3,1,2           |     B => 2,1,3
   |                         |
 2 +---------------+ 3     3 +---------------+ 2

 2 +                       2 +
   |    C => 3,2,1           |     D => 1,2,3
   |                         |
 1 +---------------+ 3     3 +---------------+ 1

 3 +                       3 +
   |    E => 2,3,1           |     F => 1,3,2
   |                         |
 1 +---------------+ 2     2 +---------------+ 1
3614 {
3615  auto d12 = sqDist( pt1, pt2 );
3616  auto d13 = sqDist( pt1, pt3 );
3617  auto d23 = sqDist( pt2, pt3 );
3618 
3619  PT* pA = 0;
3620  PT* pB = 0;
3621  PT* pM = 0;
3622 
3623  if( d12 > d13 ) // case B, D, E
3624  {
3625  pA = &pt2;
3626  if( d12 > d23 ) // case B, D
3627  {
3628  pB = &pt1;
3629  pM = &pt3;
3630  if( d13 > d23 )
3631  std::swap( *pA, *pB );
3632  }
3633  else // case E
3634  {
3635  pB = &pt3;
3636  pM = &pt1;
3637  }
3638  }
3639  else // case A, C, F
3640  {
3641  pA = &pt3;
3642  if( d13 > d23 ) // A, F
3643  {
3644  pB = &pt1;
3645  pM = &pt2;
3646  if( d12 > d23 )
3647  std::swap( *pA, *pB );
3648  }
3649  else // case C
3650  {
3651  pB = &pt2;
3652  pM = &pt1;
3653  }
3654  }
3655 
3656  return std::array<PT,3>{ *pA, *pB, *pM };
3657 }
HOMOG2D_INUMTYPE sqDist(const Point2d_< FPT1 > &pt1, const Point2d_< FPT2 > &pt2)
Free function, squared distance between points (sqrt not needed for comparisons, and can save some ti...
Definition: homog2d.hpp:3574
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOrthogonalLine_B2()

template<typename T1 , typename T2 >
Line2d_<T1> h2d::priv::getOrthogonalLine_B2 ( const Point2d_< T2 > &  pt,
const Line2d_< T1 > &  li 
)

Helper function for impl_getOrthogonalLine_A() and impl_getOrthogonalLine_B(), Compute orthogonal line to li at point pt (that must lie on the line)

3738 {
3739  auto arr = li.get(); // get array of 3 values
3740  Line2d_<T1> out(
3741  -arr[1],
3742  arr[0],
3743  arr[1] * pt.getX() - arr[0] * pt.getY()
3744  );
3745  out.p_normalizePL();
3746  return out;
3747 }
Line2d li
Definition: homog2d_test.cpp:4035
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPoints_B2()

template<typename FPT , typename FPT2 , typename FPT3 >
auto h2d::priv::getPoints_B2 ( const Point2d_< FPT > &  pt,
FPT2  dist,
const Line2d_< FPT3 > &  li 
)

Helper function, factorized here for the two impl_getPoints_A() implementations.

3715 {
3716  auto arr = li.get();
3717  const HOMOG2D_INUMTYPE a = static_cast<HOMOG2D_INUMTYPE>(arr[0]);
3718  const HOMOG2D_INUMTYPE b = static_cast<HOMOG2D_INUMTYPE>(arr[1]);
3719  auto coeff = static_cast<HOMOG2D_INUMTYPE>(dist) / homog2d_sqrt( a*a + b*b );
3720 
3721  Point2d_<FPT> pt1(
3722  pt.getX() - b * coeff,
3723  pt.getY() + a * coeff
3724  );
3725  Point2d_<FPT> pt2(
3726  pt.getX() + b * coeff,
3727  pt.getY() - a * coeff
3728  );
3729  fix_order( pt1, pt2 );
3730  return std::make_pair( pt1, pt2 );
3731 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
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_sqrt
Definition: homog2d.hpp:75
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
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:
Here is the caller graph for this function:

◆ impl_drawIndexes() [1/3]

template<typename IMG , typename FPT >
void h2d::priv::impl_drawIndexes ( img::Image< IMG > &  img,
size_t  c,
const img::DrawParams dp,
const Point2d_< FPT > &  pt 
)

Draw indexes for points.

11272 {
11273  if( dp._dpValues._showIndex )
11274  drawText( img, std::to_string(c), pt, dp );
11275 }
void drawText(img::Image< U > &im, std::string str, Point2d_< FPT > pt, img::DrawParams dp=img::DrawParams())
Free function, draws text str at position pt.
Definition: homog2d.hpp:11261
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:
Here is the caller graph for this function:

◆ impl_drawIndexes() [2/3]

template<typename IMG , typename FPT >
void h2d::priv::impl_drawIndexes ( img::Image< IMG > &  img,
size_t  c,
const img::DrawParams dp,
const Segment_< FPT > &  seg 
)

Draw indexes for segment.

11281 {
11282  if( dp._dpValues._showIndex )
11283  drawText( img, std::to_string(c), seg.getCenter(), dp );
11284 }
void drawText(img::Image< U > &im, std::string str, Point2d_< FPT > pt, img::DrawParams dp=img::DrawParams())
Free function, draws text str at position pt.
Definition: homog2d.hpp:11261
Segment seg
Definition: homog2d_test.cpp:4033
Here is the call graph for this function:

◆ impl_drawIndexes() [3/3]

template<typename IMG , typename DUMMY >
void h2d::priv::impl_drawIndexes ( img::Image< IMG > &  ,
size_t  ,
const img::DrawParams ,
const DUMMY &   
)

Default signature, will be instanciated if no other fits (and does nothing)

11290 {}

◆ impl_dsize() [1/2]

template<typename T >
std::pair<int,int> h2d::priv::impl_dsize ( const detail::DataFpType< T > &  )
inline

Implementation of dsize(), returns nb of bits of mantissa and exponent (default implementation)

1143  {
1144  return std::make_pair(
1145  std::numeric_limits<T>::digits,
1146  sizeof(T)*8-std::numeric_limits<T>::digits-1
1147  );
1148  }
Here is the caller graph for this function:

◆ impl_dsize() [2/2]

template<long unsigned int M, long unsigned int E>
std::pair<int,int> h2d::priv::impl_dsize ( const detail::DataFpType< ttmath::Big< M, E >> &  )
inline

Implementation for ttmath types.

1183  {
1184  return std::make_pair( M*sizeof(size_t)*8, E*sizeof(size_t)*8 );
1185  }

◆ impl_dtype() [1/5]

Dtype h2d::priv::impl_dtype ( const detail::DataFpType< float > &  )
inline
1152  {
1153  return Dtype::Float;
1154  }
Here is the caller graph for this function:

◆ impl_dtype() [2/5]

Dtype h2d::priv::impl_dtype ( const detail::DataFpType< double > &  )
inline
1157  {
1158  return Dtype::Double;
1159  }

◆ impl_dtype() [3/5]

Dtype h2d::priv::impl_dtype ( const detail::DataFpType< long double > &  )
inline
1162  {
1163  return Dtype::LongDouble;
1164  }

◆ impl_dtype() [4/5]

template<typename T >
Dtype h2d::priv::impl_dtype ( const detail::DataFpType< T > &  )
inline
1168  {
1169  return Dtype::Other;
1170  }

◆ impl_dtype() [5/5]

template<long unsigned int M, long unsigned int E>
Dtype h2d::priv::impl_dtype ( const detail::DataFpType< ttmath::Big< M, E >> &  )
inline

Implementation for ttmath types.

1176  {
1177  return Dtype::Ttmath;
1178  }

◆ is_valid_circle()

template<typename FPT1 , typename PT >
bool h2d::priv::is_valid_circle ( const Circle_< FPT1 > &  circ,
const std::vector< PT > &  pts 
)

Free Function to check whether a circle encloses the given points.

5635 {
5636  for( const auto& pt: pts )
5637  if( !pt.isInside( circ ) )
5638  return false;
5639  return true;
5640 }
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:

◆ p_getSegs()

template<typename ST , typename PLT , typename FPT >
std::vector<ST> h2d::priv::p_getSegs ( const base::PolylineBase< PLT, FPT > &  pl,
const ST &   
)

Private helper function for base::PolylineBase::getSegs() and base::PolylineBase::getOSegs()

5998 {
5999  auto siz = pl.size();
6000  if( siz < 2 ) // nothing to return
6001  return std::vector<ST>();
6002 
6003  std::vector<ST> out;
6004  out.reserve( siz );
6005  for( size_t i=0; i<siz-1; i++ )
6006  {
6007  const auto& pt1 = pl.getPoint(i);
6008  const auto& pt2 = pl.getPoint(i+1);
6009  out.emplace_back( ST(pt1,pt2) );
6010  }
6011  if constexpr( std::is_same_v<PLT,typ::IsClosed> )
6012  out.push_back( ST(pl.getPoint(siz-1), pl.getPoint(0) ) );
6013  return out;
6014 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ printArray()

template<typename T , size_t N>
void h2d::priv::printArray ( const std::array< T, N > &  v,
std::string  msg = std::string() 
)
1207 {
1208  std::cout << "array: " << msg << " #=" << N << '\n';
1209  for( const auto& elem: v )
1210  std::cout << elem << "-";
1211  std::cout << '\n';
1212 }

◆ printVector()

template<typename T >
void h2d::priv::printVector ( const std::vector< T > &  v,
std::string  msg = std::string(),
bool  linefeed = false 
)
1191 {
1192  std::cout << "vector: ";
1193  if( !msg.empty() )
1194  std::cout << msg;
1195  std::cout << " #=" << v.size() << '\n';
1196  size_t c=0;
1197  for( const auto& elem: v )
1198  {
1199  if( linefeed )
1200  std::cout << c++ << ": ";
1201  std::cout << elem << (linefeed?'\n':'-');
1202  }
1203  std::cout << '\n';
1204 }

◆ printVectorPairs()

template<typename T >
void h2d::priv::printVectorPairs ( const std::vector< std::pair< T, T >> &  v)
1215 {
1216  std::cout << "vector of pairs: #=" << v.size() << '\n';
1217  for( const auto& elem: v )
1218  std::cout << " [" << (int)elem.first << "-" << (int)elem.second << "] ";
1219  std::cout << '\n';
1220 }

◆ sign()

template<typename T >
int h2d::priv::sign ( val)

Get sign of value.

source: https://stackoverflow.com/a/4609795/

3564  {
3565  return (T(0) < val) - (val < T(0));
3566 }
Here is the caller graph for this function:

◆ sqDist()

template<typename FPT1 , typename FPT2 >
HOMOG2D_INUMTYPE h2d::priv::sqDist ( const Point2d_< FPT1 > &  pt1,
const Point2d_< FPT2 > &  pt2 
)

Free function, squared distance between points (sqrt not needed for comparisons, and can save some time)

See also
Point2d_::distTo()
dist( const Point2d_&, const Point2d_& )
3575 {
3576  auto dx = (HOMOG2D_INUMTYPE)pt1.getX() - pt2.getX();
3577  auto dy = (HOMOG2D_INUMTYPE)pt1.getY() - pt2.getY();
3578  return dx*dx + dy*dy;
3579 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
Here is the call graph for this function:
Here is the caller graph for this function: