mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-11-01 13:12:38 -06:00
Replacing ClipperLib::IntPoint with Eigen point as a first step to
make the ClipperLib paths and polygons compatible with Slic3r paths and polygons without conversions and memory allocations.
This commit is contained in:
parent
29cd8aac26
commit
7112ac61b6
14 changed files with 416 additions and 401 deletions
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue