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

Namespaces

namespace  __nfp
 
namespace  __parallel
 
namespace  nfp
 A collection of static methods for handling the no fit polygon creation.
 
namespace  opt
 
namespace  placers
 
namespace  pointlike
 
namespace  selections
 
namespace  shapelike
 
namespace  svg
 

Classes

class  _Box
 An abstraction of a box;. More...
 
class  _Circle
 
class  _Item
 An item to be placed on a bin. More...
 
class  _Nester
 
struct  _NumTag
 
struct  _NumTag< boost::rational< T > >
 
struct  _NumTag< LargeInt >
 
class  _Rectangle
 Subclass of _Item for regular rectangle items. More...
 
class  _Segment
 An abstraction of a directed line segment with two points. More...
 
struct  always_false
 
struct  BigIntTag
 
struct  BoxTag
 
struct  CircleTag
 
struct  ClosureType
 
struct  ClosureType< Slic3r::Points >
 
struct  ClosureType< Slic3r::Polygon >
 
struct  ComputeType
 Getting the computation type for a certain geometry type. It is the coordinate type by default but it is advised that a type with larger precision and (or) range is specified. More...
 
struct  ComputeType< GeomClass, false >
 A compute type is introduced to hold the results of computations on coordinates and points. It should be larger in range than the coordinate type or the range of coordinates should be limited to not loose precision. More...
 
struct  ComputeType< I, true >
 
struct  ConstItemRange
 
struct  ContourType
 Meta function to derive the contour type for a polygon which could be itself. More...
 
struct  ContourType< DefaultMultiShape< S > >
 
struct  ContourType< Slic3r::ExPolygon >
 
struct  ContourType< Slic3r::ExPolygons >
 
struct  CoordType
 Getting the coordinate data type for a geometry class. More...
 
struct  CoordType< Slic3r::Point >
 
struct  CoordType< Slic3r::Vec2crd >
 
struct  DefaultMultiShape
 The default multi shape container. More...
 
class  Degrees
 Data type representing degrees. It supports conversion to radians. More...
 
struct  DErr
 
class  Double
 Only for the Radian and Degrees classes to behave as doubles. More...
 
struct  DoublePrecision
 libnest2d will choose a default compute type for various coordinate types if the backend has not specified anything. More...
 
struct  DoublePrecision< double >
 
struct  DoublePrecision< float >
 
struct  DoublePrecision< int16_t >
 
struct  DoublePrecision< int32_t >
 
struct  DoublePrecision< int8_t >
 
struct  DOut
 
struct  genSeq
 
struct  genSeq< 0, Nseq... >
 
struct  genSeq< I, Nseq... >
 
class  GeometryException
 
struct  HolesContainer
 A meta function to derive a container type for holes in a polygon. More...
 
struct  HolesContainer< Slic3r::ExPolygon >
 
struct  index_sequence
 C++11 compatible implementation of the index_sequence type from C++14. More...
 
struct  invoke_result
 
struct  MultiPolygonTag
 
struct  MultiShape
 The MultiShape Type trait which gets the container type for a geometry type. More...
 
struct  MultiShape< Slic3r::ExPolygon >
 
struct  NestConfig
 
struct  NestControl
 
struct  OrientationType
 
struct  OrientationType< Slic3r::Points >
 
struct  OrientationType< Slic3r::Polygon >
 
struct  PathTag
 
class  PlacementStrategyLike
 A wrapper interface (trait) class for any placement strategy provider. More...
 
struct  PointPair
 A point pair base class for other point pairs (segment, box, ...). More...
 
struct  PointTag
 
struct  PointType
 Getting the type of point structure used by a shape. More...
 
struct  PointType< _Box< S > >
 
struct  PointType< _Circle< S > >
 
struct  PointType< _Segment< S > >
 
struct  PointType< Slic3r::Points >
 
struct  PointType< Slic3r::Polygon >
 
struct  PointType< std::vector< Slic3r::Vec2crd > >
 
struct  PolygonTag
 
class  Radians
 Data type representing radians. It supports conversion to degrees. More...
 
struct  RationalTag
 
struct  remove_cvref
 
class  RotatedBox
 
struct  ScalarTag
 
class  SelectionStrategyLike
 
struct  ShapeTag
 Meta-function to derive the tag of a shape type. More...
 
struct  ShapeTag< Slic3r::ExPolygon >
 
struct  ShapeTag< Slic3r::ExPolygons >
 
struct  ShapeTag< Slic3r::Point >
 
struct  ShapeTag< Slic3r::Points >
 
struct  ShapeTag< Slic3r::Polygon >
 
struct  ShapeTag< Slic3r::Vec2crd >
 
struct  ShapeTag< std::vector< Slic3r::Vec2crd > >
 

Typedefs

template<class T >
using Vec = Slic3r::Vec< 2, T >
 
using PointImpl = Slic3r::Point
 
using PathImpl = Slic3r::Polygon
 
using HoleStore = Slic3r::Polygons
 
using PolygonImpl = Slic3r::ExPolygon
 
template<class T >
using remove_cvref_t = typename remove_cvref< T >::type
 
template<class T >
using remove_ref_t = typename std::remove_reference< T >::type
 
template<bool B, class T >
using enable_if_t = typename std::enable_if< B, T >::type
 
template<class F , class... Args>
using invoke_result_t = typename invoke_result< F, Args... >::type
 
template<class T >
using NumTag = typename _NumTag< remove_cvref_t< T > >::Type
 
template<class S >
using Tag = typename ShapeTag< remove_cvref_t< S > >::Type
 Tag will be used instead of typename ShapeTag<S>::Type
 
template<class S >
using TContour = typename ContourType< remove_cvref_t< S > >::Type
 TContour instead of typename ContourType<S>::type
 
template<class Shape >
using TPoint = typename PointType< remove_cvref_t< Shape > >::Type
 TPoint<ShapeClass> as shorthand for typename PointType<ShapeClass>::Type.
 
template<class GeomType >
using TCoord = typename CoordType< remove_cvref_t< GeomType > >::Type
 TCoord<GeomType> as shorthand for typename CoordType<GeomType>::Type.
 
template<class T >
using TCompute = typename ComputeType< remove_cvref_t< T > >::Type
 TCompute<T> shorthand for typename ComputeType<T>::Type
 
template<class S >
using THolesContainer = typename HolesContainer< remove_cvref_t< S > >::Type
 Shorthand for typename HolesContainer<S>::Type
 
template<class S >
using TMultiShape = typename MultiShape< remove_cvref_t< S > >::Type
 use TMultiShape instead of typename MultiShape<S>::Type
 
using Point = PointImpl
 
using Coord = TCoord< PointImpl >
 
using Box = _Box< PointImpl >
 
using Segment = _Segment< PointImpl >
 
using Circle = _Circle< PointImpl >
 
using MultiPolygon = TMultiShape< PolygonImpl >
 
using Item = _Item< PolygonImpl >
 
using Rectangle = _Rectangle< PolygonImpl >
 
using PackGroup = _PackGroup< PolygonImpl >
 
using FillerSelection = selections::_FillerSelection< PolygonImpl >
 
using FirstFitSelection = selections::_FirstFitSelection< PolygonImpl >
 
