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

An abstraction of a box;. More...

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

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

Public Types

using Tag = BoxTag
 
using PointType = P
 

Public Member Functions

 _Box (const P &center={TCoord< P >(0), TCoord< P >(0)})
 
 _Box (const P &p, const P &pp)
 
 _Box (TCoord< P > width, TCoord< P > height, const P &p={TCoord< P >(0), TCoord< P >(0)})
 
const P & minCorner () const BP2D_NOEXCEPT
 
const P & maxCorner () const BP2D_NOEXCEPT
 
P & minCorner () BP2D_NOEXCEPT
 
P & maxCorner () BP2D_NOEXCEPT
 
TCoord< P > width () const BP2D_NOEXCEPT
 
TCoord< P > height () const BP2D_NOEXCEPT
 
center () const BP2D_NOEXCEPT
 
template<class Unit = TCompute<P>>
Unit area () const BP2D_NOEXCEPT
 

Static Public Member Functions

static _Box infinite (const P &center={TCoord< P >(0), TCoord< P >(0)})
 

Private Attributes

p1
 
p2
 

Detailed Description

template<class P>
class libnest2d::_Box< P >

An abstraction of a box;.

Member Typedef Documentation

◆ PointType

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

◆ Tag

template<class P >
using libnest2d::_Box< P >::Tag = BoxTag

Constructor & Destructor Documentation

◆ _Box() [1/3]

template<class P >
libnest2d::_Box< P >::_Box ( const P &  center = {TCoord<P>(0), TCoord<P>(0)})
inline
180 {TCoord<P>(0), TCoord<P>(0)}):
181 _Box(TCoord<P>(0), TCoord<P>(0), center) {}
_Box(const P &center={TCoord< P >(0), TCoord< P >(0)})
Definition geometry_traits.hpp:180
P center() const BP2D_NOEXCEPT
Definition geometry_traits.hpp:499
typename CoordType< remove_cvref_t< GeomType > >::Type TCoord
TCoord<GeomType> as shorthand for typename CoordType<GeomType>::Type.
Definition geometry_traits.hpp:56

◆ _Box() [2/3]

template<class P >
libnest2d::_Box< P >::_Box ( const P &  p,
const P &  pp 
)
inline
183 :
184 PointPair<P>({p, pp}) {}

◆ _Box() [3/3]

template<class P >
libnest2d::_Box< P >::_Box ( TCoord< P >  width,
TCoord< P >  height,
const P &  p = {TCoord<P>(0), TCoord<P>(0)} 
)
inline
476 :
477 PointPair<P>({center - P{width / 2, height / 2},
478 center + P{width / 2, height / 2} +
479 P{modulo(width, TCoord<P>(2)),
480 modulo(height, TCoord<P>(2))}}) {}
TCoord< P > width() const BP2D_NOEXCEPT
Definition geometry_traits.hpp:412
TCoord< P > height() const BP2D_NOEXCEPT
Definition geometry_traits.hpp:418
enable_if_t< std::is_floating_point< T >::value, T > modulo(const T &v, const T &m)
Definition geometry_traits.hpp:465

References libnest2d::_Box< P >::center(), libnest2d::_Box< P >::height(), libnest2d::modulo(), and libnest2d::_Box< P >::width().

+ Here is the call graph for this function:

Member Function Documentation

◆ area()

template<class P >
template<class Unit = TCompute<P>>
Unit libnest2d::_Box< P >::area ( ) const
inline
202 {
203 constexpr TCoord<P> Zero{0};
204 Unit s = width() < Zero || height() < Zero ? Unit(-1) : Unit(1);
205 return s * libnest2d::abs(Unit(width()) * height());
206 }
int64_t Unit
Definition MinAreaBoundingBox.cpp:23
T abs(const T &v, ScalarTag)
A local version for abs that is garanteed to work with libnest2d types.
Definition common.hpp:213

References libnest2d::abs(), libnest2d::_Box< P >::height(), and libnest2d::_Box< P >::width().

Referenced by Slic3r::arrangement::fixed_overfit().

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

◆ center()

template<class P >
P libnest2d::_Box< P >::center
inline
499 {
500 auto& minc = minCorner();
501 auto& maxc = maxCorner();
502
503 using Coord = TCoord<P>;
504
505 P ret = { // No rounding here, we dont know if these are int coords
506 // Doing the division like this increases the max range of x and y coord
507 getX(minc) / Coord(2) + getX(maxc) / Coord(2),
508 getY(minc) / Coord(2) + getY(maxc) / Coord(2)
509 };
510
511 return ret;
512}
const P & minCorner() const BP2D_NOEXCEPT
Definition geometry_traits.hpp:190
const P & maxCorner() const BP2D_NOEXCEPT
Definition geometry_traits.hpp:191
TCoord< P > getX(const P &p)
Definition geometry_traits.hpp:424
TCoord< PointImpl > Coord
Definition libnest2d.hpp:30
TCoord< P > getY(const P &p)
Definition geometry_traits.hpp:427

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

Referenced by libnest2d::_Box< P >::_Box(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::finalAlign(), Slic3r::arrangement::AutoArranger< TBin >::objfunc(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::overfit(), and libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::setInitialPosition().

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

◆ height()

template<class P >
TCoord< P > libnest2d::_Box< P >::height
inline
419{
421}
TCoord< P > y(const P &p)
Definition geometry_traits.hpp:303

References libnest2d::pointlike::y().

Referenced by libnest2d::_Box< P >::_Box(), libnest2d::placers::_BottomLeftPlacer< RawShape >::_trypack(), libnest2d::_Box< P >::area(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::overfit(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::overfit(), and libnest2d::svg::SVGWriter< RawShape >::setSize().

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

◆ infinite()

template<class P >
_Box< P > libnest2d::_Box< P >::infinite ( const P &  center = {TCoord<P>(0), TCoord<P>(0)})
inlinestatic
483 {
484 using C = TCoord<P>;
485 _Box<P> ret;
486
487 // It is important for Mx and My to be strictly less than half of the
488 // range of type C. width(), height() and area() will not overflow this way.
489 C Mx = C((std::numeric_limits<C>::lowest() + 2 * getX(center)) / 4.01);
490 C My = C((std::numeric_limits<C>::lowest() + 2 * getY(center)) / 4.01);
491
492 ret.maxCorner() = center - P{Mx, My};
493 ret.minCorner() = center + P{Mx, My};
494
495 return ret;
496}

References libnest2d::getX(), libnest2d::getY(), libnest2d::_Box< P >::maxCorner(), and libnest2d::_Box< P >::minCorner().

+ Here is the call graph for this function:

◆ maxCorner() [1/2]

template<class P >
P & libnest2d::_Box< P >::maxCorner ( )
inline
194{ return p2; }
P p2
Definition geometry_traits.hpp:165

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

◆ maxCorner() [2/2]

◆ minCorner() [1/2]

template<class P >
P & libnest2d::_Box< P >::minCorner ( )
inline
193{ return p1; }
P p1
Definition geometry_traits.hpp:164

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

◆ minCorner() [2/2]

◆ width()

template<class P >
TCoord< P > libnest2d::_Box< P >::width
inline
413{
415}
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297

References libnest2d::pointlike::x().

Referenced by libnest2d::_Box< P >::_Box(), libnest2d::placers::_BottomLeftPlacer< RawShape >::_trypack(), libnest2d::_Box< P >::area(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::overfit(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::overfit(), and libnest2d::svg::SVGWriter< RawShape >::setSize().

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

Member Data Documentation

◆ p1

◆ p2


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