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:
Vojtech Bubnik 2021-04-14 09:22:51 +02:00
parent 29cd8aac26
commit 7112ac61b6
14 changed files with 416 additions and 401 deletions

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,8 @@
#include <inttypes.h> #include <inttypes.h>
#include <functional> #include <functional>
#include <Eigen/Geometry>
#define CLIPPER_VERSION "6.2.6" #define CLIPPER_VERSION "6.2.6"
//use_xyz: adds a Z member to IntPoint. Adds a minor cost to perfomance. //use_xyz: adds a Z member to IntPoint. Adds a minor cost to perfomance.
@ -88,6 +90,16 @@ enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative };
static constexpr cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL; static constexpr cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL;
#endif // CLIPPERLIB_INT32 #endif // CLIPPERLIB_INT32
#if 1
using IntPoint = Eigen::Matrix<cInt,
#ifdef use_xyz
3
#else // use_xyz
2
#endif // use_xyz
, 1, Eigen::DontAlign>;
using DoublePoint = Eigen::Matrix<double, 2, 1, Eigen::DontAlign>;
#else
struct IntPoint { struct IntPoint {
cInt X; cInt X;
cInt Y; cInt Y;
@ -107,10 +119,18 @@ struct IntPoint {
return a.X != b.X || a.Y != b.Y; return a.X != b.X || a.Y != b.Y;
} }
}; };
struct DoublePoint
{
double X;
double Y;
DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
DoublePoint(IntPoint ip) : X((double)ip.x()), Y((double)ip.y()) {}
};
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
typedef std::vector< IntPoint > Path; typedef std::vector<IntPoint> Path;
typedef std::vector< Path > Paths; typedef std::vector<Path> Paths;
inline Path& operator <<(Path& poly, const IntPoint& p) {poly.push_back(p); return poly;} inline Path& operator <<(Path& poly, const IntPoint& p) {poly.push_back(p); return poly;}
inline Paths& operator <<(Paths& polys, const Path& p) {polys.push_back(p); return polys;} inline Paths& operator <<(Paths& polys, const Path& p) {polys.push_back(p); return polys;}
@ -119,13 +139,6 @@ std::ostream& operator <<(std::ostream &s, const IntPoint &p);
std::ostream& operator <<(std::ostream &s, const Path &p); std::ostream& operator <<(std::ostream &s, const Path &p);
std::ostream& operator <<(std::ostream &s, const Paths &p); std::ostream& operator <<(std::ostream &s, const Paths &p);
struct DoublePoint
{
double X;
double Y;
DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {}
};
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifdef use_xyz #ifdef use_xyz

View File

@ -23,10 +23,12 @@ struct Polygon {
Contour(std::move(cont)), Holes(std::move(holes)) {} Contour(std::move(cont)), Holes(std::move(holes)) {}
}; };
#if 0
inline IntPoint& operator +=(IntPoint& p, const IntPoint& pa ) { inline IntPoint& operator +=(IntPoint& p, const IntPoint& pa ) {
// This could be done with SIMD // This could be done with SIMD
p.X += pa.X;
p.Y += pa.Y; p.x() += pa.x();
p.y() += pa.y();
return p; return p;
} }
@ -37,15 +39,15 @@ inline IntPoint operator+(const IntPoint& p1, const IntPoint& p2) {
} }
inline IntPoint& operator -=(IntPoint& p, const IntPoint& pa ) { inline IntPoint& operator -=(IntPoint& p, const IntPoint& pa ) {
p.X -= pa.X; p.x() -= pa.x();
p.Y -= pa.Y; p.y() -= pa.y();
return p; return p;
} }
inline IntPoint operator -(const IntPoint& p ) { inline IntPoint operator -(const IntPoint& p ) {
IntPoint ret = p; IntPoint ret = p;
ret.X = -ret.X; ret.x() = -ret.x();
ret.Y = -ret.Y; ret.y() = -ret.y();
return ret; return ret;
} }
@ -56,8 +58,8 @@ inline IntPoint operator-(const IntPoint& p1, const IntPoint& p2) {
} }
inline IntPoint& operator *=(IntPoint& p, const IntPoint& pa ) { inline IntPoint& operator *=(IntPoint& p, const IntPoint& pa ) {
p.X *= pa.X; p.x() *= pa.x();
p.Y *= pa.Y; p.y() *= pa.y();
return p; return p;
} }
@ -66,6 +68,7 @@ inline IntPoint operator*(const IntPoint& p1, const IntPoint& p2) {
ret *= p2; ret *= p2;
return ret; return ret;
} }
#endif
} }

