Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libnest2d::_Segment< P > Class Template Reference

An abstraction of a directed line segment with two points. More...

#include <src/libnest2d/include/libnest2d/geometry_traits.hpp>

+ Inheritance diagram for libnest2d::_Segment< P >:
+ Collaboration diagram for libnest2d::_Segment< P >:

Public Types

using PointType = P
 

Public Member Functions

 _Segment ()=default
 
 _Segment (const P &p, const P &pp)
 
const P & first () const BP2D_NOEXCEPT
 Get the first point.
 
const P & second () const BP2D_NOEXCEPT
 The end point.
 
void first (const P &p) BP2D_NOEXCEPT
 
void second (const P &p) BP2D_NOEXCEPT
 
Radians angleToXaxis () const
 Returns the angle measured to the X (horizontal) axis.
 
template<class Unit = TCompute<P>>
Unit sqlength () const
 The length of the segment in the measure of the coordinate system.
 

Private Attributes

Radians angletox_ = std::nan("")
 
p1
 
p2
 

Detailed Description

template<class P>
class libnest2d::_Segment< P >

An abstraction of a directed line segment with two points.

Member Typedef Documentation

◆ PointType

template<class P >
using libnest2d::_Segment< P >::PointType = P

Constructor & Destructor Documentation

◆ _Segment() [1/2]

template<class P >
libnest2d::_Segment< P >::_Segment ( )
inlinedefault

◆ _Segment() [2/2]

template<class P >
libnest2d::_Segment< P >::_Segment ( const P &  p,
const P &  pp 
)
inline
256 :
257 PointPair<P>({p, pp}) {}

Member Function Documentation

◆ angleToXaxis()

template<class P >
Radians libnest2d::_Segment< P >::angleToXaxis
inline

Returns the angle measured to the X (horizontal) axis.

443{
444 if(std::isnan(static_cast<double>(angletox_))) {
445 TCoord<P> dx = getX(second()) - getX(first());
446 TCoord<P> dy = getY(second()) - getY(first());
447
448 double a = std::atan2(dy, dx);
449 auto s = std::signbit(a);
450
451 if(s) a += Pi_2;
452 angletox_ = a;
453 }
454 return angletox_;
455}
Radians angletox_
Definition geometry_traits.hpp:249
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
TCoord< P > getX(const P &p)
Definition geometry_traits.hpp:424
TCoord< P > getY(const P &p)
Definition geometry_traits.hpp:427
const double BP2D_CONSTEXPR Pi_2
Definition common.hpp:98

References libnest2d::getX(), libnest2d::getY(), and libnest2d::Pi_2.

+ Here is the call graph for this function:

◆ first() [1/2]

template<class P >
const P & libnest2d::_Segment< P >::first ( ) const
inline

Get the first point.

Returns
Returns the starting point.
263{ return p1; }
P p1
Definition geometry_traits.hpp:164

References libnest2d::PointPair< P >::p1.

Referenced by boost::geometry::traits::indexed_access< bp2d::Segment, 0, 0 >::get(), boost::geometry::traits::indexed_access< bp2d::Segment, 0, 1 >::get(), libnest2d::pointlike::horizontalDistance(), boost::geometry::traits::indexed_access< bp2d::Segment, 0, 0 >::set(), boost::geometry::traits::indexed_access< bp2d::Segment, 0, 1 >::set(), and libnest2d::pointlike::verticalDistance().

+ Here is the caller graph for this function:

◆ first() [2/2]

template<class P >
void libnest2d::_Segment< P >::first ( const P &  p)
inline
272 {
273 angletox_ = std::nan(""); p1 = p;
274 }

References libnest2d::_Segment< P >::angletox_, and libnest2d::PointPair< P >::p1.

◆ second() [1/2]

template<class P >
const P & libnest2d::_Segment< P >::second ( ) const
inline

The end point.

Returns
Returns the end point of the segment.
269{ return p2; }
P p2
Definition geometry_traits.hpp:165

References libnest2d::PointPair< P >::p2.

Referenced by boost::geometry::traits::indexed_access< bp2d::Segment, 1, 0 >::get(), boost::geometry::traits::indexed_access< bp2d::Segment, 1, 1 >::get(), libnest2d::pointlike::horizontalDistance(), boost::geometry::traits::indexed_access< bp2d::Segment, 1, 0 >::set(), boost::geometry::traits::indexed_access< bp2d::Segment, 1, 1 >::set(), and libnest2d::pointlike::verticalDistance().

+ Here is the caller graph for this function:

◆ second() [2/2]

template<class P >
void libnest2d::_Segment< P >::second ( const P &  p)
inline
276 {
277 angletox_ = std::nan(""); p2 = p;
278 }

References libnest2d::_Segment< P >::angletox_, and libnest2d::PointPair< P >::p2.

◆ sqlength()

template<class P >
template<class Unit >
Unit libnest2d::_Segment< P >::sqlength
inline

The length of the segment in the measure of the coordinate system.

460{
461 return pointlike::squaredDistance<P, Unit>(first(), second());
462}

Member Data Documentation

◆ angletox_

template<class P >
Radians libnest2d::_Segment< P >::angletox_ = std::nan("")
mutableprivate

◆ p1

◆ p2


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