Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libnest2d::pointlike Namespace Reference

Functions

template<class P >
TCoord< P > x (const P &p)
 
template<class P >
TCoord< P > y (const P &p)
 
template<class P >
TCoord< P > & x (P &p)
 
template<class P >
TCoord< P > & y (P &p)
 
template<class P , class Unit = TCompute<P>>
Unit squaredDistance (const P &p1, const P &p2)
 
template<class P >
double distance (const P &p1, const P &p2)
 
template<class Pt >
Pt perp (const Pt &p)
 
template<class Pt , class Unit = TCompute<Pt>>
Unit dotperp (const Pt &a, const Pt &b)
 
template<class Pt , class Unit = TCompute<Pt>>
Unit dot (const Pt &a, const Pt &b)
 
template<class Pt , class Unit = TCompute<Pt>>
Unit magnsq (const Pt &p)
 
template<class P , class Unit = TCompute<P>>
std::pair< Unit, bool > horizontalDistance (const P &p, const _Segment< P > &s)
 
template<class P , class Unit = TCompute<P>>
std::pair< Unit, bool > verticalDistance (const P &p, const _Segment< P > &s)
 

Function Documentation

◆ distance()

template<class P >
double libnest2d::pointlike::distance ( const P &  p1,
const P &  p2 
)
inline
330{
331 return std::sqrt(squaredDistance<P, double>(p1, p2));
332}

Referenced by libnest2d::placers::minimizeCircle(), Slic3r::arrangement::AutoArranger< TBin >::objfunc(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::overfit(), and libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::trypack().

+ Here is the caller graph for this function:

◆ dot()

template<class Pt , class Unit = TCompute<Pt>>
Unit libnest2d::pointlike::dot ( const Pt &  a,
const Pt &  b 
)
inline
349{
350 return Unit(x(a)) * x(b) + Unit(y(a)) * y(b);
351}
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297

References x(), and y().

Referenced by libnest2d::nfp::nfpConvexOnly(), and libnest2d::rotcalipers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dotperp()

template<class Pt , class Unit = TCompute<Pt>>
Unit libnest2d::pointlike::dotperp ( const Pt &  a,
const Pt &  b 
)
inline
342{
343 return Unit(x(a)) * Unit(y(b)) - Unit(y(a)) * Unit(x(b));
344}

References x(), and y().

Referenced by libnest2d::nfp::nfpConvexOnly().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ horizontalDistance()

template<class P , class Unit = TCompute<P>>
std::pair< Unit, bool > libnest2d::pointlike::horizontalDistance ( const P &  p,
const _Segment< P > &  s 
)
inline
363{
364 namespace pl = pointlike;
365 auto x = Unit(pl::x(p)), y = Unit(pl::y(p));
366 auto x1 = Unit(pl::x(s.first())), y1 = Unit(pl::y(s.first()));
367 auto x2 = Unit(pl::x(s.second())), y2 = Unit(pl::y(s.second()));
368
369 Unit ret;
370
371 if( (y < y1 && y < y2) || (y > y1 && y > y2) )
372 return {0, false};
373 if ((y == y1 && y == y2) && (x > x1 && x > x2))
374 ret = std::min( x-x1, x -x2);
375 else if( (y == y1 && y == y2) && (x < x1 && x < x2))
376 ret = -std::min(x1 - x, x2 - x);
377 else if(y == y1 && y == y2)
378 ret = 0;
379 else
380 ret = x - x1 + (x1 - x2)*(y1 - y)/(y1 - y2);
381
382 return {ret, true};
383}
const P & first() const BP2D_NOEXCEPT
Get the first point.
Definition geometry_traits.hpp:263
const P & second() const BP2D_NOEXCEPT
The end point.
Definition geometry_traits.hpp:269

References libnest2d::_Segment< P >::first(), libnest2d::_Segment< P >::second(), x(), and y().

+ Here is the call graph for this function:

◆ magnsq()

template<class Pt , class Unit = TCompute<Pt>>
Unit libnest2d::pointlike::magnsq ( const Pt &  p)
inline
356{
357 return Unit(x(p)) * x(p) + Unit(y(p)) * y(p);
358}

References x(), and y().

Referenced by libnest2d::nfp::nfpConvexOnly(), and libnest2d::rotcalipers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ perp()

template<class Pt >
Pt libnest2d::pointlike::perp ( const Pt &  p)
inline
336{
337 return Pt(y(p), -x(p));
338}

References x(), and y().

Referenced by libnest2d::rectarea(), and libnest2d::rotcalipers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ squaredDistance()

template<class P , class Unit = TCompute<P>>
Unit libnest2d::pointlike::squaredDistance ( const P &  p1,
const P &  p2 
)
inline
322{
323 auto x1 = Unit(x(p1)), y1 = Unit(y(p1)), x2 = Unit(x(p2)), y2 = Unit(y(p2));
324 Unit a = (x2 - x1), b = (y2 - y1);
325 return a * a + b * b;
326}

References x(), and y().

Referenced by libnest2d::shapelike::isInside().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ verticalDistance()

template<class P , class Unit = TCompute<P>>
std::pair< Unit, bool > libnest2d::pointlike::verticalDistance ( const P &  p,
const _Segment< P > &  s 
)
inline
388{
389 namespace pl = pointlike;
390 auto x = Unit(pl::x(p)), y = Unit(pl::y(p));
391 auto x1 = Unit(pl::x(s.first())), y1 = Unit(pl::y(s.first()));
392 auto x2 = Unit(pl::x(s.second())), y2 = Unit(pl::y(s.second()));
393
394 Unit ret;
395
396 if( (x < x1 && x < x2) || (x > x1 && x > x2) )
397 return {0, false};
398 if ((x == x1 && x == x2) && (y > y1 && y > y2))
399 ret = std::min( y-y1, y -y2);
400 else if( (x == x1 && x == x2) && (y < y1 && y < y2))
401 ret = -std::min(y1 - y, y2 - y);
402 else if(x == x1 && x == x2)
403 ret = 0;
404 else
405 ret = y - y1 + (y1 - y2)*(x1 - x)/(x1 - x2);
406
407 return {ret, true};
408}

References libnest2d::_Segment< P >::first(), libnest2d::_Segment< P >::second(), x(), and y().

+ Here is the call graph for this function:

◆ x() [1/2]

template<class P >
TCoord< P > libnest2d::pointlike::x ( const P &  p)
inline
298{
299 return p.x();
300}

Referenced by dot(), dotperp(), horizontalDistance(), magnsq(), perp(), squaredDistance(), verticalDistance(), and libnest2d::_Box< P >::width().

+ Here is the caller graph for this function:

◆ x() [2/2]

template<class P >
TCoord< P > & libnest2d::pointlike::x ( P &  p)
inline
310{
311 return p.x();
312}

◆ y() [1/2]

template<class P >
TCoord< P > libnest2d::pointlike::y ( const P &  p)
inline
304{
305 return p.y();
306}

Referenced by dot(), dotperp(), libnest2d::_Box< P >::height(), horizontalDistance(), magnsq(), perp(), squaredDistance(), and verticalDistance().

+ Here is the caller graph for this function:

◆ y() [2/2]

template<class P >
TCoord< P > & libnest2d::pointlike::y ( P &  p)
inline
316{
317 return p.y();
318}