View File

@ -46,25 +46,25 @@ namespace pointlike {
// Tell libnest2d how to extract the X coord from a ClipperPoint object // Tell libnest2d how to extract the X coord from a ClipperPoint object
template<> inline ClipperLib::cInt x(const PointImpl& p) 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 // Tell libnest2d how to extract the Y coord from a ClipperPoint object
template<> inline ClipperLib::cInt y(const PointImpl& p) 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 // Tell libnest2d how to extract the X coord from a ClipperPoint object
template<> inline ClipperLib::cInt& x(PointImpl& p) 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 // Tell libnest2d how to extract the Y coord from a ClipperPoint object
template<> inline ClipperLib::cInt& y(PointImpl& p) 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"; ss << "Contour {\n";
for(auto p : sh.Contour) { for(auto p : sh.Contour) {
ss << "\t" << p.X << " " << p.Y << "\n"; ss << "\t" << p.x() << " " << p.y() << "\n";
} }
ss << "}\n"; ss << "}\n";
@ -152,7 +152,7 @@ template<> inline std::string toString(const PolygonImpl& sh)
ss << "Holes {\n"; ss << "Holes {\n";
for(auto p : h) { for(auto p : h) {
ss << "\t{\n"; ss << "\t{\n";
ss << "\t\t" << p.X << " " << p.Y << "\n"; ss << "\t\t" << p.x() << " " << p.y() << "\n";
ss << "\t}\n"; ss << "\t}\n";
} }
ss << "}\n"; ss << "}\n";
@ -238,14 +238,14 @@ inline void rotate(PolygonImpl& sh, const Radians& rads)
for(auto& p : sh.Contour) { for(auto& p : sh.Contour) {
p = { p = {
static_cast<Coord>(p.X * cosa - p.Y * sina), static_cast<Coord>(p.x() * cosa - p.y() * sina),
static_cast<Coord>(p.X * sina + p.Y * cosa) static_cast<Coord>(p.x() * sina + p.y() * cosa)
}; };
} }
for(auto& hole : sh.Holes) for(auto& p : hole) { for(auto& hole : sh.Holes) for(auto& p : hole) {
p = { p = {
static_cast<Coord>(p.X * cosa - p.Y * sina), static_cast<Coord>(p.x() * cosa - p.y() * sina),
static_cast<Coord>(p.X * sina + p.Y * cosa) static_cast<Coord>(p.x() * sina + p.y() * cosa)
}; };
} }
} }
@ -277,7 +277,7 @@ inline TMultiShape<PolygonImpl> clipper_execute(
if(!poly.Contour.empty() ) { if(!poly.Contour.empty() ) {
auto front_p = poly.Contour.front(); auto front_p = poly.Contour.front();
auto &back_p = poly.Contour.back(); 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); poly.Contour.emplace_back(front_p);
} }
@ -294,7 +294,7 @@ inline TMultiShape<PolygonImpl> clipper_execute(
if(!poly.Contour.empty() ) { if(!poly.Contour.empty() ) {
auto front_p = poly.Contour.front(); auto front_p = poly.Contour.front();
auto &back_p = poly.Contour.back(); 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); poly.Contour.emplace_back(front_p);
} }

View File

@ -250,8 +250,8 @@ template<class RawShape> class EdgeCache {
Vertex ret = edge.first(); Vertex ret = edge.first();
// Get the point on the edge which lies in ed distance from the start // Get the point on the edge which lies in ed distance from the start
ret += { static_cast<Coord>(std::round(ed*std::cos(angle))), ret += Vertex(static_cast<Coord>(std::round(ed*std::cos(angle))),
static_cast<Coord>(std::round(ed*std::sin(angle))) }; static_cast<Coord>(std::round(ed*std::sin(angle))));
return ret; return ret;
} }
@ -344,7 +344,8 @@ inline void correctNfpPosition(nfp::NfpResult<RawShape>& nfp,
auto dtouch = touch_sh - touch_other; auto dtouch = touch_sh - touch_other;
auto top_other = orbiter.rightmostTopVertex() + dtouch; auto top_other = orbiter.rightmostTopVertex() + dtouch;
auto dnfp = top_other - nfp.second; // nfp.second is the nfp reference point 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> template<class RawShape>
@ -473,7 +474,8 @@ public:
auto bbin = sl::boundingBox(bin); auto bbin = sl::boundingBox(bin);
auto d = bbch.center() - bbin.center(); auto d = bbch.center() - bbin.center();
auto chullcpy = chull; 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; return sl::isInside(chullcpy, bin) ? -1.0 : 1.0;
} }
@ -724,8 +726,7 @@ private:
auto rawobjfunc = [_objfunc, iv, startpos] auto rawobjfunc = [_objfunc, iv, startpos]
(Vertex v, Item& itm) (Vertex v, Item& itm)
{ {
auto d = v - iv; auto d = (v - iv) + startpos;
d += startpos;
itm.translation(d); itm.translation(d);
return _objfunc(itm); return _objfunc(itm);
}; };
@ -742,8 +743,7 @@ private:
&item, &bin, &iv, &startpos] (const Optimum& o) &item, &bin, &iv, &startpos] (const Optimum& o)
{ {
auto v = getNfpPoint(o); auto v = getNfpPoint(o);
auto d = v - iv; auto d = (v - iv) + startpos;
d += startpos;
item.translation(d); item.translation(d);
merged_pile.emplace_back(item.transformedShape()); merged_pile.emplace_back(item.transformedShape());
@ -877,8 +877,7 @@ private:
} }
if( best_score < global_score ) { if( best_score < global_score ) {
auto d = getNfpPoint(optimum) - iv; auto d = (getNfpPoint(optimum) - iv) + startpos;
d += startpos;
final_tr = d; final_tr = d;
final_rot = initial_rot + rot; final_rot = initial_rot + rot;
can_pack = true; can_pack = true;

View File

@ -56,8 +56,8 @@ template<class Tout = double, class = FloatingOnly<Tout>, int...EigenArgs>
inline constexpr Eigen::Matrix<Tout, 2, EigenArgs...> unscaled( inline constexpr Eigen::Matrix<Tout, 2, EigenArgs...> unscaled(
const ClipperLib::IntPoint &v) noexcept const ClipperLib::IntPoint &v) noexcept
{ {
return Eigen::Matrix<Tout, 2, EigenArgs...>{unscaled<Tout>(v.X), return Eigen::Matrix<Tout, 2, EigenArgs...>{unscaled<Tout>(v.x()),
unscaled<Tout>(v.Y)}; unscaled<Tout>(v.y())};
} }
namespace arrangement { namespace arrangement {
@ -644,7 +644,7 @@ void arrange(ArrangePolygons & arrangables,
for(size_t i = 0; i < items.size(); ++i) { for(size_t i = 0; i < items.size(); ++i) {
clppr::IntPoint tr = items[i].translation(); clppr::IntPoint tr = items[i].translation();
arrangables[i].translation = {coord_t(tr.X), coord_t(tr.Y)}; arrangables[i].translation = {coord_t(tr.x()), coord_t(tr.y())};
arrangables[i].rotation = items[i].rotation(); arrangables[i].rotation = items[i].rotation();
arrangables[i].bed_idx = items[i].binId(); arrangables[i].bed_idx = items[i].binId();
} }

View File

@ -78,7 +78,7 @@ static ConstPrintObjectPtrs get_top_level_objects_with_brim(const Print &print)
// Assign the maximum Z from four points. This values is valid index of the island // Assign the maximum Z from four points. This values is valid index of the island
clipper.ZFillFunction([](const ClipperLib_Z::IntPoint &e1bot, const ClipperLib_Z::IntPoint &e1top, const ClipperLib_Z::IntPoint &e2bot, clipper.ZFillFunction([](const ClipperLib_Z::IntPoint &e1bot, const ClipperLib_Z::IntPoint &e1top, const ClipperLib_Z::IntPoint &e2bot,
const ClipperLib_Z::IntPoint &e2top, ClipperLib_Z::IntPoint &pt) { const ClipperLib_Z::IntPoint &e2top, ClipperLib_Z::IntPoint &pt) {
pt.Z = std::max(std::max(e1bot.Z, e1top.Z), std::max(e2bot.Z, e2top.Z)); pt.z() = std::max(std::max(e1bot.z(), e1top.z()), std::max(e2bot.z(), e2top.z()));
}); });
// Add islands // Add islands
clipper.AddPaths(islands_clip, ClipperLib_Z::ptSubject, true); clipper.AddPaths(islands_clip, ClipperLib_Z::ptSubject, true);
@ -90,9 +90,9 @@ static ConstPrintObjectPtrs get_top_level_objects_with_brim(const Print &print)
ConstPrintObjectPtrs top_level_objects_with_brim; ConstPrintObjectPtrs top_level_objects_with_brim;
for (int i = 0; i < islands_polytree.ChildCount(); ++i) { for (int i = 0; i < islands_polytree.ChildCount(); ++i) {
for (const ClipperLib_Z::IntPoint &point : islands_polytree.Childs[i]->Contour) { for (const ClipperLib_Z::IntPoint &point : islands_polytree.Childs[i]->Contour) {
if (point.Z != 0 && processed_objects_idx.find(island_to_object[point.Z - 1]->id().id) == processed_objects_idx.end()) { if (point.z() != 0 && processed_objects_idx.find(island_to_object[point.z() - 1]->id().id) == processed_objects_idx.end()) {
top_level_objects_with_brim.emplace_back(island_to_object[point.Z - 1]); top_level_objects_with_brim.emplace_back(island_to_object[point.z() - 1]);
processed_objects_idx.insert(island_to_object[point.Z - 1]->id().id); processed_objects_idx.insert(island_to_object[point.z() - 1]->id().id);
} }
} }
} }
@ -456,7 +456,7 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance
clipper.ZFillFunction([](const ClipperLib_Z::IntPoint& e1bot, const ClipperLib_Z::IntPoint& e1top, const ClipperLib_Z::IntPoint& e2bot, const ClipperLib_Z::IntPoint& e2top, ClipperLib_Z::IntPoint& pt) { clipper.ZFillFunction([](const ClipperLib_Z::IntPoint& e1bot, const ClipperLib_Z::IntPoint& e1top, const ClipperLib_Z::IntPoint& e2bot, const ClipperLib_Z::IntPoint& e2top, ClipperLib_Z::IntPoint& pt) {
// Assign a valid input loop identifier. Such an identifier is strictly positive, the next line is safe even in case one side of a segment // Assign a valid input loop identifier. Such an identifier is strictly positive, the next line is safe even in case one side of a segment
// hat the Z coordinate not set to the contour coordinate. // hat the Z coordinate not set to the contour coordinate.
pt.Z = std::max(std::max(e1bot.Z, e1top.Z), std::max(e2bot.Z, e2top.Z)); pt.z() = std::max(std::max(e1bot.z(), e1top.z()), std::max(e2bot.z(), e2top.z()));
}); });
// add polygons // add polygons
clipper.AddPaths(input_clip, ClipperLib_Z::ptSubject, false); clipper.AddPaths(input_clip, ClipperLib_Z::ptSubject, false);
@ -474,8 +474,8 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance
for (const ClipperLib_Z::Path &path : loops_trimmed) { for (const ClipperLib_Z::Path &path : loops_trimmed) {
size_t input_idx = 0; size_t input_idx = 0;
for (const ClipperLib_Z::IntPoint &pt : path) for (const ClipperLib_Z::IntPoint &pt : path)
if (pt.Z > 0) { if (pt.z() > 0) {
input_idx = (size_t)pt.Z; input_idx = (size_t)pt.z();
break; break;
} }
assert(input_idx != 0); assert(input_idx != 0);
@ -492,14 +492,14 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance
size_t j = i + 1; size_t j = i + 1;
for (; j < loops_trimmed_order.size() && loops_trimmed_order[i].second == loops_trimmed_order[j].second; ++ j) ; for (; j < loops_trimmed_order.size() && loops_trimmed_order[i].second == loops_trimmed_order[j].second; ++ j) ;
const ClipperLib_Z::Path &first_path = *loops_trimmed_order[i].first; const ClipperLib_Z::Path &first_path = *loops_trimmed_order[i].first;
if (i + 1 == j && first_path.size() > 3 && first_path.front().X == first_path.back().X && first_path.front().Y == first_path.back().Y) { if (i + 1 == j && first_path.size() > 3 && first_path.front().x() == first_path.back().x() && first_path.front().y() == first_path.back().y()) {
auto *loop = new ExtrusionLoop(); auto *loop = new ExtrusionLoop();
brim.entities.emplace_back(loop); brim.entities.emplace_back(loop);
loop->paths.emplace_back(erSkirt, float(flow.mm3_per_mm()), float(flow.width()), float(print.skirt_first_layer_height())); loop->paths.emplace_back(erSkirt, float(flow.mm3_per_mm()), float(flow.width()), float(print.skirt_first_layer_height()));
Points &points = loop->paths.front().polyline.points; Points &points = loop->paths.front().polyline.points;
points.reserve(first_path.size()); points.reserve(first_path.size());
for (const ClipperLib_Z::IntPoint &pt : first_path) for (const ClipperLib_Z::IntPoint &pt : first_path)
points.emplace_back(coord_t(pt.X), coord_t(pt.Y)); points.emplace_back(coord_t(pt.x()), coord_t(pt.y()));
i = j; i = j;
} else { } else {
//FIXME The path chaining here may not be optimal. //FIXME The path chaining here may not be optimal.
@ -511,7 +511,7 @@ ExtrusionEntityCollection make_brim(const Print &print, PrintTryCancel try_cance
Points &points = static_cast<ExtrusionPath*>(this_loop_trimmed.entities.back())->polyline.points; Points &points = static_cast<ExtrusionPath*>(this_loop_trimmed.entities.back())->polyline.points;
points.reserve(path.size()); points.reserve(path.size());
for (const ClipperLib_Z::IntPoint &pt : path) for (const ClipperLib_Z::IntPoint &pt : path)
points.emplace_back(coord_t(pt.X), coord_t(pt.Y)); points.emplace_back(coord_t(pt.x()), coord_t(pt.y()));
} }
chain_and_reorder_extrusion_entities(this_loop_trimmed.entities, &last_pt); chain_and_reorder_extrusion_entities(this_loop_trimmed.entities, &last_pt);
brim.entities.reserve(brim.entities.size() + this_loop_trimmed.entities.size()); brim.entities.reserve(brim.entities.size() + this_loop_trimmed.entities.size());

View File

@ -131,7 +131,7 @@ Slic3r::Polygon ClipperPath_to_Slic3rPolygon(const ClipperLib::Path &input)
{ {
Polygon retval; Polygon retval;
for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit) for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit)
retval.points.emplace_back(pit->X, pit->Y); retval.points.emplace_back(pit->x(), pit->y());
return retval; return retval;
} }
@ -139,7 +139,7 @@ Slic3r::Polyline ClipperPath_to_Slic3rPolyline(const ClipperLib::Path &input)
{ {
Polyline retval; Polyline retval;
for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit) for (ClipperLib::Path::const_iterator pit = input.begin(); pit != input.end(); ++pit)
retval.points.emplace_back(pit->X, pit->Y); retval.points.emplace_back(pit->x(), pit->y());
return retval; return retval;
} }
@ -752,7 +752,7 @@ ClipperLib::PolyNodes order_nodes(const ClipperLib::PolyNodes &nodes)
for (const ClipperLib::PolyNode *node : nodes) for (const ClipperLib::PolyNode *node : nodes)
ordering_points.emplace_back( ordering_points.emplace_back(
Point(node->Contour.front().X, node->Contour.front().Y)); Point(node->Contour.front().x(), node->Contour.front().y()));
// perform the ordering // perform the ordering
ClipperLib::PolyNodes ordered_nodes = ClipperLib::PolyNodes ordered_nodes =
@ -777,7 +777,7 @@ static void traverse_pt_outside_in(const ClipperLib::PolyNodes &nodes, Polygons
Points ordering_points; Points ordering_points;
ordering_points.reserve(nodes.size()); ordering_points.reserve(nodes.size());
for (const ClipperLib::PolyNode *node : nodes) for (const ClipperLib::PolyNode *node : nodes)
ordering_points.emplace_back(node->Contour.front().X, node->Contour.front().Y); ordering_points.emplace_back(node->Contour.front().x(), node->Contour.front().y());
// Perform the ordering, push results recursively. // Perform the ordering, push results recursively.
//FIXME pass the last point to chain_clipper_polynodes? //FIXME pass the last point to chain_clipper_polynodes?

View File

@ -17,42 +17,42 @@ class BoundingBox;
class Line; class Line;
class MultiPoint; class MultiPoint;
class Point; class Point;
typedef Point Vector; using Vector = Point;
// Eigen types, to replace the Slic3r's own types in the future. // Eigen types, to replace the Slic3r's own types in the future.
// Vector types with a fixed point coordinate base type. // Vector types with a fixed point coordinate base type.
typedef Eigen::Matrix<coord_t, 2, 1, Eigen::DontAlign> Vec2crd; using Vec2crd = Eigen::Matrix<coord_t, 2, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<coord_t, 3, 1, Eigen::DontAlign> Vec3crd; using Vec3crd = Eigen::Matrix<coord_t, 3, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<int, 2, 1, Eigen::DontAlign> Vec2i; using Vec2i = Eigen::Matrix<int, 2, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<int, 3, 1, Eigen::DontAlign> Vec3i; using Vec3i = Eigen::Matrix<int, 3, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<int32_t, 2, 1, Eigen::DontAlign> Vec2i32; using Vec2i32 = Eigen::Matrix<int32_t, 2, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<int64_t, 2, 1, Eigen::DontAlign> Vec2i64; using Vec2i64 = Eigen::Matrix<int64_t, 2, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<int32_t, 3, 1, Eigen::DontAlign> Vec3i32; using Vec3i32 = Eigen::Matrix<int32_t, 3, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<int64_t, 3, 1, Eigen::DontAlign> Vec3i64; using Vec3i64 = Eigen::Matrix<int64_t, 3, 1, Eigen::DontAlign>;
// Vector types with a double coordinate base type. // Vector types with a double coordinate base type.
typedef Eigen::Matrix<float, 2, 1, Eigen::DontAlign> Vec2f; using Vec2f = Eigen::Matrix<float, 2, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<float, 3, 1, Eigen::DontAlign> Vec3f; using Vec3f = Eigen::Matrix<float, 3, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<double, 2, 1, Eigen::DontAlign> Vec2d; using Vec2d = Eigen::Matrix<double, 2, 1, Eigen::DontAlign>;
typedef Eigen::Matrix<double, 3, 1, Eigen::DontAlign> Vec3d; using Vec3d = Eigen::Matrix<double, 3, 1, Eigen::DontAlign>;
typedef std::vector<Point> Points; using Points = std::vector<Point>;
typedef std::vector<Point*> PointPtrs; using PointPtrs = std::vector<Point*>;
typedef std::vector<const Point*> PointConstPtrs; using PointConstPtrs = std::vector<const Point*>;
typedef std::vector<Vec3crd> Points3; using Points3 = std::vector<Vec3crd>;
typedef std::vector<Vec2d> Pointfs; using Pointfs = std::vector<Vec2d>;
typedef std::vector<Vec2d> Vec2ds; using Vec2ds = std::vector<Vec2d>;
typedef std::vector<Vec3d> Pointf3s; using Pointf3s = std::vector<Vec3d>;
typedef Eigen::Matrix<float, 2, 2, Eigen::DontAlign> Matrix2f; using Matrix2f = Eigen::Matrix<float, 2, 2, Eigen::DontAlign>;
typedef Eigen::Matrix<double, 2, 2, Eigen::DontAlign> Matrix2d; using Matrix2d = Eigen::Matrix<double, 2, 2, Eigen::DontAlign>;
typedef Eigen::Matrix<float, 3, 3, Eigen::DontAlign> Matrix3f; using Matrix3f = Eigen::Matrix<float, 3, 3, Eigen::DontAlign>;
typedef Eigen::Matrix<double, 3, 3, Eigen::DontAlign> Matrix3d; using Matrix3d = Eigen::Matrix<double, 3, 3, Eigen::DontAlign>;
typedef Eigen::Transform<float, 2, Eigen::Affine, Eigen::DontAlign> Transform2f; using Transform2f = Eigen::Transform<float, 2, Eigen::Affine, Eigen::DontAlign>;
typedef Eigen::Transform<double, 2, Eigen::Affine, Eigen::DontAlign> Transform2d; using Transform2d = Eigen::Transform<double, 2, Eigen::Affine, Eigen::DontAlign>;
typedef Eigen::Transform<float, 3, Eigen::Affine, Eigen::DontAlign> Transform3f; using Transform3f = Eigen::Transform<float, 3, Eigen::Affine, Eigen::DontAlign>;
typedef Eigen::Transform<double, 3, Eigen::Affine, Eigen::DontAlign> Transform3d; using Transform3d = Eigen::Transform<double, 3, Eigen::Affine, Eigen::DontAlign>;
inline bool operator<(const Vec2d &lhs, const Vec2d &rhs) { return lhs(0) < rhs(0) || (lhs(0) == rhs(0) && lhs(1) < rhs(1)); } inline bool operator<(const Vec2d &lhs, const Vec2d &rhs) { return lhs(0) < rhs(0) || (lhs(0) == rhs(0) && lhs(1) < rhs(1)); }
@ -101,7 +101,7 @@ template<int N, class T> using Vec = Eigen::Matrix<T, N, 1, Eigen::DontAlign, N
class Point : public Vec2crd class Point : public Vec2crd
{ {
public: public:
typedef coord_t coord_type; using coord_type = coord_t;
Point() : Vec2crd(0, 0) {} Point() : Vec2crd(0, 0) {}
Point(int32_t x, int32_t y) : Vec2crd(coord_t(x), coord_t(y)) {} Point(int32_t x, int32_t y) : Vec2crd(coord_t(x), coord_t(y)) {}
@ -337,7 +337,7 @@ public:
} }
private: private:
typedef typename std::unordered_multimap<Vec2crd, ValueType, PointHash> map_type; using map_type = typename std::unordered_multimap<Vec2crd, ValueType, PointHash>;
PointAccessor m_point_accessor; PointAccessor m_point_accessor;
map_type m_map; map_type m_map;
coord_t m_search_radius; coord_t m_search_radius;
@ -439,11 +439,11 @@ inline Point align_to_grid(Point coord, Point spacing, Point base)
#include <boost/polygon/polygon.hpp> #include <boost/polygon/polygon.hpp>
namespace boost { namespace polygon { namespace boost { namespace polygon {
template <> template <>
struct geometry_concept<Slic3r::Point> { typedef point_concept type; }; struct geometry_concept<Slic3r::Point> { using type = point_concept; };
template <> template <>
struct point_traits<Slic3r::Point> { struct point_traits<Slic3r::Point> {
typedef coord_t coordinate_type; using coordinate_type = coord_t;
static inline coordinate_type get(const Slic3r::Point& point, orientation_2d orient) { static inline coordinate_type get(const Slic3r::Point& point, orientation_2d orient) {
return static_cast<coordinate_type>(point((orient == HORIZONTAL) ? 0 : 1)); return static_cast<coordinate_type>(point((orient == HORIZONTAL) ? 0 : 1));
@ -452,7 +452,7 @@ namespace boost { namespace polygon {
template <> template <>
struct point_mutable_traits<Slic3r::Point> { struct point_mutable_traits<Slic3r::Point> {
typedef coord_t coordinate_type; using coordinate_type = coord_t;
static inline void set(Slic3r::Point& point, orientation_2d orient, coord_t value) { static inline void set(Slic3r::Point& point, orientation_2d orient, coord_t value) {
point((orient == HORIZONTAL) ? 0 : 1) = value; point((orient == HORIZONTAL) ? 0 : 1) = value;
} }

View File

@ -77,8 +77,8 @@ protected:
double getPx(const Point &p) { return p(0) * m_pxdim_scaled.w_mm; } double getPx(const Point &p) { return p(0) * m_pxdim_scaled.w_mm; }
double getPy(const Point &p) { return p(1) * m_pxdim_scaled.h_mm; } double getPy(const Point &p) { return p(1) * m_pxdim_scaled.h_mm; }
agg::path_storage to_path(const Polygon &poly) { return to_path(poly.points); } agg::path_storage to_path(const Polygon &poly) { return to_path(poly.points); }
double getPx(const ClipperLib::IntPoint &p) { return p.X * m_pxdim_scaled.w_mm; } double getPx(const ClipperLib::IntPoint &p) { return p.x() * m_pxdim_scaled.w_mm; }
double getPy(const ClipperLib::IntPoint& p) { return p.Y * m_pxdim_scaled.h_mm; } double getPy(const ClipperLib::IntPoint& p) { return p.y() * m_pxdim_scaled.h_mm; }
template<class PointVec> agg::path_storage _to_path(const PointVec& v) template<class PointVec> agg::path_storage _to_path(const PointVec& v)
{ {

View File

@ -806,8 +806,8 @@ static ClipperPolygons get_all_polygons(const SliceRecord& record, SliceOrigin o
} }
if(is_lefthanded) { if(is_lefthanded) {
for(auto& p : poly.Contour) p.X = -p.X; for(auto& p : poly.Contour) p.x() = -p.x();
for(auto& h : poly.Holes) for(auto& p : h) p.X = -p.X; for(auto& h : poly.Holes) for(auto& p : h) p.x() = -p.x();
} }
sl::rotate(poly, double(instances[i].rotation)); sl::rotate(poly, double(instances[i].rotation));

View File

@ -273,8 +273,8 @@ std::string SVG::get_path_d(const ClipperLib::Path &path, double scale, bool clo
std::ostringstream d; std::ostringstream d;
d << "M "; d << "M ";
for (ClipperLib::Path::const_iterator p = path.begin(); p != path.end(); ++p) { for (ClipperLib::Path::const_iterator p = path.begin(); p != path.end(); ++p) {
d << to_svg_x(scale * p->X - origin(0)) << " "; d << to_svg_x(scale * p->x() - origin(0)) << " ";
d << to_svg_y(scale * p->Y - origin(1)) << " "; d << to_svg_y(scale * p->y() - origin(1)) << " ";
} }
if (closed) d << "z"; if (closed) d << "z";
return d.str(); return d.str();

View File

@ -140,15 +140,15 @@ TEST_CASE("boundingCircle", "[Geometry]") {
PolygonImpl p = {{{0, 10}, {10, 0}, {0, -10}, {0, 10}}, {}}; PolygonImpl p = {{{0, 10}, {10, 0}, {0, -10}, {0, 10}}, {}};
Circle c = boundingCircle(p); Circle c = boundingCircle(p);
REQUIRE(c.center().X == 0); REQUIRE(c.center().x() == 0);
REQUIRE(c.center().Y == 0); REQUIRE(c.center().y() == 0);
REQUIRE(c.radius() == Approx(10)); REQUIRE(c.radius() == Approx(10));
shapelike::translate(p, PointImpl{10, 10}); shapelike::translate(p, PointImpl{10, 10});
c = boundingCircle(p); c = boundingCircle(p);
REQUIRE(c.center().X == 10); REQUIRE(c.center().x() == 10);
REQUIRE(c.center().Y == 10); REQUIRE(c.center().y() == 10);
REQUIRE(c.radius() == Approx(10)); REQUIRE(c.radius() == Approx(10));
auto parts = prusaParts(); auto parts = prusaParts();
@ -616,7 +616,7 @@ TEST_CASE("EmptyItemShouldBeUntouched", "[Nesting]") {
std::vector<Item> items; std::vector<Item> items;
items.emplace_back(Item{}); // Emplace empty item items.emplace_back(Item{}); // Emplace empty item
items.emplace_back(Item{0, 200, 0}); // Emplace zero area item items.emplace_back(Item{ { 0, 0} , { 200, 0 }, { 0, 0 } }); // Emplace zero area item
size_t bins = libnest2d::nest(items, bin); size_t bins = libnest2d::nest(items, bin);
@ -661,12 +661,12 @@ TEST_CASE("Items can be preloaded", "[Nesting]") {
REQUIRE(bins == 1); REQUIRE(bins == 1);
REQUIRE(fixed_rect.binId() == 0); REQUIRE(fixed_rect.binId() == 0);
REQUIRE(fixed_rect.translation().X == bin.center().X); REQUIRE(fixed_rect.translation().x() == bin.center().x());
REQUIRE(fixed_rect.translation().Y == bin.center().Y); REQUIRE(fixed_rect.translation().y() == bin.center().y());
REQUIRE(movable_rect.binId() == 0); REQUIRE(movable_rect.binId() == 0);
REQUIRE(movable_rect.translation().X != bin.center().X); REQUIRE(movable_rect.translation().x() != bin.center().x());
REQUIRE(movable_rect.translation().Y != bin.center().Y); REQUIRE(movable_rect.translation().y() != bin.center().y());
} }
SECTION("Preloaded Item should not affect free bins") { SECTION("Preloaded Item should not affect free bins") {
@ -677,14 +677,14 @@ TEST_CASE("Items can be preloaded", "[Nesting]") {
REQUIRE(bins == 2); REQUIRE(bins == 2);
REQUIRE(fixed_rect.binId() == 1); REQUIRE(fixed_rect.binId() == 1);
REQUIRE(fixed_rect.translation().X == bin.center().X); REQUIRE(fixed_rect.translation().x() == bin.center().x());
REQUIRE(fixed_rect.translation().Y == bin.center().Y); REQUIRE(fixed_rect.translation().y() == bin.center().y());
REQUIRE(movable_rect.binId() == 0); REQUIRE(movable_rect.binId() == 0);
auto bb = movable_rect.boundingBox(); auto bb = movable_rect.boundingBox();
REQUIRE(bb.center().X == bin.center().X); REQUIRE(bb.center().x() == bin.center().x());
REQUIRE(bb.center().Y == bin.center().Y); REQUIRE(bb.center().y() == bin.center().y());
} }
} }

View File

@ -26,7 +26,7 @@ namespace Slic3r {
pt.Y += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA; pt.Y += CLIPPER_OFFSET_SCALE_ROUNDING_DELTA;
pt.X >>= CLIPPER_OFFSET_POWER_OF_2; pt.X >>= CLIPPER_OFFSET_POWER_OF_2;
pt.Y >>= CLIPPER_OFFSET_POWER_OF_2; pt.Y >>= CLIPPER_OFFSET_POWER_OF_2;
out.emplace_back(coord_t(pt.X), coord_t(pt.Y)); out.emplace_back(coord_t(pt.x()), coord_t(pt.y()));
} }
return out; return out;
} }