using DJDHeuristic = selections::_DJDHeuristic< PolygonImpl >
 
template<class Bin >
using _NfpPlacer = placers::_NofitPolyPlacer< PolygonImpl, Bin >
 
using NfpPlacer = _NfpPlacer< Box >
 
using BottomLeftPlacer = placers::_BottomLeftPlacer< PolygonImpl >
 
template<class RawShape >
using _ItemRef = std::reference_wrapper< _Item< RawShape > >
 
template<class RawShape >
using _ItemGroup = std::vector< _ItemRef< RawShape > >
 
template<class RawShape >
using _PackGroup = std::vector< std::vector< _ItemRef< RawShape > > >
 A list of packed item vectors. Each vector represents a bin.
 
using ProgressFunction = std::function< void(unsigned)>
 
using StopCondition = std::function< bool(void)>
 
template<size_t N>
using make_index_sequence = typename genSeq< N >::Type
 Helper alias to make an index sequence from 0 to N.
 
template<class... Args>
using index_sequence_for = make_index_sequence< sizeof...(Args)>
 Helper alias to make an index sequence for a parameter pack.
 
using LargeInt = boost::multiprecision::int128_t
 

Enumerations

enum class  GeomErr : std::size_t { OFFSET , MERGE , NFP }
 
enum class  Orientation { CLOCKWISE , COUNTER_CLOCKWISE }
 
enum class  Closure { OPEN , CLOSED }
 
enum class  Formats { WKT , SVG }
 

Functions

template<class T >
DOut && operator<< (DOut &&out, T &&d)
 
template<class T >
DErr && operator<< (DErr &&out, T &&d)
 
DOut dout ()
 
DErr derr ()
 
bool operator== (const Degrees &deg, const Radians &rads)
 
bool operator== (const Radians &rads, const Degrees &deg)
 
template<class T >
abs (const T &v, ScalarTag)
 A local version for abs that is garanteed to work with libnest2d types.
 
template<class T >
abs (const T &v)
 
template<class T2 , class T1 >
T2 cast (const T1 &v, ScalarTag, ScalarTag)
 
template<class T2 , class T1 >
T2 cast (const T1 &v)
 
template<class T >
constexpr bool is_clockwise ()
 
template<class P >
TCoord< P > getX (const P &p)
 
template<class P >
TCoord< P > getY (const P &p)
 
template<class P >
void setX (P &p, const TCoord< P > &val)
 
template<class P >
void setY (P &p, const TCoord< P > &val)
 
template<class T >
enable_if_t< std::is_floating_point< T >::value, T > modulo (const T &v, const T &m)
 
template<class T >
enable_if_t< std::is_integral< T >::value, T > modulo (const T &v, const T &m)
 
template<class Placer = NfpPlacer, class Selector = FirstFitSelection, class Iterator = std::vector<Item>::iterator>
std::size_t nest (Iterator from, Iterator to, const typename Placer::BinType &bin, Coord dist=0, const NestConfig< Placer, Selector > &cfg={}, NestControl ctl={})
 
template<class Placer = NfpPlacer, class Selector = FirstFitSelection, class Container = std::vector<Item>>
std::size_t nest (Container &&cont, const typename Placer::BinType &bin, Coord dist=0, const NestConfig< Placer, Selector > &cfg={}, NestControl ctl={})
 
template<class T = double>
enable_if_t< std::is_arithmetic< T >::value, TCoord< PointImpl > > mm (T val=T(1))
 
template<class Sh >
Sh create_rect (TCoord< Sh > width, TCoord< Sh > height)
 
template<class Container >
ConstItemRange< typename Container::const_iterator > rem (typename Container::const_iterator it, const Container &cont)
 
template<class Poly , class Pt = TPoint<Poly>, class Unit = TCompute<Pt>>
Poly removeCollinearPoints (const Poly &sh, Unit eps=Unit(0))
 
template<class Pt , class Unit = TCompute<Pt>, class R = TCompute<Pt>>
rectarea (const Pt &w, const Pt &vb, const Pt &vr, const Pt &vt, const Pt &vl)
 
template<class Pt , class Unit = TCompute<Pt>, class R = TCompute<Pt>, class It = typename std::vector<Pt>::const_iterator>
rectarea (const Pt &w, const std::array< It, 4 > &rect)
 
template<class Pt , class Unit = TCompute<Pt>, class R = TCompute<Pt>>
rectarea (const Pt &w, const Unit &a, const Unit &b)
 
template<class R , class Pt , class Unit >
rectarea (const RotatedBox< Pt, Unit > &rb)
 
template<class RawShape , class Unit = TCompute<RawShape>, class Ratio = TCompute<RawShape>, class VisitFn >
void rotcalipers (const RawShape &sh, VisitFn &&visitfn)
 
template<class S , class Unit = TCompute<S>, class Ratio = TCompute<S>>
RotatedBox< TPoint< S >, Unit > minAreaBoundingBox (const S &sh)
 
template<class RawShape >
Radians minAreaBoundingBoxRotation (const RawShape &sh)
 
template<class S , class Unit = TCompute<S>, class Ratio = TCompute<S>>
Radians fitIntoBoxRotation (const S &shape, const _Box< TPoint< S > > &box, Radians eps=1e-4)
 
template<class RawShape >
Radians findBestRotation (_Item< RawShape > &item)
 
template<class Iterator >
void findMinimumBoundingBoxRotations (Iterator from, Iterator to)
 
template std::size_t nest (std::vector< Item >::iterator from, std::vector< Item >::iterator to, const Box &bin, Coord dist, const NestConfig< NfpPlacer, FirstFitSelection > &cfg, NestControl ctl)
 
template std::size_t nest (std::vector< Item >::iterator from, std::vector< Item >::iterator to, const Box &bin, Coord dist, const NestConfig< BottomLeftPlacer, FirstFitSelection > &cfg, NestControl ctl)
 

Variables

const double BP2D_CONSTEXPR Pi = 3.141592653589793238463
 
const double BP2D_CONSTEXPR Pi_2 = 2*Pi
 
const std::string ERROR_STR []
 
template<class T >
const constexpr Orientation OrientationTypeV
 
template<class T >
const constexpr Closure ClosureTypeV
 
static const constexpr int BIN_ID_UNSET = -1
 

Class Documentation

◆ libnest2d::_NumTag

struct libnest2d::_NumTag
template<class T>
struct libnest2d::_NumTag< T >
Class Members
typedef value, ScalarTag > Type

◆ libnest2d::_NumTag< boost::rational< T > >

struct libnest2d::_NumTag< boost::rational< T > >
template<class T>
struct libnest2d::_NumTag< boost::rational< T > >
Class Members
typedef RationalTag Type

◆ libnest2d::_NumTag< LargeInt >

struct libnest2d::_NumTag< LargeInt >
Class Members
typedef ScalarTag Type

◆ libnest2d::BigIntTag

struct libnest2d::BigIntTag

◆ libnest2d::BoxTag

struct libnest2d::BoxTag

◆ libnest2d::CircleTag

struct libnest2d::CircleTag

◆ libnest2d::ComputeType

struct libnest2d::ComputeType
template<class T, bool = std::is_arithmetic<T>::value>
struct libnest2d::ComputeType< T, bool >

Getting the computation type for a certain geometry type. It is the coordinate type by default but it is advised that a type with larger precision and (or) range is specified.

◆ libnest2d::ComputeType< GeomClass, false >

struct libnest2d::ComputeType< GeomClass, false >
template<class GeomClass>
struct libnest2d::ComputeType< GeomClass, false >

A compute type is introduced to hold the results of computations on coordinates and points. It should be larger in range than the coordinate type or the range of coordinates should be limited to not loose precision.

Class Members
typedef typename ComputeType< TCoord< GeomClass > >::Type Type

◆ libnest2d::ComputeType< I, true >

struct libnest2d::ComputeType< I, true >
template<class I>
struct libnest2d::ComputeType< I, true >
Class Members
typedef typename Type Type

◆ libnest2d::ContourType

struct libnest2d::ContourType
template<class S>
struct libnest2d::ContourType< S >

Meta function to derive the contour type for a polygon which could be itself.

Class Members
typedef S Type

◆ libnest2d::ContourType< DefaultMultiShape< S > >

struct libnest2d::ContourType< DefaultMultiShape< S > >
template<class S>
struct libnest2d::ContourType< DefaultMultiShape< S > >
Class Members
typedef typename Type Type

◆ libnest2d::ContourType< Slic3r::ExPolygon >

struct libnest2d::ContourType< Slic3r::ExPolygon >
Class Members
typedef Polygon Type

◆ libnest2d::ContourType< Slic3r::ExPolygons >

struct libnest2d::ContourType< Slic3r::ExPolygons >
Class Members
typedef Polygon Type

◆ libnest2d::DErr

struct libnest2d::DErr
+ Collaboration diagram for libnest2d::DErr:
Class Members
ostream & out = std::cerr

◆ libnest2d::DoublePrecision

struct libnest2d::DoublePrecision
template<class T>
struct libnest2d::DoublePrecision< T >

libnest2d will choose a default compute type for various coordinate types if the backend has not specified anything.

Class Members
typedef T Type

◆ libnest2d::DoublePrecision< double >

struct libnest2d::DoublePrecision< double >
Class Members
typedef long double Type

◆ libnest2d::DoublePrecision< float >

struct libnest2d::DoublePrecision< float >
Class Members
typedef double Type

◆ libnest2d::DoublePrecision< int16_t >

struct libnest2d::DoublePrecision< int16_t >
Class Members
typedef int32_t Type

◆ libnest2d::DoublePrecision< int32_t >

struct libnest2d::DoublePrecision< int32_t >
Class Members
typedef int64_t Type

◆ libnest2d::DoublePrecision< int8_t >

struct libnest2d::DoublePrecision< int8_t >
Class Members
typedef int16_t Type

◆ libnest2d::DOut

struct libnest2d::DOut
+ Collaboration diagram for libnest2d::DOut:
Class Members
ostream & out = std::cout

◆ libnest2d::genSeq

struct libnest2d::genSeq
template<size_t... Nseq>
struct libnest2d::genSeq< Nseq >

◆ libnest2d::genSeq< 0, Nseq... >

struct libnest2d::genSeq< 0, Nseq... >
template<size_t ... Nseq>
struct libnest2d::genSeq< 0, Nseq... >
Class Members
typedef index_sequence< Nseq... > Type

◆ libnest2d::genSeq< I, Nseq... >

struct libnest2d::genSeq< I, Nseq... >
template<size_t I, size_t... Nseq>
struct libnest2d::genSeq< I, Nseq... >
Class Members
typedef typename Type Type

◆ libnest2d::HolesContainer

struct libnest2d::HolesContainer
template<class S>
struct libnest2d::HolesContainer< S >

A meta function to derive a container type for holes in a polygon.

Class Members
typedef vector< TContour< S > > Type

◆ libnest2d::HolesContainer< Slic3r::ExPolygon >

struct libnest2d::HolesContainer< Slic3r::ExPolygon >
Class Members
typedef Polygons Type

◆ libnest2d::invoke_result

struct libnest2d::invoke_result
template<class F, class... Args>
struct libnest2d::invoke_result< F, Args >
Class Members
typedef typename type type

◆ libnest2d::MultiPolygonTag

struct libnest2d::MultiPolygonTag

◆ libnest2d::MultiShape

struct libnest2d::MultiShape
template<class S>
struct libnest2d::MultiShape< S >

The MultiShape Type trait which gets the container type for a geometry type.

Class Members
typedef DefaultMultiShape< S > Type

◆ libnest2d::MultiShape< Slic3r::ExPolygon >

struct libnest2d::MultiShape< Slic3r::ExPolygon >
Class Members
typedef ExPolygons Type

◆ libnest2d::PathTag

struct libnest2d::PathTag

◆ libnest2d::PointTag

struct libnest2d::PointTag

◆ libnest2d::PointType

struct libnest2d::PointType
template<class Sh>
struct libnest2d::PointType< Sh >

Getting the type of point structure used by a shape.

Class Members
typedef typename PointType< TContour< Sh > >::Type Type

◆ libnest2d::PointType< _Box< S > >

struct libnest2d::PointType< _Box< S > >
template<class S>
struct libnest2d::PointType< _Box< S > >
Class Members
typedef typename PointType Type

◆ libnest2d::PointType< _Circle< S > >

struct libnest2d::PointType< _Circle< S > >
template<class S>
struct libnest2d::PointType< _Circle< S > >
Class Members
typedef typename PointType Type

◆ libnest2d::PointType< _Segment< S > >

struct libnest2d::PointType< _Segment< S > >
template<class S>
struct libnest2d::PointType< _Segment< S > >
Class Members
typedef typename PointType Type

◆ libnest2d::PointType< Slic3r::Points >

struct libnest2d::PointType< Slic3r::Points >
Class Members
typedef Point Type

◆ libnest2d::PointType< Slic3r::Polygon >

struct libnest2d::PointType< Slic3r::Polygon >
Class Members
typedef Point Type

◆ libnest2d::PointType< std::vector< Slic3r::Vec2crd > >

struct libnest2d::PointType< std::vector< Slic3r::Vec2crd > >
Class Members
typedef Vec2crd Type

◆ libnest2d::PolygonTag

struct libnest2d::PolygonTag

◆ libnest2d::RationalTag

struct libnest2d::RationalTag

◆ libnest2d::remove_cvref

struct libnest2d::remove_cvref
template<class T>
struct libnest2d::remove_cvref< T >
Class Members
typedef typename type >::type type

◆ libnest2d::ScalarTag

struct libnest2d::ScalarTag

◆ libnest2d::ShapeTag

struct libnest2d::ShapeTag
template<class Shape>
struct libnest2d::ShapeTag< Shape >

Meta-function to derive the tag of a shape type.

Class Members
typedef typename Tag Type

◆ libnest2d::ShapeTag< Slic3r::ExPolygon >

struct libnest2d::ShapeTag< Slic3r::ExPolygon >
Class Members
typedef PolygonTag Type

◆ libnest2d::ShapeTag< Slic3r::ExPolygons >

