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

Functions

template<class RawShape , class Unit = TCompute<RawShape>>
bool _vsort (const TPoint< RawShape > &v1, const TPoint< RawShape > &v2)
 
template<class EdgeList , class RawShape , class Vertex = TPoint<RawShape>>
void buildPolygon (const EdgeList &edgelist, RawShape &rpoly, Vertex &top_nfp)
 
template<class Container , class Iterator = typename Container::iterator>
void advance (Iterator &it, Container &cont, bool direction)
 

Function Documentation

◆ _vsort()

template<class RawShape , class Unit = TCompute<RawShape>>
bool libnest2d::__nfp::_vsort ( const TPoint< RawShape > &  v1,
const TPoint< RawShape > &  v2 
)
inline
17{
18 Unit x1 = getX(v1), x2 = getX(v2), y1 = getY(v1), y2 = getY(v2);
19 return y1 == y2 ? x1 < x2 : y1 < y2;
20}
TCoord< P > getX(const P &p)
Definition geometry_traits.hpp:424
TCoord< P > getY(const P &p)
Definition geometry_traits.hpp:427

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

+ Here is the call graph for this function:

◆ advance()

template<class Container , class Iterator = typename Container::iterator>
void libnest2d::__nfp::advance ( Iterator &  it,
Container &  cont,
bool  direction 
)
64{
65 int dir = direction ? 1 : -1;
66 if(dir < 0 && it == cont.begin()) it = std::prev(cont.end());
67 else it += dir;
68 if(dir > 0 && it == cont.end()) it = cont.begin();
69}

◆ buildPolygon()

template<class EdgeList , class RawShape , class Vertex = TPoint<RawShape>>
void libnest2d::__nfp::buildPolygon ( const EdgeList &  edgelist,
RawShape &  rpoly,
Vertex &  top_nfp 
)
inline
26{
27 namespace sl = shapelike;
28
29 auto& rsh = sl::contour(rpoly);
30
31 sl::reserve(rsh, 2 * edgelist.size());
32
33 // Add the two vertices from the first edge into the final polygon.
34 sl::addVertex(rsh, edgelist.front().first());
35 sl::addVertex(rsh, edgelist.front().second());
36
37 // Sorting function for the nfp reference vertex search
38 auto& cmp = _vsort<RawShape>;
39
40 // the reference (rightmost top) vertex so far
41 top_nfp = *std::max_element(sl::cbegin(rsh), sl::cend(rsh), cmp );
42
43 auto tmp = std::next(sl::begin(rsh));
44
45 // Construct final nfp by placing each edge to the end of the previous
46 for(auto eit = std::next(edgelist.begin());
47 eit != edgelist.end();
48 ++eit)
49 {
50 auto d = *tmp - eit->first();
51 Vertex p = eit->second() + d;
52
53 sl::addVertex(rsh, p);
54
55 // Set the new reference vertex
56 if(cmp(top_nfp, p)) top_nfp = p;
57
58 tmp = std::next(tmp);
59 }
60}

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

+ Here is the call graph for this function: