mirror of
https://github.com/FULU-Foundation/OrcaSlicer-bambulab.git
synced 2026-09-13 06:08:10 +02:00
Working arrange_objects with DJD selection heuristic and a bottom-left placement strategy.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#include "clipper_backend.hpp"
|
||||
|
||||
namespace libnest2d {
|
||||
|
||||
namespace {
|
||||
class HoleCache {
|
||||
friend struct libnest2d::ShapeLike;
|
||||
|
||||
std::unordered_map< const PolygonImpl*, ClipperLib::Paths> map;
|
||||
|
||||
ClipperLib::Paths& _getHoles(const PolygonImpl* p) {
|
||||
ClipperLib::Paths& paths = map[p];
|
||||
|
||||
if(paths.size() != p->Childs.size()) {
|
||||
paths.reserve(p->Childs.size());
|
||||
|
||||
for(auto np : p->Childs) {
|
||||
paths.emplace_back(np->Contour);
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
ClipperLib::Paths& getHoles(PolygonImpl& p) {
|
||||
return _getHoles(&p);
|
||||
}
|
||||
|
||||
const ClipperLib::Paths& getHoles(const PolygonImpl& p) {
|
||||
return _getHoles(&p);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
HoleCache holeCache;
|
||||
|
||||
template<>
|
||||
std::string ShapeLike::toString(const PolygonImpl& sh)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
for(auto p : sh.Contour) {
|
||||
ss << p.X << " " << p.Y << "\n";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<> PolygonImpl ShapeLike::create( std::initializer_list< PointImpl > il)
|
||||
{
|
||||
PolygonImpl p;
|
||||
p.Contour = il;
|
||||
|
||||
// Expecting that the coordinate system Y axis is positive in upwards
|
||||
// direction
|
||||
if(ClipperLib::Orientation(p.Contour)) {
|
||||
// Not clockwise then reverse the b*tch
|
||||
ClipperLib::ReversePath(p.Contour);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
template<>
|
||||
const THolesContainer<PolygonImpl>& ShapeLike::holes(
|
||||
const PolygonImpl& sh)
|
||||
{
|
||||
return holeCache.getHoles(sh);
|
||||
}
|
||||
|
||||
template<>
|
||||
THolesContainer<PolygonImpl>& ShapeLike::holes(PolygonImpl& sh) {
|
||||
return holeCache.getHoles(sh);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user