struct libnest2d::ShapeTag< Slic3r::ExPolygons >
Class Members
typedef MultiPolygonTag Type

◆ libnest2d::ShapeTag< Slic3r::Point >

struct libnest2d::ShapeTag< Slic3r::Point >
Class Members
typedef PointTag Type

◆ libnest2d::ShapeTag< Slic3r::Points >

struct libnest2d::ShapeTag< Slic3r::Points >
Class Members
typedef PathTag Type

◆ libnest2d::ShapeTag< Slic3r::Polygon >

struct libnest2d::ShapeTag< Slic3r::Polygon >
Class Members
typedef PathTag Type

◆ libnest2d::ShapeTag< Slic3r::Vec2crd >

struct libnest2d::ShapeTag< Slic3r::Vec2crd >
Class Members
typedef PointTag Type

◆ libnest2d::ShapeTag< std::vector< Slic3r::Vec2crd > >

struct libnest2d::ShapeTag< std::vector< Slic3r::Vec2crd > >
Class Members
typedef PathTag Type

Typedef Documentation

◆ _ItemGroup

template<class RawShape >
using libnest2d::_ItemGroup = typedef std::vector<_ItemRef<RawShape> >

◆ _ItemRef

template<class RawShape >
using libnest2d::_ItemRef = typedef std::reference_wrapper<_Item<RawShape> >

◆ _NfpPlacer

template<class Bin >
using libnest2d::_NfpPlacer = typedef placers::_NofitPolyPlacer<PolygonImpl, Bin>

◆ _PackGroup

template<class RawShape >
using libnest2d::_PackGroup = typedef std::vector<std::vector<_ItemRef<RawShape> >>

A list of packed item vectors. Each vector represents a bin.

◆ BottomLeftPlacer

◆ Box

using libnest2d::Box = typedef _Box<PointImpl>

◆ Circle

◆ Coord

using libnest2d::Coord = typedef TCoord<PointImpl>

◆ DJDHeuristic

◆ enable_if_t

template<bool B, class T >
using libnest2d::enable_if_t = typedef typename std::enable_if<B, T>::type

◆ FillerSelection

◆ FirstFitSelection

◆ HoleStore

◆ index_sequence_for

template<class... Args>
using libnest2d::index_sequence_for = typedef make_index_sequence<sizeof...(Args)>

Helper alias to make an index sequence for a parameter pack.

◆ invoke_result_t

template<class F , class... Args>
using libnest2d::invoke_result_t = typedef typename invoke_result<F, Args...>::type

◆ Item

using libnest2d::Item = typedef _Item<PolygonImpl>

◆ LargeInt

using libnest2d::LargeInt = typedef boost::multiprecision::int128_t

◆ make_index_sequence

template<size_t N>
using libnest2d::make_index_sequence = typedef typename genSeq<N>::Type

Helper alias to make an index sequence from 0 to N.

◆ MultiPolygon

◆ NfpPlacer

◆ NumTag

template<class T >
using libnest2d::NumTag = typedef typename _NumTag<remove_cvref_t<T> >::Type

◆ PackGroup

◆ PathImpl

◆ Point

using libnest2d::Point = typedef PointImpl

◆ PointImpl

◆ PolygonImpl

◆ ProgressFunction

using libnest2d::ProgressFunction = typedef std::function<void(unsigned)>

◆ Rectangle

◆ remove_cvref_t

template<class T >
using libnest2d::remove_cvref_t = typedef typename remove_cvref<T>::type

◆ remove_ref_t

template<class T >
using libnest2d::remove_ref_t = typedef typename std::remove_reference<T>::type

◆ Segment

◆ StopCondition

using libnest2d::StopCondition = typedef std::function<bool(void)>

◆ Tag

template<class S >
using libnest2d::Tag = typedef typename ShapeTag<remove_cvref_t<S> >::Type

Tag will be used instead of typename ShapeTag<S>::Type

◆ TCompute

template<class T >
using libnest2d::TCompute = typedef typename ComputeType<remove_cvref_t<T> >::Type

TCompute<T> shorthand for typename ComputeType<T>::Type

◆ TContour

template<class S >
using libnest2d::TContour = typedef typename ContourType<remove_cvref_t<S> >::Type

TContour instead of typename ContourType<S>::type

◆ TCoord

template<class GeomType >
using libnest2d::TCoord = typedef typename CoordType<remove_cvref_t<GeomType> >::Type

TCoord<GeomType> as shorthand for typename CoordType<GeomType>::Type.

◆ THolesContainer

template<class S >
using libnest2d::THolesContainer = typedef typename HolesContainer<remove_cvref_t<S> >::Type

Shorthand for typename HolesContainer<S>::Type

◆ TMultiShape

template<class S >
using libnest2d::TMultiShape = typedef typename MultiShape<remove_cvref_t<S> >::Type

use TMultiShape instead of typename MultiShape<S>::Type

◆ TPoint

template<class Shape >
using libnest2d::TPoint = typedef typename PointType<remove_cvref_t<Shape> >::Type

TPoint<ShapeClass> as shorthand for typename PointType<ShapeClass>::Type.

◆ Vec

template<class T >
using libnest2d::Vec = typedef Slic3r::Vec<2, T>

Enumeration Type Documentation

◆ Closure

enum class libnest2d::Closure
strong
Enumerator
OPEN 
CLOSED 

◆ Formats

enum class libnest2d::Formats
strong
Enumerator
WKT 
SVG 
514 {
515 WKT,
516 SVG
517};

◆ GeomErr

enum class libnest2d::GeomErr : std::size_t
strong
Enumerator
OFFSET 
MERGE 
NFP 
171 : std::size_t {
172 OFFSET,
173 MERGE,
174 NFP
175};

◆ Orientation

enum class libnest2d::Orientation
strong
Enumerator
CLOCKWISE 
COUNTER_CLOCKWISE 

Function Documentation

◆ abs() [1/2]

template<class T >
T libnest2d::abs ( const T &  v)
inline
218{ return abs(v, NumTag<T>()); }
typename _NumTag< remove_cvref_t< T > >::Type NumTag
Definition common.hpp:210

◆ abs() [2/2]

template<class T >
T libnest2d::abs ( const T &  v,
ScalarTag   
)
inline

A local version for abs that is garanteed to work with libnest2d types.

214{
215 return std::abs(v);
216}

Referenced by libnest2d::_Box< P >::area().

+ Here is the caller graph for this function:

◆ cast() [1/2]

template<class T2 , class T1 >
T2 libnest2d::cast ( const T1 &  v)
inline
225 {
226 return cast<T2, T1>(v, NumTag<T1>(), NumTag<T2>());
227}

◆ cast() [2/2]

template<class T2 , class T1 >
T2 libnest2d::cast ( const T1 &  v,
ScalarTag  ,
ScalarTag   
)
inline
221{
222 return static_cast<T2>(v);
223}

◆ create_rect()

template<class Sh >
Sh libnest2d::create_rect ( TCoord< Sh >  width,
TCoord< Sh >  height 
)
468{
469 auto sh = sl::create<Sh>(
470 {{0, 0}, {0, height}, {width, height}, {width, 0}});
471
472 if constexpr (ClosureTypeV<Sh> == Closure::CLOSED)
473 sl::addVertex(sh, {0, 0});
474
475 if constexpr (OrientationTypeV<Sh> == Orientation::COUNTER_CLOCKWISE)
476 std::reverse(sl::begin(sh), sl::end(sh));
477
478 return sh;
479}
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:539
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:540

References libnest2d::shapelike::addVertex(), libnest2d::shapelike::begin(), CLOSED, COUNTER_CLOCKWISE, and libnest2d::shapelike::end().

+ Here is the call graph for this function:

◆ derr()

DErr libnest2d::derr ( )
inline
64{ return DErr(); }
Definition common.hpp:42

Referenced by libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::trypack().

+ Here is the caller graph for this function:

◆ dout()

DOut libnest2d::dout ( )
inline
63{ return DOut(); }
Definition common.hpp:36

Referenced by libnest2d::shapelike::offset(), and libnest2d::selections::_DJDHeuristic< RawShape >::packItems().

+ Here is the caller graph for this function:

◆ findBestRotation()

template<class RawShape >
Radians libnest2d::findBestRotation ( _Item< RawShape > &  item)
11 {
12 opt::StopCriteria stopcr;
13 stopcr.absolute_score_difference = 0.01;
14 stopcr.max_iterations = 10000;
16
17 auto orig_rot = item.rotation();
18
19 auto result = solver.optimize_min([&item, &orig_rot](Radians rot){
20 item.rotation(orig_rot + rot);
21 auto bb = item.boundingBox();
22 return std::sqrt(bb.height()*bb.width());
23 }, opt::initvals(Radians(0)), opt::bound<Radians>(-Pi/2, Pi/2));
24
25 item.rotation(orig_rot);
26
27 return std::get<0>(result.optimum);
28}
Radians rotation() const BP2D_NOEXCEPT
Definition nester.hpp:326
Box boundingBox() const
Definition nester.hpp:382
Data type representing radians. It supports conversion to degrees.
Definition common.hpp:119
typename OptimizerSubclass< m >::Type TOptimizer
Optimizer type based on the method provided in parameter m.
Definition optimizer.hpp:242
double absolute_score_difference
If the absolute value difference between two scores.
Definition optimizer.hpp:102
unsigned max_iterations
The max allowed number of iterations.
Definition optimizer.hpp:115
A type for specifying the stop criteria.
Definition optimizer.hpp:99

References libnest2d::opt::StopCriteria::absolute_score_difference, libnest2d::_Item< RawShape >::boundingBox(), libnest2d::opt::initvals(), libnest2d::opt::StopCriteria::max_iterations, Pi, and libnest2d::_Item< RawShape >::rotation().

Referenced by findMinimumBoundingBoxRotations().

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

◆ findMinimumBoundingBoxRotations()

template<class Iterator >
void libnest2d::findMinimumBoundingBoxRotations ( Iterator  from,
Iterator  to 
)
31 {
32 using V = typename std::iterator_traits<Iterator>::value_type;
33 std::for_each(from, to, [](V& item){
34 Radians rot = findBestRotation(item);
35 item.rotate(rot);
36 });
37}
Radians findBestRotation(_Item< RawShape > &item)
Definition rotfinder.hpp:11

References findBestRotation().

+ Here is the call graph for this function:

◆ fitIntoBoxRotation()

template<class S , class Unit = TCompute<S>, class Ratio = TCompute<S>>
Radians libnest2d::fitIntoBoxRotation ( const S &  shape,
const _Box< TPoint< S > > &  box,
Radians  eps = 1e-4 
)
312{
313 constexpr auto get_aspect_r = [](const auto &b) -> double {
314 return double(b.width()) / b.height();
315 };
316
317 auto aspect_r = get_aspect_r(box);
318
319 RotatedBox<TPoint<S>, Unit> prev_rbox;
320 Radians a_from = 0., a_to = 0.;
321 auto visitfn = [&](const RotatedBox<TPoint<S>, Unit> &rbox) {
322 bool lower_prev = get_aspect_r(prev_rbox) < aspect_r;
323 bool lower_current = get_aspect_r(rbox) < aspect_r;
324
325 if (lower_prev != lower_current) {
326 a_from = prev_rbox.angleToX();
327 a_to = rbox.angleToX();
328 return false;
329 }
330
331 return true;
332 };
333
334 rotcalipers<S, Unit, Ratio>(shape, visitfn);
335
336 auto rot_shape_bb = [&shape](Radians r) {
337 auto s = shape;
338 sl::rotate(s, r);
339 return sl::boundingBox(s);
340 };
341
342 auto rot_aspect_r = [&rot_shape_bb, &get_aspect_r](Radians r) {
343 return get_aspect_r(rot_shape_bb(r));
344 };
345
346 // Lets bisect the retrieved interval where the correct aspect ratio is.
347 double ar_from = rot_aspect_r(a_from);
348 auto would_fit = [&box](const _Box<TPoint<S>> &b) {
349 return b.width() < box.width() && b.height() < box.height();
350 };
351
352 Radians middle = (a_from + a_to) / 2.;
353 _Box<TPoint<S>> box_middle = rot_shape_bb(middle);
354 while (!would_fit(box_middle) && std::abs(a_to - a_from) > eps)
355 {
356 double ar_middle = get_aspect_r(box_middle);
357 if ((ar_from < aspect_r) != (ar_middle < aspect_r))
358 a_to = middle;
359 else
360 a_from = middle;
361
362 ar_from = rot_aspect_r(a_from);
363 middle = (a_from + a_to) / 2.;
364 box_middle = rot_shape_bb(middle);
365 }
366
367 return middle;
368}
TCoord< P > width() const BP2D_NOEXCEPT
Definition geometry_traits.hpp:412
TCoord< P > height() const BP2D_NOEXCEPT
Definition geometry_traits.hpp:418

References libnest2d::RotatedBox< Pt, Unit >::angleToX(), libnest2d::shapelike::boundingBox(), and libnest2d::shapelike::rotate().

+ Here is the call graph for this function:

◆ getX()

template<class P >
TCoord< P > libnest2d::getX ( const P &  p)
424{ return pointlike::x<P>(p); }

References getX().

