From 86da6610977d15e43842b83f5714daf0cc6cdc90 Mon Sep 17 00:00:00 2001 From: bubnikv <bubnikv@gmail.com> Date: Tue, 14 Aug 2018 18:33:26 +0200 Subject: [PATCH] Changing the internal representation of Point / Pointf / Point3 / Pointf3 to Eigen Matrix types, first step --- xs/src/libslic3r/BoundingBox.cpp | 98 +++---- xs/src/libslic3r/BoundingBox.hpp | 46 ++-- xs/src/libslic3r/BridgeDetector.cpp | 10 +- xs/src/libslic3r/ClipperUtils.cpp | 4 +- xs/src/libslic3r/Config.hpp | 16 +- xs/src/libslic3r/EdgeGrid.cpp | 284 ++++++++++----------- xs/src/libslic3r/ExPolygon.cpp | 43 ++-- xs/src/libslic3r/ExtrusionSimulator.cpp | 44 ++-- xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp | 14 +- xs/src/libslic3r/Fill/FillBase.hpp | 4 +- xs/src/libslic3r/Fill/FillConcentric.cpp | 2 +- xs/src/libslic3r/Fill/FillGyroid.cpp | 26 +- xs/src/libslic3r/Fill/FillHoneycomb.cpp | 6 +- xs/src/libslic3r/Fill/FillPlanePath.cpp | 20 +- xs/src/libslic3r/Fill/FillRectilinear.cpp | 24 +- xs/src/libslic3r/Fill/FillRectilinear2.cpp | 62 ++--- xs/src/libslic3r/Fill/FillRectilinear3.cpp | 70 ++--- xs/src/libslic3r/Format/3mf.cpp | 6 +- xs/src/libslic3r/Format/AMF.cpp | 8 +- xs/src/libslic3r/Format/PRUS.cpp | 4 +- xs/src/libslic3r/GCode.cpp | 62 ++--- xs/src/libslic3r/GCode/Analyzer.cpp | 22 +- xs/src/libslic3r/GCode/CoolingBuffer.cpp | 6 +- xs/src/libslic3r/GCode/PrintExtents.cpp | 24 +- xs/src/libslic3r/GCodeWriter.cpp | 48 ++-- xs/src/libslic3r/Geometry.cpp | 84 +++--- xs/src/libslic3r/Geometry.hpp | 30 +-- xs/src/libslic3r/Layer.cpp | 8 +- xs/src/libslic3r/LayerRegion.cpp | 8 +- xs/src/libslic3r/Line.cpp | 50 ++-- xs/src/libslic3r/Model.cpp | 124 ++++----- xs/src/libslic3r/Model.hpp | 2 +- xs/src/libslic3r/MultiPoint.cpp | 40 +-- xs/src/libslic3r/Point.cpp | 140 +++++----- xs/src/libslic3r/Point.hpp | 172 +++++++------ xs/src/libslic3r/Polygon.cpp | 38 +-- xs/src/libslic3r/Polygon.hpp | 2 +- xs/src/libslic3r/Polyline.cpp | 4 +- xs/src/libslic3r/Polyline.hpp | 2 +- xs/src/libslic3r/PolylineCollection.cpp | 10 +- xs/src/libslic3r/Print.cpp | 6 +- xs/src/libslic3r/PrintConfig.cpp | 2 +- xs/src/libslic3r/PrintObject.cpp | 12 +- xs/src/libslic3r/SVG.cpp | 50 ++-- xs/src/libslic3r/Slicing.cpp | 24 +- xs/src/libslic3r/SupportMaterial.cpp | 42 +-- xs/src/libslic3r/Surface.cpp | 6 +- xs/src/libslic3r/SurfaceCollection.cpp | 4 +- xs/src/libslic3r/TriangleMesh.cpp | 84 +++--- xs/src/perlglue.cpp | 16 +- xs/src/slic3r/GUI/2DBed.cpp | 58 ++--- xs/src/slic3r/GUI/3DScene.cpp | 96 +++---- xs/src/slic3r/GUI/3DScene.hpp | 20 +- xs/src/slic3r/GUI/BedShapeDialog.cpp | 20 +- xs/src/slic3r/GUI/Field.cpp | 12 +- xs/src/slic3r/GUI/GLCanvas3D.cpp | 148 +++++------ xs/src/slic3r/GUI/GLGizmo.cpp | 68 ++--- xs/src/xsinit.h | 7 + xs/xsp/BoundingBox.xsp | 50 ++-- xs/xsp/Point.xsp | 42 +-- 60 files changed, 1228 insertions(+), 1206 deletions(-) diff --git a/xs/src/libslic3r/BoundingBox.cpp b/xs/src/libslic3r/BoundingBox.cpp index 4355cd61b..7ab45c9d2 100644 --- a/xs/src/libslic3r/BoundingBox.cpp +++ b/xs/src/libslic3r/BoundingBox.cpp @@ -27,14 +27,14 @@ BoundingBox::polygon(Polygon* polygon) const { polygon->points.clear(); polygon->points.resize(4); - polygon->points[0].x = this->min.x; - polygon->points[0].y = this->min.y; - polygon->points[1].x = this->max.x; - polygon->points[1].y = this->min.y; - polygon->points[2].x = this->max.x; - polygon->points[2].y = this->max.y; - polygon->points[3].x = this->min.x; - polygon->points[3].y = this->max.y; + polygon->points[0].x() = this->min.x(); + polygon->points[0].y() = this->min.y(); + polygon->points[1].x() = this->max.x(); + polygon->points[1].y() = this->min.y(); + polygon->points[2].x() = this->max.x(); + polygon->points[2].y() = this->max.y(); + polygon->points[3].x() = this->min.x(); + polygon->points[3].y() = this->max.y(); } Polygon @@ -50,8 +50,8 @@ BoundingBox BoundingBox::rotated(double angle) const BoundingBox out; out.merge(this->min.rotated(angle)); out.merge(this->max.rotated(angle)); - out.merge(Point(this->min.x, this->max.y).rotated(angle)); - out.merge(Point(this->max.x, this->min.y).rotated(angle)); + out.merge(Point(this->min.x(), this->max.y()).rotated(angle)); + out.merge(Point(this->max.x(), this->min.y()).rotated(angle)); return out; } @@ -60,8 +60,8 @@ BoundingBox BoundingBox::rotated(double angle, const Point ¢er) const BoundingBox out; out.merge(this->min.rotated(angle, center)); out.merge(this->max.rotated(angle, center)); - out.merge(Point(this->min.x, this->max.y).rotated(angle, center)); - out.merge(Point(this->max.x, this->min.y).rotated(angle, center)); + out.merge(Point(this->min.x(), this->max.y()).rotated(angle, center)); + out.merge(Point(this->max.x(), this->min.y()).rotated(angle, center)); return out; } @@ -79,10 +79,10 @@ template <class PointClass> void BoundingBoxBase<PointClass>::merge(const PointClass &point) { if (this->defined) { - this->min.x = std::min(point.x, this->min.x); - this->min.y = std::min(point.y, this->min.y); - this->max.x = std::max(point.x, this->max.x); - this->max.y = std::max(point.y, this->max.y); + this->min.x() = std::min(point.x(), this->min.x()); + this->min.y() = std::min(point.y(), this->min.y()); + this->max.x() = std::max(point.x(), this->max.x()); + this->max.y() = std::max(point.y(), this->max.y()); } else { this->min = this->max = point; this->defined = true; @@ -102,13 +102,13 @@ template void BoundingBoxBase<Pointf>::merge(const Pointfs &points); template <class PointClass> void BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb) { - assert(bb.defined || bb.min.x >= bb.max.x || bb.min.y >= bb.max.y); + assert(bb.defined || bb.min.x() >= bb.max.x() || bb.min.y() >= bb.max.y()); if (bb.defined) { if (this->defined) { - this->min.x = std::min(bb.min.x, this->min.x); - this->min.y = std::min(bb.min.y, this->min.y); - this->max.x = std::max(bb.max.x, this->max.x); - this->max.y = std::max(bb.max.y, this->max.y); + this->min.x() = std::min(bb.min.x(), this->min.x()); + this->min.y() = std::min(bb.min.y(), this->min.y()); + this->max.x() = std::max(bb.max.x(), this->max.x()); + this->max.y() = std::max(bb.max.y(), this->max.y()); } else { this->min = bb.min; this->max = bb.max; @@ -123,8 +123,8 @@ template <class PointClass> void BoundingBox3Base<PointClass>::merge(const PointClass &point) { if (this->defined) { - this->min.z = std::min(point.z, this->min.z); - this->max.z = std::max(point.z, this->max.z); + this->min.z() = std::min(point.z(), this->min.z()); + this->max.z() = std::max(point.z(), this->max.z()); } BoundingBoxBase<PointClass>::merge(point); } @@ -140,11 +140,11 @@ template void BoundingBox3Base<Pointf3>::merge(const Pointf3s &points); template <class PointClass> void BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb) { - assert(bb.defined || bb.min.x >= bb.max.x || bb.min.y >= bb.max.y || bb.min.z >= bb.max.z); + assert(bb.defined || bb.min.x() >= bb.max.x() || bb.min.y() >= bb.max.y() || bb.min.z() >= bb.max.z()); if (bb.defined) { if (this->defined) { - this->min.z = std::min(bb.min.z, this->min.z); - this->max.z = std::max(bb.max.z, this->max.z); + this->min.z() = std::min(bb.min.z(), this->min.z()); + this->max.z() = std::max(bb.max.z(), this->max.z()); } BoundingBoxBase<PointClass>::merge(bb); } @@ -154,7 +154,7 @@ template void BoundingBox3Base<Pointf3>::merge(const BoundingBox3Base<Pointf3> & template <class PointClass> PointClass BoundingBoxBase<PointClass>::size() const { - return PointClass(this->max.x - this->min.x, this->max.y - this->min.y); + return PointClass(this->max.x() - this->min.x(), this->max.y() - this->min.y()); } template Point BoundingBoxBase<Point>::size() const; template Pointf BoundingBoxBase<Pointf>::size() const; @@ -162,15 +162,15 @@ template Pointf BoundingBoxBase<Pointf>::size() const; template <class PointClass> PointClass BoundingBox3Base<PointClass>::size() const { - return PointClass(this->max.x - this->min.x, this->max.y - this->min.y, this->max.z - this->min.z); + return PointClass(this->max.x() - this->min.x(), this->max.y() - this->min.y(), this->max.z() - this->min.z()); } template Pointf3 BoundingBox3Base<Pointf3>::size() const; template <class PointClass> double BoundingBoxBase<PointClass>::radius() const { assert(this->defined); - double x = this->max.x - this->min.x; - double y = this->max.y - this->min.y; + double x = this->max.x() - this->min.x(); + double y = this->max.y() - this->min.y(); return 0.5 * sqrt(x*x+y*y); } template double BoundingBoxBase<Point>::radius() const; @@ -178,9 +178,9 @@ template double BoundingBoxBase<Pointf>::radius() const; template <class PointClass> double BoundingBox3Base<PointClass>::radius() const { - double x = this->max.x - this->min.x; - double y = this->max.y - this->min.y; - double z = this->max.z - this->min.z; + double x = this->max.x() - this->min.x(); + double y = this->max.y() - this->min.y(); + double z = this->max.z() - this->min.z(); return 0.5 * sqrt(x*x+y*y+z*z); } template double BoundingBox3Base<Pointf3>::radius() const; @@ -206,8 +206,8 @@ template <class PointClass> PointClass BoundingBoxBase<PointClass>::center() const { return PointClass( - (this->max.x + this->min.x)/2, - (this->max.y + this->min.y)/2 + (this->max.x() + this->min.x())/2, + (this->max.y() + this->min.y())/2 ); } template Point BoundingBoxBase<Point>::center() const; @@ -217,9 +217,9 @@ template <class PointClass> PointClass BoundingBox3Base<PointClass>::center() const { return PointClass( - (this->max.x + this->min.x)/2, - (this->max.y + this->min.y)/2, - (this->max.z + this->min.z)/2 + (this->max.x() + this->min.x())/2, + (this->max.y() + this->min.y())/2, + (this->max.z() + this->min.z())/2 ); } template Pointf3 BoundingBox3Base<Pointf3>::center() const; @@ -228,7 +228,7 @@ template <class PointClass> coordf_t BoundingBox3Base<PointClass>::max_size() const { PointClass s = size(); - return std::max(s.x, std::max(s.y, s.z)); + return std::max(s.x(), std::max(s.y(), s.z())); } template coordf_t BoundingBox3Base<Pointf3>::max_size() const; @@ -248,8 +248,8 @@ static inline coord_t _align_to_grid(const coord_t coord, const coord_t spacing) void BoundingBox::align_to_grid(const coord_t cell_size) { if (this->defined) { - min.x = _align_to_grid(min.x, cell_size); - min.y = _align_to_grid(min.y, cell_size); + min.x() = _align_to_grid(min.x(), cell_size); + min.y() = _align_to_grid(min.y(), cell_size); } } @@ -257,14 +257,14 @@ BoundingBoxf3 BoundingBoxf3::transformed(const std::vector<float>& matrix) const { Eigen::Matrix<float, 3, 8> vertices; - vertices(0, 0) = (float)min.x; vertices(1, 0) = (float)min.y; vertices(2, 0) = (float)min.z; - vertices(0, 1) = (float)max.x; vertices(1, 1) = (float)min.y; vertices(2, 1) = (float)min.z; - vertices(0, 2) = (float)max.x; vertices(1, 2) = (float)max.y; vertices(2, 2) = (float)min.z; - vertices(0, 3) = (float)min.x; vertices(1, 3) = (float)max.y; vertices(2, 3) = (float)min.z; - vertices(0, 4) = (float)min.x; vertices(1, 4) = (float)min.y; vertices(2, 4) = (float)max.z; - vertices(0, 5) = (float)max.x; vertices(1, 5) = (float)min.y; vertices(2, 5) = (float)max.z; - vertices(0, 6) = (float)max.x; vertices(1, 6) = (float)max.y; vertices(2, 6) = (float)max.z; - vertices(0, 7) = (float)min.x; vertices(1, 7) = (float)max.y; vertices(2, 7) = (float)max.z; + vertices(0, 0) = (float)min.x(); vertices(1, 0) = (float)min.y(); vertices(2, 0) = (float)min.z(); + vertices(0, 1) = (float)max.x(); vertices(1, 1) = (float)min.y(); vertices(2, 1) = (float)min.z(); + vertices(0, 2) = (float)max.x(); vertices(1, 2) = (float)max.y(); vertices(2, 2) = (float)min.z(); + vertices(0, 3) = (float)min.x(); vertices(1, 3) = (float)max.y(); vertices(2, 3) = (float)min.z(); + vertices(0, 4) = (float)min.x(); vertices(1, 4) = (float)min.y(); vertices(2, 4) = (float)max.z(); + vertices(0, 5) = (float)max.x(); vertices(1, 5) = (float)min.y(); vertices(2, 5) = (float)max.z(); + vertices(0, 6) = (float)max.x(); vertices(1, 6) = (float)max.y(); vertices(2, 6) = (float)max.z(); + vertices(0, 7) = (float)min.x(); vertices(1, 7) = (float)max.y(); vertices(2, 7) = (float)max.z(); Eigen::Transform<float, 3, Eigen::Affine> m; ::memcpy((void*)m.data(), (const void*)matrix.data(), 16 * sizeof(float)); diff --git a/xs/src/libslic3r/BoundingBox.hpp b/xs/src/libslic3r/BoundingBox.hpp index 5324dbe3b..13f1de5bd 100644 --- a/xs/src/libslic3r/BoundingBox.hpp +++ b/xs/src/libslic3r/BoundingBox.hpp @@ -22,23 +22,23 @@ public: BoundingBoxBase() : defined(false) {}; BoundingBoxBase(const PointClass &pmin, const PointClass &pmax) : - min(pmin), max(pmax), defined(pmin.x < pmax.x && pmin.y < pmax.y) {} + min(pmin), max(pmax), defined(pmin.x() < pmax.x() && pmin.y() < pmax.y()) {} BoundingBoxBase(const std::vector<PointClass>& points) { if (points.empty()) CONFESS("Empty point set supplied to BoundingBoxBase constructor"); typename std::vector<PointClass>::const_iterator it = points.begin(); - this->min.x = this->max.x = it->x; - this->min.y = this->max.y = it->y; + this->min.x() = this->max.x() = it->x(); + this->min.y() = this->max.y() = it->y(); for (++it; it != points.end(); ++it) { - this->min.x = std::min(it->x, this->min.x); - this->min.y = std::min(it->y, this->min.y); - this->max.x = std::max(it->x, this->max.x); - this->max.y = std::max(it->y, this->max.y); + this->min.x() = std::min(it->x(), this->min.x()); + this->min.y() = std::min(it->y(), this->min.y()); + this->max.x() = std::max(it->x(), this->max.x()); + this->max.y() = std::max(it->y(), this->max.y()); } - this->defined = (this->min.x < this->max.x) && (this->min.y < this->max.y); + this->defined = (this->min.x() < this->max.x()) && (this->min.y() < this->max.y()); } void merge(const PointClass &point); void merge(const std::vector<PointClass> &points); @@ -47,16 +47,16 @@ public: PointClass size() const; double radius() const; void translate(coordf_t x, coordf_t y) { assert(this->defined); this->min.translate(x, y); this->max.translate(x, y); } - void translate(const Pointf &pos) { this->translate(pos.x, pos.y); } + void translate(const Pointf &pos) { this->translate(pos.x(), pos.y()); } void offset(coordf_t delta); PointClass center() const; bool contains(const PointClass &point) const { - return point.x >= this->min.x && point.x <= this->max.x - && point.y >= this->min.y && point.y <= this->max.y; + return point.x() >= this->min.x() && point.x() <= this->max.x() + && point.y() >= this->min.y() && point.y() <= this->max.y(); } bool overlap(const BoundingBoxBase<PointClass> &other) const { - return ! (this->max.x < other.min.x || this->min.x > other.max.x || - this->max.y < other.min.y || this->min.y > other.max.y); + return ! (this->max.x() < other.min.x() || this->min.x() > other.max.x() || + this->max.y() < other.min.y() || this->min.y() > other.max.y()); } bool operator==(const BoundingBoxBase<PointClass> &rhs) { return this->min == rhs.min && this->max == rhs.max; } bool operator!=(const BoundingBoxBase<PointClass> &rhs) { return ! (*this == rhs); } @@ -69,7 +69,7 @@ public: BoundingBox3Base() : BoundingBoxBase<PointClass>() {}; BoundingBox3Base(const PointClass &pmin, const PointClass &pmax) : BoundingBoxBase<PointClass>(pmin, pmax) - { if (pmin.z >= pmax.z) BoundingBoxBase<PointClass>::defined = false; } + { if (pmin.z() >= pmax.z()) BoundingBoxBase<PointClass>::defined = false; } BoundingBox3Base(const std::vector<PointClass>& points) : BoundingBoxBase<PointClass>(points) { @@ -77,13 +77,13 @@ public: CONFESS("Empty point set supplied to BoundingBox3Base constructor"); typename std::vector<PointClass>::const_iterator it = points.begin(); - this->min.z = this->max.z = it->z; + this->min.z() = this->max.z() = it->z(); for (++it; it != points.end(); ++it) { - this->min.z = std::min(it->z, this->min.z); - this->max.z = std::max(it->z, this->max.z); + this->min.z() = std::min(it->z(), this->min.z()); + this->max.z() = std::max(it->z(), this->max.z()); } - this->defined &= (this->min.z < this->max.z); + this->defined &= (this->min.z() < this->max.z()); } void merge(const PointClass &point); void merge(const std::vector<PointClass> &points); @@ -91,13 +91,13 @@ public: PointClass size() const; double radius() const; void translate(coordf_t x, coordf_t y, coordf_t z) { this->min.translate(x, y, z); this->max.translate(x, y, z); } - void translate(const Pointf3 &pos) { this->translate(pos.x, pos.y, pos.z); } + void translate(const Pointf3 &pos) { this->translate(pos.x(), pos.y(), pos.z()); } void offset(coordf_t delta); PointClass center() const; coordf_t max_size() const; bool contains(const PointClass &point) const { - return BoundingBoxBase<PointClass>::contains(point) && point.z >= this->min.z && point.z <= this->max.z; + return BoundingBoxBase<PointClass>::contains(point) && point.z() >= this->min.z() && point.z() <= this->max.z(); } bool contains(const BoundingBox3Base<PointClass>& other) const { @@ -105,7 +105,7 @@ public: } bool intersects(const BoundingBox3Base<PointClass>& other) const { - return (this->min.x < other.max.x) && (this->max.x > other.min.x) && (this->min.y < other.max.y) && (this->max.y > other.min.y) && (this->min.z < other.max.z) && (this->max.z > other.min.z); + return (this->min.x() < other.max.x()) && (this->max.x() > other.min.x()) && (this->min.y() < other.max.y()) && (this->max.y() > other.min.y()) && (this->min.z() < other.max.z()) && (this->max.z() > other.min.z()); } }; @@ -159,13 +159,13 @@ public: template<typename VT> inline bool empty(const BoundingBoxBase<VT> &bb) { - return ! bb.defined || bb.min.x >= bb.max.x || bb.min.y >= bb.max.y; + return ! bb.defined || bb.min.x() >= bb.max.x() || bb.min.y() >= bb.max.y(); } template<typename VT> inline bool empty(const BoundingBox3Base<VT> &bb) { - return ! bb.defined || bb.min.x >= bb.max.x || bb.min.y >= bb.max.y || bb.min.z >= bb.max.z; + return ! bb.defined || bb.min.x() >= bb.max.x() || bb.min.y() >= bb.max.y() || bb.min.z() >= bb.max.z(); } } // namespace Slic3r diff --git a/xs/src/libslic3r/BridgeDetector.cpp b/xs/src/libslic3r/BridgeDetector.cpp index a5272683f..52214fcfb 100644 --- a/xs/src/libslic3r/BridgeDetector.cpp +++ b/xs/src/libslic3r/BridgeDetector.cpp @@ -102,16 +102,16 @@ bool BridgeDetector::detect_angle(double bridge_direction_override) // Get an oriented bounding box around _anchor_regions. BoundingBox bbox = get_extents_rotated(this->_anchor_regions, - angle); // Cover the region with line segments. - lines.reserve((bbox.max.y - bbox.min.y + this->spacing) / this->spacing); + lines.reserve((bbox.max.y() - bbox.min.y() + this->spacing) / this->spacing); double s = sin(angle); double c = cos(angle); //FIXME Vojtech: The lines shall be spaced half the line width from the edge, but then // some of the test cases fail. Need to adjust the test cases then? -// for (coord_t y = bbox.min.y + this->spacing / 2; y <= bbox.max.y; y += this->spacing) - for (coord_t y = bbox.min.y; y <= bbox.max.y; y += this->spacing) +// for (coord_t y = bbox.min.y() + this->spacing / 2; y <= bbox.max.y(); y += this->spacing) + for (coord_t y = bbox.min.y(); y <= bbox.max.y(); y += this->spacing) lines.push_back(Line( - Point((coord_t)round(c * bbox.min.x - s * y), (coord_t)round(c * y + s * bbox.min.x)), - Point((coord_t)round(c * bbox.max.x - s * y), (coord_t)round(c * y + s * bbox.max.x)))); + Point((coord_t)round(c * bbox.min.x() - s * y), (coord_t)round(c * y + s * bbox.min.x())), + Point((coord_t)round(c * bbox.max.x() - s * y), (coord_t)round(c * y + s * bbox.max.x())))); } double total_length = 0; diff --git a/xs/src/libslic3r/ClipperUtils.cpp b/xs/src/libslic3r/ClipperUtils.cpp index 31a12aa77..d27a3e30e 100644 --- a/xs/src/libslic3r/ClipperUtils.cpp +++ b/xs/src/libslic3r/ClipperUtils.cpp @@ -171,7 +171,7 @@ Slic3rMultiPoint_to_ClipperPath(const MultiPoint &input) { ClipperLib::Path retval; for (Points::const_iterator pit = input.points.begin(); pit != input.points.end(); ++pit) - retval.push_back(ClipperLib::IntPoint( (*pit).x, (*pit).y )); + retval.push_back(ClipperLib::IntPoint( (*pit).x(), (*pit).y() )); return retval; } @@ -181,7 +181,7 @@ Slic3rMultiPoint_to_ClipperPath_reversed(const Slic3r::MultiPoint &input) ClipperLib::Path output; output.reserve(input.points.size()); for (Slic3r::Points::const_reverse_iterator pit = input.points.rbegin(); pit != input.points.rend(); ++pit) - output.push_back(ClipperLib::IntPoint( (*pit).x, (*pit).y )); + output.push_back(ClipperLib::IntPoint( (*pit).x(), (*pit).y() )); return output; } diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 377bdbea4..23ea3622f 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -637,9 +637,9 @@ public: std::string serialize() const override { std::ostringstream ss; - ss << this->value.x; + ss << this->value.x(); ss << ","; - ss << this->value.y; + ss << this->value.y(); return ss.str(); } @@ -647,8 +647,8 @@ public: { UNUSED(append); char dummy; - return sscanf(str.data(), " %lf , %lf %c", &this->value.x, &this->value.y, &dummy) == 2 || - sscanf(str.data(), " %lf x %lf %c", &this->value.x, &this->value.y, &dummy) == 2; + return sscanf(str.data(), " %lf , %lf %c", &this->value.x(), &this->value.y(), &dummy) == 2 || + sscanf(str.data(), " %lf x %lf %c", &this->value.x(), &this->value.y(), &dummy) == 2; } }; @@ -671,9 +671,9 @@ public: std::ostringstream ss; for (Pointfs::const_iterator it = this->values.begin(); it != this->values.end(); ++it) { if (it - this->values.begin() != 0) ss << ","; - ss << it->x; + ss << it->x(); ss << "x"; - ss << it->y; + ss << it->y(); } return ss.str(); } @@ -700,9 +700,9 @@ public: std::istringstream iss(point_str); std::string coord_str; if (std::getline(iss, coord_str, 'x')) { - std::istringstream(coord_str) >> point.x; + std::istringstream(coord_str) >> point.x(); if (std::getline(iss, coord_str, 'x')) { - std::istringstream(coord_str) >> point.y; + std::istringstream(coord_str) >> point.y(); } } this->values.push_back(point); diff --git a/xs/src/libslic3r/EdgeGrid.cpp b/xs/src/libslic3r/EdgeGrid.cpp index 733ff2ad7..78120a471 100644 --- a/xs/src/libslic3r/EdgeGrid.cpp +++ b/xs/src/libslic3r/EdgeGrid.cpp @@ -117,15 +117,15 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) m_bbox.merge(pts[j]); } coord_t eps = 16; - m_bbox.min.x -= eps; - m_bbox.min.y -= eps; - m_bbox.max.x += eps; - m_bbox.max.y += eps; + m_bbox.min.x() -= eps; + m_bbox.min.y() -= eps; + m_bbox.max.x() += eps; + m_bbox.max.y() += eps; // 2) Initialize the edge grid. m_resolution = resolution; - m_cols = (m_bbox.max.x - m_bbox.min.x + m_resolution - 1) / m_resolution; - m_rows = (m_bbox.max.y - m_bbox.min.y + m_resolution - 1) / m_resolution; + m_cols = (m_bbox.max.x() - m_bbox.min.x() + m_resolution - 1) / m_resolution; + m_rows = (m_bbox.max.y() - m_bbox.min.y() + m_resolution - 1) / m_resolution; m_cells.assign(m_rows * m_cols, Cell()); // 3) First round of contour rasterization, count the edges per grid cell. @@ -135,15 +135,15 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) // End points of the line segment. Slic3r::Point p1(pts[j]); Slic3r::Point p2 = pts[(j + 1 == pts.size()) ? 0 : j + 1]; - p1.x -= m_bbox.min.x; - p1.y -= m_bbox.min.y; - p2.x -= m_bbox.min.x; - p2.y -= m_bbox.min.y; + p1.x() -= m_bbox.min.x(); + p1.y() -= m_bbox.min.y(); + p2.x() -= m_bbox.min.x(); + p2.y() -= m_bbox.min.y(); // Get the cells of the end points. - coord_t ix = p1.x / m_resolution; - coord_t iy = p1.y / m_resolution; - coord_t ixb = p2.x / m_resolution; - coord_t iyb = p2.y / m_resolution; + coord_t ix = p1.x() / m_resolution; + coord_t iy = p1.y() / m_resolution; + coord_t ixb = p2.x() / m_resolution; + coord_t iyb = p2.y() / m_resolution; assert(ix >= 0 && ix < m_cols); assert(iy >= 0 && iy < m_rows); assert(ixb >= 0 && ixb < m_cols); @@ -154,13 +154,13 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) // Both ends fall into the same cell. continue; // Raster the centeral part of the line. - coord_t dx = std::abs(p2.x - p1.x); - coord_t dy = std::abs(p2.y - p1.y); - if (p1.x < p2.x) { - int64_t ex = int64_t((ix + 1)*m_resolution - p1.x) * int64_t(dy); - if (p1.y < p2.y) { + coord_t dx = std::abs(p2.x() - p1.x()); + coord_t dy = std::abs(p2.y() - p1.y()); + if (p1.x() < p2.x()) { + int64_t ex = int64_t((ix + 1)*m_resolution - p1.x()) * int64_t(dy); + if (p1.y() < p2.y()) { // x positive, y positive - int64_t ey = int64_t((iy + 1)*m_resolution - p1.y) * int64_t(dx); + int64_t ey = int64_t((iy + 1)*m_resolution - p1.y()) * int64_t(dx); do { assert(ix <= ixb && iy <= iyb); if (ex < ey) { @@ -185,7 +185,7 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) } else { // x positive, y non positive - int64_t ey = int64_t(p1.y - iy*m_resolution) * int64_t(dx); + int64_t ey = int64_t(p1.y() - iy*m_resolution) * int64_t(dx); do { assert(ix <= ixb && iy >= iyb); if (ex <= ey) { @@ -203,10 +203,10 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) } } else { - int64_t ex = int64_t(p1.x - ix*m_resolution) * int64_t(dy); - if (p1.y < p2.y) { + int64_t ex = int64_t(p1.x() - ix*m_resolution) * int64_t(dy); + if (p1.y() < p2.y()) { // x non positive, y positive - int64_t ey = int64_t((iy + 1)*m_resolution - p1.y) * int64_t(dx); + int64_t ey = int64_t((iy + 1)*m_resolution - p1.y()) * int64_t(dx); do { assert(ix >= ixb && iy <= iyb); if (ex < ey) { @@ -225,7 +225,7 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) } else { // x non positive, y non positive - int64_t ey = int64_t(p1.y - iy*m_resolution) * int64_t(dx); + int64_t ey = int64_t(p1.y() - iy*m_resolution) * int64_t(dx); do { assert(ix >= ixb && iy >= iyb); if (ex < ey) { @@ -279,15 +279,15 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) // End points of the line segment. Slic3r::Point p1(pts[j]); Slic3r::Point p2 = pts[(j + 1 == pts.size()) ? 0 : j + 1]; - p1.x -= m_bbox.min.x; - p1.y -= m_bbox.min.y; - p2.x -= m_bbox.min.x; - p2.y -= m_bbox.min.y; + p1.x() -= m_bbox.min.x(); + p1.y() -= m_bbox.min.y(); + p2.x() -= m_bbox.min.x(); + p2.y() -= m_bbox.min.y(); // Get the cells of the end points. - coord_t ix = p1.x / m_resolution; - coord_t iy = p1.y / m_resolution; - coord_t ixb = p2.x / m_resolution; - coord_t iyb = p2.y / m_resolution; + coord_t ix = p1.x() / m_resolution; + coord_t iy = p1.y() / m_resolution; + coord_t ixb = p2.x() / m_resolution; + coord_t iyb = p2.y() / m_resolution; assert(ix >= 0 && ix < m_cols); assert(iy >= 0 && iy < m_rows); assert(ixb >= 0 && ixb < m_cols); @@ -298,13 +298,13 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) // Both ends fall into the same cell. continue; // Raster the centeral part of the line. - coord_t dx = std::abs(p2.x - p1.x); - coord_t dy = std::abs(p2.y - p1.y); - if (p1.x < p2.x) { - int64_t ex = int64_t((ix + 1)*m_resolution - p1.x) * int64_t(dy); - if (p1.y < p2.y) { + coord_t dx = std::abs(p2.x() - p1.x()); + coord_t dy = std::abs(p2.y() - p1.y()); + if (p1.x() < p2.x()) { + int64_t ex = int64_t((ix + 1)*m_resolution - p1.x()) * int64_t(dy); + if (p1.y() < p2.y()) { // x positive, y positive - int64_t ey = int64_t((iy + 1)*m_resolution - p1.y) * int64_t(dx); + int64_t ey = int64_t((iy + 1)*m_resolution - p1.y()) * int64_t(dx); do { assert(ix <= ixb && iy <= iyb); if (ex < ey) { @@ -329,7 +329,7 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) } else { // x positive, y non positive - int64_t ey = int64_t(p1.y - iy*m_resolution) * int64_t(dx); + int64_t ey = int64_t(p1.y() - iy*m_resolution) * int64_t(dx); do { assert(ix <= ixb && iy >= iyb); if (ex <= ey) { @@ -347,10 +347,10 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) } } else { - int64_t ex = int64_t(p1.x - ix*m_resolution) * int64_t(dy); - if (p1.y < p2.y) { + int64_t ex = int64_t(p1.x() - ix*m_resolution) * int64_t(dy); + if (p1.y() < p2.y()) { // x non positive, y positive - int64_t ey = int64_t((iy + 1)*m_resolution - p1.y) * int64_t(dx); + int64_t ey = int64_t((iy + 1)*m_resolution - p1.y()) * int64_t(dx); do { assert(ix >= ixb && iy <= iyb); if (ex < ey) { @@ -369,7 +369,7 @@ void EdgeGrid::Grid::create_from_m_contours(coord_t resolution) } else { // x non positive, y non positive - int64_t ey = int64_t(p1.y - iy*m_resolution) * int64_t(dx); + int64_t ey = int64_t(p1.y() - iy*m_resolution) * int64_t(dx); do { assert(ix >= ixb && iy >= iyb); if (ex < ey) { @@ -429,15 +429,15 @@ bool EdgeGrid::Grid::intersect(const MultiPoint &polyline, bool closed) Point p1 = p1src; Point p2 = p2src; // Discretize the line segment p1, p2. - p1.x -= m_bbox.min.x; - p1.y -= m_bbox.min.y; - p2.x -= m_bbox.min.x; - p2.y -= m_bbox.min.y; + p1.x() -= m_bbox.min.x(); + p1.y() -= m_bbox.min.y(); + p2.x() -= m_bbox.min.x(); + p2.y() -= m_bbox.min.y(); // Get the cells of the end points. - coord_t ix = div_floor(p1.x, m_resolution); - coord_t iy = div_floor(p1.y, m_resolution); - coord_t ixb = div_floor(p2.x, m_resolution); - coord_t iyb = div_floor(p2.y, m_resolution); + coord_t ix = div_floor(p1.x(), m_resolution); + coord_t iy = div_floor(p1.y(), m_resolution); + coord_t ixb = div_floor(p2.x(), m_resolution); + coord_t iyb = div_floor(p2.y(), m_resolution); // assert(ix >= 0 && ix < m_cols); // assert(iy >= 0 && iy < m_rows); // assert(ixb >= 0 && ixb < m_cols); @@ -449,12 +449,12 @@ bool EdgeGrid::Grid::intersect(const MultiPoint &polyline, bool closed) // Both ends fall into the same cell. continue; // Raster the centeral part of the line. - coord_t dx = std::abs(p2.x - p1.x); - coord_t dy = std::abs(p2.y - p1.y); - if (p1.x < p2.x) { - int64_t ex = int64_t((ix + 1)*m_resolution - p1.x) * int64_t(dy); - if (p1.y < p2.y) { - int64_t ey = int64_t((iy + 1)*m_resolution - p1.y) * int64_t(dx); + coord_t dx = std::abs(p2.x() - p1.x()); + coord_t dy = std::abs(p2.y() - p1.y()); + if (p1.x() < p2.x()) { + int64_t ex = int64_t((ix + 1)*m_resolution - p1.x()) * int64_t(dy); + if (p1.y() < p2.y()) { + int64_t ey = int64_t((iy + 1)*m_resolution - p1.y()) * int64_t(dx); do { assert(ix <= ixb && iy <= iyb); if (ex < ey) { @@ -479,7 +479,7 @@ bool EdgeGrid::Grid::intersect(const MultiPoint &polyline, bool closed) } while (ix != ixb || iy != iyb); } else { - int64_t ey = int64_t(p1.y - iy*m_resolution) * int64_t(dx); + int64_t ey = int64_t(p1.y() - iy*m_resolution) * int64_t(dx); do { assert(ix <= ixb && iy >= iyb); if (ex <= ey) { @@ -498,9 +498,9 @@ bool EdgeGrid::Grid::intersect(const MultiPoint &polyline, bool closed) } } else { - int64_t ex = int64_t(p1.x - ix*m_resolution) * int64_t(dy); - if (p1.y < p2.y) { - int64_t ey = int64_t((iy + 1)*m_resolution - p1.y) * int64_t(dx); + int64_t ex = int64_t(p1.x() - ix*m_resolution) * int64_t(dy); + if (p1.y() < p2.y()) { + int64_t ey = int64_t((iy + 1)*m_resolution - p1.y()) * int64_t(dx); do { assert(ix >= ixb && iy <= iyb); if (ex < ey) { @@ -519,7 +519,7 @@ bool EdgeGrid::Grid::intersect(const MultiPoint &polyline, bool closed) } while (ix != ixb || iy != iyb); } else { - int64_t ey = int64_t(p1.y - iy*m_resolution) * int64_t(dx); + int64_t ey = int64_t(p1.y() - iy*m_resolution) * int64_t(dx); do { assert(ix >= ixb && iy >= iyb); if (ex < ey) { @@ -556,8 +556,8 @@ bool EdgeGrid::Grid::line_cell_intersect(const Point &p1a, const Point &p2a, con { BoundingBox bbox(p1a, p1a); bbox.merge(p2a); - int64_t va_x = p2a.x - p1a.x; - int64_t va_y = p2a.y - p1a.y; + int64_t va_x = p2a.x() - p1a.x(); + int64_t va_y = p2a.y() - p1a.y(); for (size_t i = cell.begin; i != cell.end; ++ i) { const std::pair<size_t, size_t> &cell_data = m_cell_data[i]; // Contour indexed by the ith line of this cell. @@ -576,21 +576,21 @@ bool EdgeGrid::Grid::line_cell_intersect(const Point &p1a, const Point &p2a, con if (! bbox.overlap(bbox2)) continue; // Now intersect the two line segments using exact arithmetics. - int64_t w1_x = p1b.x - p1a.x; - int64_t w1_y = p1b.y - p1a.y; - int64_t w2_x = p2b.x - p1a.x; - int64_t w2_y = p2b.y - p1a.y; + int64_t w1_x = p1b.x() - p1a.x(); + int64_t w1_y = p1b.y() - p1a.y(); + int64_t w2_x = p2b.x() - p1a.x(); + int64_t w2_y = p2b.y() - p1a.y(); int64_t side1 = va_x * w1_y - va_y * w1_x; int64_t side2 = va_x * w2_y - va_y * w2_x; if (side1 == side2 && side1 != 0) // The line segments don't intersect. continue; - w1_x = p1a.x - p1b.x; - w1_y = p1a.y - p1b.y; - w2_x = p2a.x - p1b.x; - w2_y = p2a.y - p1b.y; - int64_t vb_x = p2b.x - p1b.x; - int64_t vb_y = p2b.y - p1b.y; + w1_x = p1a.x() - p1b.x(); + w1_y = p1a.y() - p1b.y(); + w2_x = p2a.x() - p1b.x(); + w2_y = p2a.y() - p1b.y(); + int64_t vb_x = p2b.x() - p1b.x(); + int64_t vb_y = p2b.y() - p1b.y(); side1 = vb_x * w1_y - vb_y * w1_x; side2 = vb_x * w2_y - vb_y * w2_x; if (side1 == side2 && side1 != 0) @@ -607,13 +607,13 @@ bool EdgeGrid::Grid::line_cell_intersect(const Point &p1a, const Point &p2a, con bool EdgeGrid::Grid::inside(const Point &pt_src) { Point p = pt_src; - p.x -= m_bbox.min.x; - p.y -= m_bbox.min.y; + p.x() -= m_bbox.min.x(); + p.y() -= m_bbox.min.y(); // Get the cell of the point. - if (p.x < 0 || p.y < 0) + if (p.x() < 0 || p.y() < 0) return false; - coord_t ix = p.x / m_resolution; - coord_t iy = p.y / m_resolution; + coord_t ix = p.x() / m_resolution; + coord_t iy = p.y() / m_resolution; if (ix >= this->m_cols || iy >= this->m_rows) return false; @@ -634,21 +634,21 @@ bool EdgeGrid::Grid::inside(const Point &pt_src) idx2 = 0; const Point &p1 = contour[idx1]; const Point &p2 = contour[idx2]; - if (p1.y < p2.y) { - if (p.y < p1.y || p.y > p2.y) + if (p1.y() < p2.y()) { + if (p.y() < p1.y() || p.y() > p2.y()) continue; //FIXME finish this! int64_t vx = 0;// pt_src //FIXME finish this! int64_t det = 0; - } else if (p1.y != p2.y) { - assert(p1.y > p2.y); - if (p.y < p2.y || p.y > p1.y) + } else if (p1.y() != p2.y()) { + assert(p1.y() > p2.y()); + if (p.y() < p2.y() || p.y() > p1.y()) continue; } else { - assert(p1.y == p2.y); - if (p1.y == p.y) { - if (p.x >= p1.x && p.x <= p2.x) + assert(p1.y() == p2.y()); + if (p1.y() == p.y()) { + if (p.x() >= p1.x() && p.x() <= p2.x()) // On the segment. return true; // Before or after the segment. @@ -769,7 +769,7 @@ void EdgeGrid::Grid::calculate_sdf() // Segment vector const Slic3r::Point v_seg = p1.vector_to(p2); // l2 of v_seg - const int64_t l2_seg = int64_t(v_seg.x) * int64_t(v_seg.x) + int64_t(v_seg.y) * int64_t(v_seg.y); + const int64_t l2_seg = int64_t(v_seg.x()) * int64_t(v_seg.x()) + int64_t(v_seg.y()) * int64_t(v_seg.y()); // For each corner of this cell and its 1 ring neighbours: for (int corner_y = -1; corner_y < 3; ++ corner_y) { coord_t corner_r = r + corner_y; @@ -780,28 +780,28 @@ void EdgeGrid::Grid::calculate_sdf() if (corner_c < 0 || corner_c >= ncols) continue; float &d_min = m_signed_distance_field[corner_r * ncols + corner_c]; - Slic3r::Point pt(m_bbox.min.x + corner_c * m_resolution, m_bbox.min.y + corner_r * m_resolution); + Slic3r::Point pt(m_bbox.min.x() + corner_c * m_resolution, m_bbox.min.y() + corner_r * m_resolution); Slic3r::Point v_pt = p1.vector_to(pt); // dot(p2-p1, pt-p1) - int64_t t_pt = int64_t(v_seg.x) * int64_t(v_pt.x) + int64_t(v_seg.y) * int64_t(v_pt.y); + int64_t t_pt = int64_t(v_seg.x()) * int64_t(v_pt.x()) + int64_t(v_seg.y()) * int64_t(v_pt.y()); if (t_pt < 0) { // Closest to p1. - double dabs = sqrt(int64_t(v_pt.x) * int64_t(v_pt.x) + int64_t(v_pt.y) * int64_t(v_pt.y)); + double dabs = sqrt(int64_t(v_pt.x()) * int64_t(v_pt.x()) + int64_t(v_pt.y()) * int64_t(v_pt.y())); if (dabs < d_min) { // Previous point. const Slic3r::Point &p0 = pts[(ipt == 0) ? (pts.size() - 1) : ipt - 1]; Slic3r::Point v_seg_prev = p0.vector_to(p1); - int64_t t2_pt = int64_t(v_seg_prev.x) * int64_t(v_pt.x) + int64_t(v_seg_prev.y) * int64_t(v_pt.y); + int64_t t2_pt = int64_t(v_seg_prev.x()) * int64_t(v_pt.x()) + int64_t(v_seg_prev.y()) * int64_t(v_pt.y()); if (t2_pt > 0) { // Inside the wedge between the previous and the next segment. // Set the signum depending on whether the vertex is convex or reflex. - int64_t det = int64_t(v_seg_prev.x) * int64_t(v_seg.y) - int64_t(v_seg_prev.y) * int64_t(v_seg.x); + int64_t det = int64_t(v_seg_prev.x()) * int64_t(v_seg.y()) - int64_t(v_seg_prev.y()) * int64_t(v_seg.x()); assert(det != 0); d_min = dabs; // Fill in an unsigned vector towards the zero iso surface. float *l = &L[(corner_r * ncols + corner_c) << 1]; - l[0] = std::abs(v_pt.x); - l[1] = std::abs(v_pt.y); + l[0] = std::abs(v_pt.x()); + l[1] = std::abs(v_pt.y()); #ifdef _DEBUG double dabs2 = sqrt(l[0]*l[0]+l[1]*l[1]); assert(std::abs(dabs-dabs2) < 1e-4 * std::max(dabs, dabs2)); @@ -816,7 +816,7 @@ void EdgeGrid::Grid::calculate_sdf() } else { // Closest to the segment. assert(t_pt >= 0 && t_pt <= l2_seg); - int64_t d_seg = int64_t(v_seg.y) * int64_t(v_pt.x) - int64_t(v_seg.x) * int64_t(v_pt.y); + int64_t d_seg = int64_t(v_seg.y()) * int64_t(v_pt.x()) - int64_t(v_seg.x()) * int64_t(v_pt.y()); double d = double(d_seg) / sqrt(double(l2_seg)); double dabs = std::abs(d); if (dabs < d_min) { @@ -824,8 +824,8 @@ void EdgeGrid::Grid::calculate_sdf() // Fill in an unsigned vector towards the zero iso surface. float *l = &L[(corner_r * ncols + corner_c) << 1]; float linv = float(d_seg) / float(l2_seg); - l[0] = std::abs(float(v_seg.y) * linv); - l[1] = std::abs(float(v_seg.x) * linv); + l[0] = std::abs(float(v_seg.y()) * linv); + l[1] = std::abs(float(v_seg.x()) * linv); #ifdef _DEBUG double dabs2 = sqrt(l[0]*l[0]+l[1]*l[1]); assert(std::abs(dabs-dabs2) <= 1e-4 * std::max(dabs, dabs2)); @@ -1059,8 +1059,8 @@ void EdgeGrid::Grid::calculate_sdf() float EdgeGrid::Grid::signed_distance_bilinear(const Point &pt) const { - coord_t x = pt.x - m_bbox.min.x; - coord_t y = pt.y - m_bbox.min.y; + coord_t x = pt.x() - m_bbox.min.x(); + coord_t y = pt.y() - m_bbox.min.y(); coord_t w = m_resolution * m_cols; coord_t h = m_resolution * m_rows; bool clamped = false; @@ -1124,39 +1124,39 @@ float EdgeGrid::Grid::signed_distance_bilinear(const Point &pt) const bool EdgeGrid::Grid::signed_distance_edges(const Point &pt, coord_t search_radius, coordf_t &result_min_dist, bool *pon_segment) const { BoundingBox bbox; - bbox.min = bbox.max = Point(pt.x - m_bbox.min.x, pt.y - m_bbox.min.y); + bbox.min = bbox.max = Point(pt.x() - m_bbox.min.x(), pt.y() - m_bbox.min.y()); bbox.defined = true; // Upper boundary, round to grid and test validity. - bbox.max.x += search_radius; - bbox.max.y += search_radius; - if (bbox.max.x < 0 || bbox.max.y < 0) + bbox.max.x() += search_radius; + bbox.max.y() += search_radius; + if (bbox.max.x() < 0 || bbox.max.y() < 0) return false; - bbox.max.x /= m_resolution; - bbox.max.y /= m_resolution; - if (bbox.max.x >= m_cols) - bbox.max.x = m_cols - 1; - if (bbox.max.y >= m_rows) - bbox.max.y = m_rows - 1; + bbox.max.x() /= m_resolution; + bbox.max.y() /= m_resolution; + if (bbox.max.x() >= m_cols) + bbox.max.x() = m_cols - 1; + if (bbox.max.y() >= m_rows) + bbox.max.y() = m_rows - 1; // Lower boundary, round to grid and test validity. - bbox.min.x -= search_radius; - bbox.min.y -= search_radius; - if (bbox.min.x < 0) - bbox.min.x = 0; - if (bbox.min.y < 0) - bbox.min.y = 0; - bbox.min.x /= m_resolution; - bbox.min.y /= m_resolution; + bbox.min.x() -= search_radius; + bbox.min.y() -= search_radius; + if (bbox.min.x() < 0) + bbox.min.x() = 0; + if (bbox.min.y() < 0) + bbox.min.y() = 0; + bbox.min.x() /= m_resolution; + bbox.min.y() /= m_resolution; // Is the interval empty? - if (bbox.min.x > bbox.max.x || - bbox.min.y > bbox.max.y) + if (bbox.min.x() > bbox.max.x() || + bbox.min.y() > bbox.max.y()) return false; // Traverse all cells in the bounding box. float d_min = search_radius; // Signum of the distance field at pt. int sign_min = 0; bool on_segment = false; - for (int r = bbox.min.y; r <= bbox.max.y; ++ r) { - for (int c = bbox.min.x; c <= bbox.max.x; ++ c) { + for (int r = bbox.min.y(); r <= bbox.max.y(); ++ r) { + for (int c = bbox.min.x(); c <= bbox.max.x(); ++ c) { const Cell &cell = m_cells[r * m_cols + c]; for (size_t i = cell.begin; i < cell.end; ++ i) { const Slic3r::Points &pts = *m_contours[m_cell_data[i].first]; @@ -1167,22 +1167,22 @@ bool EdgeGrid::Grid::signed_distance_edges(const Point &pt, coord_t search_radiu Slic3r::Point v_seg = p1.vector_to(p2); Slic3r::Point v_pt = p1.vector_to(pt); // dot(p2-p1, pt-p1) - int64_t t_pt = int64_t(v_seg.x) * int64_t(v_pt.x) + int64_t(v_seg.y) * int64_t(v_pt.y); + int64_t t_pt = int64_t(v_seg.x()) * int64_t(v_pt.x()) + int64_t(v_seg.y()) * int64_t(v_pt.y()); // l2 of seg - int64_t l2_seg = int64_t(v_seg.x) * int64_t(v_seg.x) + int64_t(v_seg.y) * int64_t(v_seg.y); + int64_t l2_seg = int64_t(v_seg.x()) * int64_t(v_seg.x()) + int64_t(v_seg.y()) * int64_t(v_seg.y()); if (t_pt < 0) { // Closest to p1. - double dabs = sqrt(int64_t(v_pt.x) * int64_t(v_pt.x) + int64_t(v_pt.y) * int64_t(v_pt.y)); + double dabs = sqrt(int64_t(v_pt.x()) * int64_t(v_pt.x()) + int64_t(v_pt.y()) * int64_t(v_pt.y())); if (dabs < d_min) { // Previous point. const Slic3r::Point &p0 = pts[(ipt == 0) ? (pts.size() - 1) : ipt - 1]; Slic3r::Point v_seg_prev = p0.vector_to(p1); - int64_t t2_pt = int64_t(v_seg_prev.x) * int64_t(v_pt.x) + int64_t(v_seg_prev.y) * int64_t(v_pt.y); + int64_t t2_pt = int64_t(v_seg_prev.x()) * int64_t(v_pt.x()) + int64_t(v_seg_prev.y()) * int64_t(v_pt.y()); if (t2_pt > 0) { // Inside the wedge between the previous and the next segment. d_min = dabs; // Set the signum depending on whether the vertex is convex or reflex. - int64_t det = int64_t(v_seg_prev.x) * int64_t(v_seg.y) - int64_t(v_seg_prev.y) * int64_t(v_seg.x); + int64_t det = int64_t(v_seg_prev.x()) * int64_t(v_seg.y()) - int64_t(v_seg_prev.y()) * int64_t(v_seg.x()); assert(det != 0); sign_min = (det > 0) ? 1 : -1; on_segment = false; @@ -1195,7 +1195,7 @@ bool EdgeGrid::Grid::signed_distance_edges(const Point &pt, coord_t search_radiu } else { // Closest to the segment. assert(t_pt >= 0 && t_pt <= l2_seg); - int64_t d_seg = int64_t(v_seg.y) * int64_t(v_pt.x) - int64_t(v_seg.x) * int64_t(v_pt.y); + int64_t d_seg = int64_t(v_seg.y()) * int64_t(v_pt.x()) - int64_t(v_seg.x()) * int64_t(v_pt.y()); double d = double(d_seg) / sqrt(double(l2_seg)); double dabs = std::abs(d); if (dabs < d_min) { @@ -1307,7 +1307,7 @@ Polygons EdgeGrid::Grid::contours_simplified(coord_t offset) const const Line &line_next = lines[it->second]; const Vector v1 = line_current.vector(); const Vector v2 = line_next.vector(); - int64_t cross = int64_t(v1.x) * int64_t(v2.y) - int64_t(v2.x) * int64_t(v1.y); + int64_t cross = int64_t(v1.x()) * int64_t(v2.y()) - int64_t(v2.x()) * int64_t(v1.y()); if (cross > 0) { // This has to be a convex right angle. There is no better next line. i_next = it->second; @@ -1328,10 +1328,10 @@ Polygons EdgeGrid::Grid::contours_simplified(coord_t offset) const Polygon &poly = out[i]; for (size_t j = 0; j < poly.points.size(); ++ j) { Point &p = poly.points[j]; - p.x *= m_resolution; - p.y *= m_resolution; - p.x += m_bbox.min.x; - p.y += m_bbox.min.y; + p.x() *= m_resolution; + p.y() *= m_resolution; + p.x() += m_bbox.min.x(); + p.y() += m_bbox.min.y(); } // Shrink the contour slightly, so if the same contour gets discretized and simplified again, one will get the same result. // Remove collineaer points. @@ -1341,11 +1341,11 @@ Polygons EdgeGrid::Grid::contours_simplified(coord_t offset) const size_t j0 = (j == 0) ? poly.points.size() - 1 : j - 1; size_t j2 = (j + 1 == poly.points.size()) ? 0 : j + 1; Point v = poly.points[j2] - poly.points[j0]; - if (v.x != 0 && v.y != 0) { + if (v.x() != 0 && v.y() != 0) { // This is a corner point. Copy it to the output contour. Point p = poly.points[j]; - p.y += (v.x < 0) ? - offset : offset; - p.x += (v.y > 0) ? - offset : offset; + p.y() += (v.x() < 0) ? - offset : offset; + p.x() += (v.y() > 0) ? - offset : offset; pts.push_back(p); } } @@ -1357,8 +1357,8 @@ Polygons EdgeGrid::Grid::contours_simplified(coord_t offset) const #if 0 void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coord_t resolution, const char *path) { - unsigned int w = (bbox.max.x - bbox.min.x + resolution - 1) / resolution; - unsigned int h = (bbox.max.y - bbox.min.y + resolution - 1) / resolution; + unsigned int w = (bbox.max.x() - bbox.min.x() + resolution - 1) / resolution; + unsigned int h = (bbox.max.y() - bbox.min.y() + resolution - 1) / resolution; wxImage img(w, h); unsigned char *data = img.GetData(); memset(data, 0, w * h * 3); @@ -1371,7 +1371,7 @@ void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coo for (coord_t r = 0; r < h; ++r) { for (coord_t c = 0; c < w; ++ c) { unsigned char *pxl = data + (((h - r - 1) * w) + c) * 3; - Point pt(c * resolution + bbox.min.x, r * resolution + bbox.min.y); + Point pt(c * resolution + bbox.min.x(), r * resolution + bbox.min.y()); coordf_t min_dist; bool on_segment = true; #if 0 @@ -1409,8 +1409,8 @@ void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coo pxl[2] = 0; } - float gridx = float(pt.x - grid.bbox().min.x) / float(grid.resolution()); - float gridy = float(pt.y - grid.bbox().min.y) / float(grid.resolution()); + float gridx = float(pt.x() - grid.bbox().min.x()) / float(grid.resolution()); + float gridy = float(pt.y() - grid.bbox().min.y()) / float(grid.resolution()); if (gridx >= -0.4f && gridy >= -0.4f && gridx <= grid.cols() + 0.4f && gridy <= grid.rows() + 0.4f) { int ix = int(floor(gridx + 0.5f)); int iy = int(floor(gridy + 0.5f)); diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index cd57fd7b0..ad2e9faed 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -361,7 +361,7 @@ ExPolygon::get_trapezoids2(Polygons* polygons) const std::vector<coord_t> xx; xx.reserve(pp.size()); for (Points::const_iterator p = pp.begin(); p != pp.end(); ++p) - xx.push_back(p->x); + xx.push_back(p->x()); std::sort(xx.begin(), xx.end()); // find trapezoids by looping from first to next-to-last coordinate @@ -372,14 +372,14 @@ ExPolygon::get_trapezoids2(Polygons* polygons) const // build rectangle Polygon poly; poly.points.resize(4); - poly[0].x = *x; - poly[0].y = bb.min.y; - poly[1].x = next_x; - poly[1].y = bb.min.y; - poly[2].x = next_x; - poly[2].y = bb.max.y; - poly[3].x = *x; - poly[3].y = bb.max.y; + poly[0].x() = *x; + poly[0].y() = bb.min.y(); + poly[1].x() = next_x; + poly[1].y() = bb.min.y(); + poly[2].x() = next_x; + poly[2].y() = bb.max.y(); + poly[3].x() = *x; + poly[3].y() = bb.max.y(); // intersect with this expolygon // append results to return value @@ -426,9 +426,9 @@ ExPolygon::triangulate_pp(Polygons* polygons) const p.Init(int(ex->contour.points.size())); //printf(PRINTF_ZU "\n0\n", ex->contour.points.size()); for (Points::const_iterator point = ex->contour.points.begin(); point != ex->contour.points.end(); ++point) { - p[ point-ex->contour.points.begin() ].x = point->x; - p[ point-ex->contour.points.begin() ].y = point->y; - //printf("%ld %ld\n", point->x, point->y); + p[ point-ex->contour.points.begin() ].x = point->x(); + p[ point-ex->contour.points.begin() ].y = point->y(); + //printf("%ld %ld\n", point->x(), point->y()); } p.SetHole(false); input.push_back(p); @@ -440,9 +440,9 @@ ExPolygon::triangulate_pp(Polygons* polygons) const p.Init(hole->points.size()); //printf(PRINTF_ZU "\n1\n", hole->points.size()); for (Points::const_iterator point = hole->points.begin(); point != hole->points.end(); ++point) { - p[ point-hole->points.begin() ].x = point->x; - p[ point-hole->points.begin() ].y = point->y; - //printf("%ld %ld\n", point->x, point->y); + p[ point-hole->points.begin() ].x = point->x(); + p[ point-hole->points.begin() ].y = point->y(); + //printf("%ld %ld\n", point->x(), point->y()); } p.SetHole(true); input.push_back(p); @@ -460,8 +460,8 @@ ExPolygon::triangulate_pp(Polygons* polygons) const Polygon p; p.points.resize(num_points); for (long i = 0; i < num_points; ++i) { - p.points[i].x = coord_t((*poly)[i].x); - p.points[i].y = coord_t((*poly)[i].y); + p.points[i].x() = coord_t((*poly)[i].x); + p.points[i].y() = coord_t((*poly)[i].y); } polygons->push_back(p); } @@ -479,7 +479,7 @@ ExPolygon::triangulate_p2t(Polygons* polygons) const std::vector<p2t::Point*> ContourPoints; for (Points::const_iterator point = ex->contour.points.begin(); point != ex->contour.points.end(); ++point) { // We should delete each p2t::Point object - ContourPoints.push_back(new p2t::Point(point->x, point->y)); + ContourPoints.push_back(new p2t::Point(point->x(), point->y())); } p2t::CDT cdt(ContourPoints); @@ -488,7 +488,7 @@ ExPolygon::triangulate_p2t(Polygons* polygons) const std::vector<p2t::Point*> points; for (Points::const_iterator point = hole->points.begin(); point != hole->points.end(); ++point) { // will be destructed in SweepContext::~SweepContext - points.push_back(new p2t::Point(point->x, point->y)); + points.push_back(new p2t::Point(point->x(), point->y())); } cdt.AddHole(points); } @@ -506,9 +506,8 @@ ExPolygon::triangulate_p2t(Polygons* polygons) const polygons->push_back(p); } - for(std::vector<p2t::Point*>::iterator it = ContourPoints.begin(); it != ContourPoints.end(); ++it) { - delete *it; - } + for (p2t::Point *ptr : ContourPoints) + delete ptr; } } diff --git a/xs/src/libslic3r/ExtrusionSimulator.cpp b/xs/src/libslic3r/ExtrusionSimulator.cpp index daecbc0d1..58531b7c5 100644 --- a/xs/src/libslic3r/ExtrusionSimulator.cpp +++ b/xs/src/libslic3r/ExtrusionSimulator.cpp @@ -893,24 +893,24 @@ ExtrusionSimulator::~ExtrusionSimulator() void ExtrusionSimulator::set_image_size(const Point &image_size) { // printf("ExtrusionSimulator::set_image_size()\n"); - if (this->image_size.x == image_size.x && - this->image_size.y == image_size.y) + if (this->image_size.x() == image_size.x() && + this->image_size.y() == image_size.y()) return; // printf("Setting image size: %d, %d\n", image_size.x, image_size.y); this->image_size = image_size; // Allocate the image data in an RGBA format. // printf("Allocating image data, size %d\n", image_size.x * image_size.y * 4); - pimpl->image_data.assign(image_size.x * image_size.y * 4, 0); + pimpl->image_data.assign(image_size.x() * image_size.y() * 4, 0); // printf("Allocating image data, allocated\n"); //FIXME fill the image with red vertical lines. - for (size_t r = 0; r < image_size.y; ++ r) { - for (size_t c = 0; c < image_size.x; c += 2) { + for (size_t r = 0; r < image_size.y(); ++ r) { + for (size_t c = 0; c < image_size.x(); c += 2) { // Color red - pimpl->image_data[r * image_size.x * 4 + c * 4] = 255; + pimpl->image_data[r * image_size.x() * 4 + c * 4] = 255; // Opacity full - pimpl->image_data[r * image_size.x * 4 + c * 4 + 3] = 255; + pimpl->image_data[r * image_size.x() * 4 + c * 4 + 3] = 255; } } // printf("Allocating image data, set\n"); @@ -922,8 +922,8 @@ void ExtrusionSimulator::set_viewport(const BoundingBox &viewport) if (this->viewport != viewport) { this->viewport = viewport; Point sz = viewport.size(); - pimpl->accumulator.resize(boost::extents[sz.y][sz.x]); - pimpl->bitmap.resize(boost::extents[sz.y*pimpl->bitmap_oversampled][sz.x*pimpl->bitmap_oversampled]); + pimpl->accumulator.resize(boost::extents[sz.y()][sz.x()]); + pimpl->bitmap.resize(boost::extents[sz.y()*pimpl->bitmap_oversampled][sz.x()*pimpl->bitmap_oversampled]); // printf("Accumulator size: %d, %d\n", sz.y, sz.x); } } @@ -943,8 +943,8 @@ void ExtrusionSimulator::reset_accumulator() // printf("ExtrusionSimulator::reset_accumulator()\n"); Point sz = viewport.size(); // printf("Reset accumulator, Accumulator size: %d, %d\n", sz.y, sz.x); - memset(&pimpl->accumulator[0][0], 0, sizeof(float) * sz.x * sz.y); - memset(&pimpl->bitmap[0][0], 0, sz.x * sz.y * pimpl->bitmap_oversampled * pimpl->bitmap_oversampled); + memset(&pimpl->accumulator[0][0], 0, sizeof(float) * sz.x() * sz.y()); + memset(&pimpl->bitmap[0][0], 0, sz.x() * sz.y() * pimpl->bitmap_oversampled * pimpl->bitmap_oversampled); pimpl->extrusion_points.clear(); // printf("Reset accumulator, done.\n"); } @@ -955,17 +955,17 @@ void ExtrusionSimulator::extrude_to_accumulator(const ExtrusionPath &path, const // Convert the path to V2f points, shift and scale them to the viewport. std::vector<V2f> polyline; polyline.reserve(path.polyline.points.size()); - float scalex = float(viewport.size().x) / float(bbox.size().x); - float scaley = float(viewport.size().y) / float(bbox.size().y); + float scalex = float(viewport.size().x()) / float(bbox.size().x()); + float scaley = float(viewport.size().y()) / float(bbox.size().y()); float w = scale_(path.width) * scalex; float h = scale_(path.height) * scalex; w = scale_(path.mm3_per_mm / path.height) * scalex; // printf("scalex: %f, scaley: %f\n", scalex, scaley); - // printf("bbox: %d,%d %d,%d\n", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y); + // printf("bbox: %d,%d %d,%d\n", bbox.min.x(), bbox.min.y, bbox.max.x(), bbox.max.y); for (Points::const_iterator it = path.polyline.points.begin(); it != path.polyline.points.end(); ++ it) { - // printf("point %d,%d\n", it->x+shift.x, it->y+shift.y); + // printf("point %d,%d\n", it->x+shift.x(), it->y+shift.y); ExtrusionPoint ept; - ept.center = V2f(float(it->x+shift.x-bbox.min.x) * scalex, float(it->y+shift.y-bbox.min.y) * scaley); + ept.center = V2f(float(it->x()+shift.x()-bbox.min.x()) * scalex, float(it->y()+shift.y()-bbox.min.y()) * scaley); ept.radius = w/2.f; ept.height = 0.5f; polyline.push_back(ept.center); @@ -989,9 +989,9 @@ void ExtrusionSimulator::evaluate_accumulator(ExtrusionSimulationType simulation if (simulationType > ExtrusionSimulationDontSpread) { // Average the cells of a bitmap into a lower resolution floating point mask. - A2f mask(boost::extents[sz.y][sz.x]); - for (int r = 0; r < sz.y; ++r) { - for (int c = 0; c < sz.x; ++c) { + A2f mask(boost::extents[sz.y()][sz.x()]); + for (int r = 0; r < sz.y(); ++r) { + for (int c = 0; c < sz.x(); ++c) { float p = 0; for (int j = 0; j < pimpl->bitmap_oversampled; ++ j) { for (int i = 0; i < pimpl->bitmap_oversampled; ++ i) { @@ -1009,9 +1009,9 @@ void ExtrusionSimulator::evaluate_accumulator(ExtrusionSimulationType simulation } // Color map the accumulator. - for (int r = 0; r < sz.y; ++r) { - unsigned char *ptr = &pimpl->image_data[(image_size.x * (viewport.min.y + r) + viewport.min.x) * 4]; - for (int c = 0; c < sz.x; ++c) { + for (int r = 0; r < sz.y(); ++r) { + unsigned char *ptr = &pimpl->image_data[(image_size.x() * (viewport.min.y() + r) + viewport.min.x()) * 4]; + for (int c = 0; c < sz.x(); ++c) { #if 1 float p = pimpl->accumulator[r][c]; #else diff --git a/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp b/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp index aa9774784..27814b658 100644 --- a/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp +++ b/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp @@ -54,9 +54,9 @@ static std::vector<coordf_t> perpendPoints(const coordf_t offset, const size_t b // components that are outside these limits are set to the limits. static inline void trim(Pointfs &pts, coordf_t minX, coordf_t minY, coordf_t maxX, coordf_t maxY) { - for (Pointfs::iterator it = pts.begin(); it != pts.end(); ++ it) { - it->x = clamp(minX, maxX, it->x); - it->y = clamp(minY, maxY, it->y); + for (Pointf &pt : pts) { + pt.x() = clamp(minX, maxX, pt.x()); + pt.y() = clamp(minY, maxY, pt.y()); } } @@ -128,7 +128,7 @@ static Polylines makeGrid(coord_t z, coord_t gridSize, size_t gridWidth, size_t result.push_back(Polyline()); Polyline &polyline = result.back(); for (Pointfs::const_iterator it = it_polylines->begin(); it != it_polylines->end(); ++ it) - polyline.points.push_back(Point(coord_t(it->x * scaleFactor), coord_t(it->y * scaleFactor))); + polyline.points.push_back(Point(coord_t(it->x() * scaleFactor), coord_t(it->y() * scaleFactor))); } return result; } @@ -153,13 +153,13 @@ void Fill3DHoneycomb::_fill_surface_single( Polylines polylines = makeGrid( scale_(this->z), distance, - ceil(bb.size().x / distance) + 1, - ceil(bb.size().y / distance) + 1, + ceil(bb.size().x() / distance) + 1, + ceil(bb.size().y() / distance) + 1, ((this->layer_id/thickness_layers) % 2) + 1); // move pattern in place for (Polylines::iterator it = polylines.begin(); it != polylines.end(); ++ it) - it->translate(bb.min.x, bb.min.y); + it->translate(bb.min.x(), bb.min.y()); // clip pattern to boundaries polylines = intersection_pl(polylines, (Polygons)expolygon); diff --git a/xs/src/libslic3r/Fill/FillBase.hpp b/xs/src/libslic3r/Fill/FillBase.hpp index 62d18e518..2b8a16b19 100644 --- a/xs/src/libslic3r/Fill/FillBase.hpp +++ b/xs/src/libslic3r/Fill/FillBase.hpp @@ -121,11 +121,11 @@ public: return aligned; } static Point _align_to_grid(Point coord, Point spacing) - { return Point(_align_to_grid(coord.x, spacing.x), _align_to_grid(coord.y, spacing.y)); } + { return Point(_align_to_grid(coord.x(), spacing.x()), _align_to_grid(coord.y(), spacing.y())); } static coord_t _align_to_grid(coord_t coord, coord_t spacing, coord_t base) { return base + _align_to_grid(coord - base, spacing); } static Point _align_to_grid(Point coord, Point spacing, Point base) - { return Point(_align_to_grid(coord.x, spacing.x, base.x), _align_to_grid(coord.y, spacing.y, base.y)); } + { return Point(_align_to_grid(coord.x(), spacing.x(), base.x()), _align_to_grid(coord.y(), spacing.y(), base.y())); } }; } // namespace Slic3r diff --git a/xs/src/libslic3r/Fill/FillConcentric.cpp b/xs/src/libslic3r/Fill/FillConcentric.cpp index b21ad2799..860f36777 100644 --- a/xs/src/libslic3r/Fill/FillConcentric.cpp +++ b/xs/src/libslic3r/Fill/FillConcentric.cpp @@ -20,7 +20,7 @@ void FillConcentric::_fill_surface_single( coord_t distance = coord_t(min_spacing / params.density); if (params.density > 0.9999f && !params.dont_adjust) { - distance = this->_adjust_solid_spacing(bounding_box.size().x, distance); + distance = this->_adjust_solid_spacing(bounding_box.size().x(), distance); this->spacing = unscale(distance); } diff --git a/xs/src/libslic3r/Fill/FillGyroid.cpp b/xs/src/libslic3r/Fill/FillGyroid.cpp index 89d5d231e..7e208083b 100644 --- a/xs/src/libslic3r/Fill/FillGyroid.cpp +++ b/xs/src/libslic3r/Fill/FillGyroid.cpp @@ -34,21 +34,21 @@ static inline Polyline make_wave( double z_cos, double z_sin, bool vertical) { std::vector<Pointf> points = one_period; - double period = points.back().x; + double period = points.back().x(); points.pop_back(); int n = points.size(); do { - points.emplace_back(Pointf(points[points.size()-n].x + period, points[points.size()-n].y)); - } while (points.back().x < width); - points.back().x = width; + points.emplace_back(Pointf(points[points.size()-n].x() + period, points[points.size()-n].y())); + } while (points.back().x() < width); + points.back().x() = width; // and construct the final polyline to return: Polyline polyline; for (auto& point : points) { - point.y += offset; - point.y = clamp(0., height, double(point.y)); + point.y() += offset; + point.y() = clamp(0., height, double(point.y())); if (vertical) - std::swap(point.x, point.y); + std::swap(point.x(), point.y()); polyline.points.emplace_back(convert_to<Point>(point * scaleFactor)); } @@ -73,12 +73,12 @@ static std::vector<Pointf> make_one_period(double width, double scaleFactor, dou auto& tp = points[i]; // this point auto& rp = points[i+1]; // right point // calculate distance of the point to the line: - double dist_mm = unscale(scaleFactor * std::abs( (rp.y - lp.y)*tp.x + (lp.x - rp.x)*tp.y + (rp.x*lp.y - rp.y*lp.x) ) / std::hypot((rp.y - lp.y),(lp.x - rp.x))); + double dist_mm = unscale(scaleFactor * std::abs( (rp.y() - lp.y())*tp.x() + (lp.x() - rp.x())*tp.y() + (rp.x()*lp.y() - rp.y()*lp.x()) ) / std::hypot((rp.y() - lp.y()),(lp.x() - rp.x()))); if (dist_mm > tolerance) { // if the difference from straight line is more than this - double x = 0.5f * (points[i-1].x + points[i].x); + double x = 0.5f * (points[i-1].x() + points[i].x()); points.emplace_back(Pointf(x, f(x, z_sin, z_cos, vertical, flip))); - x = 0.5f * (points[i+1].x + points[i].x); + x = 0.5f * (points[i+1].x() + points[i].x()); points.emplace_back(Pointf(x, f(x, z_sin, z_cos, vertical, flip))); std::sort(points.begin(), points.end()); // we added the points to the end, but need them all in order --i; // decrement i so we also check the first newly added point @@ -143,12 +143,12 @@ void FillGyroid::_fill_surface_single( scale_(this->z), density_adjusted, this->spacing, - ceil(bb.size().x / distance) + 1., - ceil(bb.size().y / distance) + 1.); + ceil(bb.size().x() / distance) + 1., + ceil(bb.size().y() / distance) + 1.); // move pattern in place for (Polyline &polyline : polylines) - polyline.translate(bb.min.x, bb.min.y); + polyline.translate(bb.min.x(), bb.min.y()); // clip pattern to boundaries polylines = intersection_pl(polylines, (Polygons)expolygon); diff --git a/xs/src/libslic3r/Fill/FillHoneycomb.cpp b/xs/src/libslic3r/Fill/FillHoneycomb.cpp index aa0e0f6b0..c22d5a2d7 100644 --- a/xs/src/libslic3r/Fill/FillHoneycomb.cpp +++ b/xs/src/libslic3r/Fill/FillHoneycomb.cpp @@ -50,13 +50,13 @@ void FillHoneycomb::_fill_surface_single( bounding_box.merge(_align_to_grid(bounding_box.min, Point(m.hex_width, m.pattern_height))); } - coord_t x = bounding_box.min.x; - while (x <= bounding_box.max.x) { + coord_t x = bounding_box.min.x(); + while (x <= bounding_box.max.x()) { Polygon p; coord_t ax[2] = { x + m.x_offset, x + m.distance - m.x_offset }; for (size_t i = 0; i < 2; ++ i) { std::reverse(p.points.begin(), p.points.end()); // turn first half upside down - for (coord_t y = bounding_box.min.y; y <= bounding_box.max.y; y += m.y_short + m.hex_side + m.y_short + m.hex_side) { + for (coord_t y = bounding_box.min.y(); y <= bounding_box.max.y(); y += m.y_short + m.hex_side + m.y_short + m.hex_side) { p.points.push_back(Point(ax[1], y + m.y_offset)); p.points.push_back(Point(ax[0], y + m.y_short - m.y_offset)); p.points.push_back(Point(ax[0], y + m.y_short + m.hex_side + m.y_offset)); diff --git a/xs/src/libslic3r/Fill/FillPlanePath.cpp b/xs/src/libslic3r/Fill/FillPlanePath.cpp index f71ef95a1..f872c1ef8 100644 --- a/xs/src/libslic3r/Fill/FillPlanePath.cpp +++ b/xs/src/libslic3r/Fill/FillPlanePath.cpp @@ -24,14 +24,14 @@ void FillPlanePath::_fill_surface_single( Point shift = this->_centered() ? bounding_box.center() : bounding_box.min; - expolygon.translate(-shift.x, -shift.y); - bounding_box.translate(-shift.x, -shift.y); + expolygon.translate(-shift.x(), -shift.y()); + bounding_box.translate(-shift.x(), -shift.y()); Pointfs pts = _generate( - coord_t(ceil(coordf_t(bounding_box.min.x) / distance_between_lines)), - coord_t(ceil(coordf_t(bounding_box.min.y) / distance_between_lines)), - coord_t(ceil(coordf_t(bounding_box.max.x) / distance_between_lines)), - coord_t(ceil(coordf_t(bounding_box.max.y) / distance_between_lines))); + coord_t(ceil(coordf_t(bounding_box.min.x()) / distance_between_lines)), + coord_t(ceil(coordf_t(bounding_box.min.y()) / distance_between_lines)), + coord_t(ceil(coordf_t(bounding_box.max.x()) / distance_between_lines)), + coord_t(ceil(coordf_t(bounding_box.max.y()) / distance_between_lines))); Polylines polylines; if (pts.size() >= 2) { @@ -41,8 +41,8 @@ void FillPlanePath::_fill_surface_single( polyline.points.reserve(pts.size()); for (Pointfs::iterator it = pts.begin(); it != pts.end(); ++ it) polyline.points.push_back(Point( - coord_t(floor(it->x * distance_between_lines + 0.5)), - coord_t(floor(it->y * distance_between_lines + 0.5)))); + coord_t(floor(it->x() * distance_between_lines + 0.5)), + coord_t(floor(it->y() * distance_between_lines + 0.5)))); // intersection(polylines_src, offset((Polygons)expolygon, scale_(0.02)), &polylines); polylines = intersection_pl(polylines, to_polygons(expolygon)); @@ -62,7 +62,7 @@ void FillPlanePath::_fill_surface_single( // paths must be repositioned and rotated back for (Polylines::iterator it = polylines.begin(); it != polylines.end(); ++ it) { - it->translate(shift.x, shift.y); + it->translate(shift.x(), shift.y()); it->rotate(direction.first); } } @@ -162,7 +162,7 @@ Pointfs FillHilbertCurve::_generate(coord_t min_x, coord_t min_y, coord_t max_x, line.reserve(sz2); for (size_t i = 0; i < sz2; ++ i) { Point p = hilbert_n_to_xy(i); - line.push_back(Pointf(p.x + min_x, p.y + min_y)); + line.push_back(Pointf(p.x() + min_x, p.y() + min_y)); } return line; } diff --git a/xs/src/libslic3r/Fill/FillRectilinear.cpp b/xs/src/libslic3r/Fill/FillRectilinear.cpp index 5ba30ba51..e7f40a21b 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear.cpp @@ -26,7 +26,7 @@ void FillRectilinear::_fill_surface_single( // define flow spacing according to requested density if (params.density > 0.9999f && !params.dont_adjust) { - this->_line_spacing = this->_adjust_solid_spacing(bounding_box.size().x, this->_line_spacing); + this->_line_spacing = this->_adjust_solid_spacing(bounding_box.size().x(), this->_line_spacing); this->spacing = unscale(this->_line_spacing); } else { // extend bounding box so that our pattern will be aligned with other layers @@ -38,14 +38,14 @@ void FillRectilinear::_fill_surface_single( } // generate the basic pattern - coord_t x_max = bounding_box.max.x + SCALED_EPSILON; + coord_t x_max = bounding_box.max.x() + SCALED_EPSILON; Lines lines; - for (coord_t x = bounding_box.min.x; x <= x_max; x += this->_line_spacing) - lines.push_back(this->_line(lines.size(), x, bounding_box.min.y, bounding_box.max.y)); + for (coord_t x = bounding_box.min.x(); x <= x_max; x += this->_line_spacing) + lines.push_back(this->_line(lines.size(), x, bounding_box.min.y(), bounding_box.max.y())); if (this->_horizontal_lines()) { - coord_t y_max = bounding_box.max.y + SCALED_EPSILON; - for (coord_t y = bounding_box.min.y; y <= y_max; y += this->_line_spacing) - lines.push_back(Line(Point(bounding_box.min.x, y), Point(bounding_box.max.x, y))); + coord_t y_max = bounding_box.max.y() + SCALED_EPSILON; + for (coord_t y = bounding_box.min.y(); y <= y_max; y += this->_line_spacing) + lines.push_back(Line(Point(bounding_box.min.x(), y), Point(bounding_box.max.x(), y))); } // clip paths against a slightly larger expolygon, so that the first and last paths @@ -72,10 +72,10 @@ void FillRectilinear::_fill_surface_single( for (Polylines::iterator it_polyline = polylines.begin(); it_polyline != polylines.end(); ++ it_polyline) { Point *first_point = &it_polyline->points.front(); Point *last_point = &it_polyline->points.back(); - if (first_point->y > last_point->y) + if (first_point->y() > last_point->y()) std::swap(first_point, last_point); - first_point->y -= extra; - last_point->y += extra; + first_point->y() -= extra; + last_point->y() += extra; } size_t n_polylines_out_old = polylines_out.size(); @@ -106,7 +106,7 @@ void FillRectilinear::_fill_surface_single( const Vector distance = first_point.vector_to(last_point); // TODO: we should also check that both points are on a fill_boundary to avoid // connecting paths on the boundaries of internal regions - if (this->_can_connect(std::abs(distance.x), std::abs(distance.y)) && + if (this->_can_connect(std::abs(distance.x()), std::abs(distance.y())) && expolygon_off.contains(Line(last_point, first_point))) { // Append the polyline. pts_end.insert(pts_end.end(), it_polyline->points.begin(), it_polyline->points.end()); @@ -122,7 +122,7 @@ void FillRectilinear::_fill_surface_single( // paths must be rotated back for (Polylines::iterator it = polylines_out.begin() + n_polylines_out_old; it != polylines_out.end(); ++ it) { // No need to translate, the absolute position is irrelevant. - // it->translate(- direction.second.x, - direction.second.y); + // it->translate(- direction.second.x(), - direction.second.y()); it->rotate(direction.first); } } diff --git a/xs/src/libslic3r/Fill/FillRectilinear2.cpp b/xs/src/libslic3r/Fill/FillRectilinear2.cpp index ddd785101..4416626f6 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear2.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear2.cpp @@ -42,12 +42,12 @@ static inline coordf_t segment_length(const Polygon &poly, size_t seg1, const Po Point px = (i == 0) ? p1 : p2; Point pa = poly.points[((seg == 0) ? poly.points.size() : seg) - 1]; Point pb = poly.points[seg]; - if (pa.x > pb.x) - std::swap(pa.x, pb.x); - if (pa.y > pb.y) - std::swap(pa.y, pb.y); - assert(px.x >= pa.x && px.x <= pb.x); - assert(px.y >= pa.y && px.y <= pb.y); + if (pa.x() > pb.x()) + std::swap(pa.x(), pb.x()); + if (pa.y() > pb.y()) + std::swap(pa.y(), pb.y()); + assert(px.x() >= pa.x() && px.x() <= pb.x()); + assert(px.y() >= pa.y() && px.y() <= pb.y()); } #endif /* SLIC3R_DEBUG */ const Point *pPrev = &p1; @@ -791,7 +791,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP // define flow spacing according to requested density if (params.full_infill() && !params.dont_adjust) { - line_spacing = this->_adjust_solid_spacing(bounding_box.size().x, line_spacing); + line_spacing = this->_adjust_solid_spacing(bounding_box.size().x(), line_spacing); this->spacing = unscale(line_spacing); } else { // extend bounding box so that our pattern will be aligned with other layers @@ -799,7 +799,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP Point refpt = rotate_vector.second.rotated(- rotate_vector.first); // _align_to_grid will not work correctly with positive pattern_shift. coord_t pattern_shift_scaled = coord_t(scale_(pattern_shift)) % line_spacing; - refpt.x -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled); + refpt.x() -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled); bounding_box.merge(_align_to_grid( bounding_box.min, Point(line_spacing, line_spacing), @@ -808,8 +808,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP // Intersect a set of euqally spaced vertical lines wiht expolygon. // n_vlines = ceil(bbox_width / line_spacing) - size_t n_vlines = (bounding_box.max.x - bounding_box.min.x + line_spacing - 1) / line_spacing; - coord_t x0 = bounding_box.min.x; + size_t n_vlines = (bounding_box.max.x() - bounding_box.min.x() + line_spacing - 1) / line_spacing; + coord_t x0 = bounding_box.min.x(); if (params.full_infill()) x0 += (line_spacing + SCALED_EPSILON) / 2; @@ -842,8 +842,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP const Point &p1 = contour[iPrev]; const Point &p2 = contour[iSegment]; // Which of the equally spaced vertical lines is intersected by this segment? - coord_t l = p1.x; - coord_t r = p2.x; + coord_t l = p1.x(); + coord_t r = p2.x(); if (l > r) std::swap(l, r); // il, ir are the left / right indices of vertical lines intersecting a segment @@ -869,33 +869,33 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP assert(l <= this_x); assert(r >= this_x); // Calculate the intersection position in y axis. x is known. - if (p1.x == this_x) { - if (p2.x == this_x) { + if (p1.x() == this_x) { + if (p2.x() == this_x) { // Ignore strictly vertical segments. continue; } - is.pos_p = p1.y; + is.pos_p = p1.y(); is.pos_q = 1; - } else if (p2.x == this_x) { - is.pos_p = p2.y; + } else if (p2.x() == this_x) { + is.pos_p = p2.y(); is.pos_q = 1; } else { // First calculate the intersection parameter 't' as a rational number with non negative denominator. - if (p2.x > p1.x) { - is.pos_p = this_x - p1.x; - is.pos_q = p2.x - p1.x; + if (p2.x() > p1.x()) { + is.pos_p = this_x - p1.x(); + is.pos_q = p2.x() - p1.x(); } else { - is.pos_p = p1.x - this_x; - is.pos_q = p1.x - p2.x; + is.pos_p = p1.x() - this_x; + is.pos_q = p1.x() - p2.x(); } assert(is.pos_p >= 0 && is.pos_p <= is.pos_q); // Make an intersection point from the 't'. - is.pos_p *= int64_t(p2.y - p1.y); - is.pos_p += p1.y * int64_t(is.pos_q); + is.pos_p *= int64_t(p2.y() - p1.y()); + is.pos_p += p1.y() * int64_t(is.pos_q); } // +-1 to take rounding into account. - assert(is.pos() + 1 >= std::min(p1.y, p2.y)); - assert(is.pos() <= std::max(p1.y, p2.y) + 1); + assert(is.pos() + 1 >= std::min(p1.y(), p2.y())); + assert(is.pos() <= std::max(p1.y(), p2.y()) + 1); segs[i].intersections.push_back(is); } } @@ -919,7 +919,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP const Points &contour = poly_with_offset.contour(iContour).points; size_t iSegment = sil.intersections[i].iSegment; size_t iPrev = ((iSegment == 0) ? contour.size() : iSegment) - 1; - coord_t dir = contour[iSegment].x - contour[iPrev].x; + coord_t dir = contour[iSegment].x() - contour[iPrev].x(); bool low = dir > 0; sil.intersections[i].type = poly_with_offset.is_contour_outer(iContour) ? (low ? SegmentIntersection::OUTER_LOW : SegmentIntersection::OUTER_HIGH) : @@ -1066,7 +1066,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP intrsctn.consumed_vertical_up : seg.intersections[i-1].consumed_vertical_up; if (! consumed) { - coordf_t dist2 = sqr(coordf_t(pointLast.x - seg.pos)) + sqr(coordf_t(pointLast.y - intrsctn.pos())); + coordf_t dist2 = sqr(coordf_t(pointLast.x() - seg.pos)) + sqr(coordf_t(pointLast.y() - intrsctn.pos())); if (dist2 < dist2min) { dist2min = dist2; i_vline = i_vline2; @@ -1356,8 +1356,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP // Handle nearly zero length edges. if (polyline_current->points.size() <= 1 || (polyline_current->points.size() == 2 && - std::abs(polyline_current->points.front().x - polyline_current->points.back().x) < SCALED_EPSILON && - std::abs(polyline_current->points.front().y - polyline_current->points.back().y) < SCALED_EPSILON)) + std::abs(polyline_current->points.front().x() - polyline_current->points.back().x()) < SCALED_EPSILON && + std::abs(polyline_current->points.front().y() - polyline_current->points.back().y()) < SCALED_EPSILON)) polylines_out.pop_back(); intrsctn = NULL; i_intersection = -1; @@ -1383,7 +1383,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP // paths must be rotated back for (Polylines::iterator it = polylines_out.begin() + n_polylines_out_initial; it != polylines_out.end(); ++ it) { // No need to translate, the absolute position is irrelevant. - // it->translate(- rotate_vector.second.x, - rotate_vector.second.y); + // it->translate(- rotate_vector.second.x(), - rotate_vector.second.y()); assert(! it->has_duplicate_points()); it->rotate(rotate_vector.first); //FIXME rather simplify the paths to avoid very short edges? diff --git a/xs/src/libslic3r/Fill/FillRectilinear3.cpp b/xs/src/libslic3r/Fill/FillRectilinear3.cpp index cccea3030..3c29c95f7 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear3.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear3.cpp @@ -223,24 +223,24 @@ Point SegmentIntersection::pos() const const Pointf p2 = convert_to<Pointf>(line->pos); const Pointf v2 = convert_to<Pointf>(line->dir); // Intersect the two rays. - double denom = v1.x * v2.y - v2.x * v1.y; + double denom = v1.x() * v2.y() - v2.x() * v1.y(); Point out; if (denom == 0.) { // Lines are collinear. As the pos() method is not supposed to be called on collinear vectors, // the source vectors are not quite collinear. Return the center of the contour segment. out = seg_start + seg_end; - out.x >>= 1; - out.y >>= 1; + out.x() >>= 1; + out.y() >>= 1; } else { // Find the intersection point. - double t = (v2.x * (p1.y - p2.y) - v2.y * (p1.x - p2.x)) / denom; + double t = (v2.x() * (p1.y() - p2.y()) - v2.y() * (p1.x() - p2.x())) / denom; if (t < 0.) out = seg_start; else if (t > 1.) out = seg_end; else { - out.x = coord_t(floor(p1.x + t * v1.x + 0.5)); - out.y = coord_t(floor(p1.y + t * v1.y + 0.5)); + out.x() = coord_t(floor(p1.x() + t * v1.x() + 0.5)); + out.y() = coord_t(floor(p1.y() + t * v1.y() + 0.5)); } } return out; @@ -317,8 +317,8 @@ int SegmentIntersection::ordering_along_line(const SegmentIntersection &other) c int64_t denom2 = cross(this->line->dir, vec_b); Point vx_a = seg_start_a - this->line->pos; Point vx_b = seg_start_b - this->line->pos; - int64_t t1_times_denom1 = int64_t(vx_a.x) * int64_t(vec_a.y) - int64_t(vx_a.y) * int64_t(vec_a.x); - int64_t t2_times_denom2 = int64_t(vx_b.x) * int64_t(vec_b.y) - int64_t(vx_b.y) * int64_t(vec_b.x); + int64_t t1_times_denom1 = int64_t(vx_a.x()) * int64_t(vec_a.y()) - int64_t(vx_a.y()) * int64_t(vec_a.x()); + int64_t t2_times_denom2 = int64_t(vx_b.x()) * int64_t(vec_b.y()) - int64_t(vx_b.y()) * int64_t(vec_b.x()); assert(denom1 != 0); assert(denom2 != 0); return Int128::compare_rationals_filtered(t1_times_denom1, denom1, t2_times_denom2, denom2); @@ -389,7 +389,7 @@ static bool prepare_infill_hatching_segments( // Define the flow spacing according to requested density. if (params.full_infill() && ! params.dont_adjust) { // Full infill, adjust the line spacing to fit an integer number of lines. - out.line_spacing = Fill::_adjust_solid_spacing(bounding_box.size().x, line_spacing); + out.line_spacing = Fill::_adjust_solid_spacing(bounding_box.size().x(), line_spacing); // Report back the adjusted line spacing. fill_dir_params.spacing = float(unscale(line_spacing)); } else { @@ -398,7 +398,7 @@ static bool prepare_infill_hatching_segments( Point refpt = rotate_vector.second.rotated(- out.angle); // _align_to_grid will not work correctly with positive pattern_shift. coord_t pattern_shift_scaled = coord_t(scale_(fill_dir_params.pattern_shift)) % line_spacing; - refpt.x -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled); + refpt.x() -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled); bounding_box.merge(Fill::_align_to_grid( bounding_box.min, Point(line_spacing, line_spacing), @@ -407,13 +407,13 @@ static bool prepare_infill_hatching_segments( // Intersect a set of euqally spaced vertical lines wiht expolygon. // n_vlines = ceil(bbox_width / line_spacing) - size_t n_vlines = (bounding_box.max.x - bounding_box.min.x + line_spacing - 1) / line_spacing; - coord_t x0 = bounding_box.min.x; + size_t n_vlines = (bounding_box.max.x() - bounding_box.min.x() + line_spacing - 1) / line_spacing; + coord_t x0 = bounding_box.min.x(); if (params.full_infill()) x0 += coord_t((line_spacing + SCALED_EPSILON) / 2); out.line_spacing = line_spacing; - out.start_point = Point(x0, bounding_box.min.y); + out.start_point = Point(x0, bounding_box.min.y()); out.start_point.rotate(out.angle); #ifdef SLIC3R_DEBUG @@ -436,10 +436,10 @@ static bool prepare_infill_hatching_segments( for (size_t i = 0; i < n_vlines; ++ i) { auto &seg = out.segs[i]; seg.idx = i; - // seg.x = x0 + coord_t(i) * line_spacing; + // seg.x() = x0 + coord_t(i) * line_spacing; coord_t x = x0 + coord_t(i) * line_spacing; - seg.pos.x = coord_t(floor(cos_a * x - sin_a * bounding_box.min.y + 0.5)); - seg.pos.y = coord_t(floor(cos_a * bounding_box.min.y + sin_a * x + 0.5)); + seg.pos.x() = coord_t(floor(cos_a * x - sin_a * bounding_box.min.y() + 0.5)); + seg.pos.y() = coord_t(floor(cos_a * bounding_box.min.y() + sin_a * x + 0.5)); seg.dir = out.direction; } @@ -454,7 +454,7 @@ static bool prepare_infill_hatching_segments( const Point *pr = &contour[iSegment]; // Orient the segment to the direction vector. const Point v = *pr - *pl; - int orientation = Int128::sign_determinant_2x2_filtered(v.x, v.y, out.direction.x, out.direction.y); + int orientation = Int128::sign_determinant_2x2_filtered(v.x(), v.y(), out.direction.x(), out.direction.y()); if (orientation == 0) // Ignore strictly vertical segments. continue; @@ -462,8 +462,8 @@ static bool prepare_infill_hatching_segments( // Always orient the input segment consistently towards the hatching direction. std::swap(pl, pr); // Which of the equally spaced vertical lines is intersected by this segment? - coord_t l = (coord_t)floor(cos_a * pl->x + sin_a * pl->y - SCALED_EPSILON); - coord_t r = (coord_t)ceil (cos_a * pr->x + sin_a * pr->y + SCALED_EPSILON); + coord_t l = (coord_t)floor(cos_a * pl->x() + sin_a * pl->y() - SCALED_EPSILON); + coord_t r = (coord_t)ceil (cos_a * pr->x() + sin_a * pr->y() + SCALED_EPSILON); assert(l < r - SCALED_EPSILON); // il, ir are the left / right indices of vertical lines intersecting a segment int il = std::max<int>(0, (l - x0 + line_spacing) / line_spacing); @@ -479,9 +479,9 @@ static bool prepare_infill_hatching_segments( // 2) all lines from il to ir intersect <pl, pr>. assert(il >= 0 && ir < int(out.segs.size())); for (int i = il; i <= ir; ++ i) { - // assert(out.segs[i].x == i * line_spacing + x0); - // assert(l <= out.segs[i].x); - // assert(r >= out.segs[i].x); + // assert(out.segs[i].x() == i * line_spacing + x0); + // assert(l <= out.segs[i].x()); + // assert(r >= out.segs[i].x()); SegmentIntersection is; is.line = &out.segs[i]; is.expoly_with_offset = &poly_with_offset; @@ -491,10 +491,10 @@ static bool prepare_infill_hatching_segments( // +-1 to take rounding into account. assert(int128::orient(out.segs[i].pos, out.segs[i].pos + out.direction, *pl) >= 0); assert(int128::orient(out.segs[i].pos, out.segs[i].pos + out.direction, *pr) <= 0); - assert(is.pos().x + 1 >= std::min(pl->x, pr->x)); - assert(is.pos().y + 1 >= std::min(pl->y, pr->y)); - assert(is.pos().x <= std::max(pl->x, pr->x) + 1); - assert(is.pos().y <= std::max(pl->y, pr->y) + 1); + assert(is.pos().x() + 1 >= std::min(pl->x(), pr->x())); + assert(is.pos().y() + 1 >= std::min(pl->y(), pr->y())); + assert(is.pos().x() <= std::max(pl->x(), pr->x()) + 1); + assert(is.pos().y() <= std::max(pl->y(), pr->y()) + 1); out.segs[i].intersections.push_back(is); } } @@ -659,12 +659,12 @@ static inline coordf_t segment_length(const Polygon &poly, size_t seg1, const Po Point px = (i == 0) ? p1 : p2; Point pa = poly.points[((seg == 0) ? poly.points.size() : seg) - 1]; Point pb = poly.points[seg]; - if (pa.x > pb.x) - std::swap(pa.x, pb.x); - if (pa.y > pb.y) - std::swap(pa.y, pb.y); - assert(px.x >= pa.x && px.x <= pb.x); - assert(px.y >= pa.y && px.y <= pb.y); + if (pa.x() > pb.x()) + std::swap(pa.x(), pb.x()); + if (pa.y() > pb.y()) + std::swap(pa.y(), pb.y()); + assert(px.x() >= pa.x() && px.x() <= pb.x()); + assert(px.y() >= pa.y() && px.y() <= pb.y()); } #endif /* SLIC3R_DEBUG */ const Point *pPrev = &p1; @@ -1481,8 +1481,8 @@ static bool fill_hatching_segments_legacy( // Handle nearly zero length edges. if (polyline_current->points.size() <= 1 || (polyline_current->points.size() == 2 && - std::abs(polyline_current->points.front().x - polyline_current->points.back().x) < SCALED_EPSILON && - std::abs(polyline_current->points.front().y - polyline_current->points.back().y) < SCALED_EPSILON)) + std::abs(polyline_current->points.front().x() - polyline_current->points.back().x()) < SCALED_EPSILON && + std::abs(polyline_current->points.front().y() - polyline_current->points.back().y()) < SCALED_EPSILON)) polylines_out.pop_back(); intrsctn = NULL; i_intersection = -1; @@ -1510,7 +1510,7 @@ static bool fill_hatching_segments_legacy( // paths must be rotated back for (Polylines::iterator it = polylines_out.begin() + n_polylines_out_initial; it != polylines_out.end(); ++ it) { // No need to translate, the absolute position is irrelevant. - // it->translate(- rotate_vector.second.x, - rotate_vector.second.y); + // it->translate(- rotate_vector.second.x(), - rotate_vector.second.y()); assert(! it->has_duplicate_points()); //it->rotate(rotate_vector.first); //FIXME rather simplify the paths to avoid very short edges? diff --git a/xs/src/libslic3r/Format/3mf.cpp b/xs/src/libslic3r/Format/3mf.cpp index 2c32db1a6..6b81fc9c0 100644 --- a/xs/src/libslic3r/Format/3mf.cpp +++ b/xs/src/libslic3r/Format/3mf.cpp @@ -1352,8 +1352,8 @@ namespace Slic3r { double angle_z = (rotation.axis() == Eigen::Vector3d::UnitZ()) ? rotation.angle() : -rotation.angle(); #endif - instance.offset.x = offset_x; - instance.offset.y = offset_y; + instance.offset.x() = offset_x; + instance.offset.y() = offset_y; instance.scaling_factor = sx; instance.rotation = angle_z; } @@ -1801,7 +1801,7 @@ namespace Slic3r { } Eigen::Affine3f transform; - transform = Eigen::Translation3f((float)instance->offset.x, (float)instance->offset.y, 0.0f) * Eigen::AngleAxisf((float)instance->rotation, Eigen::Vector3f::UnitZ()) * Eigen::Scaling((float)instance->scaling_factor); + transform = Eigen::Translation3f((float)instance->offset.x(), (float)instance->offset.y(), 0.0f) * Eigen::AngleAxisf((float)instance->rotation, Eigen::Vector3f::UnitZ()) * Eigen::Scaling((float)instance->scaling_factor); build_items.emplace_back(instance_id, transform.matrix()); stream << " </" << OBJECT_TAG << ">\n"; diff --git a/xs/src/libslic3r/Format/AMF.cpp b/xs/src/libslic3r/Format/AMF.cpp index 21d4b4d3b..3dc0418ae 100644 --- a/xs/src/libslic3r/Format/AMF.cpp +++ b/xs/src/libslic3r/Format/AMF.cpp @@ -496,8 +496,8 @@ void AMFParserContext::endDocument() for (const Instance &instance : object.second.instances) if (instance.deltax_set && instance.deltay_set) { ModelInstance *mi = m_model.objects[object.second.idx]->add_instance(); - mi->offset.x = instance.deltax; - mi->offset.y = instance.deltay; + mi->offset.x() = instance.deltax; + mi->offset.y() = instance.deltay; mi->rotation = instance.rz_set ? instance.rz : 0.f; mi->scaling_factor = instance.scale_set ? instance.scale : 1.f; } @@ -829,8 +829,8 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c " <scale>%lf</scale>\n" " </instance>\n", object_id, - instance->offset.x, - instance->offset.y, + instance->offset.x(), + instance->offset.y(), instance->rotation, instance->scaling_factor); //FIXME missing instance->scaling_factor diff --git a/xs/src/libslic3r/Format/PRUS.cpp b/xs/src/libslic3r/Format/PRUS.cpp index 1809eaead..b73a71352 100644 --- a/xs/src/libslic3r/Format/PRUS.cpp +++ b/xs/src/libslic3r/Format/PRUS.cpp @@ -207,8 +207,8 @@ bool load_prus(const char *path, Model *model) for (size_t c = 0; c < 3; ++ c) trafo[r][c] += mat_trafo(r, c); } - instance_offset.x = position[0] - zero[0]; - instance_offset.y = position[1] - zero[1]; + instance_offset.x() = position[0] - zero[0]; + instance_offset.y() = position[1] - zero[1]; trafo[2][3] = position[2] / instance_scaling_factor; trafo_set = true; } diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index f0b37ade3..da56807ae 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -49,7 +49,7 @@ Polyline AvoidCrossingPerimeters::travel_to(const GCode &gcodegen, const Point & // If use_external, then perform the path planning in the world coordinate system (correcting for the gcodegen offset). // Otherwise perform the path planning in the coordinate system of the active object. bool use_external = this->use_external_mp || this->use_external_mp_once; - Point scaled_origin = use_external ? Point::new_scale(gcodegen.origin().x, gcodegen.origin().y) : Point(0, 0); + Point scaled_origin = use_external ? Point::new_scale(gcodegen.origin().x(), gcodegen.origin().y()) : Point(0, 0); Polyline result = (use_external ? m_external_mp.get() : m_layer_mp.get())-> shortest_path(gcodegen.last_pos() + scaled_origin, point + scaled_origin); if (use_external) @@ -65,7 +65,7 @@ std::string OozePrevention::pre_toolchange(GCode &gcodegen) if (!this->standby_points.empty()) { // get current position in print coordinates Pointf3 writer_pos = gcodegen.writer().get_position(); - Point pos = Point::new_scale(writer_pos.x, writer_pos.y); + Point pos = Point::new_scale(writer_pos.x(), writer_pos.y()); // find standby point Point standby_point; @@ -160,7 +160,7 @@ Wipe::wipe(GCode &gcodegen, bool toolchange) static inline Point wipe_tower_point_to_object_point(GCode &gcodegen, const WipeTower::xy &wipe_tower_pt) { - return Point(scale_(wipe_tower_pt.x - gcodegen.origin().x), scale_(wipe_tower_pt.y - gcodegen.origin().y)); + return Point(scale_(wipe_tower_pt.x - gcodegen.origin().x()), scale_(wipe_tower_pt.y - gcodegen.origin().y())); } std::string WipeTowerIntegration::append_tcr(GCode &gcodegen, const WipeTower::ToolChangeResult &tcr, int new_extruder_id) const @@ -262,7 +262,7 @@ std::string WipeTowerIntegration::tool_change(GCode &gcodegen, int extruder_id, std::string WipeTowerIntegration::finalize(GCode &gcodegen) { std::string gcode; - if (std::abs(gcodegen.writer().get_position().z - m_final_purge.print_z) > EPSILON) + if (std::abs(gcodegen.writer().get_position().z() - m_final_purge.print_z) > EPSILON) gcode += gcodegen.change_layer(m_final_purge.print_z); gcode += append_tcr(gcodegen, m_final_purge, -1); return gcode; @@ -699,7 +699,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) for (unsigned int extruder_id : print.extruders()) { const Pointf &extruder_offset = print.config.extruder_offset.get_at(extruder_id); Polygon s(outer_skirt); - s.translate(-scale_(extruder_offset.x), -scale_(extruder_offset.y)); + s.translate(-scale_(extruder_offset.x()), -scale_(extruder_offset.y())); skirts.emplace_back(std::move(s)); } m_ooze_prevention.enable = true; @@ -725,7 +725,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) // Print objects from the smallest to the tallest to avoid collisions // when moving onto next object starting point. std::vector<PrintObject*> objects(print.objects); - std::sort(objects.begin(), objects.end(), [](const PrintObject* po1, const PrintObject* po2) { return po1->size.z < po2->size.z; }); + std::sort(objects.begin(), objects.end(), [](const PrintObject* po1, const PrintObject* po2) { return po1->size.z() < po2->size.z(); }); size_t finished_objects = 0; for (size_t object_id = initial_print_object_id; object_id < objects.size(); ++ object_id) { const PrintObject &object = *objects[object_id]; @@ -742,7 +742,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) final_extruder_id = tool_ordering.last_extruder(); assert(final_extruder_id != (unsigned int)-1); } - this->set_origin(unscale(copy.x), unscale(copy.y)); + this->set_origin(unscale(copy.x()), unscale(copy.y())); if (finished_objects > 0) { // Move to the origin position for the copy we're going to print. // This happens before Z goes down to layer 0 again, so that no collision happens hopefully. @@ -849,7 +849,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) { DynamicConfig config; config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index)); - config.set_key_value("layer_z", new ConfigOptionFloat(m_writer.get_position().z - m_config.z_offset.value)); + config.set_key_value("layer_z", new ConfigOptionFloat(m_writer.get_position().z() - m_config.z_offset.value)); if (print.config.single_extruder_multi_material) { // Process the end_filament_gcode for the active filament only. _writeln(file, this->placeholder_parser_process("end_filament_gcode", print.config.end_filament_gcode.get_at(m_writer.extruder()->id()), m_writer.extruder()->id(), &config)); @@ -1304,8 +1304,8 @@ void GCode::process_layer( layer_surface_bboxes.push_back(get_extents(expoly.contour)); auto point_inside_surface = [&layer, &layer_surface_bboxes](const size_t i, const Point &point) { const BoundingBox &bbox = layer_surface_bboxes[i]; - return point.x >= bbox.min.x && point.x < bbox.max.x && - point.y >= bbox.min.y && point.y < bbox.max.y && + return point.x() >= bbox.min.x() && point.x() < bbox.max.x() && + point.y() >= bbox.min.y() && point.y() < bbox.max.y() && layer.slices.expolygons[i].contour.contains(point); }; @@ -1455,7 +1455,7 @@ void GCode::process_layer( if (m_last_obj_copy != this_object_copy) m_avoid_crossing_perimeters.use_external_mp_once = true; m_last_obj_copy = this_object_copy; - this->set_origin(unscale(copy.x), unscale(copy.y)); + this->set_origin(unscale(copy.x()), unscale(copy.y())); if (object_by_extruder.support != nullptr && !print_wipe_extrusions) { m_layer = layers[layer_id].support_layer; gcode += this->extrude_support( @@ -1544,8 +1544,8 @@ void GCode::set_origin(const Pointf &pointf) { // if origin increases (goes towards right), last_pos decreases because it goes towards left const Point translate( - scale_(m_origin.x - pointf.x), - scale_(m_origin.y - pointf.y) + scale_(m_origin.x() - pointf.x()), + scale_(m_origin.y() - pointf.y()) ); m_last_pos.translate(translate); m_wipe.path.translate(translate); @@ -1680,11 +1680,11 @@ static Points::iterator project_point_to_polygon_and_insert(Polygon &polygon, co const Point &p2 = polygon.points[j]; const Slic3r::Point v_seg = p1.vector_to(p2); const Slic3r::Point v_pt = p1.vector_to(pt); - const int64_t l2_seg = int64_t(v_seg.x) * int64_t(v_seg.x) + int64_t(v_seg.y) * int64_t(v_seg.y); - int64_t t_pt = int64_t(v_seg.x) * int64_t(v_pt.x) + int64_t(v_seg.y) * int64_t(v_pt.y); + const int64_t l2_seg = int64_t(v_seg.x()) * int64_t(v_seg.x()) + int64_t(v_seg.y()) * int64_t(v_seg.y()); + int64_t t_pt = int64_t(v_seg.x()) * int64_t(v_pt.x()) + int64_t(v_seg.y()) * int64_t(v_pt.y()); if (t_pt < 0) { // Closest to p1. - double dabs = sqrt(int64_t(v_pt.x) * int64_t(v_pt.x) + int64_t(v_pt.y) * int64_t(v_pt.y)); + double dabs = sqrt(int64_t(v_pt.x()) * int64_t(v_pt.x()) + int64_t(v_pt.y()) * int64_t(v_pt.y())); if (dabs < d_min) { d_min = dabs; i_min = i; @@ -1697,7 +1697,7 @@ static Points::iterator project_point_to_polygon_and_insert(Polygon &polygon, co } else { // Closest to the segment. assert(t_pt >= 0 && t_pt <= l2_seg); - int64_t d_seg = int64_t(v_seg.y) * int64_t(v_pt.x) - int64_t(v_seg.x) * int64_t(v_pt.y); + int64_t d_seg = int64_t(v_seg.y()) * int64_t(v_pt.x()) - int64_t(v_seg.x()) * int64_t(v_pt.y()); double d = double(d_seg) / sqrt(double(l2_seg)); double dabs = std::abs(d); if (dabs < d_min) { @@ -1706,8 +1706,8 @@ static Points::iterator project_point_to_polygon_and_insert(Polygon &polygon, co // Evaluate the foot point. pt_min = p1; double linv = double(d_seg) / double(l2_seg); - pt_min.x = pt.x - coord_t(floor(double(v_seg.y) * linv + 0.5)); - pt_min.y = pt.y + coord_t(floor(double(v_seg.x) * linv + 0.5)); + pt_min.x() = pt.x() - coord_t(floor(double(v_seg.y()) * linv + 0.5)); + pt_min.y() = pt.y() + coord_t(floor(double(v_seg.x()) * linv + 0.5)); assert(Line(p1, p2).distance_to(pt_min) < scale_(1e-5)); } } @@ -1777,8 +1777,8 @@ std::vector<float> polygon_angles_at_vertices(const Polygon &polygon, const std: const Point &p2 = polygon.points[idx_next]; const Point v1 = p0.vector_to(p1); const Point v2 = p1.vector_to(p2); - int64_t dot = int64_t(v1.x)*int64_t(v2.x) + int64_t(v1.y)*int64_t(v2.y); - int64_t cross = int64_t(v1.x)*int64_t(v2.y) - int64_t(v1.y)*int64_t(v2.x); + int64_t dot = int64_t(v1.x())*int64_t(v2.x()) + int64_t(v1.y())*int64_t(v2.y()); + int64_t cross = int64_t(v1.x())*int64_t(v2.y()) - int64_t(v1.y())*int64_t(v2.x()); float angle = float(atan2(double(cross), double(dot))); angles[idx_curr] = angle; } @@ -1802,10 +1802,10 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou { static int iRun = 0; BoundingBox bbox = (*lower_layer_edge_grid)->bbox(); - bbox.min.x -= scale_(5.f); - bbox.min.y -= scale_(5.f); - bbox.max.x += scale_(5.f); - bbox.max.y += scale_(5.f); + bbox.min.x() -= scale_(5.f); + bbox.min.y() -= scale_(5.f); + bbox.max.x() += scale_(5.f); + bbox.max.y() += scale_(5.f); EdgeGrid::save_png(*(*lower_layer_edge_grid), bbox, scale_(0.1f), debug_out_path("GCode_extrude_loop_edge_grid-%d.png", iRun++)); } #endif @@ -1841,7 +1841,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou break; case spRear: last_pos = m_layer->object()->bounding_box().center(); - last_pos.y += coord_t(3. * m_layer->object()->bounding_box().radius()); + last_pos.y() += coord_t(3. * m_layer->object()->bounding_box().radius()); last_pos_weight = 5.f; break; } @@ -1974,7 +1974,7 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou //FIXME Better parametrize the loop by its length. Polygon polygon = loop.polygon(); Point centroid = polygon.centroid(); - last_pos = Point(polygon.bounding_box().max.x, centroid.y); + last_pos = Point(polygon.bounding_box().max.x(), centroid.y()); last_pos.rotate(fmod((float)rand()/16.0, 2.0*PI), centroid); } // Find the closest point, avoid overhangs. @@ -2532,8 +2532,8 @@ Pointf GCode::point_to_gcode(const Point &point) const { Pointf extruder_offset = EXTRUDER_CONFIG(extruder_offset); return Pointf( - unscale(point.x) + m_origin.x - extruder_offset.x, - unscale(point.y) + m_origin.y - extruder_offset.y); + unscale(point.x()) + m_origin.x() - extruder_offset.x(), + unscale(point.y()) + m_origin.y() - extruder_offset.y()); } // convert a model-space scaled point into G-code coordinates @@ -2541,8 +2541,8 @@ Point GCode::gcode_to_point(const Pointf &point) const { Pointf extruder_offset = EXTRUDER_CONFIG(extruder_offset); return Point( - scale_(point.x - m_origin.x + extruder_offset.x), - scale_(point.y - m_origin.y + extruder_offset.y)); + scale_(point.x() - m_origin.x() + extruder_offset.x()), + scale_(point.y() - m_origin.y() + extruder_offset.y())); } diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index b7ecee5a4..44e6e9acb 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -683,7 +683,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ // constructs the polylines while traversing the moves for (const GCodeMove& move : extrude_moves->second) { - if ((data != move.data) || (z != move.start_position.z) || (position != move.start_position) || (volumetric_rate != move.data.feedrate * (float)move.data.mm3_per_mm)) + if ((data != move.data) || (z != move.start_position.z()) || (position != move.start_position) || (volumetric_rate != move.data.feedrate * (float)move.data.mm3_per_mm)) { // store current polyline polyline.remove_duplicate_points(); @@ -693,12 +693,12 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ polyline = Polyline(); // add both vertices of the move - polyline.append(Point(scale_(move.start_position.x), scale_(move.start_position.y))); - polyline.append(Point(scale_(move.end_position.x), scale_(move.end_position.y))); + polyline.append(Point(scale_(move.start_position.x()), scale_(move.start_position.y()))); + polyline.append(Point(scale_(move.end_position.x()), scale_(move.end_position.y()))); // update current values data = move.data; - z = move.start_position.z; + z = move.start_position.z(); volumetric_rate = move.data.feedrate * (float)move.data.mm3_per_mm; height_range.update_from(move.data.height); width_range.update_from(move.data.width); @@ -707,7 +707,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ } else // append end vertex of the move to current polyline - polyline.append(Point(scale_(move.end_position.x), scale_(move.end_position.y))); + polyline.append(Point(scale_(move.end_position.x()), scale_(move.end_position.y()))); // update current values position = move.end_position; @@ -756,7 +756,7 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) for (const GCodeMove& move : travel_moves->second) { GCodePreviewData::Travel::EType move_type = (move.delta_extruder < 0.0f) ? GCodePreviewData::Travel::Retract : ((move.delta_extruder > 0.0f) ? GCodePreviewData::Travel::Extrude : GCodePreviewData::Travel::Move); - GCodePreviewData::Travel::Polyline::EDirection move_direction = ((move.start_position.x != move.end_position.x) || (move.start_position.y != move.end_position.y)) ? GCodePreviewData::Travel::Polyline::Generic : GCodePreviewData::Travel::Polyline::Vertical; + GCodePreviewData::Travel::Polyline::EDirection move_direction = ((move.start_position.x() != move.end_position.x()) || (move.start_position.y() != move.end_position.y())) ? GCodePreviewData::Travel::Polyline::Generic : GCodePreviewData::Travel::Polyline::Vertical; if ((type != move_type) || (direction != move_direction) || (feedrate != move.data.feedrate) || (position != move.start_position) || (extruder_id != move.data.extruder_id)) { @@ -768,12 +768,12 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) polyline = Polyline3(); // add both vertices of the move - polyline.append(Point3(scale_(move.start_position.x), scale_(move.start_position.y), scale_(move.start_position.z))); - polyline.append(Point3(scale_(move.end_position.x), scale_(move.end_position.y), scale_(move.end_position.z))); + polyline.append(Point3(scale_(move.start_position.x()), scale_(move.start_position.y()), scale_(move.start_position.z()))); + polyline.append(Point3(scale_(move.end_position.x()), scale_(move.end_position.y()), scale_(move.end_position.z()))); } else // append end vertex of the move to current polyline - polyline.append(Point3(scale_(move.end_position.x), scale_(move.end_position.y), scale_(move.end_position.z))); + polyline.append(Point3(scale_(move.end_position.x()), scale_(move.end_position.y()), scale_(move.end_position.z()))); // update current values position = move.end_position; @@ -804,7 +804,7 @@ void GCodeAnalyzer::_calc_gcode_preview_retractions(GCodePreviewData& preview_da for (const GCodeMove& move : retraction_moves->second) { // store position - Point3 position(scale_(move.start_position.x), scale_(move.start_position.y), scale_(move.start_position.z)); + Point3 position(scale_(move.start_position.x()), scale_(move.start_position.y()), scale_(move.start_position.z())); preview_data.retraction.positions.emplace_back(position, move.data.width, move.data.height); } } @@ -818,7 +818,7 @@ void GCodeAnalyzer::_calc_gcode_preview_unretractions(GCodePreviewData& preview_ for (const GCodeMove& move : unretraction_moves->second) { // store position - Point3 position(scale_(move.start_position.x), scale_(move.start_position.y), scale_(move.start_position.z)); + Point3 position(scale_(move.start_position.x()), scale_(move.start_position.y()), scale_(move.start_position.z())); preview_data.unretraction.positions.emplace_back(position, move.data.width, move.data.height); } } diff --git a/xs/src/libslic3r/GCode/CoolingBuffer.cpp b/xs/src/libslic3r/GCode/CoolingBuffer.cpp index a15247693..78855ec4a 100644 --- a/xs/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/xs/src/libslic3r/GCode/CoolingBuffer.cpp @@ -24,9 +24,9 @@ void CoolingBuffer::reset() { m_current_pos.assign(5, 0.f); Pointf3 pos = m_gcodegen.writer().get_position(); - m_current_pos[0] = float(pos.x); - m_current_pos[1] = float(pos.y); - m_current_pos[2] = float(pos.z); + m_current_pos[0] = float(pos.x()); + m_current_pos[1] = float(pos.y()); + m_current_pos[2] = float(pos.z()); m_current_pos[4] = float(m_gcodegen.config().travel_speed.value); } diff --git a/xs/src/libslic3r/GCode/PrintExtents.cpp b/xs/src/libslic3r/GCode/PrintExtents.cpp index 3c3f0f8d5..a943f1b23 100644 --- a/xs/src/libslic3r/GCode/PrintExtents.cpp +++ b/xs/src/libslic3r/GCode/PrintExtents.cpp @@ -19,10 +19,10 @@ static inline BoundingBox extrusion_polyline_extents(const Polyline &polyline, c if (! polyline.points.empty()) bbox.merge(polyline.points.front()); for (const Point &pt : polyline.points) { - bbox.min.x = std::min(bbox.min.x, pt.x - radius); - bbox.min.y = std::min(bbox.min.y, pt.y - radius); - bbox.max.x = std::max(bbox.max.x, pt.x + radius); - bbox.max.y = std::max(bbox.max.y, pt.y + radius); + bbox.min.x() = std::min(bbox.min.x(), pt.x() - radius); + bbox.min.y() = std::min(bbox.min.y(), pt.y() - radius); + bbox.max.x() = std::max(bbox.max.x(), pt.x() + radius); + bbox.max.y() = std::max(bbox.max.y(), pt.y() + radius); } return bbox; } @@ -146,10 +146,10 @@ BoundingBoxf get_wipe_tower_extrusions_extents(const Print &print, const coordf_ Pointf p2(e.pos.x, e.pos.y); bbox.merge(p1); coordf_t radius = 0.5 * e.width; - bbox.min.x = std::min(bbox.min.x, std::min(p1.x, p2.x) - radius); - bbox.min.y = std::min(bbox.min.y, std::min(p1.y, p2.y) - radius); - bbox.max.x = std::max(bbox.max.x, std::max(p1.x, p2.x) + radius); - bbox.max.y = std::max(bbox.max.y, std::max(p1.y, p2.y) + radius); + bbox.min.x() = std::min(bbox.min.x(), std::min(p1.x(), p2.x()) - radius); + bbox.min.y() = std::min(bbox.min.y(), std::min(p1.y(), p2.y()) - radius); + bbox.max.x() = std::max(bbox.max.x(), std::max(p1.x(), p2.x()) + radius); + bbox.max.y() = std::max(bbox.max.y(), std::max(p1.y(), p2.y()) + radius); } } } @@ -170,10 +170,10 @@ BoundingBoxf get_wipe_tower_priming_extrusions_extents(const Print &print) Pointf p2(e.pos.x, e.pos.y); bbox.merge(p1); coordf_t radius = 0.5 * e.width; - bbox.min.x = std::min(bbox.min.x, std::min(p1.x, p2.x) - radius); - bbox.min.y = std::min(bbox.min.y, std::min(p1.y, p2.y) - radius); - bbox.max.x = std::max(bbox.max.x, std::max(p1.x, p2.x) + radius); - bbox.max.y = std::max(bbox.max.y, std::max(p1.y, p2.y) + radius); + bbox.min.x() = std::min(bbox.min.x(), std::min(p1.x(), p2.x()) - radius); + bbox.min.y() = std::min(bbox.min.y(), std::min(p1.y(), p2.y()) - radius); + bbox.max.x() = std::max(bbox.max.x(), std::max(p1.x(), p2.x()) + radius); + bbox.max.y() = std::max(bbox.max.y(), std::max(p1.y(), p2.y()) + radius); } } } diff --git a/xs/src/libslic3r/GCodeWriter.cpp b/xs/src/libslic3r/GCodeWriter.cpp index 34e6b7ec3..39c431169 100644 --- a/xs/src/libslic3r/GCodeWriter.cpp +++ b/xs/src/libslic3r/GCodeWriter.cpp @@ -278,12 +278,12 @@ std::string GCodeWriter::set_speed(double F, const std::string &comment, const s std::string GCodeWriter::travel_to_xy(const Pointf &point, const std::string &comment) { - m_pos.x = point.x; - m_pos.y = point.y; + m_pos.x() = point.x(); + m_pos.y() = point.y(); std::ostringstream gcode; - gcode << "G1 X" << XYZF_NUM(point.x) - << " Y" << XYZF_NUM(point.y) + gcode << "G1 X" << XYZF_NUM(point.x()) + << " Y" << XYZF_NUM(point.y()) << " F" << XYZF_NUM(this->config.travel_speed.value * 60.0); COMMENT(comment); gcode << "\n"; @@ -296,9 +296,9 @@ std::string GCodeWriter::travel_to_xyz(const Pointf3 &point, const std::string & don't perform the Z move but we only move in the XY plane and adjust the nominal Z by reducing the lift amount that will be used for unlift. */ - if (!this->will_move_z(point.z)) { - double nominal_z = m_pos.z - m_lifted; - m_lifted = m_lifted - (point.z - nominal_z); + if (!this->will_move_z(point.z())) { + double nominal_z = m_pos.z() - m_lifted; + m_lifted = m_lifted - (point.z() - nominal_z); return this->travel_to_xy(point); } @@ -308,9 +308,9 @@ std::string GCodeWriter::travel_to_xyz(const Pointf3 &point, const std::string & m_pos = point; std::ostringstream gcode; - gcode << "G1 X" << XYZF_NUM(point.x) - << " Y" << XYZF_NUM(point.y) - << " Z" << XYZF_NUM(point.z) + gcode << "G1 X" << XYZF_NUM(point.x()) + << " Y" << XYZF_NUM(point.y()) + << " Z" << XYZF_NUM(point.z()) << " F" << XYZF_NUM(this->config.travel_speed.value * 60.0); COMMENT(comment); gcode << "\n"; @@ -323,7 +323,7 @@ std::string GCodeWriter::travel_to_z(double z, const std::string &comment) we don't perform the move but we only adjust the nominal Z by reducing the lift amount that will be used for unlift. */ if (!this->will_move_z(z)) { - double nominal_z = m_pos.z - m_lifted; + double nominal_z = m_pos.z() - m_lifted; m_lifted = m_lifted - (z - nominal_z); return ""; } @@ -336,7 +336,7 @@ std::string GCodeWriter::travel_to_z(double z, const std::string &comment) std::string GCodeWriter::_travel_to_z(double z, const std::string &comment) { - m_pos.z = z; + m_pos.z() = z; std::ostringstream gcode; gcode << "G1 Z" << XYZF_NUM(z) @@ -351,8 +351,8 @@ bool GCodeWriter::will_move_z(double z) const /* If target Z is lower than current Z but higher than nominal Z we don't perform an actual Z move. */ if (m_lifted > 0) { - double nominal_z = m_pos.z - m_lifted; - if (z >= nominal_z && z <= m_pos.z) + double nominal_z = m_pos.z() - m_lifted; + if (z >= nominal_z && z <= m_pos.z()) return false; } return true; @@ -360,13 +360,13 @@ bool GCodeWriter::will_move_z(double z) const std::string GCodeWriter::extrude_to_xy(const Pointf &point, double dE, const std::string &comment) { - m_pos.x = point.x; - m_pos.y = point.y; + m_pos.x() = point.x(); + m_pos.y() = point.y(); m_extruder->extrude(dE); std::ostringstream gcode; - gcode << "G1 X" << XYZF_NUM(point.x) - << " Y" << XYZF_NUM(point.y) + gcode << "G1 X" << XYZF_NUM(point.x()) + << " Y" << XYZF_NUM(point.y()) << " " << m_extrusion_axis << E_NUM(m_extruder->E()); COMMENT(comment); gcode << "\n"; @@ -380,9 +380,9 @@ std::string GCodeWriter::extrude_to_xyz(const Pointf3 &point, double dE, const s m_extruder->extrude(dE); std::ostringstream gcode; - gcode << "G1 X" << XYZF_NUM(point.x) - << " Y" << XYZF_NUM(point.y) - << " Z" << XYZF_NUM(point.z) + gcode << "G1 X" << XYZF_NUM(point.x()) + << " Y" << XYZF_NUM(point.y()) + << " Z" << XYZF_NUM(point.z()) << " " << m_extrusion_axis << E_NUM(m_extruder->E()); COMMENT(comment); gcode << "\n"; @@ -486,12 +486,12 @@ std::string GCodeWriter::lift() { double above = this->config.retract_lift_above.get_at(m_extruder->id()); double below = this->config.retract_lift_below.get_at(m_extruder->id()); - if (m_pos.z >= above && (below == 0 || m_pos.z <= below)) + if (m_pos.z() >= above && (below == 0 || m_pos.z() <= below)) target_lift = this->config.retract_lift.get_at(m_extruder->id()); } if (m_lifted == 0 && target_lift > 0) { m_lifted = target_lift; - return this->_travel_to_z(m_pos.z + target_lift, "lift Z"); + return this->_travel_to_z(m_pos.z() + target_lift, "lift Z"); } return ""; } @@ -500,7 +500,7 @@ std::string GCodeWriter::unlift() { std::string gcode; if (m_lifted > 0) { - gcode += this->_travel_to_z(m_pos.z - m_lifted, "restore layer Z"); + gcode += this->_travel_to_z(m_pos.z() - m_lifted, "restore layer Z"); m_lifted = 0; } return gcode; diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index 39b626ee3..fafc10629 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -198,7 +198,7 @@ namespace Slic3r { namespace Geometry { static bool sort_points (Point a, Point b) { - return (a.x < b.x) || (a.x == b.x && a.y < b.y); + return (a.x() < b.x()) || (a.x() == b.x() && a.y() < b.y()); } /* This implementation is based on Andrew's monotone chain 2D convex hull algorithm */ @@ -349,30 +349,30 @@ struct ArrangeItem { coordf_t weight; bool operator<(const ArrangeItem &other) const { return weight < other.weight || - ((weight == other.weight) && (pos.y < other.pos.y || (pos.y == other.pos.y && pos.x < other.pos.x))); + ((weight == other.weight) && (pos.y() < other.pos.y() || (pos.y() == other.pos.y() && pos.x() < other.pos.x()))); } }; Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const BoundingBoxf* bed_bounding_box) { // Use actual part size (the largest) plus separation distance (half on each side) in spacing algorithm. - const Pointf cell_size(part_size.x + gap, part_size.y + gap); + const Pointf cell_size(part_size.x() + gap, part_size.y() + gap); const BoundingBoxf bed_bbox = (bed_bounding_box != NULL && bed_bounding_box->defined) ? *bed_bounding_box : // Bogus bed size, large enough not to trigger the unsufficient bed size error. BoundingBoxf( Pointf(0, 0), - Pointf(cell_size.x * num_parts, cell_size.y * num_parts)); + Pointf(cell_size.x() * num_parts, cell_size.y() * num_parts)); // This is how many cells we have available into which to put parts. - size_t cellw = size_t(floor((bed_bbox.size().x + gap) / cell_size.x)); - size_t cellh = size_t(floor((bed_bbox.size().y + gap) / cell_size.y)); + size_t cellw = size_t(floor((bed_bbox.size().x() + gap) / cell_size.x())); + size_t cellh = size_t(floor((bed_bbox.size().y() + gap) / cell_size.y())); if (num_parts > cellw * cellh) CONFESS(PRINTF_ZU " parts won't fit in your print area!\n", num_parts); // Get a bounding box of cellw x cellh cells, centered at the center of the bed. - Pointf cells_size(cellw * cell_size.x - gap, cellh * cell_size.y - gap); + Pointf cells_size(cellw * cell_size.x() - gap, cellh * cell_size.y() - gap); Pointf cells_offset(bed_bbox.center() - 0.5 * cells_size); BoundingBoxf cells_bb(cells_offset, cells_size + cells_offset); @@ -380,19 +380,19 @@ Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const B std::vector<ArrangeItem> cellsorder(cellw * cellh, ArrangeItem()); for (size_t j = 0; j < cellh; ++ j) { // Center of the jth row on the bed. - coordf_t cy = linint(j + 0.5, 0., double(cellh), cells_bb.min.y, cells_bb.max.y); + coordf_t cy = linint(j + 0.5, 0., double(cellh), cells_bb.min.y(), cells_bb.max.y()); // Offset from the bed center. - coordf_t yd = cells_bb.center().y - cy; + coordf_t yd = cells_bb.center().y() - cy; for (size_t i = 0; i < cellw; ++ i) { // Center of the ith column on the bed. - coordf_t cx = linint(i + 0.5, 0., double(cellw), cells_bb.min.x, cells_bb.max.x); + coordf_t cx = linint(i + 0.5, 0., double(cellw), cells_bb.min.x(), cells_bb.max.x()); // Offset from the bed center. - coordf_t xd = cells_bb.center().x - cx; + coordf_t xd = cells_bb.center().x() - cx; // Cell with a distance from the bed center. ArrangeItem &ci = cellsorder[j * cellw + i]; // Cell center - ci.pos.x = cx; - ci.pos.y = cy; + ci.pos.x() = cx; + ci.pos.y() = cy; // Square distance of the cell center to the bed center. ci.weight = xd * xd + yd * yd; } @@ -405,7 +405,7 @@ Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const B Pointfs positions; positions.reserve(num_parts); for (std::vector<ArrangeItem>::const_iterator it = cellsorder.begin(); it != cellsorder.end(); ++ it) - positions.push_back(Pointf(it->pos.x - 0.5 * part_size.x, it->pos.y - 0.5 * part_size.y)); + positions.push_back(Pointf(it->pos.x() - 0.5 * part_size.x(), it->pos.y() - 0.5 * part_size.y())); return positions; } #else @@ -430,26 +430,26 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi Pointf part = part_size; // use actual part size (the largest) plus separation distance (half on each side) in spacing algorithm - part.x += dist; - part.y += dist; + part.x() += dist; + part.y() += dist; Pointf area; if (bb != NULL && bb->defined) { area = bb->size(); } else { // bogus area size, large enough not to trigger the error below - area.x = part.x * total_parts; - area.y = part.y * total_parts; + area.x() = part.x() * total_parts; + area.y() = part.y() * total_parts; } // this is how many cells we have available into which to put parts - size_t cellw = floor((area.x + dist) / part.x); - size_t cellh = floor((area.y + dist) / part.y); + size_t cellw = floor((area.x() + dist) / part.x()); + size_t cellh = floor((area.y() + dist) / part.y()); if (total_parts > (cellw * cellh)) return false; // total space used by cells - Pointf cells(cellw * part.x, cellh * part.y); + Pointf cells(cellw * part.x(), cellh * part.y()); // bounding box of total space used by cells BoundingBoxf cells_bb; @@ -458,8 +458,8 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi // center bounding box to area cells_bb.translate( - (area.x - cells.x) / 2, - (area.y - cells.y) / 2 + (area.x() - cells.x()) / 2, + (area.y() - cells.y()) / 2 ); // list of cells, sorted by distance from center @@ -468,15 +468,15 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi // work out distance for all cells, sort into list for (size_t i = 0; i <= cellw-1; ++i) { for (size_t j = 0; j <= cellh-1; ++j) { - coordf_t cx = linint(i + 0.5, 0, cellw, cells_bb.min.x, cells_bb.max.x); - coordf_t cy = linint(j + 0.5, 0, cellh, cells_bb.min.y, cells_bb.max.y); + coordf_t cx = linint(i + 0.5, 0, cellw, cells_bb.min.x(), cells_bb.max.x()); + coordf_t cy = linint(j + 0.5, 0, cellh, cells_bb.min.y(), cells_bb.max.y()); - coordf_t xd = fabs((area.x / 2) - cx); - coordf_t yd = fabs((area.y / 2) - cy); + coordf_t xd = fabs((area.x() / 2) - cx); + coordf_t yd = fabs((area.y() / 2) - cy); ArrangeItem c; - c.pos.x = cx; - c.pos.y = cy; + c.pos.x() = cx; + c.pos.y() = cy; c.index_x = i; c.index_y = j; c.dist = xd * xd + yd * yd - fabs((cellw / 2) - (i + 0.5)); @@ -533,13 +533,13 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi coordf_t cx = c.item.index_x - lx; coordf_t cy = c.item.index_y - ty; - positions.push_back(Pointf(cx * part.x, cy * part.y)); + positions.push_back(Pointf(cx * part.x(), cy * part.y())); } if (bb != NULL && bb->defined) { for (Pointfs::iterator p = positions.begin(); p != positions.end(); ++p) { - p->x += bb->min.x; - p->y += bb->min.y; + p->x() += bb->min.x(); + p->y() += bb->min.y(); } } @@ -676,10 +676,10 @@ static inline void dump_voronoi_to_svg(const Lines &lines, /* const */ voronoi_d const bool primaryEdgesOnly = false; BoundingBox bbox = BoundingBox(lines); - bbox.min.x -= coord_t(1. / SCALING_FACTOR); - bbox.min.y -= coord_t(1. / SCALING_FACTOR); - bbox.max.x += coord_t(1. / SCALING_FACTOR); - bbox.max.y += coord_t(1. / SCALING_FACTOR); + bbox.min.x() -= coord_t(1. / SCALING_FACTOR); + bbox.min.y() -= coord_t(1. / SCALING_FACTOR); + bbox.max.x() += coord_t(1. / SCALING_FACTOR); + bbox.max.y() += coord_t(1. / SCALING_FACTOR); ::Slic3r::SVG svg(path, bbox); @@ -689,7 +689,7 @@ static inline void dump_voronoi_to_svg(const Lines &lines, /* const */ voronoi_d // bbox.scale(1.2); // For clipping of half-lines to some reasonable value. // The line will then be clipped by the SVG viewer anyway. - const double bbox_dim_max = double(bbox.max.x - bbox.min.x) + double(bbox.max.y - bbox.min.y); + const double bbox_dim_max = double(bbox.max.x() - bbox.min.x()) + double(bbox.max.y() - bbox.min.y()); // For the discretization of the Voronoi parabolic segments. const double discretization_step = 0.0005 * bbox_dim_max; @@ -697,8 +697,8 @@ static inline void dump_voronoi_to_svg(const Lines &lines, /* const */ voronoi_d std::vector<Voronoi::Internal::segment_type> segments; for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++ it) segments.push_back(Voronoi::Internal::segment_type( - Voronoi::Internal::point_type(double(it->a.x), double(it->a.y)), - Voronoi::Internal::point_type(double(it->b.x), double(it->b.y)))); + Voronoi::Internal::point_type(double(it->a.x()), double(it->a.y())), + Voronoi::Internal::point_type(double(it->b.x()), double(it->b.y())))); // Color exterior edges. for (voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it) @@ -712,7 +712,7 @@ static inline void dump_voronoi_to_svg(const Lines &lines, /* const */ voronoi_d } // Draw the input polygon. for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it) - svg.draw(Line(Point(coord_t(it->a.x), coord_t(it->a.y)), Point(coord_t(it->b.x), coord_t(it->b.y))), inputSegmentColor, inputSegmentLineWidth); + svg.draw(Line(Point(coord_t(it->a.x()), coord_t(it->a.y())), Point(coord_t(it->b.x()), coord_t(it->b.y()))), inputSegmentColor, inputSegmentLineWidth); #if 1 // Draw voronoi vertices. @@ -828,8 +828,8 @@ public: Lines2VDSegments(const Lines &alines) : lines(alines) {} typename VD::segment_type operator[](size_t idx) const { return typename VD::segment_type( - typename VD::point_type(typename VD::coord_type(lines[idx].a.x), typename VD::coord_type(lines[idx].a.y)), - typename VD::point_type(typename VD::coord_type(lines[idx].b.x), typename VD::coord_type(lines[idx].b.y))); + typename VD::point_type(typename VD::coord_type(lines[idx].a.x()), typename VD::coord_type(lines[idx].a.y())), + typename VD::point_type(typename VD::coord_type(lines[idx].b.x()), typename VD::coord_type(lines[idx].b.y()))); } private: const Lines &lines; diff --git a/xs/src/libslic3r/Geometry.hpp b/xs/src/libslic3r/Geometry.hpp index c2c3dc8b7..1ac0ce59f 100644 --- a/xs/src/libslic3r/Geometry.hpp +++ b/xs/src/libslic3r/Geometry.hpp @@ -30,9 +30,9 @@ enum Orientation static inline Orientation orient(const Point &a, const Point &b, const Point &c) { // BOOST_STATIC_ASSERT(sizeof(coord_t) * 2 == sizeof(int64_t)); - int64_t u = int64_t(b.x) * int64_t(c.y) - int64_t(b.y) * int64_t(c.x); - int64_t v = int64_t(a.x) * int64_t(c.y) - int64_t(a.y) * int64_t(c.x); - int64_t w = int64_t(a.x) * int64_t(b.y) - int64_t(a.y) * int64_t(b.x); + int64_t u = int64_t(b.x()) * int64_t(c.y()) - int64_t(b.y()) * int64_t(c.x()); + int64_t v = int64_t(a.x()) * int64_t(c.y()) - int64_t(a.y()) * int64_t(c.x()); + int64_t w = int64_t(a.x()) * int64_t(b.y()) - int64_t(a.y()) * int64_t(b.x()); int64_t d = u - v + w; return (d > 0) ? ORIENTATION_CCW : ((d == 0) ? ORIENTATION_COLINEAR : ORIENTATION_CW); } @@ -52,7 +52,7 @@ static inline bool is_ccw(const Polygon &poly) for (unsigned int i = 1; i < poly.points.size(); ++ i) { const Point &pmin = poly.points[imin]; const Point &p = poly.points[i]; - if (p.x < pmin.x || (p.x == pmin.x && p.y < pmin.y)) + if (p.x() < pmin.x() || (p.x() == pmin.x() && p.y() < pmin.y())) imin = i; } @@ -68,24 +68,24 @@ static inline bool is_ccw(const Polygon &poly) inline bool ray_ray_intersection(const Pointf &p1, const Vectorf &v1, const Pointf &p2, const Vectorf &v2, Pointf &res) { - double denom = v1.x * v2.y - v2.x * v1.y; + double denom = v1.x() * v2.y() - v2.x() * v1.y(); if (std::abs(denom) < EPSILON) return false; - double t = (v2.x * (p1.y - p2.y) - v2.y * (p1.x - p2.x)) / denom; - res.x = p1.x + t * v1.x; - res.y = p1.y + t * v1.y; + double t = (v2.x() * (p1.y() - p2.y()) - v2.y() * (p1.x() - p2.x())) / denom; + res.x() = p1.x() + t * v1.x(); + res.y() = p1.y() + t * v1.y(); return true; } inline bool segment_segment_intersection(const Pointf &p1, const Vectorf &v1, const Pointf &p2, const Vectorf &v2, Pointf &res) { - double denom = v1.x * v2.y - v2.x * v1.y; + double denom = v1.x() * v2.y() - v2.x() * v1.y(); if (std::abs(denom) < EPSILON) // Lines are collinear. return false; - double s12_x = p1.x - p2.x; - double s12_y = p1.y - p2.y; - double s_numer = v1.x * s12_y - v1.y * s12_x; + double s12_x = p1.x() - p2.x(); + double s12_y = p1.y() - p2.y(); + double s_numer = v1.x() * s12_y - v1.y() * s12_x; bool denom_is_positive = false; if (denom < 0.) { denom_is_positive = true; @@ -95,7 +95,7 @@ inline bool segment_segment_intersection(const Pointf &p1, const Vectorf &v1, co if (s_numer < 0.) // Intersection outside of the 1st segment. return false; - double t_numer = v2.x * s12_y - v2.y * s12_x; + double t_numer = v2.x() * s12_y - v2.y() * s12_x; if (! denom_is_positive) t_numer = - t_numer; if (t_numer < 0. || s_numer > denom || t_numer > denom) @@ -103,8 +103,8 @@ inline bool segment_segment_intersection(const Pointf &p1, const Vectorf &v1, co return false; // Intersection inside both of the segments. double t = t_numer / denom; - res.x = p1.x + t * v1.x; - res.y = p1.y + t * v1.y; + res.x() = p1.x() + t * v1.x(); + res.y() = p1.y() + t * v1.y(); return true; } diff --git a/xs/src/libslic3r/Layer.cpp b/xs/src/libslic3r/Layer.cpp index 652bcdaa0..a83267346 100644 --- a/xs/src/libslic3r/Layer.cpp +++ b/xs/src/libslic3r/Layer.cpp @@ -168,8 +168,8 @@ void Layer::export_region_slices_to_svg(const char *path) const for (Surfaces::const_iterator surface = (*region)->slices.surfaces.begin(); surface != (*region)->slices.surfaces.end(); ++surface) bbox.merge(get_extents(surface->expolygon)); Point legend_size = export_surface_type_legend_to_svg_box_size(); - Point legend_pos(bbox.min.x, bbox.max.y); - bbox.merge(Point(std::max(bbox.min.x + legend_size.x, bbox.max.x), bbox.max.y + legend_size.y)); + Point legend_pos(bbox.min.x(), bbox.max.y()); + bbox.merge(Point(std::max(bbox.min.x() + legend_size.x(), bbox.max.x()), bbox.max.y() + legend_size.y())); SVG svg(path, bbox); const float transparency = 0.5f; @@ -194,8 +194,8 @@ void Layer::export_region_fill_surfaces_to_svg(const char *path) const for (Surfaces::const_iterator surface = (*region)->fill_surfaces.surfaces.begin(); surface != (*region)->fill_surfaces.surfaces.end(); ++surface) bbox.merge(get_extents(surface->expolygon)); Point legend_size = export_surface_type_legend_to_svg_box_size(); - Point legend_pos(bbox.min.x, bbox.max.y); - bbox.merge(Point(std::max(bbox.min.x + legend_size.x, bbox.max.x), bbox.max.y + legend_size.y)); + Point legend_pos(bbox.min.x(), bbox.max.y()); + bbox.merge(Point(std::max(bbox.min.x() + legend_size.x(), bbox.max.x()), bbox.max.y() + legend_size.y())); SVG svg(path, bbox); const float transparency = 0.5f; diff --git a/xs/src/libslic3r/LayerRegion.cpp b/xs/src/libslic3r/LayerRegion.cpp index 68e17407e..fe3e91f50 100644 --- a/xs/src/libslic3r/LayerRegion.cpp +++ b/xs/src/libslic3r/LayerRegion.cpp @@ -395,8 +395,8 @@ void LayerRegion::export_region_slices_to_svg(const char *path) const for (Surfaces::const_iterator surface = this->slices.surfaces.begin(); surface != this->slices.surfaces.end(); ++surface) bbox.merge(get_extents(surface->expolygon)); Point legend_size = export_surface_type_legend_to_svg_box_size(); - Point legend_pos(bbox.min.x, bbox.max.y); - bbox.merge(Point(std::max(bbox.min.x + legend_size.x, bbox.max.x), bbox.max.y + legend_size.y)); + Point legend_pos(bbox.min.x(), bbox.max.y()); + bbox.merge(Point(std::max(bbox.min.x() + legend_size.x(), bbox.max.x()), bbox.max.y() + legend_size.y())); SVG svg(path, bbox); const float transparency = 0.5f; @@ -422,8 +422,8 @@ void LayerRegion::export_region_fill_surfaces_to_svg(const char *path) const for (Surfaces::const_iterator surface = this->fill_surfaces.surfaces.begin(); surface != this->fill_surfaces.surfaces.end(); ++surface) bbox.merge(get_extents(surface->expolygon)); Point legend_size = export_surface_type_legend_to_svg_box_size(); - Point legend_pos(bbox.min.x, bbox.max.y); - bbox.merge(Point(std::max(bbox.min.x + legend_size.x, bbox.max.x), bbox.max.y + legend_size.y)); + Point legend_pos(bbox.min.x(), bbox.max.y()); + bbox.merge(Point(std::max(bbox.min.x() + legend_size.x(), bbox.max.x()), bbox.max.y() + legend_size.y())); SVG svg(path, bbox); const float transparency = 0.5f; diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index e9d5d7742..c40bc1c7b 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/xs/src/libslic3r/Line.cpp @@ -11,8 +11,8 @@ std::string Line::wkt() const { std::ostringstream ss; - ss << "LINESTRING(" << this->a.x << " " << this->a.y << "," - << this->b.x << " " << this->b.y << ")"; + ss << "LINESTRING(" << this->a.x() << " " << this->a.y() << "," + << this->b.x() << " " << this->b.y() << ")"; return ss.str(); } @@ -67,7 +67,7 @@ Line::length() const Point Line::midpoint() const { - return Point((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0); + return Point((this->a.x() + this->b.x()) / 2.0, (this->a.y() + this->b.y()) / 2.0); } void @@ -75,10 +75,10 @@ Line::point_at(double distance, Point* point) const { double len = this->length(); *point = this->a; - if (this->a.x != this->b.x) - point->x = this->a.x + (this->b.x - this->a.x) * distance / len; - if (this->a.y != this->b.y) - point->y = this->a.y + (this->b.y - this->a.y) * distance / len; + if (this->a.x() != this->b.x()) + point->x() = this->a.x() + (this->b.x() - this->a.x()) * distance / len; + if (this->a.y() != this->b.y()) + point->y() = this->a.y() + (this->b.y() - this->a.y()) * distance / len; } Point @@ -96,13 +96,13 @@ Line::intersection_infinite(const Line &other, Point* point) const Vector d1 = this->vector(); Vector d2 = other.vector(); - double cross = d1.x * d2.y - d1.y * d2.x; + double cross = d1.x() * d2.y() - d1.y() * d2.x(); if (std::fabs(cross) < EPSILON) return false; - double t1 = (x.x * d2.y - x.y * d2.x)/cross; - point->x = this->a.x + d1.x * t1; - point->y = this->a.y + d1.y * t1; + double t1 = (x.x() * d2.y() - x.y() * d2.x())/cross; + point->x() = this->a.x() + d1.x() * t1; + point->y() = this->a.y() + d1.y() * t1; return true; } @@ -121,7 +121,7 @@ Line::distance_to(const Point &point) const double Line::atan2_() const { - return atan2(this->b.y - this->a.y, this->b.x - this->a.x); + return atan2(this->b.y() - this->a.y(), this->b.x() - this->a.x()); } double @@ -154,13 +154,13 @@ Line::parallel_to(const Line &line) const { Vector Line::vector() const { - return Vector(this->b.x - this->a.x, this->b.y - this->a.y); + return Vector(this->b.x() - this->a.x(), this->b.y() - this->a.y()); } Vector Line::normal() const { - return Vector((this->b.y - this->a.y), -(this->b.x - this->a.x)); + return Vector((this->b.y() - this->a.y()), -(this->b.x() - this->a.x())); } void @@ -182,14 +182,14 @@ Line::extend_start(double distance) bool Line::intersection(const Line& line, Point* intersection) const { - double denom = ((double)(line.b.y - line.a.y)*(this->b.x - this->a.x)) - - ((double)(line.b.x - line.a.x)*(this->b.y - this->a.y)); + double denom = ((double)(line.b.y() - line.a.y())*(this->b.x() - this->a.x())) - + ((double)(line.b.x() - line.a.x())*(this->b.y() - this->a.y())); - double nume_a = ((double)(line.b.x - line.a.x)*(this->a.y - line.a.y)) - - ((double)(line.b.y - line.a.y)*(this->a.x - line.a.x)); + double nume_a = ((double)(line.b.x() - line.a.x())*(this->a.y() - line.a.y())) - + ((double)(line.b.y() - line.a.y())*(this->a.x() - line.a.x())); - double nume_b = ((double)(this->b.x - this->a.x)*(this->a.y - line.a.y)) - - ((double)(this->b.y - this->a.y)*(this->a.x - line.a.x)); + double nume_b = ((double)(this->b.x() - this->a.x())*(this->a.y() - line.a.y())) - + ((double)(this->b.y() - this->a.y())*(this->a.x() - line.a.x())); if (fabs(denom) < EPSILON) { if (fabs(nume_a) < EPSILON && fabs(nume_b) < EPSILON) { @@ -204,8 +204,8 @@ Line::intersection(const Line& line, Point* intersection) const if (ua >= 0 && ua <= 1.0f && ub >= 0 && ub <= 1.0f) { // Get the intersection point. - intersection->x = this->a.x + ua*(this->b.x - this->a.x); - intersection->y = this->a.y + ua*(this->b.y - this->a.y); + intersection->x() = this->a.x() + ua*(this->b.x() - this->a.x()); + intersection->y() = this->a.y() + ua*(this->b.y() - this->a.y()); return true; } @@ -225,15 +225,15 @@ double Line3::length() const Vector3 Line3::vector() const { - return Vector3(b.x - a.x, b.y - a.y, b.z - a.z); + return Vector3(b.x() - a.x(), b.y() - a.y(), b.z() - a.z()); } Pointf3 Linef3::intersect_plane(double z) const { return Pointf3( - this->a.x + (this->b.x - this->a.x) * (z - this->a.z) / (this->b.z - this->a.z), - this->a.y + (this->b.y - this->a.y) * (z - this->a.z) / (this->b.z - this->a.z), + this->a.x() + (this->b.x() - this->a.x()) * (z - this->a.z()) / (this->b.z() - this->a.z()), + this->a.y() + (this->b.y() - this->a.y()) * (z - this->a.z()) / (this->b.z() - this->a.z()), z ); } diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index d6f1f05c9..dfd407632 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -257,8 +257,8 @@ void Model::center_instances_around_point(const Pointf &point) bb.merge(o->instance_bounding_box(i, false)); Sizef3 size = bb.size(); - coordf_t shift_x = -bb.min.x + point.x - size.x/2; - coordf_t shift_y = -bb.min.y + point.y - size.y/2; + coordf_t shift_x = -bb.min.x() + point.x() - size.x()/2; + coordf_t shift_y = -bb.min.y() + point.y() - size.y()/2; for (ModelObject *o : this->objects) { for (ModelInstance *i : o->instances) i->offset.translate(shift_x, shift_y); @@ -337,11 +337,11 @@ std::string toString(const Model& model, bool holes = true) { ss << "\t\t{\n"; for(auto v : expoly.contour.points) ss << "\t\t\t{" - << v.x << ", " - << v.y << "},\n"; + << v.x() << ", " + << v.y() << "},\n"; { auto v = expoly.contour.points.front(); - ss << "\t\t\t{" << v.x << ", " << v.y << "},\n"; + ss << "\t\t\t{" << v.x() << ", " << v.y() << "},\n"; } ss << "\t\t},\n"; @@ -350,11 +350,11 @@ std::string toString(const Model& model, bool holes = true) { if(holes) for(auto h : expoly.holes) { ss << "\t\t\t{\n"; for(auto v : h.points) ss << "\t\t\t\t{" - << v.x << ", " - << v.y << "},\n"; + << v.x() << ", " + << v.y() << "},\n"; { auto v = h.points.front(); - ss << "\t\t\t\t{" << v.x << ", " << v.y << "},\n"; + ss << "\t\t\t\t{" << v.x() << ", " << v.y() << "},\n"; } ss << "\t\t\t},\n"; } @@ -429,8 +429,8 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) { if(item.vertexCount() > 3) { item.rotation(objinst->rotation); item.translation( { - ClipperLib::cInt(objinst->offset.x/SCALING_FACTOR), - ClipperLib::cInt(objinst->offset.y/SCALING_FACTOR) + ClipperLib::cInt(objinst->offset.x()/SCALING_FACTOR), + ClipperLib::cInt(objinst->offset.y()/SCALING_FACTOR) }); ret.emplace_back(objinst, item); } @@ -501,12 +501,12 @@ bool arrange(Model &model, coordf_t dist, const Slic3r::BoundingBoxf* bb, bbb.scale(1.0/SCALING_FACTOR); bin = Box({ - static_cast<libnest2d::Coord>(bbb.min.x), - static_cast<libnest2d::Coord>(bbb.min.y) + static_cast<libnest2d::Coord>(bbb.min.x()), + static_cast<libnest2d::Coord>(bbb.min.y()) }, { - static_cast<libnest2d::Coord>(bbb.max.x), - static_cast<libnest2d::Coord>(bbb.max.y) + static_cast<libnest2d::Coord>(bbb.max.x()), + static_cast<libnest2d::Coord>(bbb.max.y()) }); } @@ -720,8 +720,8 @@ void Model::duplicate_objects_grid(size_t x, size_t y, coordf_t dist) for (size_t x_copy = 1; x_copy <= x; ++x_copy) { for (size_t y_copy = 1; y_copy <= y; ++y_copy) { ModelInstance* instance = object->add_instance(); - instance->offset.x = (size.x + dist) * (x_copy-1); - instance->offset.y = (size.y + dist) * (y_copy-1); + instance->offset.x() = (size.x() + dist) * (x_copy-1); + instance->offset.y() = (size.y() + dist) * (y_copy-1); } } } @@ -735,7 +735,7 @@ bool Model::looks_like_multipart_object() const if (obj->volumes.size() > 1 || obj->config.keys().size() > 1) return false; for (const ModelVolume *vol : obj->volumes) { - double zmin_this = vol->mesh.bounding_box().min.z; + double zmin_this = vol->mesh.bounding_box().min.z(); if (zmin == std::numeric_limits<double>::max()) zmin = zmin_this; else if (std::abs(zmin - zmin_this) > EPSILON) @@ -779,13 +779,13 @@ void Model::adjust_min_z() if (objects.empty()) return; - if (bounding_box().min.z < 0.0) + if (bounding_box().min.z() < 0.0) { for (ModelObject* obj : objects) { if (obj != nullptr) { - coordf_t obj_min_z = obj->bounding_box().min.z; + coordf_t obj_min_z = obj->bounding_box().min.z(); if (obj_min_z < 0.0) obj->translate(0.0, 0.0, -obj_min_z); } @@ -985,19 +985,19 @@ BoundingBoxf3 ModelObject::tight_bounding_box(bool include_modifiers) const Pointf3 p((double)v.x, (double)v.y, (double)v.z); // scale - p.x *= inst->scaling_factor; - p.y *= inst->scaling_factor; - p.z *= inst->scaling_factor; + p.x() *= inst->scaling_factor; + p.y() *= inst->scaling_factor; + p.z() *= inst->scaling_factor; // rotate Z - double x = p.x; - double y = p.y; - p.x = c * x - s * y; - p.y = s * x + c * y; + double x = p.x(); + double y = p.y(); + p.x() = c * x - s * y; + p.y() = s * x + c * y; // translate - p.x += inst->offset.x; - p.y += inst->offset.y; + p.x() += inst->offset.x(); + p.y() += inst->offset.y(); bb.merge(p); } @@ -1067,12 +1067,12 @@ void ModelObject::center_around_origin() bb.merge(v->mesh.bounding_box()); // first align to origin on XYZ - Vectorf3 vector(-bb.min.x, -bb.min.y, -bb.min.z); + Vectorf3 vector(-bb.min.x(), -bb.min.y(), -bb.min.z()); // then center it on XY Sizef3 size = bb.size(); - vector.x -= size.x/2; - vector.y -= size.y/2; + vector.x() -= size.x()/2; + vector.y() -= size.y()/2; this->translate(vector); this->origin_translation.translate(vector); @@ -1084,7 +1084,7 @@ void ModelObject::center_around_origin() Vectorf3 v = vector.negative(); v.rotate(i->rotation); v.scale(i->scaling_factor); - i->offset.translate(v.x, v.y); + i->offset.translate(v.x(), v.y()); } this->invalidate_bounding_box(); } @@ -1259,19 +1259,19 @@ void ModelObject::check_instances_print_volume_state(const BoundingBoxf3& print_ Pointf3 p((double)v.x, (double)v.y, (double)v.z); // scale - p.x *= inst->scaling_factor; - p.y *= inst->scaling_factor; - p.z *= inst->scaling_factor; + p.x() *= inst->scaling_factor; + p.y() *= inst->scaling_factor; + p.z() *= inst->scaling_factor; // rotate Z - double x = p.x; - double y = p.y; - p.x = c * x - s * y; - p.y = s * x + c * y; + double x = p.x(); + double y = p.y(); + p.x() = c * x - s * y; + p.y() = s * x + c * y; // translate - p.x += inst->offset.x; - p.y += inst->offset.y; + p.x() += inst->offset.x(); + p.y() += inst->offset.y(); bb.merge(p); } @@ -1298,15 +1298,15 @@ void ModelObject::print_info() const mesh.check_topology(); BoundingBoxf3 bb = mesh.bounding_box(); Sizef3 size = bb.size(); - cout << "size_x = " << size.x << endl; - cout << "size_y = " << size.y << endl; - cout << "size_z = " << size.z << endl; - cout << "min_x = " << bb.min.x << endl; - cout << "min_y = " << bb.min.y << endl; - cout << "min_z = " << bb.min.z << endl; - cout << "max_x = " << bb.max.x << endl; - cout << "max_y = " << bb.max.y << endl; - cout << "max_z = " << bb.max.z << endl; + cout << "size_x = " << size.x() << endl; + cout << "size_y = " << size.y() << endl; + cout << "size_z = " << size.z() << endl; + cout << "min_x = " << bb.min.x() << endl; + cout << "min_y = " << bb.min.y() << endl; + cout << "min_z = " << bb.min.z() << endl; + cout << "max_x = " << bb.max.x() << endl; + cout << "max_y = " << bb.max.y() << endl; + cout << "max_z = " << bb.max.z() << endl; cout << "number_of_facets = " << mesh.stl.stats.number_of_facets << endl; cout << "manifold = " << (mesh.is_manifold() ? "yes" : "no") << endl; @@ -1397,7 +1397,7 @@ void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) cons mesh->rotate_z(this->rotation); // rotate around mesh origin mesh->scale(this->scaling_factor); // scale around mesh origin if (!dont_translate) - mesh->translate(this->offset.x, this->offset.y, 0); + mesh->translate(this->offset.x(), this->offset.y(), 0); } BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const @@ -1420,19 +1420,19 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes if (! empty(bbox)) { // Scale the bounding box uniformly. if (std::abs(this->scaling_factor - 1.) > EPSILON) { - bbox.min.x *= float(this->scaling_factor); - bbox.min.y *= float(this->scaling_factor); - bbox.min.z *= float(this->scaling_factor); - bbox.max.x *= float(this->scaling_factor); - bbox.max.y *= float(this->scaling_factor); - bbox.max.z *= float(this->scaling_factor); + bbox.min.x() *= float(this->scaling_factor); + bbox.min.y() *= float(this->scaling_factor); + bbox.min.z() *= float(this->scaling_factor); + bbox.max.x() *= float(this->scaling_factor); + bbox.max.y() *= float(this->scaling_factor); + bbox.max.z() *= float(this->scaling_factor); } // Translate the bounding box. if (! dont_translate) { - bbox.min.x += float(this->offset.x); - bbox.min.y += float(this->offset.y); - bbox.max.x += float(this->offset.x); - bbox.max.y += float(this->offset.y); + bbox.min.x() += float(this->offset.x()); + bbox.min.y() += float(this->offset.y()); + bbox.max.x() += float(this->offset.x()); + bbox.max.y() += float(this->offset.y()); } } return bbox; @@ -1442,7 +1442,7 @@ BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, b { Eigen::Transform<float, 3, Eigen::Affine> matrix = Eigen::Transform<float, 3, Eigen::Affine>::Identity(); if (!dont_translate) - matrix.translate(Eigen::Vector3f((float)offset.x, (float)offset.y, 0.0f)); + matrix.translate(Eigen::Vector3f((float)offset.x(), (float)offset.y(), 0.0f)); matrix.rotate(Eigen::AngleAxisf(rotation, Eigen::Vector3f::UnitZ())); matrix.scale(scaling_factor); diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index f5e97fb6a..5ae5ea4d9 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -120,7 +120,7 @@ public: // A snug bounding box around the transformed non-modifier object volumes. BoundingBoxf3 instance_bounding_box(size_t instance_idx, bool dont_translate = false) const; void center_around_origin(); - void translate(const Vectorf3 &vector) { this->translate(vector.x, vector.y, vector.z); } + void translate(const Vectorf3 &vector) { this->translate(vector.x(), vector.y(), vector.z()); } void translate(coordf_t x, coordf_t y, coordf_t z); void scale(const Pointf3 &versor); void rotate(float angle, const Axis &axis); diff --git a/xs/src/libslic3r/MultiPoint.cpp b/xs/src/libslic3r/MultiPoint.cpp index 2e65492cd..d094c2893 100644 --- a/xs/src/libslic3r/MultiPoint.cpp +++ b/xs/src/libslic3r/MultiPoint.cpp @@ -27,16 +27,16 @@ MultiPoint::translate(double x, double y) void MultiPoint::translate(const Point &vector) { - this->translate(vector.x, vector.y); + this->translate(vector.x(), vector.y()); } void MultiPoint::rotate(double cos_angle, double sin_angle) { for (Point &pt : this->points) { - double cur_x = double(pt.x); - double cur_y = double(pt.y); - pt.x = coord_t(round(cos_angle * cur_x - sin_angle * cur_y)); - pt.y = coord_t(round(cos_angle * cur_y + sin_angle * cur_x)); + double cur_x = double(pt.x()); + double cur_y = double(pt.y()); + pt.x() = coord_t(round(cos_angle * cur_x - sin_angle * cur_y)); + pt.y() = coord_t(round(cos_angle * cur_y + sin_angle * cur_x)); } } @@ -46,10 +46,10 @@ MultiPoint::rotate(double angle, const Point ¢er) double s = sin(angle); double c = cos(angle); for (Points::iterator it = points.begin(); it != points.end(); ++it) { - double dx = double(it->x - center.x); - double dy = double(it->y - center.y); - it->x = (coord_t)round(double(center.x) + c * dx - s * dy); - it->y = (coord_t)round(double(center.y) + c * dy + s * dx); + double dx = double(it->x() - center.x()); + double dy = double(it->y() - center.y()); + it->x() = (coord_t)round(double(center.x()) + c * dx - s * dy); + it->y() = (coord_t)round(double(center.y()) + c * dy + s * dx); } } @@ -224,7 +224,7 @@ void MultiPoint3::translate(double x, double y) void MultiPoint3::translate(const Point& vector) { - translate(vector.x, vector.y); + translate(vector.x(), vector.y()); } double MultiPoint3::length() const @@ -281,19 +281,19 @@ BoundingBox get_extents_rotated(const Points &points, double angle) double s = sin(angle); double c = cos(angle); Points::const_iterator it = points.begin(); - double cur_x = (double)it->x; - double cur_y = (double)it->y; - bbox.min.x = bbox.max.x = (coord_t)round(c * cur_x - s * cur_y); - bbox.min.y = bbox.max.y = (coord_t)round(c * cur_y + s * cur_x); + double cur_x = (double)it->x(); + double cur_y = (double)it->y(); + bbox.min.x() = bbox.max.x() = (coord_t)round(c * cur_x - s * cur_y); + bbox.min.y() = bbox.max.y() = (coord_t)round(c * cur_y + s * cur_x); for (++it; it != points.end(); ++it) { - double cur_x = (double)it->x; - double cur_y = (double)it->y; + double cur_x = (double)it->x(); + double cur_y = (double)it->y(); coord_t x = (coord_t)round(c * cur_x - s * cur_y); coord_t y = (coord_t)round(c * cur_y + s * cur_x); - bbox.min.x = std::min(x, bbox.min.x); - bbox.min.y = std::min(y, bbox.min.y); - bbox.max.x = std::max(x, bbox.max.x); - bbox.max.y = std::max(y, bbox.max.y); + bbox.min.x() = std::min(x, bbox.min.x()); + bbox.min.y() = std::min(y, bbox.min.y()); + bbox.max.x() = std::max(x, bbox.max.x()); + bbox.max.y() = std::max(y, bbox.max.y()); } bbox.defined = true; } diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp index 2abcd26af..3d92959e1 100644 --- a/xs/src/libslic3r/Point.cpp +++ b/xs/src/libslic3r/Point.cpp @@ -3,21 +3,13 @@ #include "MultiPoint.hpp" #include "Int128.hpp" #include <algorithm> -#include <cmath> namespace Slic3r { -Point::Point(double x, double y) -{ - this->x = lrint(x); - this->y = lrint(y); -} - -std::string -Point::wkt() const +std::string Point::wkt() const { std::ostringstream ss; - ss << "POINT(" << this->x << " " << this->y << ")"; + ss << "POINT(" << this->x() << " " << this->y() << ")"; return ss.str(); } @@ -25,58 +17,58 @@ std::string Point::dump_perl() const { std::ostringstream ss; - ss << "[" << this->x << "," << this->y << "]"; + ss << "[" << this->x() << "," << this->y() << "]"; return ss.str(); } void Point::scale(double factor) { - this->x *= factor; - this->y *= factor; + this->x() *= factor; + this->y() *= factor; } void Point::translate(double x, double y) { - this->x += x; - this->y += y; + this->x() += x; + this->y() += y; } void Point::translate(const Vector &vector) { - this->translate(vector.x, vector.y); + this->translate(vector.x(), vector.y()); } void Point::rotate(double angle) { - double cur_x = (double)this->x; - double cur_y = (double)this->y; + double cur_x = (double)this->x(); + double cur_y = (double)this->y(); double s = sin(angle); double c = cos(angle); - this->x = (coord_t)round(c * cur_x - s * cur_y); - this->y = (coord_t)round(c * cur_y + s * cur_x); + this->x() = (coord_t)round(c * cur_x - s * cur_y); + this->y() = (coord_t)round(c * cur_y + s * cur_x); } void Point::rotate(double angle, const Point ¢er) { - double cur_x = (double)this->x; - double cur_y = (double)this->y; + double cur_x = (double)this->x(); + double cur_y = (double)this->y(); double s = sin(angle); double c = cos(angle); - double dx = cur_x - (double)center.x; - double dy = cur_y - (double)center.y; - this->x = (coord_t)round( (double)center.x + c * dx - s * dy ); - this->y = (coord_t)round( (double)center.y + c * dy + s * dx ); + double dx = cur_x - (double)center.x(); + double dy = cur_y - (double)center.y(); + this->x() = (coord_t)round( (double)center.x() + c * dx - s * dy ); + this->y() = (coord_t)round( (double)center.y() + c * dy + s * dx ); } bool Point::coincides_with_epsilon(const Point &point) const { - return std::abs(this->x - point.x) < SCALED_EPSILON && std::abs(this->y - point.y) < SCALED_EPSILON; + return std::abs(this->x() - point.x()) < SCALED_EPSILON && std::abs(this->y() - point.y()) < SCALED_EPSILON; } int @@ -97,12 +89,12 @@ int Point::nearest_point_index(const PointConstPtrs &points) const for (PointConstPtrs::const_iterator it = points.begin(); it != points.end(); ++it) { /* If the X distance of the candidate is > than the total distance of the best previous candidate, we know we don't want it */ - double d = sqr<double>(this->x - (*it)->x); + double d = sqr<double>(this->x() - (*it)->x()); if (distance != -1 && d > distance) continue; /* If the Y distance of the candidate is > than the total distance of the best previous candidate, we know we don't want it */ - d += sqr<double>(this->y - (*it)->y); + d += sqr<double>(this->y() - (*it)->y()); if (distance != -1 && d > distance) continue; idx = it - points.begin(); @@ -137,8 +129,8 @@ Point::nearest_point(const Points &points, Point* point) const double Point::distance_to(const Line &line) const { - const double dx = line.b.x - line.a.x; - const double dy = line.b.y - line.a.y; + const double dx = line.b.x() - line.a.x(); + const double dy = line.b.y() - line.a.y(); const double l2 = dx*dx + dy*dy; // avoid a sqrt if (l2 == 0.0) return this->distance_to(line.a); // line.a == line.b case @@ -146,12 +138,12 @@ Point::distance_to(const Line &line) const // Consider the line extending the segment, parameterized as line.a + t (line.b - line.a). // We find projection of this point onto the line. // It falls where t = [(this-line.a) . (line.b-line.a)] / |line.b-line.a|^2 - const double t = ((this->x - line.a.x) * dx + (this->y - line.a.y) * dy) / l2; + const double t = ((this->x() - line.a.x()) * dx + (this->y() - line.a.y()) * dy) / l2; if (t < 0.0) return this->distance_to(line.a); // beyond the 'a' end of the segment else if (t > 1.0) return this->distance_to(line.b); // beyond the 'b' end of the segment Point projection( - line.a.x + t * dx, - line.a.y + t * dy + line.a.x() + t * dx, + line.a.y() + t * dy ); return this->distance_to(projection); } @@ -161,8 +153,8 @@ Point::perp_distance_to(const Line &line) const { if (line.a.coincides_with(line.b)) return this->distance_to(line.a); - double n = (double)(line.b.x - line.a.x) * (double)(line.a.y - this->y) - - (double)(line.a.x - this->x) * (double)(line.b.y - line.a.y); + double n = (double)(line.b.x() - line.a.x()) * (double)(line.a.y() - this->y()) + - (double)(line.a.x() - this->x()) * (double)(line.b.y() - line.a.y()); return std::abs(n) / line.length(); } @@ -177,7 +169,7 @@ Point::perp_distance_to(const Line &line) const double Point::ccw(const Point &p1, const Point &p2) const { - return (double)(p2.x - p1.x)*(double)(this->y - p1.y) - (double)(p2.y - p1.y)*(double)(this->x - p1.x); + return (double)(p2.x() - p1.x())*(double)(this->y() - p1.y()) - (double)(p2.y() - p1.y())*(double)(this->x() - p1.x()); } double @@ -191,8 +183,8 @@ Point::ccw(const Line &line) const double Point::ccw_angle(const Point &p1, const Point &p2) const { - double angle = atan2(p1.x - this->x, p1.y - this->y) - - atan2(p2.x - this->x, p2.y - this->y); + double angle = atan2(p1.x() - this->x(), p1.y() - this->y()) + - atan2(p2.x() - this->x(), p2.y() - this->y()); // we only want to return only positive angles return angle <= 0 ? angle + 2*PI : angle; @@ -229,9 +221,9 @@ Point::projection_onto(const Line &line) const If theta is outside the interval [0,1], then one of the Line_Segment's endpoints must be closest to calling Point. */ - double lx = (double)(line.b.x - line.a.x); - double ly = (double)(line.b.y - line.a.y); - double theta = ( (double)(line.b.x - this->x)*lx + (double)(line.b.y- this->y)*ly ) + double lx = (double)(line.b.x() - line.a.x()); + double ly = (double)(line.b.y() - line.a.y()); + double theta = ( (double)(line.b.x() - this->x())*lx + (double)(line.b.y()- this->y())*ly ) / ( sqr<double>(lx) + sqr<double>(ly) ); if (0.0 <= theta && theta <= 1.0) @@ -248,26 +240,26 @@ Point::projection_onto(const Line &line) const Point Point::negative() const { - return Point(-this->x, -this->y); + return Point(-this->x(), -this->y()); } Vector Point::vector_to(const Point &point) const { - return Vector(point.x - this->x, point.y - this->y); + return Vector(point.x() - this->x(), point.y() - this->y()); } std::ostream& operator<<(std::ostream &stm, const Pointf &pointf) { - return stm << pointf.x << "," << pointf.y; + return stm << pointf.x() << "," << pointf.y(); } std::string Pointf::wkt() const { std::ostringstream ss; - ss << "POINT(" << this->x << " " << this->y << ")"; + ss << "POINT(" << this->x() << " " << this->y() << ")"; return ss.str(); } @@ -275,105 +267,105 @@ std::string Pointf::dump_perl() const { std::ostringstream ss; - ss << "[" << this->x << "," << this->y << "]"; + ss << "[" << this->x() << "," << this->y() << "]"; return ss.str(); } void Pointf::scale(double factor) { - this->x *= factor; - this->y *= factor; + this->x() *= factor; + this->y() *= factor; } void Pointf::translate(double x, double y) { - this->x += x; - this->y += y; + this->x() += x; + this->y() += y; } void Pointf::translate(const Vectorf &vector) { - this->translate(vector.x, vector.y); + this->translate(vector.x(), vector.y()); } void Pointf::rotate(double angle) { - double cur_x = this->x; - double cur_y = this->y; + double cur_x = this->x(); + double cur_y = this->y(); double s = sin(angle); double c = cos(angle); - this->x = c * cur_x - s * cur_y; - this->y = c * cur_y + s * cur_x; + this->x() = c * cur_x - s * cur_y; + this->y() = c * cur_y + s * cur_x; } void Pointf::rotate(double angle, const Pointf ¢er) { - double cur_x = this->x; - double cur_y = this->y; + double cur_x = this->x(); + double cur_y = this->y(); double s = sin(angle); double c = cos(angle); - double dx = cur_x - center.x; - double dy = cur_y - center.y; - this->x = center.x + c * dx - s * dy; - this->y = center.y + c * dy + s * dx; + double dx = cur_x - center.x(); + double dy = cur_y - center.y(); + this->x() = center.x() + c * dx - s * dy; + this->y() = center.y() + c * dy + s * dx; } Pointf Pointf::negative() const { - return Pointf(-this->x, -this->y); + return Pointf(-this->x(), -this->y()); } Vectorf Pointf::vector_to(const Pointf &point) const { - return Vectorf(point.x - this->x, point.y - this->y); + return Vectorf(point.x() - this->x(), point.y() - this->y()); } void Pointf3::scale(double factor) { Pointf::scale(factor); - this->z *= factor; + this->z() *= factor; } void Pointf3::translate(const Vectorf3 &vector) { - this->translate(vector.x, vector.y, vector.z); + this->translate(vector.x(), vector.y(), vector.z()); } void Pointf3::translate(double x, double y, double z) { Pointf::translate(x, y); - this->z += z; + this->z() += z; } double Pointf3::distance_to(const Pointf3 &point) const { - double dx = ((double)point.x - this->x); - double dy = ((double)point.y - this->y); - double dz = ((double)point.z - this->z); + double dx = ((double)point.x() - this->x()); + double dy = ((double)point.y() - this->y()); + double dz = ((double)point.z() - this->z()); return sqrt(dx*dx + dy*dy + dz*dz); } Pointf3 Pointf3::negative() const { - return Pointf3(-this->x, -this->y, -this->z); + return Pointf3(-this->x(), -this->y(), -this->z()); } Vectorf3 Pointf3::vector_to(const Pointf3 &point) const { - return Vectorf3(point.x - this->x, point.y - this->y, point.z - this->z); + return Vectorf3(point.x() - this->x(), point.y() - this->y(), point.z() - this->z()); } namespace int128 { @@ -382,12 +374,12 @@ int orient(const Point &p1, const Point &p2, const Point &p3) { Slic3r::Vector v1(p2 - p1); Slic3r::Vector v2(p3 - p1); - return Int128::sign_determinant_2x2_filtered(v1.x, v1.y, v2.x, v2.y); + return Int128::sign_determinant_2x2_filtered(v1.x(), v1.y(), v2.x(), v2.y()); } int cross(const Point &v1, const Point &v2) { - return Int128::sign_determinant_2x2_filtered(v1.x, v1.y, v2.x, v2.y); + return Int128::sign_determinant_2x2_filtered(v1.x(), v1.y(), v2.x(), v2.y()); } } diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index 87104674f..2630f58a5 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -2,12 +2,15 @@ #define slic3r_Point_hpp_ #include "libslic3r.h" +#include <cstddef> #include <vector> -#include <math.h> +#include <cmath> #include <string> #include <sstream> #include <unordered_map> +#include <Eigen/Geometry> + namespace Slic3r { class Line; @@ -28,24 +31,37 @@ typedef std::vector<Point3> Points3; typedef std::vector<Pointf> Pointfs; typedef std::vector<Pointf3> Pointf3s; +// Eigen types, to replace the Slic3r's own types in the future. +// Vector types with a fixed point coordinate base type. +typedef Eigen::Matrix<coord_t, 2, 1, Eigen::DontAlign> Vec2crd; +typedef Eigen::Matrix<coord_t, 3, 1, Eigen::DontAlign> Vec3crd; +// Vector types with a double coordinate base type. +typedef Eigen::Matrix<coordf_t, 2, 1, Eigen::DontAlign> Vec2d; +typedef Eigen::Matrix<coordf_t, 3, 1, Eigen::DontAlign> Vec3d; + class Point { public: typedef coord_t coord_type; - coord_t x; - coord_t y; - Point(coord_t _x = 0, coord_t _y = 0): x(_x), y(_y) {}; - Point(int64_t _x, int64_t _y): x(coord_t(_x)), y(coord_t(_y)) {}; // for Clipper - Point(double x, double y); + Vec2crd data; + + Point(coord_t x = 0, coord_t y = 0) { data(0) = x; data(1) = y; } + Point(int64_t x, int64_t y) : Point(coord_t(x), coord_t(y)) {} // for Clipper + Point(double x, double y) : Point(lrint(x), lrint(y)) {} static Point new_scale(coordf_t x, coordf_t y) { return Point(coord_t(scale_(x)), coord_t(scale_(y))); } - bool operator==(const Point& rhs) const { return this->x == rhs.x && this->y == rhs.y; } - bool operator!=(const Point& rhs) const { return ! (*this == rhs); } - bool operator<(const Point& rhs) const { return this->x < rhs.x || (this->x == rhs.x && this->y < rhs.y); } + const coord_t& x() const { return this->data[0]; } + coord_t& x() { return this->data[0]; } + const coord_t& y() const { return this->data[1]; } + coord_t& y() { return this->data[1]; } - Point& operator+=(const Point& rhs) { this->x += rhs.x; this->y += rhs.y; return *this; } - Point& operator-=(const Point& rhs) { this->x -= rhs.x; this->y -= rhs.y; return *this; } - Point& operator*=(const coord_t& rhs) { this->x *= rhs; this->y *= rhs; return *this; } + bool operator==(const Point& rhs) const { return this->x() == rhs.x() && this->y() == rhs.y(); } + bool operator!=(const Point& rhs) const { return ! (*this == rhs); } + bool operator<(const Point& rhs) const { return this->x() < rhs.x() || (this->x() == rhs.x() && this->y() < rhs.y()); } + + Point& operator+=(const Point& rhs) { this->x() += rhs.x(); this->y() += rhs.y(); return *this; } + Point& operator-=(const Point& rhs) { this->x() -= rhs.x(); this->y() -= rhs.y(); return *this; } + Point& operator*=(const coord_t& rhs) { this->x() *= rhs; this->y() *= rhs; return *this; } std::string wkt() const; std::string dump_perl() const; @@ -56,14 +72,14 @@ public: void rotate(double angle, const Point ¢er); Point rotated(double angle) const { Point res(*this); res.rotate(angle); return res; } Point rotated(double angle, const Point ¢er) const { Point res(*this); res.rotate(angle, center); return res; } - bool coincides_with(const Point &point) const { return this->x == point.x && this->y == point.y; } + bool coincides_with(const Point &point) const { return this->x() == point.x() && this->y() == point.y(); } bool coincides_with_epsilon(const Point &point) const; int nearest_point_index(const Points &points) const; int nearest_point_index(const PointConstPtrs &points) const; int nearest_point_index(const PointPtrs &points) const; bool nearest_point(const Points &points, Point* point) const; double distance_to(const Point &point) const { return sqrt(distance_to_sq(point)); } - double distance_to_sq(const Point &point) const { double dx = double(point.x - this->x); double dy = double(point.y - this->y); return dx*dx + dy*dy; } + double distance_to_sq(const Point &point) const { double dx = double(point.x() - this->x()); double dy = double(point.y() - this->y()); return dx*dx + dy*dy; } double distance_to(const Line &line) const; double perp_distance_to(const Line &line) const; double ccw(const Point &p1, const Point &p2) const; @@ -75,11 +91,11 @@ public: Vector vector_to(const Point &point) const; }; -inline Point operator+(const Point& point1, const Point& point2) { return Point(point1.x + point2.x, point1.y + point2.y); } -inline Point operator-(const Point& point1, const Point& point2) { return Point(point1.x - point2.x, point1.y - point2.y); } -inline Point operator*(double scalar, const Point& point2) { return Point(scalar * point2.x, scalar * point2.y); } -inline int64_t cross(const Point &v1, const Point &v2) { return int64_t(v1.x) * int64_t(v2.y) - int64_t(v1.y) * int64_t(v2.x); } -inline int64_t dot(const Point &v1, const Point &v2) { return int64_t(v1.x) * int64_t(v2.x) + int64_t(v1.y) * int64_t(v2.y); } +inline Point operator+(const Point& point1, const Point& point2) { return Point(point1.x() + point2.x(), point1.y() + point2.y()); } +inline Point operator-(const Point& point1, const Point& point2) { return Point(point1.x() - point2.x(), point1.y() - point2.y()); } +inline Point operator*(double scalar, const Point& point2) { return Point(scalar * point2.x(), scalar * point2.y()); } +inline int64_t cross(const Point &v1, const Point &v2) { return int64_t(v1.x()) * int64_t(v2.y()) - int64_t(v1.y()) * int64_t(v2.x()); } +inline int64_t dot(const Point &v1, const Point &v2) { return int64_t(v1.x()) * int64_t(v2.x()) + int64_t(v1.y()) * int64_t(v2.y()); } namespace int128 { @@ -95,7 +111,7 @@ int cross(const Point &v1, const Slic3r::Point &v2); // To be used by std::unordered_map, std::unordered_multimap and friends. struct PointHash { size_t operator()(const Point &pt) const { - return std::hash<coord_t>()(pt.x) ^ std::hash<coord_t>()(pt.y); + return std::hash<coord_t>()(pt.x()) ^ std::hash<coord_t>()(pt.y()); } }; @@ -141,13 +157,13 @@ public: void insert(const ValueType &value) { const Point *pt = m_point_accessor(value); if (pt != nullptr) - m_map.emplace(std::make_pair(Point(pt->x>>m_grid_log2, pt->y>>m_grid_log2), value)); + m_map.emplace(std::make_pair(Point(pt->x()>>m_grid_log2, pt->y()>>m_grid_log2), value)); } void insert(ValueType &&value) { const Point *pt = m_point_accessor(value); if (pt != nullptr) - m_map.emplace(std::make_pair(Point(pt->x>>m_grid_log2, pt->y>>m_grid_log2), std::move(value))); + m_map.emplace(std::make_pair(Point(pt->x()>>m_grid_log2, pt->y()>>m_grid_log2), std::move(value))); } // Return a pair of <ValueType*, distance_squared> @@ -157,12 +173,12 @@ public: const ValueType *value_min = nullptr; double dist_min = std::numeric_limits<double>::max(); // Round pt to a closest grid_cell corner. - Point grid_corner((pt.x+(m_grid_resolution>>1))>>m_grid_log2, (pt.y+(m_grid_resolution>>1))>>m_grid_log2); + Point grid_corner((pt.x()+(m_grid_resolution>>1))>>m_grid_log2, (pt.y()+(m_grid_resolution>>1))>>m_grid_log2); // For four neighbors of grid_corner: for (coord_t neighbor_y = -1; neighbor_y < 1; ++ neighbor_y) { for (coord_t neighbor_x = -1; neighbor_x < 1; ++ neighbor_x) { // Range of fragment starts around grid_corner, close to pt. - auto range = m_map.equal_range(Point(grid_corner.x + neighbor_x, grid_corner.y + neighbor_y)); + auto range = m_map.equal_range(Point(grid_corner.x() + neighbor_x, grid_corner.y() + neighbor_y)); // Find the map entry closest to pt. for (auto it = range.first; it != range.second; ++it) { const ValueType &value = it->second; @@ -194,12 +210,16 @@ private: class Point3 : public Point { public: - coord_t z; - explicit Point3(coord_t _x = 0, coord_t _y = 0, coord_t _z = 0): Point(_x, _y), z(_z) {}; + coord_t m_z; + + const coord_t& z() const { return this->m_z; } + coord_t& z() { return this->m_z; } + + explicit Point3(coord_t _x = 0, coord_t _y = 0, coord_t _z = 0): Point(_x, _y), m_z(_z) {}; static Point3 new_scale(coordf_t x, coordf_t y, coordf_t z) { return Point3(coord_t(scale_(x)), coord_t(scale_(y)), coord_t(scale_(z))); } - bool operator==(const Point3 &rhs) const { return this->x == rhs.x && this->y == rhs.y && this->z == rhs.z; } + bool operator==(const Point3 &rhs) const { return this->x() == rhs.x() && this->y() == rhs.y() && this->z() == rhs.z(); } bool operator!=(const Point3 &rhs) const { return ! (*this == rhs); } - bool coincides_with(const Point3& rhs) const { return this->x == rhs.x && this->y == rhs.y && this->z == rhs.z; } + bool coincides_with(const Point3& rhs) const { return this->x() == rhs.x() && this->y() == rhs.y() && this->z() == rhs.z(); } private: // Hide the following inherited methods: bool operator==(const Point &rhs) const; @@ -212,15 +232,17 @@ class Pointf { public: typedef coordf_t coord_type; - coordf_t x; - coordf_t y; - explicit Pointf(coordf_t _x = 0, coordf_t _y = 0): x(_x), y(_y) {}; - static Pointf new_unscale(coord_t x, coord_t y) { - return Pointf(unscale(x), unscale(y)); - }; - static Pointf new_unscale(const Point &p) { - return Pointf(unscale(p.x), unscale(p.y)); - }; + Vec2d data; + + explicit Pointf(coordf_t x = 0, coordf_t y = 0) { data(0) = x; data(1) = y; } + static Pointf new_unscale(coord_t x, coord_t y) { return Pointf(unscale(x), unscale(y)); } + static Pointf new_unscale(const Point &p) { return Pointf(unscale(p.x()), unscale(p.y())); } + + const coordf_t& x() const { return this->data[0]; } + coordf_t& x() { return this->data[0]; } + const coordf_t& y() const { return this->data[1]; } + coordf_t& y() { return this->data[1]; } + std::string wkt() const; std::string dump_perl() const; void scale(double factor); @@ -231,39 +253,41 @@ public: Pointf negative() const; Vectorf vector_to(const Pointf &point) const; - Pointf& operator+=(const Pointf& rhs) { this->x += rhs.x; this->y += rhs.y; return *this; } - Pointf& operator-=(const Pointf& rhs) { this->x -= rhs.x; this->y -= rhs.y; return *this; } - Pointf& operator*=(const coordf_t& rhs) { this->x *= rhs; this->y *= rhs; return *this; } + Pointf& operator+=(const Pointf& rhs) { this->x() += rhs.x(); this->y() += rhs.y(); return *this; } + Pointf& operator-=(const Pointf& rhs) { this->x() -= rhs.x(); this->y() -= rhs.y(); return *this; } + Pointf& operator*=(const coordf_t& rhs) { this->x() *= rhs; this->y() *= rhs; return *this; } - bool operator==(const Pointf &rhs) const { return this->x == rhs.x && this->y == rhs.y; } + bool operator==(const Pointf &rhs) const { return this->x() == rhs.x() && this->y() == rhs.y(); } bool operator!=(const Pointf &rhs) const { return ! (*this == rhs); } - bool operator< (const Pointf& rhs) const { return this->x < rhs.x || (this->x == rhs.x && this->y < rhs.y); } + bool operator< (const Pointf& rhs) const { return this->x() < rhs.x() || (this->x() == rhs.x() && this->y() < rhs.y()); } }; -inline Pointf operator+(const Pointf& point1, const Pointf& point2) { return Pointf(point1.x + point2.x, point1.y + point2.y); } -inline Pointf operator-(const Pointf& point1, const Pointf& point2) { return Pointf(point1.x - point2.x, point1.y - point2.y); } -inline Pointf operator*(double scalar, const Pointf& point2) { return Pointf(scalar * point2.x, scalar * point2.y); } -inline Pointf operator*(const Pointf& point2, double scalar) { return Pointf(scalar * point2.x, scalar * point2.y); } -inline coordf_t cross(const Pointf &v1, const Pointf &v2) { return v1.x * v2.y - v1.y * v2.x; } -inline coordf_t dot(const Pointf &v1, const Pointf &v2) { return v1.x * v2.x + v1.y * v2.y; } -inline coordf_t dot(const Pointf &v) { return v.x * v.x + v.y * v.y; } +inline Pointf operator+(const Pointf& point1, const Pointf& point2) { return Pointf(point1.x() + point2.x(), point1.y() + point2.y()); } +inline Pointf operator-(const Pointf& point1, const Pointf& point2) { return Pointf(point1.x() - point2.x(), point1.y() - point2.y()); } +inline Pointf operator*(double scalar, const Pointf& point2) { return Pointf(scalar * point2.x(), scalar * point2.y()); } +inline Pointf operator*(const Pointf& point2, double scalar) { return Pointf(scalar * point2.x(), scalar * point2.y()); } +inline coordf_t cross(const Pointf &v1, const Pointf &v2) { return v1.x() * v2.y() - v1.y() * v2.x(); } +inline coordf_t dot(const Pointf &v1, const Pointf &v2) { return v1.x() * v2.x() + v1.y() * v2.y(); } +inline coordf_t dot(const Pointf &v) { return v.x() * v.x() + v.y() * v.y(); } inline double length(const Vectorf &v) { return sqrt(dot(v)); } inline double l2(const Vectorf &v) { return dot(v); } inline Vectorf normalize(const Vectorf& v) { - coordf_t len = ::sqrt(sqr(v.x) + sqr(v.y)); + coordf_t len = ::sqrt(sqr(v.x()) + sqr(v.y())); return (len != 0.0) ? 1.0 / len * v : Vectorf(0.0, 0.0); } class Pointf3 : public Pointf { public: - coordf_t z; - explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0): Pointf(_x, _y), z(_z) {}; - static Pointf3 new_unscale(coord_t x, coord_t y, coord_t z) { - return Pointf3(unscale(x), unscale(y), unscale(z)); - }; - static Pointf3 new_unscale(const Point3& p) { return Pointf3(unscale(p.x), unscale(p.y), unscale(p.z)); } + coordf_t m_z; + + const coordf_t& z() const { return this->m_z; } + coordf_t& z() { return this->m_z; } + + explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0): Pointf(_x, _y), m_z(_z) {}; + static Pointf3 new_unscale(coord_t x, coord_t y, coord_t z) { return Pointf3(unscale(x), unscale(y), unscale(z)); } + static Pointf3 new_unscale(const Point3& p) { return Pointf3(unscale(p.x()), unscale(p.y()), unscale(p.z())); } void scale(double factor); void translate(const Vectorf3 &vector); void translate(double x, double y, double z); @@ -271,7 +295,7 @@ public: Pointf3 negative() const; Vectorf3 vector_to(const Pointf3 &point) const; - bool operator==(const Pointf3 &rhs) const { return this->x == rhs.x && this->y == rhs.y && this->z == rhs.z; } + bool operator==(const Pointf3 &rhs) const { return this->x() == rhs.x() && this->y() == rhs.y() && this->z() == rhs.z(); } bool operator!=(const Pointf3 &rhs) const { return ! (*this == rhs); } private: @@ -280,23 +304,23 @@ private: bool operator!=(const Pointf &rhs) const; }; -inline Pointf3 operator+(const Pointf3& p1, const Pointf3& p2) { return Pointf3(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z); } -inline Pointf3 operator-(const Pointf3& p1, const Pointf3& p2) { return Pointf3(p1.x - p2.x, p1.y - p2.y, p1.z - p2.z); } -inline Pointf3 operator-(const Pointf3& p) { return Pointf3(-p.x, -p.y, -p.z); } -inline Pointf3 operator*(double scalar, const Pointf3& p) { return Pointf3(scalar * p.x, scalar * p.y, scalar * p.z); } -inline Pointf3 operator*(const Pointf3& p, double scalar) { return Pointf3(scalar * p.x, scalar * p.y, scalar * p.z); } -inline Pointf3 cross(const Pointf3& v1, const Pointf3& v2) { return Pointf3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x); } -inline coordf_t dot(const Pointf3& v1, const Pointf3& v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } +inline Pointf3 operator+(const Pointf3& p1, const Pointf3& p2) { return Pointf3(p1.x() + p2.x(), p1.y() + p2.y(), p1.z() + p2.z()); } +inline Pointf3 operator-(const Pointf3& p1, const Pointf3& p2) { return Pointf3(p1.x() - p2.x(), p1.y() - p2.y(), p1.z() - p2.z()); } +inline Pointf3 operator-(const Pointf3& p) { return Pointf3(-p.x(), -p.y(), -p.z()); } +inline Pointf3 operator*(double scalar, const Pointf3& p) { return Pointf3(scalar * p.x(), scalar * p.y(), scalar * p.z()); } +inline Pointf3 operator*(const Pointf3& p, double scalar) { return Pointf3(scalar * p.x(), scalar * p.y(), scalar * p.z()); } +inline Pointf3 cross(const Pointf3& v1, const Pointf3& v2) { return Pointf3(v1.y() * v2.z() - v1.z() * v2.y(), v1.z() * v2.x() - v1.x() * v2.z(), v1.x() * v2.y() - v1.y() * v2.x()); } +inline coordf_t dot(const Pointf3& v1, const Pointf3& v2) { return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z(); } inline Pointf3 normalize(const Pointf3& v) { - coordf_t len = ::sqrt(sqr(v.x) + sqr(v.y) + sqr(v.z)); + coordf_t len = ::sqrt(sqr(v.x()) + sqr(v.y()) + sqr(v.z())); return (len != 0.0) ? 1.0 / len * v : Pointf3(0.0, 0.0, 0.0); } -template<typename TO> inline TO convert_to(const Point &src) { return TO(typename TO::coord_type(src.x), typename TO::coord_type(src.y)); } -template<typename TO> inline TO convert_to(const Pointf &src) { return TO(typename TO::coord_type(src.x), typename TO::coord_type(src.y)); } -template<typename TO> inline TO convert_to(const Point3 &src) { return TO(typename TO::coord_type(src.x), typename TO::coord_type(src.y), typename TO::coord_type(src.z)); } -template<typename TO> inline TO convert_to(const Pointf3 &src) { return TO(typename TO::coord_type(src.x), typename TO::coord_type(src.y), typename TO::coord_type(src.z)); } +template<typename TO> inline TO convert_to(const Point &src) { return TO(typename TO::coord_type(src.x()), typename TO::coord_type(src.y())); } +template<typename TO> inline TO convert_to(const Pointf &src) { return TO(typename TO::coord_type(src.x()), typename TO::coord_type(src.y())); } +template<typename TO> inline TO convert_to(const Point3 &src) { return TO(typename TO::coord_type(src.x()), typename TO::coord_type(src.y()), typename TO::coord_type(src.z())); } +template<typename TO> inline TO convert_to(const Pointf3 &src) { return TO(typename TO::coord_type(src.x()), typename TO::coord_type(src.y()), typename TO::coord_type(src.z())); } } // namespace Slic3r @@ -312,7 +336,7 @@ namespace boost { namespace polygon { typedef coord_t coordinate_type; static inline coordinate_type get(const Slic3r::Point& point, orientation_2d orient) { - return (orient == HORIZONTAL) ? point.x : point.y; + return (orient == HORIZONTAL) ? (coordinate_type)point.x() : (coordinate_type)point.y(); } }; @@ -321,14 +345,14 @@ namespace boost { namespace polygon { typedef coord_t coordinate_type; static inline void set(Slic3r::Point& point, orientation_2d orient, coord_t value) { if (orient == HORIZONTAL) - point.x = value; + point.x() = value; else - point.y = value; + point.y() = value; } static inline Slic3r::Point construct(coord_t x_value, coord_t y_value) { Slic3r::Point retval; - retval.x = x_value; - retval.y = y_value; + retval.x() = x_value; + retval.y() = y_value; return retval; } }; diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index b5fd7e64f..d409e8c32 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -88,7 +88,7 @@ int64_t Polygon::area2x() const int64_t a = 0; for (size_t i = 0, j = n - 1; i < n; ++i) - a += int64_t(poly[j].x + poly[i].x) * int64_t(poly[j].y - poly[i].y); + a += int64_t(poly[j].x() + poly[i].x()) * int64_t(poly[j].y() - poly[i].y()); j = i; } return -a * 0.5; @@ -103,7 +103,7 @@ double Polygon::area() const double a = 0.; for (size_t i = 0, j = n - 1; i < n; ++i) { - a += ((double)points[j].x + (double)points[i].x) * ((double)points[i].y - (double)points[j].y); + a += ((double)points[j].x() + (double)points[i].x()) * ((double)points[i].y() - (double)points[j].y()); j = i; } return 0.5 * a; @@ -157,17 +157,17 @@ Polygon::contains(const Point &point) const Points::const_iterator i = this->points.begin(); Points::const_iterator j = this->points.end() - 1; for (; i != this->points.end(); j = i++) { - //FIXME this test is not numerically robust. Particularly, it does not handle horizontal segments at y == point.y well. - // Does the ray with y == point.y intersect this line segment? + //FIXME this test is not numerically robust. Particularly, it does not handle horizontal segments at y == point.y() well. + // Does the ray with y == point.y() intersect this line segment? #if 1 - if ( ((i->y > point.y) != (j->y > point.y)) - && ((double)point.x < (double)(j->x - i->x) * (double)(point.y - i->y) / (double)(j->y - i->y) + (double)i->x) ) + if ( ((i->y() > point.y()) != (j->y() > point.y())) + && ((double)point.x() < (double)(j->x() - i->x()) * (double)(point.y() - i->y()) / (double)(j->y() - i->y()) + (double)i->x()) ) result = !result; #else - if ((i->y > point.y) != (j->y > point.y)) { + if ((i->y() > point.y()) != (j->y() > point.y())) { // Orientation predicated relative to i-th point. - double orient = (double)(point.x - i->x) * (double)(j->y - i->y) - (double)(point.y - i->y) * (double)(j->x - i->x); - if ((i->y > j->y) ? (orient > 0.) : (orient < 0.)) + double orient = (double)(point.x() - i->x()) * (double)(j->y() - i->y()) - (double)(point.y() - i->y()) * (double)(j->x() - i->x()); + if ((i->y() > j->y()) ? (orient > 0.) : (orient < 0.)) result = !result; } #endif @@ -225,8 +225,8 @@ Polygon::centroid() const Polyline polyline = this->split_at_first_point(); for (Points::const_iterator point = polyline.points.begin(); point != polyline.points.end() - 1; ++point) { - x_temp += (double)( point->x + (point+1)->x ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y ); - y_temp += (double)( point->y + (point+1)->y ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y ); + x_temp += (double)( point->x() + (point+1)->x() ) * ( (double)point->x()*(point+1)->y() - (double)(point+1)->x()*point->y() ); + y_temp += (double)( point->y() + (point+1)->y() ) * ( (double)point->x()*(point+1)->y() - (double)(point+1)->x()*point->y() ); } return Point(x_temp/(6*area_temp), y_temp/(6*area_temp)); @@ -238,7 +238,7 @@ Polygon::wkt() const std::ostringstream wkt; wkt << "POLYGON(("; for (Points::const_iterator p = this->points.begin(); p != this->points.end(); ++p) { - wkt << p->x << " " << p->y; + wkt << p->x() << " " << p->y(); if (p != this->points.end()-1) wkt << ","; } wkt << "))"; @@ -312,13 +312,13 @@ Point Polygon::point_projection(const Point &point) const dmin = d; proj = pt1; } - Pointf v1(coordf_t(pt1.x - pt0.x), coordf_t(pt1.y - pt0.y)); + Pointf v1(coordf_t(pt1.x() - pt0.x()), coordf_t(pt1.y() - pt0.y())); coordf_t div = dot(v1); if (div > 0.) { - Pointf v2(coordf_t(point.x - pt0.x), coordf_t(point.y - pt0.y)); + Pointf v2(coordf_t(point.x() - pt0.x()), coordf_t(point.y() - pt0.y())); coordf_t t = dot(v1, v2) / div; if (t > 0. && t < 1.) { - Point foot(coord_t(floor(coordf_t(pt0.x) + t * v1.x + 0.5)), coord_t(floor(coordf_t(pt0.y) + t * v1.y + 0.5))); + Point foot(coord_t(floor(coordf_t(pt0.x()) + t * v1.x() + 0.5)), coord_t(floor(coordf_t(pt0.y()) + t * v1.y() + 0.5))); d = foot.distance_to(point); if (d < dmin) { dmin = d; @@ -376,12 +376,12 @@ static inline bool is_stick(const Point &p1, const Point &p2, const Point &p3) { Point v1 = p2 - p1; Point v2 = p3 - p2; - int64_t dir = int64_t(v1.x) * int64_t(v2.x) + int64_t(v1.y) * int64_t(v2.y); + int64_t dir = int64_t(v1.x()) * int64_t(v2.x()) + int64_t(v1.y()) * int64_t(v2.y()); if (dir > 0) // p3 does not turn back to p1. Do not remove p2. return false; - double l2_1 = double(v1.x) * double(v1.x) + double(v1.y) * double(v1.y); - double l2_2 = double(v2.x) * double(v2.x) + double(v2.y) * double(v2.y); + double l2_1 = double(v1.x()) * double(v1.x()) + double(v1.y()) * double(v1.y()); + double l2_2 = double(v2.x()) * double(v2.x()) + double(v2.y()) * double(v2.y()); if (dir == 0) // p1, p2, p3 may make a perpendicular corner, or there is a zero edge length. // Remove p2 if it is coincident with p1 or p2. @@ -389,7 +389,7 @@ static inline bool is_stick(const Point &p1, const Point &p2, const Point &p3) // p3 turns back to p1 after p2. Are p1, p2, p3 collinear? // Calculate distance from p3 to a segment (p1, p2) or from p1 to a segment(p2, p3), // whichever segment is longer - double cross = double(v1.x) * double(v2.y) - double(v2.x) * double(v1.y); + double cross = double(v1.x()) * double(v2.y()) - double(v2.x()) * double(v1.y()); double dist2 = cross * cross / std::max(l2_1, l2_2); return dist2 < EPSILON * EPSILON; } diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index 1a02d78b7..6d0b148ef 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -27,7 +27,7 @@ public: static Polygon new_scale(std::vector<Pointf> points) { Points int_points; for (auto pt : points) - int_points.push_back(Point::new_scale(pt.x, pt.y)); + int_points.push_back(Point::new_scale(pt.x(), pt.y())); return Polygon(int_points); } Polygon& operator=(const Polygon &other) { points = other.points; return *this; } diff --git a/xs/src/libslic3r/Polyline.cpp b/xs/src/libslic3r/Polyline.cpp index 3432506c6..bd7b9bf98 100644 --- a/xs/src/libslic3r/Polyline.cpp +++ b/xs/src/libslic3r/Polyline.cpp @@ -33,7 +33,7 @@ Polyline::leftmost_point() const { Point p = this->points.front(); for (Points::const_iterator it = this->points.begin() + 1; it != this->points.end(); ++it) { - if (it->x < p.x) p = *it; + if (it->x() < p.x()) p = *it; } return p; } @@ -214,7 +214,7 @@ Polyline::wkt() const std::ostringstream wkt; wkt << "LINESTRING(("; for (Points::const_iterator p = this->points.begin(); p != this->points.end(); ++p) { - wkt << p->x << " " << p->y; + wkt << p->x() << " " << p->y(); if (p != this->points.end()-1) wkt << ","; } wkt << "))"; diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index b64743d84..46877faf9 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -25,7 +25,7 @@ public: Polyline pl; Points int_points; for (auto pt : points) - int_points.push_back(Point::new_scale(pt.x, pt.y)); + int_points.push_back(Point::new_scale(pt.x(), pt.y())); pl.append(int_points); return pl; } diff --git a/xs/src/libslic3r/PolylineCollection.cpp b/xs/src/libslic3r/PolylineCollection.cpp index ca9c64d23..dcec43c81 100644 --- a/xs/src/libslic3r/PolylineCollection.cpp +++ b/xs/src/libslic3r/PolylineCollection.cpp @@ -15,9 +15,9 @@ inline int nearest_point_index(const std::vector<Chaining> &pairs, const Point & T dmin = std::numeric_limits<T>::max(); int idx = 0; for (std::vector<Chaining>::const_iterator it = pairs.begin(); it != pairs.end(); ++it) { - T d = sqr(T(start_near.x - it->first.x)); + T d = sqr(T(start_near.x() - it->first.x())); if (d <= dmin) { - d += sqr(T(start_near.y - it->first.y)); + d += sqr(T(start_near.y() - it->first.y())); if (d < dmin) { idx = (it - pairs.begin()) * 2; dmin = d; @@ -26,9 +26,9 @@ inline int nearest_point_index(const std::vector<Chaining> &pairs, const Point & } } if (! no_reverse) { - d = sqr(T(start_near.x - it->last.x)); + d = sqr(T(start_near.x() - it->last.x())); if (d <= dmin) { - d += sqr(T(start_near.y - it->last.y)); + d += sqr(T(start_near.y() - it->last.y())); if (d < dmin) { idx = (it - pairs.begin()) * 2 + 1; dmin = d; @@ -82,7 +82,7 @@ Point PolylineCollection::leftmost_point(const Polylines &polylines) Point p = it->leftmost_point(); for (++ it; it != polylines.end(); ++it) { Point p2 = it->leftmost_point(); - if (p2.x < p.x) + if (p2.x() < p.x()) p = p2; } return p; diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index e08ae1fc4..987297251 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -538,9 +538,9 @@ bool Print::has_skirt() const std::string Print::validate() const { BoundingBox bed_box_2D = get_extents(Polygon::new_scale(config.bed_shape.values)); - BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x), unscale(bed_box_2D.min.y), 0.0), Pointf3(unscale(bed_box_2D.max.x), unscale(bed_box_2D.max.y), config.max_print_height)); + BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x()), unscale(bed_box_2D.min.y()), 0.0), Pointf3(unscale(bed_box_2D.max.x()), unscale(bed_box_2D.max.y()), config.max_print_height)); // Allow the objects to protrude below the print bed, only the part of the object above the print bed will be sliced. - print_volume.min.z = -1e10; + print_volume.min.z() = -1e10; unsigned int printable_count = 0; for (PrintObject *po : this->objects) { po->model_object()->check_instances_print_volume_state(print_volume); @@ -585,7 +585,7 @@ std::string Print::validate() const { std::vector<coord_t> object_height; for (const PrintObject *object : this->objects) - object_height.insert(object_height.end(), object->copies().size(), object->size.z); + object_height.insert(object_height.end(), object->copies().size(), object->size.z()); std::sort(object_height.begin(), object_height.end()); // Ignore the tallest *copy* (this is why we repeat height for all of them): // it will be printed as last one so its height doesn't matter. diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 7064e19fe..624ac59e4 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -2067,7 +2067,7 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va ConfigOptionPoint p; p.deserialize(value); std::ostringstream oss; - oss << "0x0," << p.value.x << "x0," << p.value.x << "x" << p.value.y << ",0x" << p.value.y; + oss << "0x0," << p.value.x() << "x0," << p.value.x() << "x" << p.value.y() << ",0x" << p.value.y(); value = oss.str(); // Maybe one day we will rename octoprint_host to print_host as it has been done in the upstream Slic3r. // Commenting this out fixes github issue #869 for now. diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 47495dad8..b060816a1 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -48,10 +48,10 @@ PrintObject::PrintObject(Print* print, ModelObject* model_object, const Bounding // don't assume it's already aligned and we don't alter the original position in model. // We store the XY translation so that we can place copies correctly in the output G-code // (copies are expressed in G-code coordinates and this translation is not publicly exposed). - this->_copies_shift = Point::new_scale(modobj_bbox.min.x, modobj_bbox.min.y); + this->_copies_shift = Point::new_scale(modobj_bbox.min.x(), modobj_bbox.min.y()); // Scale the object size and store it Pointf3 size = modobj_bbox.size(); - this->size = Point3::new_scale(size.x, size.y, size.z); + this->size = Point3::new_scale(size.x(), size.y(), size.z()); } this->reload_model_instances(); @@ -62,7 +62,7 @@ PrintObject::PrintObject(Print* print, ModelObject* model_object, const Bounding bool PrintObject::add_copy(const Pointf &point) { Points points = this->_copies; - points.push_back(Point::new_scale(point.x, point.y)); + points.push_back(Point::new_scale(point.x(), point.y())); return this->set_copies(points); } @@ -104,7 +104,7 @@ bool PrintObject::reload_model_instances() for (const ModelInstance *mi : this->_model_object->instances) { if (mi->is_printable()) - copies.emplace_back(Point::new_scale(mi->offset.x, mi->offset.y)); + copies.emplace_back(Point::new_scale(mi->offset.x(), mi->offset.y())); } return this->set_copies(copies); } @@ -1122,7 +1122,7 @@ SlicingParameters PrintObject::slicing_parameters() const { return SlicingParameters::create_from_config( this->print()->config, this->config, - unscale(this->size.z), this->print()->object_extruders()); + unscale(this->size.z()), this->print()->object_extruders()); } bool PrintObject::update_layer_height_profile(std::vector<coordf_t> &layer_height_profile) const @@ -1336,7 +1336,7 @@ std::vector<ExPolygons> PrintObject::_slice_region(size_t region_id, const std:: // consider the first one this->model_object()->instances.front()->transform_mesh(&mesh, true); // align mesh to Z = 0 (it should be already aligned actually) and apply XY shift - mesh.translate(- float(unscale(this->_copies_shift.x)), - float(unscale(this->_copies_shift.y)), -float(this->model_object()->bounding_box().min.z)); + mesh.translate(- float(unscale(this->_copies_shift.x())), - float(unscale(this->_copies_shift.y())), -float(this->model_object()->bounding_box().min.z())); // perform actual slicing TriangleMeshSlicer mslicer(&mesh); mslicer.slice(z, &layers); diff --git a/xs/src/libslic3r/SVG.cpp b/xs/src/libslic3r/SVG.cpp index c94db8e74..1d683a030 100644 --- a/xs/src/libslic3r/SVG.cpp +++ b/xs/src/libslic3r/SVG.cpp @@ -32,8 +32,8 @@ bool SVG::open(const char* afilename, const BoundingBox &bbox, const coord_t bbo this->f = boost::nowide::fopen(afilename, "w"); if (f == NULL) return false; - float w = COORD(bbox.max.x - bbox.min.x + 2 * bbox_offset); - float h = COORD(bbox.max.y - bbox.min.y + 2 * bbox_offset); + float w = COORD(bbox.max.x() - bbox.min.x() + 2 * bbox_offset); + float h = COORD(bbox.max.y() - bbox.min.y() + 2 * bbox_offset); fprintf(this->f, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n" @@ -50,7 +50,7 @@ SVG::draw(const Line &line, std::string stroke, coordf_t stroke_width) { fprintf(this->f, " <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: %s; stroke-width: %f\"", - COORD(line.a.x - origin.x), COORD(line.a.y - origin.y), COORD(line.b.x - origin.x), COORD(line.b.y - origin.y), stroke.c_str(), (stroke_width == 0) ? 1.f : COORD(stroke_width)); + COORD(line.a.x() - origin.x()), COORD(line.a.y() - origin.y()), COORD(line.b.x() - origin.x()), COORD(line.b.y() - origin.y()), stroke.c_str(), (stroke_width == 0) ? 1.f : COORD(stroke_width)); if (this->arrows) fprintf(this->f, " marker-end=\"url(#endArrow)\""); fprintf(this->f, "/>\n"); @@ -58,21 +58,21 @@ SVG::draw(const Line &line, std::string stroke, coordf_t stroke_width) void SVG::draw(const ThickLine &line, const std::string &fill, const std::string &stroke, coordf_t stroke_width) { - Pointf dir(line.b.x-line.a.x, line.b.y-line.a.y); - Pointf perp(-dir.y, dir.x); - coordf_t len = sqrt(perp.x*perp.x + perp.y*perp.y); + Pointf dir(line.b.x()-line.a.x(), line.b.y()-line.a.y()); + Pointf perp(-dir.y(), dir.x()); + coordf_t len = sqrt(perp.x()*perp.x() + perp.y()*perp.y()); coordf_t da = coordf_t(0.5)*line.a_width/len; coordf_t db = coordf_t(0.5)*line.b_width/len; fprintf(this->f, " <polygon points=\"%f,%f %f,%f %f,%f %f,%f\" style=\"fill:%s; stroke: %s; stroke-width: %f\"/>\n", - COORD(line.a.x-da*perp.x-origin.x), - COORD(line.a.y-da*perp.y-origin.y), - COORD(line.b.x-db*perp.x-origin.x), - COORD(line.b.y-db*perp.y-origin.y), - COORD(line.b.x+db*perp.x-origin.x), - COORD(line.b.y+db*perp.y-origin.y), - COORD(line.a.x+da*perp.x-origin.x), - COORD(line.a.y+da*perp.y-origin.y), + COORD(line.a.x()-da*perp.x()-origin.x()), + COORD(line.a.y()-da*perp.y()-origin.y()), + COORD(line.b.x()-db*perp.x()-origin.x()), + COORD(line.b.y()-db*perp.y()-origin.y()), + COORD(line.b.x()+db*perp.x()-origin.x()), + COORD(line.b.y()+db*perp.y()-origin.y()), + COORD(line.a.x()+da*perp.x()-origin.x()), + COORD(line.a.y()+da*perp.y()-origin.y()), fill.c_str(), stroke.c_str(), (stroke_width == 0) ? 1.f : COORD(stroke_width)); } @@ -220,7 +220,7 @@ SVG::draw(const Point &point, std::string fill, coord_t iradius) { float radius = (iradius == 0) ? 3.f : COORD(iradius); std::ostringstream svg; - svg << " <circle cx=\"" << COORD(point.x - origin.x) << "\" cy=\"" << COORD(point.y - origin.y) + svg << " <circle cx=\"" << COORD(point.x() - origin.x()) << "\" cy=\"" << COORD(point.y() - origin.y()) << "\" r=\"" << radius << "\" " << "style=\"stroke: none; fill: " << fill << "\" />"; @@ -287,8 +287,8 @@ SVG::get_path_d(const MultiPoint &mp, bool closed) const std::ostringstream d; d << "M "; for (Points::const_iterator p = mp.points.begin(); p != mp.points.end(); ++p) { - d << COORD(p->x - origin.x) << " "; - d << COORD(p->y - origin.y) << " "; + d << COORD(p->x() - origin.x()) << " "; + d << COORD(p->y() - origin.y()) << " "; } if (closed) d << "z"; return d.str(); @@ -300,8 +300,8 @@ SVG::get_path_d(const ClipperLib::Path &path, double scale, bool closed) const std::ostringstream d; d << "M "; for (ClipperLib::Path::const_iterator p = path.begin(); p != path.end(); ++p) { - d << COORD(scale * p->X - origin.x) << " "; - d << COORD(scale * p->Y - origin.y) << " "; + d << COORD(scale * p->X - origin.x()) << " "; + d << COORD(scale * p->Y - origin.y()) << " "; } if (closed) d << "z"; return d.str(); @@ -311,8 +311,8 @@ void SVG::draw_text(const Point &pt, const char *text, const char *color) { fprintf(this->f, "<text x=\"%f\" y=\"%f\" font-family=\"sans-serif\" font-size=\"20px\" fill=\"%s\">%s</text>", - COORD(pt.x-origin.x), - COORD(pt.y-origin.y), + COORD(pt.x()-origin.x()), + COORD(pt.y()-origin.y()), color, text); } @@ -320,13 +320,13 @@ void SVG::draw_legend(const Point &pt, const char *text, const char *color) { fprintf(this->f, "<circle cx=\"%f\" cy=\"%f\" r=\"10\" fill=\"%s\"/>", - COORD(pt.x-origin.x), - COORD(pt.y-origin.y), + COORD(pt.x()-origin.x()), + COORD(pt.y()-origin.y()), color); fprintf(this->f, "<text x=\"%f\" y=\"%f\" font-family=\"sans-serif\" font-size=\"10px\" fill=\"%s\">%s</text>", - COORD(pt.x-origin.x) + 20.f, - COORD(pt.y-origin.y), + COORD(pt.x()-origin.x()) + 20.f, + COORD(pt.y()-origin.y()), "black", text); } diff --git a/xs/src/libslic3r/Slicing.cpp b/xs/src/libslic3r/Slicing.cpp index e9295d1e3..f38c97cb7 100644 --- a/xs/src/libslic3r/Slicing.cpp +++ b/xs/src/libslic3r/Slicing.cpp @@ -608,17 +608,17 @@ int generate_layer_height_texture( coordf_t intensity = cos(M_PI * 0.7 * (mid - z) / h); // Color mapping from layer height to RGB. Pointf3 color( - intensity * lerp(coordf_t(color1.x), coordf_t(color2.x), t), - intensity * lerp(coordf_t(color1.y), coordf_t(color2.y), t), - intensity * lerp(coordf_t(color1.z), coordf_t(color2.z), t)); + intensity * lerp(coordf_t(color1.x()), coordf_t(color2.x()), t), + intensity * lerp(coordf_t(color1.y()), coordf_t(color2.y()), t), + intensity * lerp(coordf_t(color1.z()), coordf_t(color2.z()), t)); int row = cell / (cols - 1); int col = cell - row * (cols - 1); assert(row >= 0 && row < rows); assert(col >= 0 && col < cols); unsigned char *ptr = (unsigned char*)data + (row * cols + col) * 4; - ptr[0] = (unsigned char)clamp<int>(0, 255, int(floor(color.x + 0.5))); - ptr[1] = (unsigned char)clamp<int>(0, 255, int(floor(color.y + 0.5))); - ptr[2] = (unsigned char)clamp<int>(0, 255, int(floor(color.z + 0.5))); + ptr[0] = (unsigned char)clamp<int>(0, 255, int(floor(color.x() + 0.5))); + ptr[1] = (unsigned char)clamp<int>(0, 255, int(floor(color.y() + 0.5))); + ptr[2] = (unsigned char)clamp<int>(0, 255, int(floor(color.z() + 0.5))); ptr[3] = 255; if (col == 0 && row > 0) { // Duplicate the first value in a row as a last value of the preceding row. @@ -640,17 +640,17 @@ int generate_layer_height_texture( const Point3 &color2 = palette_raw[idx2]; // Color mapping from layer height to RGB. Pointf3 color( - lerp(coordf_t(color1.x), coordf_t(color2.x), t), - lerp(coordf_t(color1.y), coordf_t(color2.y), t), - lerp(coordf_t(color1.z), coordf_t(color2.z), t)); + lerp(coordf_t(color1.x()), coordf_t(color2.x()), t), + lerp(coordf_t(color1.y()), coordf_t(color2.y()), t), + lerp(coordf_t(color1.z()), coordf_t(color2.z()), t)); int row = cell / (cols1 - 1); int col = cell - row * (cols1 - 1); assert(row >= 0 && row < rows/2); assert(col >= 0 && col < cols/2); unsigned char *ptr = data1 + (row * cols1 + col) * 4; - ptr[0] = (unsigned char)clamp<int>(0, 255, int(floor(color.x + 0.5))); - ptr[1] = (unsigned char)clamp<int>(0, 255, int(floor(color.y + 0.5))); - ptr[2] = (unsigned char)clamp<int>(0, 255, int(floor(color.z + 0.5))); + ptr[0] = (unsigned char)clamp<int>(0, 255, int(floor(color.x() + 0.5))); + ptr[1] = (unsigned char)clamp<int>(0, 255, int(floor(color.y() + 0.5))); + ptr[2] = (unsigned char)clamp<int>(0, 255, int(floor(color.z() + 0.5))); ptr[3] = 255; if (col == 0 && row > 0) { // Duplicate the first value in a row as a last value of the preceding row. diff --git a/xs/src/libslic3r/SupportMaterial.cpp b/xs/src/libslic3r/SupportMaterial.cpp index 0cecf0014..f5cee401c 100644 --- a/xs/src/libslic3r/SupportMaterial.cpp +++ b/xs/src/libslic3r/SupportMaterial.cpp @@ -67,9 +67,9 @@ Point export_support_surface_type_legend_to_svg_box_size() void export_support_surface_type_legend_to_svg(SVG &svg, const Point &pos) { // 1st row - coord_t pos_x0 = pos.x + scale_(1.); + coord_t pos_x0 = pos.x() + scale_(1.); coord_t pos_x = pos_x0; - coord_t pos_y = pos.y + scale_(1.5); + coord_t pos_y = pos.y() + scale_(1.5); coord_t step_x = scale_(10.); svg.draw_legend(Point(pos_x, pos_y), "top contact" , support_surface_type_to_color_name(PrintObjectSupportMaterial::sltTopContact)); pos_x += step_x; @@ -82,7 +82,7 @@ void export_support_surface_type_legend_to_svg(SVG &svg, const Point &pos) svg.draw_legend(Point(pos_x, pos_y), "bottom contact" , support_surface_type_to_color_name(PrintObjectSupportMaterial::sltBottomContact)); // 2nd row pos_x = pos_x0; - pos_y = pos.y+scale_(2.8); + pos_y = pos.y()+scale_(2.8); svg.draw_legend(Point(pos_x, pos_y), "raft interface" , support_surface_type_to_color_name(PrintObjectSupportMaterial::sltRaftInterface)); pos_x += step_x; svg.draw_legend(Point(pos_x, pos_y), "raft base" , support_surface_type_to_color_name(PrintObjectSupportMaterial::sltRaftBase)); @@ -98,8 +98,8 @@ void export_print_z_polygons_to_svg(const char *path, PrintObjectSupportMaterial for (int i = 0; i < n_layers; ++ i) bbox.merge(get_extents(layers[i]->polygons)); Point legend_size = export_support_surface_type_legend_to_svg_box_size(); - Point legend_pos(bbox.min.x, bbox.max.y); - bbox.merge(Point(std::max(bbox.min.x + legend_size.x, bbox.max.x), bbox.max.y + legend_size.y)); + Point legend_pos(bbox.min.x(), bbox.max.y()); + bbox.merge(Point(std::max(bbox.min.x() + legend_size.x(), bbox.max.x()), bbox.max.y() + legend_size.y())); SVG svg(path, bbox); const float transparency = 0.5f; for (int i = 0; i < n_layers; ++ i) @@ -120,8 +120,8 @@ void export_print_z_polygons_and_extrusions_to_svg( for (int i = 0; i < n_layers; ++ i) bbox.merge(get_extents(layers[i]->polygons)); Point legend_size = export_support_surface_type_legend_to_svg_box_size(); - Point legend_pos(bbox.min.x, bbox.max.y); - bbox.merge(Point(std::max(bbox.min.x + legend_size.x, bbox.max.x), bbox.max.y + legend_size.y)); + Point legend_pos(bbox.min.x(), bbox.max.y()); + bbox.merge(Point(std::max(bbox.min.x() + legend_size.x(), bbox.max.x()), bbox.max.y() + legend_size.y())); SVG svg(path, bbox); const float transparency = 0.5f; for (int i = 0; i < n_layers; ++ i) @@ -519,12 +519,12 @@ public: Points::const_iterator i = contour.points.begin(); Points::const_iterator j = contour.points.end() - 1; for (; i != contour.points.end(); j = i ++) { - //FIXME this test is not numerically robust. Particularly, it does not handle horizontal segments at y == point.y well. - // Does the ray with y == point.y intersect this line segment? + //FIXME this test is not numerically robust. Particularly, it does not handle horizontal segments at y == point.y() well. + // Does the ray with y == point.y() intersect this line segment? for (auto &sample_inside : samples_inside) { - if ((i->y > sample_inside.first.y) != (j->y > sample_inside.first.y)) { - double x1 = (double)sample_inside.first.x; - double x2 = (double)i->x + (double)(j->x - i->x) * (double)(sample_inside.first.y - i->y) / (double)(j->y - i->y); + if ((i->y() > sample_inside.first.y()) != (j->y() > sample_inside.first.y())) { + double x1 = (double)sample_inside.first.x(); + double x2 = (double)i->x() + (double)(j->x() - i->x()) * (double)(sample_inside.first.y() - i->y()) / (double)(j->y() - i->y()); if (x1 < x2) sample_inside.second = !sample_inside.second; } @@ -585,11 +585,11 @@ private: const Point &p3 = (pt_min == &expoly.contour.points.back()) ? expoly.contour.points.front() : *(pt_min + 1); Vector v = (p3 - p2) + (p1 - p2); - double l2 = double(v.x)*double(v.x)+double(v.y)*double(v.y); + double l2 = double(v.x())*double(v.x())+double(v.y())*double(v.y()); if (l2 == 0.) return p2; double coef = 20. / sqrt(l2); - return Point(p2.x + coef * v.x, p2.y + coef * v.y); + return Point(p2.x() + coef * v.x(), p2.y() + coef * v.y()); } static Points island_samples(const ExPolygons &expolygons) @@ -789,7 +789,7 @@ PrintObjectSupportMaterial::MyLayersPtr PrintObjectSupportMaterial::top_contact_ // workaround for Clipper bug, see Slic3r::Polygon::clip_as_polyline() for (Polyline &polyline : overhang_perimeters) - polyline.points[0].x += 1; + polyline.points[0].x() += 1; // Trim the perimeters of this layer by the lower layer to get the unsupported pieces of perimeters. overhang_perimeters = diff_pl(overhang_perimeters, lower_grown_slices); @@ -2057,8 +2057,8 @@ void LoopInterfaceProcessor::generate(MyLayerExtruded &top_contact_layer, const const Point &p1 = *(it-1); const Point &p2 = *it; // Intersection of a ray (p1, p2) with a circle placed at center_last, with radius of circle_distance. - const Pointf v_seg(coordf_t(p2.x) - coordf_t(p1.x), coordf_t(p2.y) - coordf_t(p1.y)); - const Pointf v_cntr(coordf_t(p1.x - center_last.x), coordf_t(p1.y - center_last.y)); + const Pointf v_seg(coordf_t(p2.x()) - coordf_t(p1.x()), coordf_t(p2.y()) - coordf_t(p1.y())); + const Pointf v_cntr(coordf_t(p1.x() - center_last.x()), coordf_t(p1.y() - center_last.y())); coordf_t a = dot(v_seg); coordf_t b = 2. * dot(v_seg, v_cntr); coordf_t c = dot(v_cntr) - circle_distance * circle_distance; @@ -2081,7 +2081,7 @@ void LoopInterfaceProcessor::generate(MyLayerExtruded &top_contact_layer, const } seg_current_pt = &p1; seg_current_t = t; - center_last = Point(p1.x + coord_t(v_seg.x * t), p1.y + coord_t(v_seg.y * t)); + center_last = Point(p1.x() + coord_t(v_seg.x() * t), p1.y() + coord_t(v_seg.y() * t)); // It has been verified that the new point is far enough from center_last. // Ensure, that it is far enough from all the centers. std::pair<const Point*, coordf_t> circle_closest = circle_centers_lookup.find(center_last); @@ -2887,9 +2887,9 @@ void PrintObjectSupportMaterial::clip_by_pillars( BoundingBox bbox; for (LayersPtr::const_iterator it = top_contacts.begin(); it != top_contacts.end(); ++ it) bbox.merge(get_extents((*it)->polygons)); - grid.reserve(size_t(ceil(bb.size().x / pillar_spacing)) * size_t(ceil(bb.size().y / pillar_spacing))); - for (coord_t x = bb.min.x; x <= bb.max.x - pillar_size; x += pillar_spacing) { - for (coord_t y = bb.min.y; y <= bb.max.y - pillar_size; y += pillar_spacing) { + grid.reserve(size_t(ceil(bb.size().x() / pillar_spacing)) * size_t(ceil(bb.size().y() / pillar_spacing))); + for (coord_t x = bb.min.x(); x <= bb.max.x() - pillar_size; x += pillar_spacing) { + for (coord_t y = bb.min.y(); y <= bb.max.y() - pillar_size; y += pillar_spacing) { grid.push_back(pillar); for (size_t i = 0; i < pillar.points.size(); ++ i) grid.back().points[i].translate(Point(x, y)); diff --git a/xs/src/libslic3r/Surface.cpp b/xs/src/libslic3r/Surface.cpp index 384540d87..d3474e4a7 100644 --- a/xs/src/libslic3r/Surface.cpp +++ b/xs/src/libslic3r/Surface.cpp @@ -106,9 +106,9 @@ Point export_surface_type_legend_to_svg_box_size() void export_surface_type_legend_to_svg(SVG &svg, const Point &pos) { // 1st row - coord_t pos_x0 = pos.x + scale_(1.); + coord_t pos_x0 = pos.x() + scale_(1.); coord_t pos_x = pos_x0; - coord_t pos_y = pos.y + scale_(1.5); + coord_t pos_y = pos.y() + scale_(1.5); coord_t step_x = scale_(10.); svg.draw_legend(Point(pos_x, pos_y), "perimeter" , surface_type_to_color_name(stPerimeter)); pos_x += step_x; @@ -121,7 +121,7 @@ void export_surface_type_legend_to_svg(SVG &svg, const Point &pos) svg.draw_legend(Point(pos_x, pos_y), "invalid" , surface_type_to_color_name(SurfaceType(-1))); // 2nd row pos_x = pos_x0; - pos_y = pos.y+scale_(2.8); + pos_y = pos.y()+scale_(2.8); svg.draw_legend(Point(pos_x, pos_y), "internal" , surface_type_to_color_name(stInternal)); pos_x += step_x; svg.draw_legend(Point(pos_x, pos_y), "internal solid" , surface_type_to_color_name(stInternalSolid)); diff --git a/xs/src/libslic3r/SurfaceCollection.cpp b/xs/src/libslic3r/SurfaceCollection.cpp index 42ddf9574..a7fc4a648 100644 --- a/xs/src/libslic3r/SurfaceCollection.cpp +++ b/xs/src/libslic3r/SurfaceCollection.cpp @@ -170,8 +170,8 @@ void SurfaceCollection::export_to_svg(const char *path, bool show_labels) for (Surfaces::const_iterator surface = this->surfaces.begin(); surface != this->surfaces.end(); ++surface) bbox.merge(get_extents(surface->expolygon)); Point legend_size = export_surface_type_legend_to_svg_box_size(); - Point legend_pos(bbox.min.x, bbox.max.y); - bbox.merge(Point(std::max(bbox.min.x + legend_size.x, bbox.max.x), bbox.max.y + legend_size.y)); + Point legend_pos(bbox.min.x(), bbox.max.y()); + bbox.merge(Point(std::max(bbox.min.x() + legend_size.x(), bbox.max.x()), bbox.max.y() + legend_size.y())); SVG svg(path, bbox); const float transparency = 0.5f; diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 45e4b6f5d..d0d2f5fcb 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -52,20 +52,20 @@ TriangleMesh::TriangleMesh(const Pointf3s &points, const std::vector<Point3>& fa for (int i = 0; i < stl.stats.number_of_facets; i++) { stl_facet facet; - const Pointf3& ref_f1 = points[facets[i].x]; - facet.vertex[0].x = ref_f1.x; - facet.vertex[0].y = ref_f1.y; - facet.vertex[0].z = ref_f1.z; + const Pointf3& ref_f1 = points[facets[i].x()]; + facet.vertex[0].x = ref_f1.x(); + facet.vertex[0].y = ref_f1.y(); + facet.vertex[0].z = ref_f1.z(); - const Pointf3& ref_f2 = points[facets[i].y]; - facet.vertex[1].x = ref_f2.x; - facet.vertex[1].y = ref_f2.y; - facet.vertex[1].z = ref_f2.z; + const Pointf3& ref_f2 = points[facets[i].y()]; + facet.vertex[1].x = ref_f2.x(); + facet.vertex[1].y = ref_f2.y(); + facet.vertex[1].z = ref_f2.z(); - const Pointf3& ref_f3 = points[facets[i].z]; - facet.vertex[2].x = ref_f3.x; - facet.vertex[2].y = ref_f3.y; - facet.vertex[2].z = ref_f3.z; + const Pointf3& ref_f3 = points[facets[i].z()]; + facet.vertex[2].x = ref_f3.x(); + facet.vertex[2].y = ref_f3.y(); + facet.vertex[2].z = ref_f3.z(); facet.extra[0] = 0; facet.extra[1] = 0; @@ -303,9 +303,9 @@ void TriangleMesh::scale(float factor) void TriangleMesh::scale(const Pointf3 &versor) { float fversor[3]; - fversor[0] = versor.x; - fversor[1] = versor.y; - fversor[2] = versor.z; + fversor[0] = versor.x(); + fversor[1] = versor.y(); + fversor[2] = versor.z(); stl_scale_versor(&this->stl, fversor); stl_invalidate_shared_vertices(&this->stl); } @@ -400,9 +400,9 @@ void TriangleMesh::rotate(double angle, Point* center) { if (angle == 0.) return; - this->translate(float(-center->x), float(-center->y), 0); + this->translate(float(-center->x()), float(-center->y()), 0); stl_rotate_z(&(this->stl), (float)angle); - this->translate(float(+center->x), float(+center->y), 0); + this->translate(float(+center->x()), float(+center->y()), 0); } bool TriangleMesh::has_multiple_patches() const @@ -588,12 +588,12 @@ TriangleMesh::bounding_box() const { BoundingBoxf3 bb; bb.defined = true; - bb.min.x = this->stl.stats.min.x; - bb.min.y = this->stl.stats.min.y; - bb.min.z = this->stl.stats.min.z; - bb.max.x = this->stl.stats.max.x; - bb.max.y = this->stl.stats.max.y; - bb.max.z = this->stl.stats.max.z; + bb.min.x() = this->stl.stats.min.x; + bb.min.y() = this->stl.stats.min.y; + bb.min.z() = this->stl.stats.min.z; + bb.max.x() = this->stl.stats.max.x; + bb.max.y() = this->stl.stats.max.y; + bb.max.z() = this->stl.stats.max.z; return bb; } @@ -813,10 +813,10 @@ void TriangleMeshSlicer::_slice_do(size_t facet_idx, std::vector<IntersectionLin std::swap(a_id, b_id); const stl_vertex *a = &this->v_scaled_shared[a_id]; const stl_vertex *b = &this->v_scaled_shared[b_id]; - il.a.x = a->x; - il.a.y = a->y; - il.b.x = b->x; - il.b.y = b->y; + il.a.x() = a->x; + il.a.y() = a->y; + il.b.x() = b->x; + il.b.y() = b->y; il.a_id = a_id; il.b_id = b_id; (*lines)[layer_idx].push_back(il); @@ -894,10 +894,10 @@ bool TriangleMeshSlicer::slice_facet( // Two vertices are aligned with the cutting plane, the third vertex is above the cutting plane. line_out->edge_type = feBottom; } - line_out->a.x = a->x; - line_out->a.y = a->y; - line_out->b.x = b->x; - line_out->b.y = b->y; + line_out->a.x() = a->x; + line_out->a.y() = a->y; + line_out->b.x() = b->x; + line_out->b.y() = b->y; line_out->a_id = a_id; line_out->b_id = b_id; return true; @@ -907,21 +907,21 @@ bool TriangleMeshSlicer::slice_facet( // Only point a alings with the cutting plane. points_on_layer[num_points_on_layer ++] = num_points; IntersectionPoint &point = points[num_points ++]; - point.x = a->x; - point.y = a->y; + point.x() = a->x; + point.y() = a->y; point.point_id = a_id; } else if (b->z == slice_z) { // Only point b alings with the cutting plane. points_on_layer[num_points_on_layer ++] = num_points; IntersectionPoint &point = points[num_points ++]; - point.x = b->x; - point.y = b->y; + point.x() = b->x; + point.y() = b->y; point.point_id = b_id; } else if ((a->z < slice_z && b->z > slice_z) || (b->z < slice_z && a->z > slice_z)) { // A general case. The face edge intersects the cutting plane. Calculate the intersection point. IntersectionPoint &point = points[num_points ++]; - point.x = b->x + (a->x - b->x) * (slice_z - b->z) / (a->z - b->z); - point.y = b->y + (a->y - b->y) * (slice_z - b->z) / (a->z - b->z); + point.x() = b->x + (a->x - b->x) * (slice_z - b->z) / (a->z - b->z); + point.y() = b->y + (a->y - b->y) * (slice_z - b->z) / (a->z - b->z); point.edge_id = edge_id; } } @@ -1202,7 +1202,7 @@ void TriangleMeshSlicer::make_loops(std::vector<IntersectionLine> &lines, Polygo // Orient the patched up polygons CCW. This heuristic may close some holes and cavities. double area = 0.; for (size_t i = 0, j = opl.points.size() - 1; i < opl.points.size(); j = i ++) - area += double(opl.points[j].x + opl.points[i].x) * double(opl.points[i].y - opl.points[j].y); + area += double(opl.points[j].x() + opl.points[i].x()) * double(opl.points[i].y() - opl.points[j].y()); if (area < 0) std::reverse(opl.points.begin(), opl.points.end()); loops->emplace_back(std::move(opl.points)); @@ -1492,8 +1492,8 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower) facet.normal.y = 0; facet.normal.z = -1; for (size_t i = 0; i <= 2; ++i) { - facet.vertex[i].x = unscale(p.points[i].x); - facet.vertex[i].y = unscale(p.points[i].y); + facet.vertex[i].x = unscale(p.points[i].x()); + facet.vertex[i].y = unscale(p.points[i].y()); facet.vertex[i].z = z; } stl_add_facet(&upper->stl, &facet); @@ -1518,8 +1518,8 @@ void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower) facet.normal.y = 0; facet.normal.z = 1; for (size_t i = 0; i <= 2; ++i) { - facet.vertex[i].x = unscale(polygon->points[i].x); - facet.vertex[i].y = unscale(polygon->points[i].y); + facet.vertex[i].x = unscale(polygon->points[i].x()); + facet.vertex[i].y = unscale(polygon->points[i].y()); facet.vertex[i].z = z; } stl_add_facet(&lower->stl, &facet); diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index c8aadc8c3..5665f6c0f 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -485,8 +485,8 @@ SV* to_SV_pureperl(const Point* THIS) { AV* av = newAV(); av_fill(av, 1); - av_store(av, 0, newSViv(THIS->x)); - av_store(av, 1, newSViv(THIS->y)); + av_store(av, 0, newSViv(THIS->x())); + av_store(av, 1, newSViv(THIS->y())); return newRV_noinc((SV*)av); } @@ -495,8 +495,8 @@ void from_SV(SV* point_sv, Point* point) AV* point_av = (AV*)SvRV(point_sv); // get a double from Perl and round it, otherwise // it would get truncated - point->x = lrint(SvNV(*av_fetch(point_av, 0, 0))); - point->y = lrint(SvNV(*av_fetch(point_av, 1, 0))); + point->x() = lrint(SvNV(*av_fetch(point_av, 0, 0))); + point->y() = lrint(SvNV(*av_fetch(point_av, 1, 0))); } void from_SV_check(SV* point_sv, Point* point) @@ -514,8 +514,8 @@ SV* to_SV_pureperl(const Pointf* point) { AV* av = newAV(); av_fill(av, 1); - av_store(av, 0, newSVnv(point->x)); - av_store(av, 1, newSVnv(point->y)); + av_store(av, 0, newSVnv(point->x())); + av_store(av, 1, newSVnv(point->y())); return newRV_noinc((SV*)av); } @@ -526,8 +526,8 @@ bool from_SV(SV* point_sv, Pointf* point) SV* sv_y = *av_fetch(point_av, 1, 0); if (!looks_like_number(sv_x) || !looks_like_number(sv_y)) return false; - point->x = SvNV(sv_x); - point->y = SvNV(sv_y); + point->x() = SvNV(sv_x); + point->y() = SvNV(sv_y); return true; } diff --git a/xs/src/slic3r/GUI/2DBed.cpp b/xs/src/slic3r/GUI/2DBed.cpp index 6d788cf34..585205923 100644 --- a/xs/src/slic3r/GUI/2DBed.cpp +++ b/xs/src/slic3r/GUI/2DBed.cpp @@ -41,8 +41,8 @@ void Bed_2D::repaint() cbb.max.translate(0, -13); // read new size - cw = cbb.size().x; - ch = cbb.size().y; + cw = cbb.size().x(); + ch = cbb.size().y(); auto ccenter = cbb.center(); @@ -51,19 +51,19 @@ void Bed_2D::repaint() auto bed_polygon = Polygon::new_scale(m_bed_shape); auto bb = BoundingBoxf(m_bed_shape); bb.merge(Pointf(0, 0)); // origin needs to be in the visible area - auto bw = bb.size().x; - auto bh = bb.size().y; + auto bw = bb.size().x(); + auto bh = bb.size().y(); auto bcenter = bb.center(); // calculate the scaling factor for fitting bed shape in canvas area auto sfactor = std::min(cw/bw, ch/bh); auto shift = Pointf( - ccenter.x - bcenter.x * sfactor, - ccenter.y - bcenter.y * sfactor + ccenter.x() - bcenter.x() * sfactor, + ccenter.y() - bcenter.y() * sfactor ); m_scale_factor = sfactor; - m_shift = Pointf(shift.x + cbb.min.x, - shift.y - (cbb.max.y - GetSize().GetHeight())); + m_shift = Pointf(shift.x() + cbb.min.x(), + shift.y() - (cbb.max.y() - GetSize().GetHeight())); // draw bed fill dc.SetBrush(wxBrush(wxColour(255, 255, 255), wxSOLID)); @@ -71,19 +71,19 @@ void Bed_2D::repaint() for (auto pt: m_bed_shape) { Point pt_pix = to_pixels(pt); - pt_list.push_back(new wxPoint(pt_pix.x, pt_pix.y)); + pt_list.push_back(new wxPoint(pt_pix.x(), pt_pix.y())); } dc.DrawPolygon(&pt_list, 0, 0); // draw grid auto step = 10; // 1cm grid Polylines polylines; - for (auto x = bb.min.x - fmod(bb.min.x, step) + step; x < bb.max.x; x += step) { - Polyline pl = Polyline::new_scale({ Pointf(x, bb.min.y), Pointf(x, bb.max.y) }); + for (auto x = bb.min.x() - fmod(bb.min.x(), step) + step; x < bb.max.x(); x += step) { + Polyline pl = Polyline::new_scale({ Pointf(x, bb.min.y()), Pointf(x, bb.max.y()) }); polylines.push_back(pl); } - for (auto y = bb.min.y - fmod(bb.min.y, step) + step; y < bb.max.y; y += step) { - polylines.push_back(Polyline::new_scale({ Pointf(bb.min.x, y), Pointf(bb.max.x, y) })); + for (auto y = bb.min.y() - fmod(bb.min.y(), step) + step; y < bb.max.y(); y += step) { + polylines.push_back(Polyline::new_scale({ Pointf(bb.min.x(), y), Pointf(bb.max.x(), y) })); } polylines = intersection_pl(polylines, bed_polygon); @@ -93,7 +93,7 @@ void Bed_2D::repaint() for (size_t i = 0; i < pl.points.size()-1; i++){ Point pt1 = to_pixels(Pointf::new_unscale(pl.points[i])); Point pt2 = to_pixels(Pointf::new_unscale(pl.points[i+1])); - dc.DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); + dc.DrawLine(pt1.x(), pt1.y(), pt2.x(), pt2.y()); } } @@ -109,36 +109,36 @@ void Bed_2D::repaint() auto arrow_len = 6; auto arrow_angle = Geometry::deg2rad(45.0); dc.SetPen(wxPen(wxColour(255, 0, 0), 2, wxSOLID)); // red - auto x_end = Pointf(origin_px.x + axes_len, origin_px.y); - dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(x_end.x, x_end.y)); + auto x_end = Pointf(origin_px.x() + axes_len, origin_px.y()); + dc.DrawLine(wxPoint(origin_px.x(), origin_px.y()), wxPoint(x_end.x(), x_end.y())); for (auto angle : { -arrow_angle, arrow_angle }){ auto end = x_end; end.translate(-arrow_len, 0); end.rotate(angle, x_end); - dc.DrawLine(wxPoint(x_end.x, x_end.y), wxPoint(end.x, end.y)); + dc.DrawLine(wxPoint(x_end.x(), x_end.y()), wxPoint(end.x(), end.y())); } dc.SetPen(wxPen(wxColour(0, 255, 0), 2, wxSOLID)); // green - auto y_end = Pointf(origin_px.x, origin_px.y - axes_len); - dc.DrawLine(wxPoint(origin_px.x, origin_px.y), wxPoint(y_end.x, y_end.y)); + auto y_end = Pointf(origin_px.x(), origin_px.y() - axes_len); + dc.DrawLine(wxPoint(origin_px.x(), origin_px.y()), wxPoint(y_end.x(), y_end.y())); for (auto angle : { -arrow_angle, arrow_angle }) { auto end = y_end; end.translate(0, +arrow_len); end.rotate(angle, y_end); - dc.DrawLine(wxPoint(y_end.x, y_end.y), wxPoint(end.x, end.y)); + dc.DrawLine(wxPoint(y_end.x(), y_end.y()), wxPoint(end.x(), end.y())); } // draw origin dc.SetPen(wxPen(wxColour(0, 0, 0), 1, wxSOLID)); dc.SetBrush(wxBrush(wxColour(0, 0, 0), wxSOLID)); - dc.DrawCircle(origin_px.x, origin_px.y, 3); + dc.DrawCircle(origin_px.x(), origin_px.y(), 3); static const auto origin_label = wxString("(0,0)"); dc.SetTextForeground(wxColour(0, 0, 0)); dc.SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL)); auto extent = dc.GetTextExtent(origin_label); - const auto origin_label_x = origin_px.x <= cw / 2 ? origin_px.x + 1 : origin_px.x - 1 - extent.GetWidth(); - const auto origin_label_y = origin_px.y <= ch / 2 ? origin_px.y + 1 : origin_px.y - 1 - extent.GetHeight(); + const auto origin_label_x = origin_px.x() <= cw / 2 ? origin_px.x() + 1 : origin_px.x() - 1 - extent.GetWidth(); + const auto origin_label_y = origin_px.y() <= ch / 2 ? origin_px.y() + 1 : origin_px.y() - 1 - extent.GetHeight(); dc.DrawText(origin_label, origin_label_x, origin_label_y); // draw current position @@ -146,10 +146,10 @@ void Bed_2D::repaint() auto pos_px = to_pixels(m_pos); dc.SetPen(wxPen(wxColour(200, 0, 0), 2, wxSOLID)); dc.SetBrush(wxBrush(wxColour(200, 0, 0), wxTRANSPARENT)); - dc.DrawCircle(pos_px.x, pos_px.y, 5); + dc.DrawCircle(pos_px.x(), pos_px.y(), 5); - dc.DrawLine(pos_px.x - 15, pos_px.y, pos_px.x + 15, pos_px.y); - dc.DrawLine(pos_px.x, pos_px.y - 15, pos_px.x, pos_px.y + 15); + dc.DrawLine(pos_px.x() - 15, pos_px.y(), pos_px.x() + 15, pos_px.y()); + dc.DrawLine(pos_px.x(), pos_px.y() - 15, pos_px.x(), pos_px.y() + 15); } m_painted = true; @@ -160,7 +160,7 @@ Point Bed_2D::to_pixels(Pointf point){ auto p = Pointf(point); p.scale(m_scale_factor); p.translate(m_shift); - return Point(p.x, GetSize().GetHeight() - p.y); + return Point(p.x(), GetSize().GetHeight() - p.y()); } void Bed_2D::mouse_event(wxMouseEvent event){ @@ -168,7 +168,7 @@ void Bed_2D::mouse_event(wxMouseEvent event){ if (!m_painted) return; auto pos = event.GetPosition(); - auto point = to_units(Point(pos.x, pos.y)); + auto point = to_units(Point(pos.x, pos.y)); if (event.LeftDown() || event.Dragging()) { if (m_on_move) m_on_move(point) ; @@ -178,7 +178,7 @@ void Bed_2D::mouse_event(wxMouseEvent event){ // convert pixels into G - code coordinates Pointf Bed_2D::to_units(Point point){ - auto p = Pointf(point.x, GetSize().GetHeight() - point.y); + auto p = Pointf(point.x(), GetSize().GetHeight() - point.y()); p.translate(m_shift.negative()); p.scale(1 / m_scale_factor); return p; diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 2ffd788eb..51e915a57 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -284,7 +284,7 @@ const std::vector<float>& GLVolume::world_matrix() const if (m_dirty) { Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity(); - m.translate(Eigen::Vector3f((float)m_origin.x, (float)m_origin.y, (float)m_origin.z)); + m.translate(Eigen::Vector3f((float)m_origin.x(), (float)m_origin.y(), (float)m_origin.z())); m.rotate(Eigen::AngleAxisf(m_angle_z, Eigen::Vector3f::UnitZ())); m.scale(m_scale_factor); ::memcpy((void*)m_world_mat.data(), (const void*)m.data(), 16 * sizeof(float)); @@ -344,7 +344,7 @@ void GLVolume::render() const ::glCullFace(GL_BACK); ::glPushMatrix(); - ::glTranslated(m_origin.x, m_origin.y, m_origin.z); + ::glTranslated(m_origin.x(), m_origin.y(), m_origin.z()); ::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f); ::glScalef(m_scale_factor, m_scale_factor, m_scale_factor); if (this->indexed_vertex_array.indexed()) @@ -378,7 +378,7 @@ void GLVolume::render_using_layer_height() const glUniform1f(z_texture_row_to_normalized_id, (GLfloat)(1.0f / layer_height_texture_height())); if (z_cursor_id >= 0) - glUniform1f(z_cursor_id, (GLfloat)(layer_height_texture_data.print_object->model_object()->bounding_box().max.z * layer_height_texture_data.z_cursor_relative)); + glUniform1f(z_cursor_id, (GLfloat)(layer_height_texture_data.print_object->model_object()->bounding_box().max.z() * layer_height_texture_data.z_cursor_relative)); if (z_cursor_band_width_id >= 0) glUniform1f(z_cursor_band_width_id, (GLfloat)layer_height_texture_data.edit_band_width); @@ -470,7 +470,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c ::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr); ::glPushMatrix(); - ::glTranslated(m_origin.x, m_origin.y, m_origin.z); + ::glTranslated(m_origin.x(), m_origin.y(), m_origin.z()); ::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f); ::glScalef(m_scale_factor, m_scale_factor, m_scale_factor); @@ -515,7 +515,7 @@ void GLVolume::render_legacy() const ::glNormalPointer(GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data()); ::glPushMatrix(); - ::glTranslated(m_origin.x, m_origin.y, m_origin.z); + ::glTranslated(m_origin.x(), m_origin.y(), m_origin.z()); ::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f); ::glScalef(m_scale_factor, m_scale_factor, m_scale_factor); @@ -530,7 +530,7 @@ void GLVolume::render_legacy() const double GLVolume::layer_height_texture_z_to_row_id() const { - return (this->layer_height_texture.get() == nullptr) ? 0.0 : double(this->layer_height_texture->cells - 1) / (double(this->layer_height_texture->width) * this->layer_height_texture_data.print_object->model_object()->bounding_box().max.z); + return (this->layer_height_texture.get() == nullptr) ? 0.0 : double(this->layer_height_texture->cells - 1) / (double(this->layer_height_texture->width) * this->layer_height_texture_data.print_object->model_object()->bounding_box().max.z()); } void GLVolume::generate_layer_height_texture(PrintObject *print_object, bool force) @@ -634,7 +634,7 @@ std::vector<int> GLVolumeCollection::load_object( } v.is_modifier = model_volume->modifier; v.outside_printer_detection_enabled = !model_volume->modifier; - v.set_origin(Pointf3(instance->offset.x, instance->offset.y, 0.0)); + v.set_origin(Pointf3(instance->offset.x(), instance->offset.y(), 0.0)); v.set_angle_z(instance->rotation); v.set_scale_factor(instance->scaling_factor); } @@ -748,9 +748,9 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M return false; BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values)); - BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x), unscale(bed_box_2D.min.y), 0.0), Pointf3(unscale(bed_box_2D.max.x), unscale(bed_box_2D.max.y), config->opt_float("max_print_height"))); + BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x()), unscale(bed_box_2D.min.y()), 0.0), Pointf3(unscale(bed_box_2D.max.x()), unscale(bed_box_2D.max.y()), config->opt_float("max_print_height"))); // Allow the objects to protrude below the print bed - print_volume.min.z = -1e10; + print_volume.min.z() = -1e10; ModelInstance::EPrintVolumeState state = ModelInstance::PVS_Inside; bool all_contained = true; @@ -945,8 +945,8 @@ static void thick_lines_to_indexed_vertex_array( Pointf b2 = b; { double dist = 0.5 * width; // scaled - double dx = dist * v.x; - double dy = dist * v.y; + double dx = dist * v.x(); + double dy = dist * v.y(); a1.translate(+dy, -dx); a2.translate(-dy, +dx); b1.translate(+dy, -dx); @@ -955,7 +955,7 @@ static void thick_lines_to_indexed_vertex_array( // calculate new XY normals Vector n = line.normal(); - Vectorf3 xy_right_normal = Vectorf3::new_unscale(n.x, n.y, 0); + Vectorf3 xy_right_normal = Vectorf3::new_unscale(n.x(), n.y(), 0); xy_right_normal.scale(inv_len); int idx_a[4]; @@ -974,7 +974,7 @@ static void thick_lines_to_indexed_vertex_array( // Share top / bottom vertices if possible. if (is_first) { idx_a[TOP] = idx_last++; - volume.push_geometry(a.x, a.y, top_z , 0., 0., 1.); + volume.push_geometry(a.x(), a.y(), top_z , 0., 0., 1.); } else { idx_a[TOP] = idx_prev[TOP]; } @@ -982,11 +982,11 @@ static void thick_lines_to_indexed_vertex_array( if (is_first || bottom_z_different) { // Start of the 1st line segment or a change of the layer thickness while maintaining the print_z. idx_a[BOTTOM] = idx_last ++; - volume.push_geometry(a.x, a.y, bottom_z, 0., 0., -1.); + volume.push_geometry(a.x(), a.y(), bottom_z, 0., 0., -1.); idx_a[LEFT ] = idx_last ++; - volume.push_geometry(a2.x, a2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z); + volume.push_geometry(a2.x(), a2.y(), middle_z, -xy_right_normal.x(), -xy_right_normal.y(), -xy_right_normal.z()); idx_a[RIGHT] = idx_last ++; - volume.push_geometry(a1.x, a1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z); + volume.push_geometry(a1.x(), a1.y(), middle_z, xy_right_normal.x(), xy_right_normal.y(), xy_right_normal.z()); } else { idx_a[BOTTOM] = idx_prev[BOTTOM]; @@ -1007,9 +1007,9 @@ static void thick_lines_to_indexed_vertex_array( { // Allocate new left / right points for the start of this segment as these points will receive their own normals to indicate a sharp turn. idx_a[RIGHT] = idx_last++; - volume.push_geometry(a1.x, a1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z); + volume.push_geometry(a1.x(), a1.y(), middle_z, xy_right_normal.x(), xy_right_normal.y(), xy_right_normal.z()); idx_a[LEFT] = idx_last++; - volume.push_geometry(a2.x, a2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z); + volume.push_geometry(a2.x(), a2.y(), middle_z, -xy_right_normal.x(), -xy_right_normal.y(), -xy_right_normal.z()); } } if (v_dot > 0.9) { @@ -1035,17 +1035,17 @@ static void thick_lines_to_indexed_vertex_array( float *p_left_prev = n_left_prev + 3; float *n_right_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6; float *p_right_prev = n_right_prev + 3; - p_left_prev [0] = float(a2.x); - p_left_prev [1] = float(a2.y); - p_right_prev[0] = float(a1.x); - p_right_prev[1] = float(a1.y); - xy_right_normal.x += n_right_prev[0]; - xy_right_normal.y += n_right_prev[1]; + p_left_prev [0] = float(a2.x()); + p_left_prev [1] = float(a2.y()); + p_right_prev[0] = float(a1.x()); + p_right_prev[1] = float(a1.y()); + xy_right_normal.x() += n_right_prev[0]; + xy_right_normal.y() += n_right_prev[1]; xy_right_normal.scale(1. / length(xy_right_normal)); - n_left_prev [0] = float(-xy_right_normal.x); - n_left_prev [1] = float(-xy_right_normal.y); - n_right_prev[0] = float( xy_right_normal.x); - n_right_prev[1] = float( xy_right_normal.y); + n_left_prev [0] = float(-xy_right_normal.x()); + n_left_prev [1] = float(-xy_right_normal.y()); + n_right_prev[0] = float( xy_right_normal.x()); + n_right_prev[1] = float( xy_right_normal.y()); idx_a[LEFT ] = idx_prev[LEFT ]; idx_a[RIGHT] = idx_prev[RIGHT]; } @@ -1086,20 +1086,20 @@ static void thick_lines_to_indexed_vertex_array( idx_b[TOP] = idx_initial[TOP]; } else { idx_b[TOP] = idx_last ++; - volume.push_geometry(b.x, b.y, top_z , 0., 0., 1.); + volume.push_geometry(b.x(), b.y(), top_z , 0., 0., 1.); } if (is_closing && (width == width_initial) && (bottom_z == bottom_z_initial)) { idx_b[BOTTOM] = idx_initial[BOTTOM]; } else { idx_b[BOTTOM] = idx_last ++; - volume.push_geometry(b.x, b.y, bottom_z, 0., 0., -1.); + volume.push_geometry(b.x(), b.y(), bottom_z, 0., 0., -1.); } // Generate new vertices for the end of this line segment. idx_b[LEFT ] = idx_last ++; - volume.push_geometry(b2.x, b2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z); + volume.push_geometry(b2.x(), b2.y(), middle_z, -xy_right_normal.x(), -xy_right_normal.y(), -xy_right_normal.z()); idx_b[RIGHT ] = idx_last ++; - volume.push_geometry(b1.x, b1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z); + volume.push_geometry(b1.x(), b1.y(), middle_z, xy_right_normal.x(), xy_right_normal.y(), xy_right_normal.z()); memcpy(idx_prev, idx_b, 4 * sizeof(int)); bottom_z_prev = bottom_z; @@ -1184,10 +1184,10 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines, Vectorf3 n_right; Vectorf3 unit_positive_z(0.0, 0.0, 1.0); - if ((line.a.x == line.b.x) && (line.a.y == line.b.y)) + if ((line.a.x() == line.b.x()) && (line.a.y() == line.b.y())) { // vertical segment - n_right = (line.a.z < line.b.z) ? Vectorf3(-1.0, 0.0, 0.0) : Vectorf3(1.0, 0.0, 0.0); + n_right = (line.a.z() < line.b.z()) ? Vectorf3(-1.0, 0.0, 0.0) : Vectorf3(1.0, 0.0, 0.0); n_top = Vectorf3(0.0, 1.0, 0.0); } else @@ -1218,8 +1218,8 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines, int idx_b[4]; int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6); - bool z_different = (z_prev != l_a.z); - z_prev = l_b.z; + bool z_different = (z_prev != l_a.z()); + z_prev = l_b.z(); // Share top / bottom vertices if possible. if (ii == 0) @@ -1288,25 +1288,25 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines, // updates previous line normals float* normal_left_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT] * 6; - normal_left_prev[0] = float(average_n_left.x); - normal_left_prev[1] = float(average_n_left.y); - normal_left_prev[2] = float(average_n_left.z); + normal_left_prev[0] = float(average_n_left.x()); + normal_left_prev[1] = float(average_n_left.y()); + normal_left_prev[2] = float(average_n_left.z()); float* normal_right_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6; - normal_right_prev[0] = float(average_n_right.x); - normal_right_prev[1] = float(average_n_right.y); - normal_right_prev[2] = float(average_n_right.z); + normal_right_prev[0] = float(average_n_right.x()); + normal_right_prev[1] = float(average_n_right.y()); + normal_right_prev[2] = float(average_n_right.z()); // updates previous line's vertices around b float* b_left_prev = normal_left_prev + 3; - b_left_prev[0] = float(a[LEFT].x); - b_left_prev[1] = float(a[LEFT].y); - b_left_prev[2] = float(a[LEFT].z); + b_left_prev[0] = float(a[LEFT].x()); + b_left_prev[1] = float(a[LEFT].y()); + b_left_prev[2] = float(a[LEFT].z()); float* b_right_prev = normal_right_prev + 3; - b_right_prev[0] = float(a[RIGHT].x); - b_right_prev[1] = float(a[RIGHT].y); - b_right_prev[2] = float(a[RIGHT].z); + b_right_prev[0] = float(a[RIGHT].x()); + b_right_prev[1] = float(a[RIGHT].y()); + b_right_prev[2] = float(a[RIGHT].z()); idx_a[LEFT] = idx_prev[LEFT]; idx_a[RIGHT] = idx_prev[RIGHT]; diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index a2ca1de7c..42666a955 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -120,7 +120,7 @@ public: } inline void push_geometry(const Pointf3& p, const Vectorf3& n) { - push_geometry(p.x, p.y, p.z, n.x, n.y, n.z); + push_geometry(p.x(), p.y(), p.z(), n.x(), n.y(), n.z()); } inline void push_triangle(int idx1, int idx2, int idx3) { @@ -176,17 +176,17 @@ public: BoundingBoxf3 bbox; if (! this->vertices_and_normals_interleaved.empty()) { bbox.defined = true; - bbox.min.x = bbox.max.x = this->vertices_and_normals_interleaved[3]; - bbox.min.y = bbox.max.y = this->vertices_and_normals_interleaved[4]; - bbox.min.z = bbox.max.z = this->vertices_and_normals_interleaved[5]; + bbox.min.x() = bbox.max.x() = this->vertices_and_normals_interleaved[3]; + bbox.min.y() = bbox.max.y() = this->vertices_and_normals_interleaved[4]; + bbox.min.z() = bbox.max.z() = this->vertices_and_normals_interleaved[5]; for (size_t i = 9; i < this->vertices_and_normals_interleaved.size(); i += 6) { const float *verts = this->vertices_and_normals_interleaved.data() + i; - bbox.min.x = std::min<coordf_t>(bbox.min.x, verts[0]); - bbox.min.y = std::min<coordf_t>(bbox.min.y, verts[1]); - bbox.min.z = std::min<coordf_t>(bbox.min.z, verts[2]); - bbox.max.x = std::max<coordf_t>(bbox.max.x, verts[0]); - bbox.max.y = std::max<coordf_t>(bbox.max.y, verts[1]); - bbox.max.z = std::max<coordf_t>(bbox.max.z, verts[2]); + bbox.min.x() = std::min<coordf_t>(bbox.min.x(), verts[0]); + bbox.min.y() = std::min<coordf_t>(bbox.min.y(), verts[1]); + bbox.min.z() = std::min<coordf_t>(bbox.min.z(), verts[2]); + bbox.max.x() = std::max<coordf_t>(bbox.max.x(), verts[0]); + bbox.max.y() = std::max<coordf_t>(bbox.max.y(), verts[1]); + bbox.max.z() = std::max<coordf_t>(bbox.max.z(), verts[2]); } } return bbox; diff --git a/xs/src/slic3r/GUI/BedShapeDialog.cpp b/xs/src/slic3r/GUI/BedShapeDialog.cpp index 3dd60ef88..170724956 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.cpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.cpp @@ -148,13 +148,13 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) // find origin // the || 0 hack prevents "-0" which might confuse the user int x_min, x_max, y_min, y_max; - x_max = x_min = points->values[0].x; - y_max = y_min = points->values[0].y; + x_max = x_min = points->values[0].x(); + y_max = y_min = points->values[0].y(); for (auto pt : points->values){ - if (x_min > pt.x) x_min = pt.x; - if (x_max < pt.x) x_max = pt.x; - if (y_min > pt.y) y_min = pt.y; - if (y_max < pt.y) y_max = pt.y; + if (x_min > pt.x()) x_min = pt.x(); + if (x_max < pt.x()) x_max = pt.x(); + if (y_min > pt.y()) y_min = pt.y(); + if (y_max < pt.y()) y_max = pt.y(); } if (x_min < 0) x_min = 0; if (x_max < 0) x_max = 0; @@ -242,8 +242,8 @@ void BedShapePanel::update_shape() catch (const std::exception &e){ return;} - auto x = rect_size.x; - auto y = rect_size.y; + auto x = rect_size.x(); + auto y = rect_size.y(); // empty strings or '-' or other things if (x == 0 || y == 0) return; double x0 = 0.0; @@ -251,8 +251,8 @@ void BedShapePanel::update_shape() double x1 = x; double y1 = y; - auto dx = rect_origin.x; - auto dy = rect_origin.y; + auto dx = rect_origin.x(); + auto dy = rect_origin.y(); x0 -= dx; x1 -= dx; diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 36a1c396f..4efda6398 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -629,9 +629,9 @@ void PointCtrl::BUILD() wxSize field_size(40, -1); auto default_pt = static_cast<ConfigOptionPoints*>(m_opt.default_value)->values.at(0); - double val = default_pt.x; + double val = default_pt.x(); wxString X = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None); - val = default_pt.y; + val = default_pt.y(); wxString Y = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None); x_textctrl = new wxTextCtrl(m_parent, wxID_ANY, X, wxDefaultPosition, field_size); @@ -656,9 +656,9 @@ void PointCtrl::set_value(const Pointf& value, bool change_event) { m_disable_change_event = !change_event; - double val = value.x; + double val = value.x(); x_textctrl->SetValue(val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None)); - val = value.y; + val = value.y(); y_textctrl->SetValue(val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None)); m_disable_change_event = false; @@ -683,9 +683,9 @@ boost::any& PointCtrl::get_value() Pointf ret_point; double val; x_textctrl->GetValue().ToDouble(&val); - ret_point.x = val; + ret_point.x() = val; y_textctrl->GetValue().ToDouble(&val); - ret_point.y = val; + ret_point.y() = val; return m_value = ret_point; } diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 064a9adce..05feb6314 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -68,8 +68,8 @@ bool GeometryBuffer::set_from_triangles(const Polygons& triangles, float z, bool if (generate_tex_coords) m_tex_coords = std::vector<float>(t_size, 0.0f); - float min_x = (float)unscale(triangles[0].points[0].x); - float min_y = (float)unscale(triangles[0].points[0].y); + float min_x = (float)unscale(triangles[0].points[0].x()); + float min_y = (float)unscale(triangles[0].points[0].y()); float max_x = min_x; float max_y = min_y; @@ -80,8 +80,8 @@ bool GeometryBuffer::set_from_triangles(const Polygons& triangles, float z, bool for (unsigned int v = 0; v < 3; ++v) { const Point& p = t.points[v]; - float x = (float)unscale(p.x); - float y = (float)unscale(p.y); + float x = (float)unscale(p.x()); + float y = (float)unscale(p.y()); m_vertices[v_coord++] = x; m_vertices[v_coord++] = y; @@ -134,11 +134,11 @@ bool GeometryBuffer::set_from_lines(const Lines& lines, float z) unsigned int coord = 0; for (const Line& l : lines) { - m_vertices[coord++] = (float)unscale(l.a.x); - m_vertices[coord++] = (float)unscale(l.a.y); + m_vertices[coord++] = (float)unscale(l.a.x()); + m_vertices[coord++] = (float)unscale(l.a.y()); m_vertices[coord++] = z; - m_vertices[coord++] = (float)unscale(l.b.x); - m_vertices[coord++] = (float)unscale(l.b.y); + m_vertices[coord++] = (float)unscale(l.b.x()); + m_vertices[coord++] = (float)unscale(l.b.y()); m_vertices[coord++] = z; } @@ -312,7 +312,7 @@ void GLCanvas3D::Bed::set_shape(const Pointfs& shape) ExPolygon poly; for (const Pointf& p : m_shape) { - poly.contour.append(Point(scale_(p.x), scale_(p.y))); + poly.contour.append(Point(scale_(p.x()), scale_(p.y()))); } _calc_triangles(poly); @@ -366,7 +366,7 @@ void GLCanvas3D::Bed::_calc_bounding_box() m_bounding_box = BoundingBoxf3(); for (const Pointf& p : m_shape) { - m_bounding_box.merge(Pointf3(p.x, p.y, 0.0)); + m_bounding_box.merge(Pointf3(p.x(), p.y(), 0.0)); } } @@ -382,18 +382,18 @@ void GLCanvas3D::Bed::_calc_triangles(const ExPolygon& poly) void GLCanvas3D::Bed::_calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox) { Polylines axes_lines; - for (coord_t x = bed_bbox.min.x; x <= bed_bbox.max.x; x += scale_(10.0)) + for (coord_t x = bed_bbox.min.x(); x <= bed_bbox.max.x(); x += scale_(10.0)) { Polyline line; - line.append(Point(x, bed_bbox.min.y)); - line.append(Point(x, bed_bbox.max.y)); + line.append(Point(x, bed_bbox.min.y())); + line.append(Point(x, bed_bbox.max.y())); axes_lines.push_back(line); } - for (coord_t y = bed_bbox.min.y; y <= bed_bbox.max.y; y += scale_(10.0)) + for (coord_t y = bed_bbox.min.y(); y <= bed_bbox.max.y(); y += scale_(10.0)) { Polyline line; - line.append(Point(bed_bbox.min.x, y)); - line.append(Point(bed_bbox.max.x, y)); + line.append(Point(bed_bbox.min.x(), y)); + line.append(Point(bed_bbox.max.x(), y)); axes_lines.push_back(line); } @@ -597,12 +597,12 @@ void GLCanvas3D::Axes::render(bool depth_test) const ::glBegin(GL_LINES); // draw line for x axis ::glColor3f(1.0f, 0.0f, 0.0f); - ::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y, (GLfloat)origin.z); - ::glVertex3f((GLfloat)origin.x + length, (GLfloat)origin.y, (GLfloat)origin.z); + ::glVertex3f((GLfloat)origin.x(), (GLfloat)origin.y(), (GLfloat)origin.z()); + ::glVertex3f((GLfloat)origin.x() + length, (GLfloat)origin.y(), (GLfloat)origin.z()); // draw line for y axis ::glColor3f(0.0f, 1.0f, 0.0f); - ::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y, (GLfloat)origin.z); - ::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y + length, (GLfloat)origin.z); + ::glVertex3f((GLfloat)origin.x(), (GLfloat)origin.y(), (GLfloat)origin.z()); + ::glVertex3f((GLfloat)origin.x(), (GLfloat)origin.y() + length, (GLfloat)origin.z()); ::glEnd(); // draw line for Z axis // (re-enable depth test so that axis is correctly shown when objects are behind it) @@ -611,8 +611,8 @@ void GLCanvas3D::Axes::render(bool depth_test) const ::glBegin(GL_LINES); ::glColor3f(0.0f, 0.0f, 1.0f); - ::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y, (GLfloat)origin.z); - ::glVertex3f((GLfloat)origin.x, (GLfloat)origin.y, (GLfloat)origin.z + length); + ::glVertex3f((GLfloat)origin.x(), (GLfloat)origin.y(), (GLfloat)origin.z()); + ::glVertex3f((GLfloat)origin.x(), (GLfloat)origin.y(), (GLfloat)origin.z() + length); ::glEnd(); } @@ -646,10 +646,10 @@ void GLCanvas3D::CuttingPlane::_render_plane(const BoundingBoxf3& bb) const ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); float margin = 20.0f; - float min_x = bb.min.x - margin; - float max_x = bb.max.x + margin; - float min_y = bb.min.y - margin; - float max_y = bb.max.y + margin; + float min_x = bb.min.x() - margin; + float max_x = bb.max.x() + margin; + float min_y = bb.min.y() - margin; + float max_y = bb.max.y() + margin; ::glBegin(GL_QUADS); ::glColor4f(0.8f, 0.8f, 0.8f, 0.5f); @@ -860,8 +860,8 @@ float GLCanvas3D::LayersEditing::get_cursor_z_relative(const GLCanvas3D& canvas) { const Point& mouse_pos = canvas.get_local_mouse_position(); const Rect& rect = get_bar_rect_screen(canvas); - float x = (float)mouse_pos.x; - float y = (float)mouse_pos.y; + float x = (float)mouse_pos.x(); + float y = (float)mouse_pos.y(); float t = rect.get_top(); float b = rect.get_bottom(); @@ -970,7 +970,7 @@ void GLCanvas3D::LayersEditing::_render_reset_texture(const Rect& reset_rect) co void GLCanvas3D::LayersEditing::_render_active_object_annotations(const GLCanvas3D& canvas, const GLVolume& volume, const PrintObject& print_object, const Rect& bar_rect) const { - float max_z = print_object.model_object()->bounding_box().max.z; + float max_z = print_object.model_object()->bounding_box().max.z(); m_shader.start_using(); @@ -1031,7 +1031,7 @@ void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object, // Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region. layer_height_max *= 1.12; - coordf_t max_z = unscale(print_object.size.z); + coordf_t max_z = unscale(print_object.size.z()); double layer_height = dynamic_cast<const ConfigOptionFloat*>(print_object.config.option("layer_height"))->value; float l = bar_rect.get_left(); float w = bar_rect.get_right() - l; @@ -1951,15 +1951,15 @@ void GLCanvas3D::set_auto_bed_shape() Pointfs bed_shape; bed_shape.reserve(4); - bed_shape.emplace_back(center.x - max_size, center.y - max_size); - bed_shape.emplace_back(center.x + max_size, center.y - max_size); - bed_shape.emplace_back(center.x + max_size, center.y + max_size); - bed_shape.emplace_back(center.x - max_size, center.y + max_size); + bed_shape.emplace_back(center.x() - max_size, center.y() - max_size); + bed_shape.emplace_back(center.x() + max_size, center.y() - max_size); + bed_shape.emplace_back(center.x() + max_size, center.y() + max_size); + bed_shape.emplace_back(center.x() - max_size, center.y() + max_size); set_bed_shape(bed_shape); // Set the origin for painting of the coordinate system axes. - m_axes.origin = Pointf3(center.x, center.y, (coordf_t)GROUND_Z); + m_axes.origin = Pointf3(center.x(), center.y(), (coordf_t)GROUND_Z); } void GLCanvas3D::set_axes_length(float length) @@ -2283,7 +2283,7 @@ void GLCanvas3D::reload_scene(bool force) if ((extruders_count > 1) && semm && wt && !co) { // Height of a print (Show at least a slab) - coordf_t height = std::max(m_model->bounding_box().max.z, 10.0); + coordf_t height = std::max(m_model->bounding_box().max.z(), 10.0); float x = dynamic_cast<const ConfigOptionFloat*>(m_config->option("wipe_tower_x"))->value; float y = dynamic_cast<const ConfigOptionFloat*>(m_config->option("wipe_tower_y"))->value; @@ -3031,14 +3031,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // on a volume or not. int volume_idx = m_hover_volume_id; m_layers_editing.state = LayersEditing::Unknown; - if ((layer_editing_object_idx != -1) && m_layers_editing.bar_rect_contains(*this, pos.x, pos.y)) + if ((layer_editing_object_idx != -1) && m_layers_editing.bar_rect_contains(*this, pos.x(), pos.y())) { // A volume is selected and the mouse is inside the layer thickness bar. // Start editing the layer height. m_layers_editing.state = LayersEditing::Editing; _perform_layer_editing_action(&evt); } - else if ((layer_editing_object_idx != -1) && m_layers_editing.reset_rect_contains(*this, pos.x, pos.y)) + else if ((layer_editing_object_idx != -1) && m_layers_editing.reset_rect_contains(*this, pos.x(), pos.y())) { if (evt.LeftDown()) { @@ -3121,7 +3121,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { // if right clicking on volume, propagate event through callback if (m_volumes.volumes[volume_idx]->hover) - m_on_right_click_callback.call(pos.x, pos.y); + m_on_right_click_callback.call(pos.x(), pos.y()); } } } @@ -3133,16 +3133,16 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // Get new position at the same Z of the initial click point. float z0 = 0.0f; float z1 = 1.0f; - Pointf3 cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D.z); + Pointf3 cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D.z()); // Clip the new position, so the object center remains close to the bed. cur_pos.translate(m_mouse.drag.volume_center_offset); - Point cur_pos2(scale_(cur_pos.x), scale_(cur_pos.y)); + Point cur_pos2(scale_(cur_pos.x()), scale_(cur_pos.y())); if (!m_bed.contains(cur_pos2)) { Point ip = m_bed.point_projection(cur_pos2); - cur_pos.x = unscale(ip.x); - cur_pos.y = unscale(ip.y); + cur_pos.x() = unscale(ip.x()); + cur_pos.y() = unscale(ip.y()); } cur_pos.translate(m_mouse.drag.volume_center_offset.negative()); @@ -3171,7 +3171,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) for (GLVolume* v : volumes) { Pointf3 origin = v->get_origin(); - origin.translate(vector.x, vector.y, 0.0); + origin.translate(vector.x(), vector.y(), 0.0); v->set_origin(origin); } @@ -3185,7 +3185,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_mouse.dragging = true; const Pointf3& cur_pos = _mouse_to_bed_3d(pos); - m_gizmos.update(Pointf(cur_pos.x, cur_pos.y)); + m_gizmos.update(Pointf(cur_pos.x(), cur_pos.y())); std::vector<GLVolume*> volumes; if (m_mouse.drag.gizmo_volume_idx != -1) @@ -3234,7 +3234,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { const BoundingBoxf3& bb = volumes[0]->transformed_bounding_box(); const Pointf3& size = bb.size(); - m_on_update_geometry_info_callback.call(size.x, size.y, size.z, m_gizmos.get_scale()); + m_on_update_geometry_info_callback.call(size.x(), size.y(), size.z(), m_gizmos.get_scale()); } if ((m_gizmos.get_current_type() != Gizmos::Rotate) && (volumes.size() > 1)) @@ -3257,14 +3257,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (m_mouse.is_start_position_3D_defined()) { const Pointf3& orig = m_mouse.drag.start_position_3D; - m_camera.phi += (((float)pos.x - (float)orig.x) * TRACKBALLSIZE); - m_camera.set_theta(m_camera.get_theta() - ((float)pos.y - (float)orig.y) * TRACKBALLSIZE); + m_camera.phi += (((float)pos.x() - (float)orig.x()) * TRACKBALLSIZE); + m_camera.set_theta(m_camera.get_theta() - ((float)pos.y() - (float)orig.y()) * TRACKBALLSIZE); m_on_viewport_changed_callback.call(); m_dirty = true; } - m_mouse.drag.start_position_3D = Pointf3((coordf_t)pos.x, (coordf_t)pos.y, 0.0); + m_mouse.drag.start_position_3D = Pointf3((coordf_t)pos.x(), (coordf_t)pos.y(), 0.0); } else if (evt.MiddleIsDown() || evt.RightIsDown()) { @@ -3355,7 +3355,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } else if (evt.Moving()) { - m_mouse.position = Pointf((coordf_t)pos.x, (coordf_t)pos.y); + m_mouse.position = Pointf((coordf_t)pos.x(), (coordf_t)pos.y()); // Only refresh if picking is enabled, in that case the objects may get highlighted if the mouse cursor hovers over. if (m_picking_enabled) m_dirty = true; @@ -3553,13 +3553,13 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co std::vector<Pointf3> vertices; vertices.reserve(8); vertices.push_back(bb_min); - vertices.emplace_back(bb_max.x, bb_min.y, bb_min.z); - vertices.emplace_back(bb_max.x, bb_max.y, bb_min.z); - vertices.emplace_back(bb_min.x, bb_max.y, bb_min.z); - vertices.emplace_back(bb_min.x, bb_min.y, bb_max.z); - vertices.emplace_back(bb_max.x, bb_min.y, bb_max.z); + vertices.emplace_back(bb_max.x(), bb_min.y(), bb_min.z()); + vertices.emplace_back(bb_max.x(), bb_max.y(), bb_min.z()); + vertices.emplace_back(bb_min.x(), bb_max.y(), bb_min.z()); + vertices.emplace_back(bb_min.x(), bb_min.y(), bb_max.z()); + vertices.emplace_back(bb_max.x(), bb_min.y(), bb_max.z()); vertices.push_back(bb_max); - vertices.emplace_back(bb_min.x, bb_max.y, bb_max.z); + vertices.emplace_back(bb_min.x(), bb_max.y(), bb_max.z()); coordf_t max_x = 0.0; coordf_t max_y = 0.0; @@ -3570,7 +3570,7 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co for (const Pointf3 v : vertices) { // project vertex on the plane perpendicular to camera forward axis - Pointf3 pos(v.x - bb_center.x, v.y - bb_center.y, v.z - bb_center.z); + Pointf3 pos(v.x() - bb_center.x(), v.y() - bb_center.y(), v.z() - bb_center.z()); Pointf3 proj_on_plane = pos - dot(pos, forward) * forward; // calculates vertex coordinate along camera xy axes @@ -3654,7 +3654,7 @@ void GLCanvas3D::_camera_tranform() const ::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f); // yaw Pointf3 neg_target = m_camera.target.negative(); - ::glTranslatef((GLfloat)neg_target.x, (GLfloat)neg_target.y, (GLfloat)neg_target.z); + ::glTranslatef((GLfloat)neg_target.x(), (GLfloat)neg_target.y(), (GLfloat)neg_target.z()); } void GLCanvas3D::_picking_pass() const @@ -3684,7 +3684,7 @@ void GLCanvas3D::_picking_pass() const const Size& cnv_size = get_canvas_size(); GLubyte color[4]; - ::glReadPixels(pos.x, cnv_size.get_height() - pos.y - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color); + ::glReadPixels(pos.x(), cnv_size.get_height() - pos.y() - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color); int volume_id = color[0] + color[1] * 256 + color[2] * 256 * 256; m_hover_volume_id = -1; @@ -3779,7 +3779,7 @@ void GLCanvas3D::_render_objects() const if (m_config != nullptr) { const BoundingBoxf3& bed_bb = m_bed.get_bounding_box(); - m_volumes.set_print_box((float)bed_bb.min.x, (float)bed_bb.min.y, 0.0f, (float)bed_bb.max.x, (float)bed_bb.max.y, (float)m_config->opt_float("max_print_height")); + m_volumes.set_print_box((float)bed_bb.min.x(), (float)bed_bb.min.y(), 0.0f, (float)bed_bb.max.x(), (float)bed_bb.max.y(), (float)m_config->opt_float("max_print_height")); m_volumes.check_outside_state(m_config, nullptr); } // do not cull backfaces to show broken geometry, if any @@ -3986,7 +3986,7 @@ void GLCanvas3D::_perform_layer_editing_action(wxMouseEvent* evt) { const Rect& rect = LayersEditing::get_bar_rect_screen(*this); float b = rect.get_bottom(); - m_layers_editing.last_z = unscale(selected_obj->size.z) * (b - evt->GetY() - 1.0f) / (b - rect.get_top()); + m_layers_editing.last_z = unscale(selected_obj->size.z()) * (b - evt->GetY() - 1.0f) / (b - rect.get_top()); m_layers_editing.last_action = evt->ShiftDown() ? (evt->RightIsDown() ? 3 : 2) : (evt->RightIsDown() ? 0 : 1); } @@ -4030,15 +4030,15 @@ Pointf3 GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) GLdouble projection_matrix[16]; ::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix); - GLint y = viewport[3] - (GLint)mouse_pos.y; + GLint y = viewport[3] - (GLint)mouse_pos.y(); GLfloat mouse_z; if (z == nullptr) - ::glReadPixels((GLint)mouse_pos.x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z); + ::glReadPixels((GLint)mouse_pos.x(), y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z); else mouse_z = *z; GLdouble out_x, out_y, out_z; - ::gluUnProject((GLdouble)mouse_pos.x, (GLdouble)y, (GLdouble)mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z); + ::gluUnProject((GLdouble)mouse_pos.x(), (GLdouble)y, (GLdouble)mouse_z, modelview_matrix, projection_matrix, viewport, &out_x, &out_y, &out_z); return Pointf3((coordf_t)out_x, (coordf_t)out_y, (coordf_t)out_z); } @@ -4389,7 +4389,7 @@ bool GLCanvas3D::_travel_paths_by_type(const GCodePreviewData& preview_data) TypesList::iterator type = std::find(types.begin(), types.end(), Type(polyline.type)); if (type != types.end()) { - type->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z)); + type->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z())); type->volume->offsets.push_back(type->volume->indexed_vertex_array.quad_indices.size()); type->volume->offsets.push_back(type->volume->indexed_vertex_array.triangle_indices.size()); @@ -4455,7 +4455,7 @@ bool GLCanvas3D::_travel_paths_by_feedrate(const GCodePreviewData& preview_data) FeedratesList::iterator feedrate = std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate)); if (feedrate != feedrates.end()) { - feedrate->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z)); + feedrate->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z())); feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.quad_indices.size()); feedrate->volume->offsets.push_back(feedrate->volume->indexed_vertex_array.triangle_indices.size()); @@ -4521,7 +4521,7 @@ bool GLCanvas3D::_travel_paths_by_tool(const GCodePreviewData& preview_data, con ToolsList::iterator tool = std::find(tools.begin(), tools.end(), Tool(polyline.extruder_id)); if (tool != tools.end()) { - tool->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z)); + tool->volume->print_zs.push_back(unscale(polyline.polyline.bounding_box().min.z())); tool->volume->offsets.push_back(tool->volume->indexed_vertex_array.quad_indices.size()); tool->volume->offsets.push_back(tool->volume->indexed_vertex_array.triangle_indices.size()); @@ -4546,11 +4546,11 @@ void GLCanvas3D::_load_gcode_retractions(const GCodePreviewData& preview_data) m_volumes.volumes.emplace_back(volume); GCodePreviewData::Retraction::PositionsList copy(preview_data.retraction.positions); - std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2){ return p1.position.z < p2.position.z; }); + std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2){ return p1.position.z() < p2.position.z(); }); for (const GCodePreviewData::Retraction::Position& position : copy) { - volume->print_zs.push_back(unscale(position.position.z)); + volume->print_zs.push_back(unscale(position.position.z())); volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size()); volume->offsets.push_back(volume->indexed_vertex_array.triangle_indices.size()); @@ -4577,11 +4577,11 @@ void GLCanvas3D::_load_gcode_unretractions(const GCodePreviewData& preview_data) m_volumes.volumes.emplace_back(volume); GCodePreviewData::Retraction::PositionsList copy(preview_data.unretraction.positions); - std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2){ return p1.position.z < p2.position.z; }); + std::sort(copy.begin(), copy.end(), [](const GCodePreviewData::Retraction::Position& p1, const GCodePreviewData::Retraction::Position& p2){ return p1.position.z() < p2.position.z(); }); for (const GCodePreviewData::Retraction::Position& position : copy) { - volume->print_zs.push_back(unscale(position.position.z)); + volume->print_zs.push_back(unscale(position.position.z())); volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size()); volume->offsets.push_back(volume->indexed_vertex_array.triangle_indices.size()); @@ -4621,7 +4621,7 @@ void GLCanvas3D::_load_shells() } // adds wipe tower's volume - coordf_t max_z = m_print->objects[0]->model_object()->get_model()->bounding_box().max.z; + coordf_t max_z = m_print->objects[0]->model_object()->get_model()->bounding_box().max.z(); const PrintConfig& config = m_print->config; unsigned int extruders_count = config.nozzle_diameter.size(); if ((extruders_count > 1) && config.single_extruder_multi_material && config.wipe_tower && !config.complete_objects) { @@ -4716,7 +4716,7 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs) // Move a regular object. ModelObject* model_object = m_model->objects[obj_idx]; const Pointf3& origin = volume->get_origin(); - model_object->instances[instance_idx]->offset = Pointf(origin.x, origin.y); + model_object->instances[instance_idx]->offset = Pointf(origin.x(), origin.y()); model_object->invalidate_bounding_box(); object_moved = true; } @@ -4729,7 +4729,7 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs) m_on_instance_moved_callback.call(); if (wipe_tower_origin != Pointf3(0.0, 0.0, 0.0)) - m_on_wipe_tower_moved_callback.call(wipe_tower_origin.x, wipe_tower_origin.y); + m_on_wipe_tower_moved_callback.call(wipe_tower_origin.x(), wipe_tower_origin.y()); } void GLCanvas3D::_on_select(int volume_idx) diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 47b01e8a2..b67a5bedc 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -35,7 +35,7 @@ void GLGizmoBase::Grabber::render(bool hover) const float angle_z_in_deg = angle_z * 180.0f / (float)PI; ::glPushMatrix(); - ::glTranslatef((GLfloat)center.x, (GLfloat)center.y, 0.0f); + ::glTranslatef((GLfloat)center.x(), (GLfloat)center.y(), 0.0f); ::glRotatef((GLfloat)angle_z_in_deg, 0.0f, 0.0f, 1.0f); ::glDisable(GL_CULL_FACE); @@ -266,7 +266,7 @@ void GLGizmoRotate::on_render(const BoundingBoxf3& box) const m_center = box.center(); if (!m_keep_radius) { - m_radius = Offset + ::sqrt(sqr(0.5f * size.x) + sqr(0.5f * size.y)); + m_radius = Offset + ::sqrt(sqr(0.5f * size.x()) + sqr(0.5f * size.y())); m_keep_radius = true; } @@ -299,8 +299,8 @@ void GLGizmoRotate::_render_circle() const for (unsigned int i = 0; i < ScaleStepsCount; ++i) { float angle = (float)i * ScaleStepRad; - float x = m_center.x + ::cos(angle) * m_radius; - float y = m_center.y + ::sin(angle) * m_radius; + float x = m_center.x() + ::cos(angle) * m_radius; + float y = m_center.y() + ::sin(angle) * m_radius; ::glVertex3f((GLfloat)x, (GLfloat)y, 0.0f); } ::glEnd(); @@ -317,10 +317,10 @@ void GLGizmoRotate::_render_scale() const float angle = (float)i * ScaleStepRad; float cosa = ::cos(angle); float sina = ::sin(angle); - float in_x = m_center.x + cosa * m_radius; - float in_y = m_center.y + sina * m_radius; - float out_x = (i % ScaleLongEvery == 0) ? m_center.x + cosa * out_radius_long : m_center.x + cosa * out_radius_short; - float out_y = (i % ScaleLongEvery == 0) ? m_center.y + sina * out_radius_long : m_center.y + sina * out_radius_short; + float in_x = m_center.x() + cosa * m_radius; + float in_y = m_center.y() + sina * m_radius; + float out_x = (i % ScaleLongEvery == 0) ? m_center.x() + cosa * out_radius_long : m_center.x() + cosa * out_radius_short; + float out_y = (i % ScaleLongEvery == 0) ? m_center.y() + sina * out_radius_long : m_center.y() + sina * out_radius_short; ::glVertex3f((GLfloat)in_x, (GLfloat)in_y, 0.0f); ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, 0.0f); } @@ -340,10 +340,10 @@ void GLGizmoRotate::_render_snap_radii() const float angle = (float)i * step; float cosa = ::cos(angle); float sina = ::sin(angle); - float in_x = m_center.x + cosa * in_radius; - float in_y = m_center.y + sina * in_radius; - float out_x = m_center.x + cosa * out_radius; - float out_y = m_center.y + sina * out_radius; + float in_x = m_center.x() + cosa * in_radius; + float in_y = m_center.y() + sina * in_radius; + float out_x = m_center.x() + cosa * out_radius; + float out_y = m_center.y() + sina * out_radius; ::glVertex3f((GLfloat)in_x, (GLfloat)in_y, 0.0f); ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, 0.0f); } @@ -353,8 +353,8 @@ void GLGizmoRotate::_render_snap_radii() const void GLGizmoRotate::_render_reference_radius() const { ::glBegin(GL_LINES); - ::glVertex3f((GLfloat)m_center.x, (GLfloat)m_center.y, 0.0f); - ::glVertex3f((GLfloat)m_center.x + m_radius + GrabberOffset, (GLfloat)m_center.y, 0.0f); + ::glVertex3f((GLfloat)m_center.x(), (GLfloat)m_center.y(), 0.0f); + ::glVertex3f((GLfloat)m_center.x() + m_radius + GrabberOffset, (GLfloat)m_center.y(), 0.0f); ::glEnd(); } @@ -367,8 +367,8 @@ void GLGizmoRotate::_render_angle_z() const for (unsigned int i = 0; i <= AngleResolution; ++i) { float angle = (float)i * step_angle; - float x = m_center.x + ::cos(angle) * ex_radius; - float y = m_center.y + ::sin(angle) * ex_radius; + float x = m_center.x() + ::cos(angle) * ex_radius; + float y = m_center.y() + ::sin(angle) * ex_radius; ::glVertex3f((GLfloat)x, (GLfloat)y, 0.0f); } ::glEnd(); @@ -377,14 +377,14 @@ void GLGizmoRotate::_render_angle_z() const void GLGizmoRotate::_render_grabber() const { float grabber_radius = m_radius + GrabberOffset; - m_grabbers[0].center.x = m_center.x + ::cos(m_angle_z) * grabber_radius; - m_grabbers[0].center.y = m_center.y + ::sin(m_angle_z) * grabber_radius; + m_grabbers[0].center.x() = m_center.x() + ::cos(m_angle_z) * grabber_radius; + m_grabbers[0].center.y() = m_center.y() + ::sin(m_angle_z) * grabber_radius; m_grabbers[0].angle_z = m_angle_z; ::glColor3fv(BaseColor); ::glBegin(GL_LINES); - ::glVertex3f((GLfloat)m_center.x, (GLfloat)m_center.y, 0.0f); - ::glVertex3f((GLfloat)m_grabbers[0].center.x, (GLfloat)m_grabbers[0].center.y, 0.0f); + ::glVertex3f((GLfloat)m_center.x(), (GLfloat)m_center.y(), 0.0f); + ::glVertex3f((GLfloat)m_grabbers[0].center.x(), (GLfloat)m_grabbers[0].center.y(), 0.0f); ::glEnd(); ::memcpy((void*)m_grabbers[0].color, (const void*)HighlightColor, 3 * sizeof(float)); @@ -442,7 +442,7 @@ void GLGizmoScale::on_start_dragging() void GLGizmoScale::on_update(const Pointf& mouse_pos) { - Pointf center(0.5 * (m_grabbers[1].center.x + m_grabbers[0].center.x), 0.5 * (m_grabbers[3].center.y + m_grabbers[0].center.y)); + Pointf center(0.5 * (m_grabbers[1].center.x() + m_grabbers[0].center.x()), 0.5 * (m_grabbers[3].center.y() + m_grabbers[0].center.y())); coordf_t orig_len = length(m_starting_drag_position - center); coordf_t new_len = length(mouse_pos - center); @@ -455,19 +455,19 @@ void GLGizmoScale::on_render(const BoundingBoxf3& box) const { ::glDisable(GL_DEPTH_TEST); - coordf_t min_x = box.min.x - (coordf_t)Offset; - coordf_t max_x = box.max.x + (coordf_t)Offset; - coordf_t min_y = box.min.y - (coordf_t)Offset; - coordf_t max_y = box.max.y + (coordf_t)Offset; + coordf_t min_x = box.min.x() - (coordf_t)Offset; + coordf_t max_x = box.max.x() + (coordf_t)Offset; + coordf_t min_y = box.min.y() - (coordf_t)Offset; + coordf_t max_y = box.max.y() + (coordf_t)Offset; - m_grabbers[0].center.x = min_x; - m_grabbers[0].center.y = min_y; - m_grabbers[1].center.x = max_x; - m_grabbers[1].center.y = min_y; - m_grabbers[2].center.x = max_x; - m_grabbers[2].center.y = max_y; - m_grabbers[3].center.x = min_x; - m_grabbers[3].center.y = max_y; + m_grabbers[0].center.x() = min_x; + m_grabbers[0].center.y() = min_y; + m_grabbers[1].center.x() = max_x; + m_grabbers[1].center.y() = min_y; + m_grabbers[2].center.x() = max_x; + m_grabbers[2].center.y() = max_y; + m_grabbers[3].center.x() = min_x; + m_grabbers[3].center.y() = max_y; ::glLineWidth(2.0f); ::glColor3fv(BaseColor); @@ -475,7 +475,7 @@ void GLGizmoScale::on_render(const BoundingBoxf3& box) const ::glBegin(GL_LINE_LOOP); for (unsigned int i = 0; i < 4; ++i) { - ::glVertex3f((GLfloat)m_grabbers[i].center.x, (GLfloat)m_grabbers[i].center.y, 0.0f); + ::glVertex3f((GLfloat)m_grabbers[i].center.x(), (GLfloat)m_grabbers[i].center.y(), 0.0f); } ::glEnd(); diff --git a/xs/src/xsinit.h b/xs/src/xsinit.h index 9365f1979..f6080660c 100644 --- a/xs/src/xsinit.h +++ b/xs/src/xsinit.h @@ -68,6 +68,13 @@ extern "C" { #undef fputc #undef fwrite #undef fclose + + // Breaks compilation with Eigen matrices embedded into Slic3r::Point. + #undef malloc + #undef realloc + #undef free + #undef Zero + #undef select #endif /* _MSC_VER */ } #endif diff --git a/xs/xsp/BoundingBox.xsp b/xs/xsp/BoundingBox.xsp index ebeb17822..cfc11b40f 100644 --- a/xs/xsp/BoundingBox.xsp +++ b/xs/xsp/BoundingBox.xsp @@ -25,15 +25,15 @@ double radius(); Clone<Point> min_point() %code{% RETVAL = THIS->min; %}; Clone<Point> max_point() %code{% RETVAL = THIS->max; %}; - int x_min() %code{% RETVAL = THIS->min.x; %}; - int x_max() %code{% RETVAL = THIS->max.x; %}; - int y_min() %code{% RETVAL = THIS->min.y; %}; - int y_max() %code{% RETVAL = THIS->max.y; %}; - void set_x_min(double val) %code{% THIS->min.x = val; %}; - void set_x_max(double val) %code{% THIS->max.x = val; %}; - void set_y_min(double val) %code{% THIS->min.y = val; %}; - void set_y_max(double val) %code{% THIS->max.y = val; %}; - std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld;%ld,%ld", THIS->min.x, THIS->min.y, THIS->max.x, THIS->max.y); RETVAL = buf; %}; + int x_min() %code{% RETVAL = THIS->min.x(); %}; + int x_max() %code{% RETVAL = THIS->max.x(); %}; + int y_min() %code{% RETVAL = THIS->min.y(); %}; + int y_max() %code{% RETVAL = THIS->max.y(); %}; + void set_x_min(double val) %code{% THIS->min.x() = val; %}; + void set_x_max(double val) %code{% THIS->max.x() = val; %}; + void set_y_min(double val) %code{% THIS->min.y() = val; %}; + void set_y_max(double val) %code{% THIS->max.y() = val; %}; + std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld;%ld,%ld", THIS->min.x(), THIS->min.y(), THIS->max.x(), THIS->max.y()); RETVAL = buf; %}; bool defined() %code{% RETVAL = THIS->defined; %}; %{ @@ -65,15 +65,15 @@ new_from_points(CLASS, points) bool empty() %code{% RETVAL = empty(*THIS); %}; Clone<Pointf> min_point() %code{% RETVAL = THIS->min; %}; Clone<Pointf> max_point() %code{% RETVAL = THIS->max; %}; - double x_min() %code{% RETVAL = THIS->min.x; %}; - double x_max() %code{% RETVAL = THIS->max.x; %}; - double y_min() %code{% RETVAL = THIS->min.y; %}; - double y_max() %code{% RETVAL = THIS->max.y; %}; - void set_x_min(double val) %code{% THIS->min.x = val; %}; - void set_x_max(double val) %code{% THIS->max.x = val; %}; - void set_y_min(double val) %code{% THIS->min.y = val; %}; - void set_y_max(double val) %code{% THIS->max.y = val; %}; - std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf;%lf,%lf", THIS->min.x, THIS->min.y, THIS->max.x, THIS->max.y); RETVAL = buf; %}; + double x_min() %code{% RETVAL = THIS->min.x(); %}; + double x_max() %code{% RETVAL = THIS->max.x(); %}; + double y_min() %code{% RETVAL = THIS->min.y(); %}; + double y_max() %code{% RETVAL = THIS->max.y(); %}; + void set_x_min(double val) %code{% THIS->min.x() = val; %}; + void set_x_max(double val) %code{% THIS->max.x() = val; %}; + void set_y_min(double val) %code{% THIS->min.y() = val; %}; + void set_y_max(double val) %code{% THIS->max.y() = val; %}; + std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf;%lf,%lf", THIS->min.x(), THIS->min.y(), THIS->max.x(), THIS->max.y()); RETVAL = buf; %}; bool defined() %code{% RETVAL = THIS->defined; %}; %{ @@ -107,12 +107,12 @@ new_from_points(CLASS, points) bool empty() %code{% RETVAL = empty(*THIS); %}; Clone<Pointf3> min_point() %code{% RETVAL = THIS->min; %}; Clone<Pointf3> max_point() %code{% RETVAL = THIS->max; %}; - double x_min() %code{% RETVAL = THIS->min.x; %}; - double x_max() %code{% RETVAL = THIS->max.x; %}; - double y_min() %code{% RETVAL = THIS->min.y; %}; - double y_max() %code{% RETVAL = THIS->max.y; %}; - double z_min() %code{% RETVAL = THIS->min.z; %}; - double z_max() %code{% RETVAL = THIS->max.z; %}; - std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf;%lf,%lf,%lf", THIS->min.x, THIS->min.y, THIS->min.z, THIS->max.x, THIS->max.y, THIS->max.z); RETVAL = buf; %}; + double x_min() %code{% RETVAL = THIS->min.x(); %}; + double x_max() %code{% RETVAL = THIS->max.x(); %}; + double y_min() %code{% RETVAL = THIS->min.y(); %}; + double y_max() %code{% RETVAL = THIS->max.y(); %}; + double z_min() %code{% RETVAL = THIS->min.z(); %}; + double z_max() %code{% RETVAL = THIS->max.z(); %}; + std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf;%lf,%lf,%lf", THIS->min.x(), THIS->min.y(), THIS->min.z(), THIS->max.x(), THIS->max.y(), THIS->max.z()); RETVAL = buf; %}; bool defined() %code{% RETVAL = THIS->defined; %}; }; diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index b7aded6a0..26cde87ae 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -19,13 +19,13 @@ SV* pp() %code{% RETVAL = to_SV_pureperl(THIS); %}; int x() - %code{% RETVAL = THIS->x; %}; + %code{% RETVAL = THIS->x(); %}; int y() - %code{% RETVAL = THIS->y; %}; + %code{% RETVAL = THIS->y(); %}; void set_x(int val) - %code{% THIS->x = val; %}; + %code{% THIS->x() = val; %}; void set_y(int val) - %code{% THIS->y = val; %}; + %code{% THIS->y() = val; %}; int nearest_point_index(Points points); Clone<Point> nearest_point(Points points) %code{% Point p; THIS->nearest_point(points, &p); RETVAL = p; %}; @@ -49,7 +49,7 @@ %code{% RETVAL = new Point(THIS->negative()); %}; bool coincides_with_epsilon(Point* point) %code{% RETVAL = THIS->coincides_with_epsilon(*point); %}; - std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld", THIS->x, THIS->y); RETVAL = buf; %}; + std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld", THIS->x(), THIS->y()); RETVAL = buf; %}; %{ @@ -82,12 +82,12 @@ Point::coincides_with(point_sv) Clone<Point3> clone() %code{% RETVAL = THIS; %}; int x() - %code{% RETVAL = THIS->x; %}; + %code{% RETVAL = THIS->x(); %}; int y() - %code{% RETVAL = THIS->y; %}; + %code{% RETVAL = THIS->y(); %}; int z() - %code{% RETVAL = THIS->z; %}; - std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld,%ld", THIS->x, THIS->y, THIS->z); RETVAL = buf; %}; + %code{% RETVAL = THIS->z(); %}; + std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld,%ld", THIS->x(), THIS->y(), THIS->z()); RETVAL = buf; %}; }; %name{Slic3r::Pointf} class Pointf { @@ -100,13 +100,13 @@ Point::coincides_with(point_sv) SV* pp() %code{% RETVAL = to_SV_pureperl(THIS); %}; double x() - %code{% RETVAL = THIS->x; %}; + %code{% RETVAL = THIS->x(); %}; double y() - %code{% RETVAL = THIS->y; %}; + %code{% RETVAL = THIS->y(); %}; void set_x(double val) - %code{% THIS->x = val; %}; + %code{% THIS->x() = val; %}; void set_y(double val) - %code{% THIS->y = val; %}; + %code{% THIS->y() = val; %}; void translate(double x, double y); void scale(double factor); void rotate(double angle, Pointf* center) @@ -115,7 +115,7 @@ Point::coincides_with(point_sv) %code{% RETVAL = THIS->negative(); %}; Clone<Pointf> vector_to(Pointf* point) %code{% RETVAL = THIS->vector_to(*point); %}; - std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf", THIS->x, THIS->y); RETVAL = buf; %}; + std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf", THIS->x(), THIS->y()); RETVAL = buf; %}; }; %name{Slic3r::Pointf3} class Pointf3 { @@ -124,17 +124,17 @@ Point::coincides_with(point_sv) Clone<Pointf3> clone() %code{% RETVAL = THIS; %}; double x() - %code{% RETVAL = THIS->x; %}; + %code{% RETVAL = THIS->x(); %}; double y() - %code{% RETVAL = THIS->y; %}; + %code{% RETVAL = THIS->y(); %}; double z() - %code{% RETVAL = THIS->z; %}; + %code{% RETVAL = THIS->z(); %}; void set_x(double val) - %code{% THIS->x = val; %}; + %code{% THIS->x() = val; %}; void set_y(double val) - %code{% THIS->y = val; %}; + %code{% THIS->y() = val; %}; void set_z(double val) - %code{% THIS->z = val; %}; + %code{% THIS->z() = val; %}; void translate(double x, double y, double z); void scale(double factor); double distance_to(Pointf3* point) @@ -143,5 +143,5 @@ Point::coincides_with(point_sv) %code{% RETVAL = THIS->negative(); %}; Clone<Pointf3> vector_to(Pointf3* point) %code{% RETVAL = THIS->vector_to(*point); %}; - std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf", THIS->x, THIS->y, THIS->z); RETVAL = buf; %}; + std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf", THIS->x(), THIS->y(), THIS->z()); RETVAL = buf; %}; };