diff options
author | Vojtech Bubnik <bubnikv@gmail.com> | 2021-04-14 10:22:51 +0300 |
---|---|---|
committer | Vojtech Bubnik <bubnikv@gmail.com> | 2021-04-14 10:22:51 +0300 |
commit | 7112ac61b6d69c819b4f809cc2474b98051c2e88 (patch) | |
tree | 648bfc1082ea9b1f53d262a0cdcd5375d3c7f9f8 /src/libnest2d | |
parent | 29cd8aac26b4ae0bbe02334823b321aaac2e9a43 (diff) |
Replacing ClipperLib::IntPoint with Eigen point as a first step tovb_clipper_eigen
make the ClipperLib paths and polygons compatible with Slic3r paths
and polygons without conversions and memory allocations.
Diffstat (limited to 'src/libnest2d')
3 files changed, 32 insertions, 30 deletions
diff --git a/src/libnest2d/include/libnest2d/backends/clipper/clipper_polygon.hpp b/src/libnest2d/include/libnest2d/backends/clipper/clipper_polygon.hpp index 6511fbb72..d4fcd7af3 100644 --- a/src/libnest2d/include/libnest2d/backends/clipper/clipper_polygon.hpp +++ b/src/libnest2d/include/libnest2d/backends/clipper/clipper_polygon.hpp @@ -23,10 +23,12 @@ struct Polygon { Contour(std::move(cont)), Holes(std::move(holes)) {} }; +#if 0 inline IntPoint& operator +=(IntPoint& p, const IntPoint& pa ) { // This could be done with SIMD - p.X += pa.X; - p.Y += pa.Y; + + p.x() += pa.x(); + p.y() += pa.y(); return p; } @@ -37,15 +39,15 @@ inline IntPoint operator+(const IntPoint& p1, const IntPoint& p2) { } inline IntPoint& operator -=(IntPoint& p, const IntPoint& pa ) { - p.X -= pa.X; - p.Y -= pa.Y; + p.x() -= pa.x(); + p.y() -= pa.y(); return p; } inline IntPoint operator -(const IntPoint& p ) { IntPoint ret = p; - ret.X = -ret.X; - ret.Y = -ret.Y; + ret.x() = -ret.x(); + ret.y() = -ret.y(); return ret; } @@ -56,8 +58,8 @@ inline IntPoint operator-(const IntPoint& p1, const IntPoint& p2) { } inline IntPoint& operator *=(IntPoint& p, const IntPoint& pa ) { - p.X *= pa.X; - p.Y *= pa.Y; + p.x() *= pa.x(); + p.y() *= pa.y(); return p; } @@ -66,6 +68,7 @@ inline IntPoint operator*(const IntPoint& p1, const IntPoint& p2) { ret *= p2; return ret; } +#endif } diff --git a/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp b/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp index 9586db35c..5999ebf2a 100644 --- a/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp +++ b/src/libnest2d/include/libnest2d/backends/clipper/geometries.hpp @@ -46,25 +46,25 @@ namespace pointlike { // Tell libnest2d how to extract the X coord from a ClipperPoint object template<> inline ClipperLib::cInt x(const PointImpl& p) { - return p.X; + return p.x(); } // Tell libnest2d how to extract the Y coord from a ClipperPoint object template<> inline ClipperLib::cInt y(const PointImpl& p) { - return p.Y; + return p.y(); } // Tell libnest2d how to extract the X coord from a ClipperPoint object template<> inline ClipperLib::cInt& x(PointImpl& p) { - return p.X; + return p.x(); } // Tell libnest2d how to extract the Y coord from a ClipperPoint object template<> inline ClipperLib::cInt& y(PointImpl& p) { - return p.Y; + return p.y(); } } @@ -144,7 +144,7 @@ template<> inline std::string toString(const PolygonImpl& sh) ss << "Contour {\n"; for(auto p : sh.Contour) { - ss << "\t" << p.X << " " << p.Y << "\n"; + ss << "\t" << p.x() << " " << p.y() << "\n"; } ss << "}\n"; @@ -152,7 +152,7 @@ template<> inline std::string toString(const PolygonImpl& sh) ss << "Holes {\n"; for(auto p : h) { ss << "\t{\n"; - ss << "\t\t" << p.X << " " << p.Y << "\n"; + ss << "\t\t" << p.x() << " " << p.y() << "\n"; ss << "\t}\n"; } ss << "}\n"; @@ -238,14 +238,14 @@ inline void rotate(PolygonImpl& sh, const Radians& rads) for(auto& p : sh.Contour) { p = { - static_cast<Coord>(p.X * cosa - p.Y * sina), - static_cast<Coord>(p.X * sina + p.Y * cosa) + static_cast<Coord>(p.x() * cosa - p.y() * sina), + static_cast<Coord>(p.x() * sina + p.y() * cosa) }; } for(auto& hole : sh.Holes) for(auto& p : hole) { p = { - static_cast<Coord>(p.X * cosa - p.Y * sina), - static_cast<Coord>(p.X * sina + p.Y * cosa) + static_cast<Coord>(p.x() * cosa - p.y() * sina), + static_cast<Coord>(p.x() * sina + p.y() * cosa) }; } } @@ -277,7 +277,7 @@ inline TMultiShape<PolygonImpl> clipper_execute( if(!poly.Contour.empty() ) { auto front_p = poly.Contour.front(); auto &back_p = poly.Contour.back(); - if(front_p.X != back_p.X || front_p.Y != back_p.X) + if(front_p.x() != back_p.x() || front_p.y() != back_p.x()) poly.Contour.emplace_back(front_p); } @@ -294,7 +294,7 @@ inline TMultiShape<PolygonImpl> clipper_execute( if(!poly.Contour.empty() ) { auto front_p = poly.Contour.front(); auto &back_p = poly.Contour.back(); - if(front_p.X != back_p.X || front_p.Y != back_p.X) + if(front_p.x() != back_p.x() || front_p.y() != back_p.x()) poly.Contour.emplace_back(front_p); } diff --git a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp index bd9c60355..70168c85a 100644 --- a/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp +++ b/src/libnest2d/include/libnest2d/placers/nfpplacer.hpp @@ -250,8 +250,8 @@ template<class RawShape> class EdgeCache { Vertex ret = edge.first(); // Get the point on the edge which lies in ed distance from the start - ret += { static_cast<Coord>(std::round(ed*std::cos(angle))), - static_cast<Coord>(std::round(ed*std::sin(angle))) }; + ret += Vertex(static_cast<Coord>(std::round(ed*std::cos(angle))), + static_cast<Coord>(std::round(ed*std::sin(angle)))); return ret; } @@ -344,7 +344,8 @@ inline void correctNfpPosition(nfp::NfpResult<RawShape>& nfp, auto dtouch = touch_sh - touch_other; auto top_other = orbiter.rightmostTopVertex() + dtouch; auto dnfp = top_other - nfp.second; // nfp.second is the nfp reference point - shapelike::translate(nfp.first, dnfp); + //FIXME the explicit type conversion ClipperLib::IntPoint() + shapelike::translate(nfp.first, ClipperLib::IntPoint(dnfp)); } template<class RawShape> @@ -473,7 +474,8 @@ public: auto bbin = sl::boundingBox(bin); auto d = bbch.center() - bbin.center(); auto chullcpy = chull; - sl::translate(chullcpy, d); + //FIXME the explicit type conversion ClipperLib::IntPoint() + sl::translate(chullcpy, ClipperLib::IntPoint(d)); return sl::isInside(chullcpy, bin) ? -1.0 : 1.0; } @@ -724,8 +726,7 @@ private: auto rawobjfunc = [_objfunc, iv, startpos] (Vertex v, Item& itm) { - auto d = v - iv; - d += startpos; + auto d = (v - iv) + startpos; itm.translation(d); return _objfunc(itm); }; @@ -742,8 +743,7 @@ private: &item, &bin, &iv, &startpos] (const Optimum& o) { auto v = getNfpPoint(o); - auto d = v - iv; - d += startpos; + auto d = (v - iv) + startpos; item.translation(d); merged_pile.emplace_back(item.transformedShape()); @@ -877,8 +877,7 @@ private: } if( best_score < global_score ) { - auto d = getNfpPoint(optimum) - iv; - d += startpos; + auto d = (getNfpPoint(optimum) - iv) + startpos; final_tr = d; final_rot = initial_rot + rot; can_pack = true; |