Referenced by libnest2d::placers::_BottomLeftPlacer< RawShape >::_trypack(), libnest2d::__nfp::_vsort(), libnest2d::RotatedBox< Pt, Unit >::angleToX(), libnest2d::_Segment< P >::angleToXaxis(), libnest2d::shapelike::area(), libnest2d::placers::_BottomLeftPlacer< RawShape >::availableSpace(), libnest2d::shapelike::boundingBox(), libnest2d::shapelike::boundingBox(), libnest2d::_Box< P >::center(), libnest2d::shapelike::convexHull(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::finalAlign(), boost::geometry::traits::access< bp2d::PointImpl, 0 >::get(), getX(), libnest2d::_Box< P >::infinite(), libnest2d::shapelike::isConvex(), libnest2d::shapelike::isInside(), libnest2d::shapelike::isInside(), libnest2d::placers::minimizeCircle(), Slic3r::arrangement::AutoArranger< TBin >::objfunc(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::placeOutsideOfBin(), rotcalipers(), libnest2d::shapelike::serialize< libnest2d::Formats::SVG >(), libnest2d::placers::_BottomLeftPlacer< RawShape >::setInitialPosition(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::setInitialPosition(), libnest2d::placers::_BottomLeftPlacer< RawShape >::toWallPoly(), libnest2d::_Item< RawShape >::vsort(), and libnest2d::_Rectangle< Sh >::width().

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

◆ getY()

template<class P >
TCoord< P > libnest2d::getY ( const P &  p)
427{ return pointlike::y<P>(p); }

References getY().

Referenced by libnest2d::placers::_BottomLeftPlacer< RawShape >::_trypack(), libnest2d::__nfp::_vsort(), libnest2d::RotatedBox< Pt, Unit >::angleToX(), libnest2d::_Segment< P >::angleToXaxis(), libnest2d::shapelike::area(), libnest2d::placers::_BottomLeftPlacer< RawShape >::availableSpace(), libnest2d::shapelike::boundingBox(), libnest2d::shapelike::boundingBox(), libnest2d::_Box< P >::center(), libnest2d::shapelike::convexHull(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::finalAlign(), boost::geometry::traits::access< bp2d::PointImpl, 1 >::get(), getY(), libnest2d::_Rectangle< Sh >::height(), libnest2d::_Box< P >::infinite(), libnest2d::shapelike::isConvex(), libnest2d::shapelike::isInside(), libnest2d::shapelike::isInside(), libnest2d::placers::minimizeCircle(), Slic3r::arrangement::AutoArranger< TBin >::objfunc(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::placeOutsideOfBin(), rotcalipers(), libnest2d::shapelike::serialize< libnest2d::Formats::SVG >(), libnest2d::placers::_BottomLeftPlacer< RawShape >::setInitialPosition(), libnest2d::placers::_NofitPolyPlacer< RawShape, TBin >::setInitialPosition(), libnest2d::placers::_BottomLeftPlacer< RawShape >::toWallPoly(), libnest2d::_Item< RawShape >::vsort(), and libnest2d::svg::SVGWriter< RawShape >::writeShape().

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

◆ is_clockwise()

template<class T >
constexpr bool libnest2d::is_clockwise ( )
inlineconstexpr
140 {
141 return OrientationType<TContour<T>>::Value == Orientation::CLOCKWISE;
142}
Definition geometry_traits.hpp:134

References CLOCKWISE.

◆ minAreaBoundingBox()

template<class S , class Unit = TCompute<S>, class Ratio = TCompute<S>>
RotatedBox< TPoint< S >, Unit > libnest2d::minAreaBoundingBox ( const S &  sh)
278{
279 RotatedBox<TPoint<S>, Unit> minbox;
280 Ratio minarea = std::numeric_limits<Unit>::max();
281 auto minfn = [&minarea, &minbox](const RotatedBox<TPoint<S>, Unit> &rbox){
282 Ratio area = rectarea<Ratio>(rbox);
283 if (area <= minarea) {
284 minarea = area;
285 minbox = rbox;
286 }
287
288 return true; // continue search
289 };
290
291 rotcalipers<S, Unit, Ratio>(sh, minfn);
292
293 return minbox;
294}
Definition rotcalipers.hpp:13

Referenced by minAreaBoundingBoxRotation().

+ Here is the caller graph for this function:

◆ minAreaBoundingBoxRotation()

template<class RawShape >
Radians libnest2d::minAreaBoundingBoxRotation ( const RawShape &  sh)
297{
298 return minAreaBoundingBox(sh).angleToX();
299}
RotatedBox< TPoint< S >, Unit > minAreaBoundingBox(const S &sh)
Definition rotcalipers.hpp:277

References minAreaBoundingBox().

+ Here is the call graph for this function:

◆ mm()

template<class T = double>
enable_if_t< std::is_arithmetic< T >::value, TCoord< PointImpl > > libnest2d::mm ( val = T(1))
138{
140}
typename CoordType< remove_cvref_t< GeomType > >::Type TCoord
TCoord<GeomType> as shorthand for typename CoordType<GeomType>::Type.
Definition geometry_traits.hpp:56
Getting the coordinate data type for a geometry class.
Definition geometry_traits.hpp:49

◆ modulo() [1/2]

template<class T >
enable_if_t< std::is_floating_point< T >::value, T > libnest2d::modulo ( const T &  v,
const T &  m 
)
466{
467 return 0;
468}

Referenced by libnest2d::_Box< P >::_Box().

+ Here is the caller graph for this function:

◆ modulo() [2/2]

template<class T >
enable_if_t< std::is_integral< T >::value, T > libnest2d::modulo ( const T &  v,
const T &  m 
)
471{
472 return v % m;
473}

◆ nest() [1/4]

template<class Placer = NfpPlacer, class Selector = FirstFitSelection, class Container = std::vector<Item>>
std::size_t libnest2d::nest ( Container &&  cont,
const typename Placer::BinType &  bin,
Coord  dist = 0,
const NestConfig< Placer, Selector > &  cfg = {},
NestControl  ctl = {} 
)
131 {},
132 NestControl ctl = {})
133{
134 return nest<Placer, Selector>(cont.begin(), cont.end(), bin, dist, cfg, ctl);
135}

◆ nest() [2/4]

template<class Placer = NfpPlacer, class Selector = FirstFitSelection, class Iterator = std::vector<Item>::iterator>
std::size_t libnest2d::nest ( Iterator  from,
Iterator  to,
const typename Placer::BinType &  bin,
Coord  dist = 0,
const NestConfig< Placer, Selector > &  cfg = {},
NestControl  ctl = {} 
)
97 {},
98 NestControl ctl = {})
99{
100 _Nester<Placer, Selector> nester{bin, dist, cfg.placer_config, cfg.selector_config};
101 if(ctl.progressfn) nester.progressIndicator(ctl.progressfn);
102 if(ctl.stopcond) nester.stopCondition(ctl.stopcond);
103 return nester.execute(from, to);
104}
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:280
Placer::Config placer_config
Definition libnest2d.hpp:66
Selector::Config selector_config
Definition libnest2d.hpp:67
StopCondition stopcond
Definition libnest2d.hpp:81
ProgressFunction progressfn
Definition libnest2d.hpp:80

◆ nest() [3/4]

template std::size_t libnest2d::nest ( std::vector< Item >::iterator  from,
std::vector< Item >::iterator  to,
const Box bin,
Coord  dist,
const NestConfig< BottomLeftPlacer, FirstFitSelection > &  cfg,
NestControl  ctl 
)

◆ nest() [4/4]

template std::size_t libnest2d::nest ( std::vector< Item >::iterator  from,
std::vector< Item >::iterator  to,
const Box bin,
Coord  dist,
const NestConfig< NfpPlacer, FirstFitSelection > &  cfg,
NestControl  ctl 
)

◆ operator<<() [1/2]

template<class T >
DErr && libnest2d::operator<< ( DErr &&  out,
T &&  d 
)
inline
57 {
58#ifndef NDEBUG
59 out.out << d;
60#endif
61 return std::move(out);
62}
std::ostream & out
Definition common.hpp:44

References libnest2d::DOut::out.

◆ operator<<() [2/2]

template<class T >
DOut && libnest2d::operator<< ( DOut &&  out,
T &&  d 
)
inline
49 {
50#ifndef NDEBUG
51 out.out << d;
52#endif
53 return std::move(out);
54}
std::ostream & out
Definition common.hpp:38

References libnest2d::DOut::out.

◆ operator==() [1/2]

bool libnest2d::operator== ( const Degrees deg,
const Radians rads 
)
inline
155 {
156 Degrees deg2 = rads;
157 auto diff = std::abs(deg - deg2);
158 return diff < 0.0001;
159}
Data type representing degrees. It supports conversion to radians.
Definition common.hpp:148

◆ operator==() [2/2]

bool libnest2d::operator== ( const Radians rads,
const Degrees deg 
)
inline
161 {
162 return deg == rads;
163}

◆ rectarea() [1/4]

template<class Pt , class Unit = TCompute<Pt>, class R = TCompute<Pt>>
R libnest2d::rectarea ( const Pt &  w,
const Pt &  vb,
const Pt &  vr,
const Pt &  vt,
const Pt &  vl 
)
inline
76{
77 Unit a = pl::dot<Pt, Unit>(w, vr - vl);
78 Unit b = pl::dot<Pt, Unit>(-pl::perp(w), vt - vb);
79 R m = R(a) / pl::magnsq<Pt, Unit>(w);
80 m = m * b;
81 return m;
82};

References libnest2d::pointlike::perp().

+ Here is the call graph for this function:

◆ rectarea() [2/4]

template<class Pt , class Unit = TCompute<Pt>, class R = TCompute<Pt>, class It = typename std::vector<Pt>::const_iterator>
R libnest2d::rectarea ( const Pt &  w,
const std::array< It, 4 > &  rect 
)
inline
89{
90 return rectarea<Pt, Unit, R>(w, *rect[0], *rect[1], *rect[2], *rect[3]);
91}

◆ rectarea() [3/4]

template<class Pt , class Unit = TCompute<Pt>, class R = TCompute<Pt>>
R libnest2d::rectarea ( const Pt &  w,
const Unit &  a,
const Unit &  b 
)
inline
97{
98 R m = R(a) / pl::magnsq<Pt, Unit>(w);
99 m = m * b;
100 return m;
101};

◆ rectarea() [4/4]

template<class R , class Pt , class Unit >
R libnest2d::rectarea ( const RotatedBox< Pt, Unit > &  rb)
inline
105{
106 return rectarea<Pt, Unit, R>(rb.axis(), rb.bottom_extent(), rb.right_extent());
107};
Unit right_extent() const
Definition rotcalipers.hpp:36
const Pt & axis() const
Definition rotcalipers.hpp:37
Unit bottom_extent() const
Definition rotcalipers.hpp:35

References libnest2d::RotatedBox< Pt, Unit >::axis(), libnest2d::RotatedBox< Pt, Unit >::bottom_extent(), and libnest2d::RotatedBox< Pt, Unit >::right_extent().

+ Here is the call graph for this function:

◆ rem()

template<class Container >
ConstItemRange< typename Container::const_iterator > libnest2d::rem ( typename Container::const_iterator  it,
const Container &  cont 
)
inline
534 {
535 return {std::next(it), cont.end()};
536}

Referenced by libnest2d::placers::PlacerBoilerplate< Subclass, RawShape, TBin, Cfg >::pack(), libnest2d::selections::_DJDHeuristic< RawShape >::packItems(), and libnest2d::selections::_FirstFitSelection< RawShape >::packItems().

+ Here is the caller graph for this function:

◆ removeCollinearPoints()

template<class Poly , class Pt = TPoint<Poly>, class Unit = TCompute<Pt>>
Poly libnest2d::removeCollinearPoints ( const Poly &  sh,
Unit  eps = Unit(0) 
)
49{
50 Poly ret; sl::reserve(ret, sl::contourVertexCount(sh));
51
52 Pt eprev = *sl::cbegin(sh) - *std::prev(sl::cend(sh));
53
54 auto it = sl::cbegin(sh);
55 auto itx = std::next(it);
56 if(itx != sl::cend(sh)) while (it != sl::cend(sh))
57 {
58 Pt enext = *itx - *it;
59
60 auto dp = pl::dotperp<Pt, Unit>(eprev, enext);
61 if(abs(dp) > eps) sl::addVertex(ret, *it);
62
63 eprev = enext;
64 if (++itx == sl::cend(sh)) itx = sl::cbegin(sh);
65 ++it;
66 }
67
68 return ret;
69}

References libnest2d::shapelike::addVertex(), libnest2d::shapelike::cbegin(), libnest2d::shapelike::cend(), libnest2d::shapelike::contourVertexCount(), and libnest2d::shapelike::reserve().

Referenced by Slic3r::minAreaBoundigBox_().

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

◆ rotcalipers()

template<class RawShape , class Unit = TCompute<RawShape>, class Ratio = TCompute<RawShape>, class VisitFn >
void libnest2d::rotcalipers ( const RawShape &  sh,
VisitFn &&  visitfn 
)
116{
117 using Point = TPoint<RawShape>;
118 using Iterator = typename TContour<RawShape>::const_iterator;
119 using pointlike::dot; using pointlike::magnsq; using pointlike::perp;
120
121 // Get the first and the last vertex iterator
122 auto first = sl::cbegin(sh);
123 auto last = std::prev(sl::cend(sh));
124
125 // Check conditions and return undefined box if input is not sane.
126 if(last == first) return;
127 if(getX(*first) == getX(*last) && getY(*first) == getY(*last)) --last;
128 if(last - first < 2) return;
129
130 RawShape shcpy; // empty at this point
131 {
132 Point p = *first, q = *std::next(first), r = *last;
133
134 // Determine orientation from first 3 vertex (should be consistent)
135 Unit d = (Unit(getY(q)) - getY(p)) * (Unit(getX(r)) - getX(p)) -
136 (Unit(getX(q)) - getX(p)) * (Unit(getY(r)) - getY(p));
137
138 if(d > 0) {
139 // The polygon is clockwise. A flip is needed (for now)
140 sl::reserve(shcpy, last - first);
141 auto it = last; while(it != first) sl::addVertex(shcpy, *it--);
142 sl::addVertex(shcpy, *first);
143 first = sl::cbegin(shcpy); last = std::prev(sl::cend(shcpy));
144 }
145 }
146
147 // Cyclic iterator increment
148 auto inc = [&first, &last](Iterator& it) {
149 if(it == last) it = first; else ++it;
150 };
151
152 // Cyclic previous iterator
153 auto prev = [&first, &last](Iterator it) {
154 return it == first ? last : std::prev(it);
155 };
156
157 // Cyclic next iterator
158 auto next = [&first, &last](Iterator it) {
159 return it == last ? first : std::next(it);
160 };
161
162 // Establish initial (axis aligned) rectangle support verices by determining
163 // polygon extremes:
164
165 auto it = first;
166 Iterator minX = it, maxX = it, minY = it, maxY = it;
167
168 do { // Linear walk through the vertices and save the extreme positions
169
170 Point v = *it, d = v - *minX;
171 if(getX(d) < 0 || (getX(d) == 0 && getY(d) < 0)) minX = it;
172
173 d = v - *maxX;
174 if(getX(d) > 0 || (getX(d) == 0 && getY(d) > 0)) maxX = it;
175
176 d = v - *minY;
177 if(getY(d) < 0 || (getY(d) == 0 && getX(d) > 0)) minY = it;
178
179 d = v - *maxY;
180 if(getY(d) > 0 || (getY(d) == 0 && getX(d) < 0)) maxY = it;
181
182 } while(++it != std::next(last));
183
184 // Update the vertices defining the bounding rectangle. The rectangle with
185 // the smallest rotation is selected and the supporting vertices are
186 // returned in the 'rect' argument.
187 auto update = [&next, &inc]
188 (const Point& w, std::array<Iterator, 4>& rect)
189 {
190 Iterator B = rect[0], Bn = next(B);
191 Iterator R = rect[1], Rn = next(R);
192 Iterator T = rect[2], Tn = next(T);
193 Iterator L = rect[3], Ln = next(L);
194
195 Point b = *Bn - *B, r = *Rn - *R, t = *Tn - *T, l = *Ln - *L;
196 Point pw = perp(w);
197 using Pt = Point;
198
199 Unit dotwpb = dot<Pt, Unit>( w, b), dotwpr = dot<Pt, Unit>(-pw, r);
200 Unit dotwpt = dot<Pt, Unit>(-w, t), dotwpl = dot<Pt, Unit>( pw, l);
201 Unit dw = magnsq<Pt, Unit>(w);
202
203 std::array<Ratio, 4> angles;
204 angles[0] = (Ratio(dotwpb) / magnsq<Pt, Unit>(b)) * dotwpb;
205 angles[1] = (Ratio(dotwpr) / magnsq<Pt, Unit>(r)) * dotwpr;
206 angles[2] = (Ratio(dotwpt) / magnsq<Pt, Unit>(t)) * dotwpt;
207 angles[3] = (Ratio(dotwpl) / magnsq<Pt, Unit>(l)) * dotwpl;
208
209 using AngleIndex = std::pair<Ratio, size_t>;
210 std::vector<AngleIndex> A; A.reserve(4);
211
212 for (size_t i = 3, j = 0; j < 4; i = j++) {
213 if(rect[i] != rect[j] && angles[i] < dw) {
214 auto iv = std::make_pair(angles[i], i);
215 auto it = std::lower_bound(A.begin(), A.end(), iv,
216 [](const AngleIndex& ai,
217 const AngleIndex& aj)
218 {
219 return ai.first > aj.first;
220 });
221
222 A.insert(it, iv);
223 }
224 }
225
226 // The polygon is supposed to be a rectangle.
227 if(A.empty()) return false;
228
229 auto amin = A.front().first;
230 auto imin = A.front().second;
231 for(auto& a : A) if(a.first == amin) inc(rect[a.second]);
232
233 std::rotate(rect.begin(), rect.begin() + imin, rect.end());
234
235 return true;
236 };
237
238 Point w(1, 0);
239 std::array<Iterator, 4> rect = {minY, maxX, maxY, minX};
240
241 {
242 Unit a = dot<Point, Unit>(w, *rect[1] - *rect[3]);
243 Unit b = dot<Point, Unit>(-perp(w), *rect[2] - *rect[0]);
244 if (!visitfn(RotatedBox<Point, Unit>{w, a, b}))
245 return;
246 }
247
248 // An edge might be examined twice in which case the algorithm terminates.
249 size_t c = 0, count = last - first + 1;
250 std::vector<bool> edgemask(count, false);
251
252 while(c++ < count)
253 {
254 // Update the support vertices, if cannot be updated, break the cycle.
255 if(! update(w, rect)) break;
256
257 size_t eidx = size_t(rect[0] - first);
258
259 if(edgemask[eidx]) break;
260 edgemask[eidx] = true;
261
262 // get the unnormalized direction vector
263 w = *rect[0] - *prev(rect[0]);
264
265 Unit a = dot<Point, Unit>(w, *rect[1] - *rect[3]);
266 Unit b = dot<Point, Unit>(-perp(w), *rect[2] - *rect[0]);
267 if (!visitfn(RotatedBox<Point, Unit>{w, a, b}))
268 break;
269 }
270}
Definition Point.hpp:158
if(!(yy_init))
Definition lexer.c:1190
int64_t Unit
Definition MinAreaBoundingBox.cpp:23
std::vector< Triangle >::iterator Iterator
Definition points_inside_component.cpp:35
IGL_INLINE void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Definition count.cpp:12
Pt perp(const Pt &p)
Definition geometry_traits.hpp:335
TCoord< P > getX(const P &p)
Definition geometry_traits.hpp:424
typename PointType< remove_cvref_t< Shape > >::Type TPoint
TPoint<ShapeClass> as shorthand for typename PointType<ShapeClass>::Type.
Definition geometry_traits.hpp:46
typename ContourType< remove_cvref_t< S > >::Type TContour
TContour instead of typename ContourType<S>::type
Definition geometry_traits.hpp:37
TCoord< P > getY(const P &p)
Definition geometry_traits.hpp:427
Kernel::Point_2 Point
Definition point_areas.cpp:20
#define L(s)
Definition I18N.hpp:18

References libnest2d::shapelike::addVertex(), libnest2d::shapelike::cbegin(), libnest2d::shapelike::cend(), libnest2d::pointlike::dot(), getX(), getY(), L, libnest2d::pointlike::magnsq(), libnest2d::pointlike::perp(), and libnest2d::shapelike::reserve().

+ Here is the call graph for this function:

◆ setX()

template<class P >
void libnest2d::setX ( P &  p,
const TCoord< P > &  val 
)
431{
432 pointlike::x<P>(p) = val;
433}

References setX().

Referenced by libnest2d::shapelike::boundingBox(), boost::geometry::traits::access< bp2d::PointImpl, 0 >::set(), and setX().

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

◆ setY()

template<class P >
void libnest2d::setY ( P &  p,
const TCoord< P > &  val 
)
437{
438 pointlike::y<P>(p) = val;
439}

References setY().

Referenced by libnest2d::shapelike::boundingBox(), boost::geometry::traits::access< bp2d::PointImpl, 1 >::set(), setY(), and libnest2d::svg::SVGWriter< RawShape >::writeShape().

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

Variable Documentation

◆ BIN_ID_UNSET

◆ ClosureTypeV

template<class T >
const constexpr Closure libnest2d::ClosureTypeV
inlineconstexpr
Initial value:
=
ClosureType<TContour<T>>::Value

◆ ERROR_STR

const std::string libnest2d::ERROR_STR[]
Initial value:
= {
"Offsetting could not be done! An invalid geometry may have been added.",
"Error while merging geometries!",
"No fit polygon cannot be calculated."
}

Referenced by libnest2d::GeometryException::errorstr().

◆ OrientationTypeV

template<class T >
const constexpr Orientation libnest2d::OrientationTypeV
inlineconstexpr
Initial value:
=
OrientationType<TContour<T>>::Value

◆ Pi

◆ Pi_2