diff --git a/xs/src/libslic3r/BridgeDetector.cpp b/xs/src/libslic3r/BridgeDetector.cpp index 52214fcfb..dffd043e6 100644 --- a/xs/src/libslic3r/BridgeDetector.cpp +++ b/xs/src/libslic3r/BridgeDetector.cpp @@ -182,9 +182,9 @@ std::vector BridgeDetector::bridge_direction_candidates() const /* we also test angles of each open supporting edge (this finds the optimal angle for C-shaped supports) */ - for (Polylines::const_iterator edge = this->_edges.begin(); edge != this->_edges.end(); ++edge) - if (! edge->first_point().coincides_with(edge->last_point())) - angles.push_back(Line(edge->first_point(), edge->last_point()).direction()); + for (const Polyline &edge : this->_edges) + if (edge.first_point() != edge.last_point()) + angles.push_back(Line(edge.first_point(), edge.last_point()).direction()); // remove duplicates double min_resolution = PI/180.0; // 1 degree diff --git a/xs/src/libslic3r/ClipperUtils.cpp b/xs/src/libslic3r/ClipperUtils.cpp index d27a3e30e..b5a18838c 100644 --- a/xs/src/libslic3r/ClipperUtils.cpp +++ b/xs/src/libslic3r/ClipperUtils.cpp @@ -595,26 +595,26 @@ Polylines _clipper_pl(ClipperLib::ClipType clipType, const Polygons &subject, co to recombine continuous polylines. */ for (size_t i = 0; i < retval.size(); ++i) { for (size_t j = i+1; j < retval.size(); ++j) { - if (retval[i].points.back().coincides_with(retval[j].points.front())) { + if (retval[i].points.back() == retval[j].points.front()) { /* If last point of i coincides with first point of j, append points of j to i and delete j */ retval[i].points.insert(retval[i].points.end(), retval[j].points.begin()+1, retval[j].points.end()); retval.erase(retval.begin() + j); --j; - } else if (retval[i].points.front().coincides_with(retval[j].points.back())) { + } else if (retval[i].points.front() == retval[j].points.back()) { /* If first point of i coincides with last point of j, prepend points of j to i and delete j */ retval[i].points.insert(retval[i].points.begin(), retval[j].points.begin(), retval[j].points.end()-1); retval.erase(retval.begin() + j); --j; - } else if (retval[i].points.front().coincides_with(retval[j].points.front())) { + } else if (retval[i].points.front() == retval[j].points.front()) { /* Since Clipper does not preserve orientation of polylines, also check the case when first point of i coincides with first point of j. */ retval[j].reverse(); retval[i].points.insert(retval[i].points.begin(), retval[j].points.begin(), retval[j].points.end()-1); retval.erase(retval.begin() + j); --j; - } else if (retval[i].points.back().coincides_with(retval[j].points.back())) { + } else if (retval[i].points.back() == retval[j].points.back()) { /* Since Clipper does not preserve orientation of polylines, also check the case when last point of i coincides with last point of j. */ retval[j].reverse(); diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index ad2e9faed..036b037ca 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -294,14 +294,14 @@ ExPolygon::medial_axis(double max_width, double min_width, ThickPolylines* polyl // find another polyline starting here for (size_t j = i+1; j < pp.size(); ++j) { ThickPolyline& other = pp[j]; - if (polyline.last_point().coincides_with(other.last_point())) { + if (polyline.last_point() == other.last_point()) { other.reverse(); - } else if (polyline.first_point().coincides_with(other.last_point())) { + } else if (polyline.first_point() == other.last_point()) { polyline.reverse(); other.reverse(); - } else if (polyline.first_point().coincides_with(other.first_point())) { + } else if (polyline.first_point() == other.first_point()) { polyline.reverse(); - } else if (!polyline.last_point().coincides_with(other.first_point())) { + } else if (polyline.last_point() != other.first_point()) { continue; } diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index da56807ae..ab9e10ec1 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -2213,7 +2213,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, std::string gcode; // go to first point of extrusion path - if (!m_last_pos_defined || !m_last_pos.coincides_with(path.first_point())) { + if (!m_last_pos_defined || m_last_pos != path.first_point()) { gcode += this->travel_to( path.first_point(), path.role(), diff --git a/xs/src/libslic3r/GCode/WipeTower.hpp b/xs/src/libslic3r/GCode/WipeTower.hpp index 36cebeb84..9ee8a0409 100644 --- a/xs/src/libslic3r/GCode/WipeTower.hpp +++ b/xs/src/libslic3r/GCode/WipeTower.hpp @@ -31,7 +31,7 @@ public: xy out(0,0); float temp_x = x - width / 2.f; float temp_y = y - depth / 2.f; - angle *= M_PI/180.; + angle *= float(M_PI/180.); out.x += (temp_x - origin.x) * cos(angle) - (temp_y - origin.y) * sin(angle); out.y += (temp_x - origin.x) * sin(angle) + (temp_y - origin.y) * cos(angle); return out + origin; diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index fafc10629..ee58815ab 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -229,7 +229,7 @@ convex_hull(Points points) hull.points.resize(k); - assert( hull.points.front().coincides_with(hull.points.back()) ); + assert( hull.points.front() == hull.points.back() ); hull.points.pop_back(); } @@ -910,7 +910,7 @@ MedialAxis::build(ThickPolylines* polylines) assert(polyline.width.size() == polyline.points.size()*2 - 2); // prevent loop endpoints from being extended - if (polyline.first_point().coincides_with(polyline.last_point())) { + if (polyline.first_point() == polyline.last_point()) { polyline.endpoints.first = false; polyline.endpoints.second = false; } @@ -1003,7 +1003,7 @@ MedialAxis::validate_edge(const VD::edge_type* edge) // this could maybe be optimized (checking inclusion of the endpoints // might give false positives as they might belong to the contour itself) if (this->expolygon != NULL) { - if (line.a.coincides_with(line.b)) { + if (line.a == line.b) { // in this case, contains(line) returns a false positive if (!this->expolygon->contains(line.a)) return false; } else { diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index e2108af22..383845a0d 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/xs/src/libslic3r/Line.cpp @@ -109,7 +109,7 @@ Line::intersection_infinite(const Line &other, Point* point) const bool Line::coincides_with(const Line &line) const { - return this->a.coincides_with(line.a) && this->b.coincides_with(line.b); + return this->a == line.a && this->b == line.b; } double @@ -220,22 +220,19 @@ Line::ccw(const Point& point) const double Line3::length() const { - return (b.data - a.data).norm(); + return (b - a).norm(); } Vector3 Line3::vector() const { - return Vector3(b.data - a.data); + return Vector3(b - a); } -Pointf3 -Linef3::intersect_plane(double z) const +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()), - z - ); + Vec3d v = this->b - this->a; + double t = (z - this->a.z()) / v.z(); + return Pointf3(this->a.x() + v.x() * t, this->a.y() + v.y() * t, z); } void diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 5ae5ea4d9..6c299fc4c 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -210,6 +210,7 @@ public: friend class ModelObject; +// Transform3d transform; double rotation; // Rotation around the Z axis, in radians around mesh center point double scaling_factor; Pointf offset; // in unscaled coordinates diff --git a/xs/src/libslic3r/MultiPoint.cpp b/xs/src/libslic3r/MultiPoint.cpp index f19d37644..403761a5e 100644 --- a/xs/src/libslic3r/MultiPoint.cpp +++ b/xs/src/libslic3r/MultiPoint.cpp @@ -40,9 +40,9 @@ void MultiPoint::rotate(double angle, const Point ¢er) double s = sin(angle); double c = cos(angle); for (Point &pt : points) { - Vec2crd dif(pt.data - center.data); - pt.x() = (coord_t)round(double(center.x()) + c * dif[0] - s * dif[1]); - pt.y() = (coord_t)round(double(center.y()) + c * dif[1] + s * dif[0]); + Vec2crd v(pt - center); + pt.x() = (coord_t)round(double(center.x()) + c * v[0] - s * v[1]); + pt.y() = (coord_t)round(double(center.y()) + c * v[1] + s * v[0]); } } @@ -70,9 +70,9 @@ MultiPoint::length() const int MultiPoint::find_point(const Point &point) const { - for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) { - if (it->coincides_with(point)) return it - this->points.begin(); - } + for (const Point &pt : this->points) + if (pt == point) + return &pt - &this->points.front(); return -1; // not found } @@ -93,7 +93,7 @@ bool MultiPoint::has_duplicate_points() const { for (size_t i = 1; i < points.size(); ++i) - if (points[i-1].coincides_with(points[i])) + if (points[i-1] == points[i]) return true; return false; } @@ -103,7 +103,7 @@ MultiPoint::remove_duplicate_points() { size_t j = 0; for (size_t i = 1; i < points.size(); ++i) { - if (points[j].coincides_with(points[i])) { + if (points[j] == points[i]) { // Just increase index i. } else { ++ j; @@ -234,15 +234,11 @@ BoundingBox3 MultiPoint3::bounding_box() const bool MultiPoint3::remove_duplicate_points() { size_t j = 0; - for (size_t i = 1; i < points.size(); ++i) - { - if (points[j].coincides_with(points[i])) - { + for (size_t i = 1; i < points.size(); ++i) { + if (points[j] == points[i]) { // Just increase index i. - } - else - { - ++j; + } else { + ++ j; if (j < i) points[j] = points[i]; } diff --git a/xs/src/libslic3r/PerimeterGenerator.cpp b/xs/src/libslic3r/PerimeterGenerator.cpp index 1d2e6248f..b6ed33f79 100644 --- a/xs/src/libslic3r/PerimeterGenerator.cpp +++ b/xs/src/libslic3r/PerimeterGenerator.cpp @@ -452,7 +452,7 @@ ExtrusionEntityCollection PerimeterGenerator::_variable_width(const ThickPolylin paths.emplace_back(std::move(path)); // Append paths to collection. if (! paths.empty()) { - if (paths.front().first_point().coincides_with(paths.back().last_point())) + if (paths.front().first_point() == paths.back().last_point()) coll.append(ExtrusionLoop(paths)); else coll.append(paths); diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp index 4c3fb2d94..da5520e26 100644 --- a/xs/src/libslic3r/Point.cpp +++ b/xs/src/libslic3r/Point.cpp @@ -24,8 +24,8 @@ void Point::rotate(double angle) { double cur_x = (double)this->x(); double cur_y = (double)this->y(); - double s = sin(angle); - double c = cos(angle); + 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); } @@ -34,8 +34,8 @@ void Point::rotate(double angle, const Point ¢er) { double cur_x = (double)this->x(); double cur_y = (double)this->y(); - double s = sin(angle); - double c = cos(angle); + 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 ); @@ -122,7 +122,7 @@ double Point::distance_to(const Line &line) const double Point::perp_distance_to(const Line &line) const { - if (line.a.coincides_with(line.b)) return this->distance_to(line.a); + if (line.a == 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()); @@ -176,7 +176,7 @@ Point Point::projection_onto(const MultiPoint &poly) const Point Point::projection_onto(const Line &line) const { - if (line.a.coincides_with(line.b)) return line.a; + if (line.a == line.b) return line.a; /* (Ported from VisiLibity by Karl J. Obermeyer) @@ -226,8 +226,8 @@ void Pointf::rotate(double angle) { double cur_x = this->x(); double cur_y = this->y(); - double s = sin(angle); - double c = cos(angle); + double s = ::sin(angle); + double c = ::cos(angle); this->x() = c * cur_x - s * cur_y; this->y() = c * cur_y + s * cur_x; } @@ -236,8 +236,8 @@ void Pointf::rotate(double angle, const Pointf ¢er) { double cur_x = this->x(); double cur_y = this->y(); - double s = sin(angle); - double c = cos(angle); + 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; diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index 568dfb1ff..1de8c22bc 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -35,45 +35,49 @@ typedef std::vector Pointf3s; // Vector types with a fixed point coordinate base type. typedef Eigen::Matrix Vec2crd; typedef Eigen::Matrix Vec3crd; + // Vector types with a double coordinate base type. typedef Eigen::Matrix Vec2f; typedef Eigen::Matrix Vec3f; -typedef Eigen::Matrix Vec2d; -typedef Eigen::Matrix Vec3d; +typedef Eigen::Matrix Vec2d; +typedef Eigen::Matrix Vec3d; typedef Eigen::Transform Transform2f; typedef Eigen::Transform Transform2d; typedef Eigen::Transform Transform3f; typedef Eigen::Transform Transform3d; -class Point +class Point : public Vec2crd { public: typedef coord_t coord_type; - 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)) {} - explicit Point(const Vec2crd &rhs) { this->data = rhs; } - explicit Point(Vec2crd &&rhs) { this->data = std::move(rhs); } + Point() : Vec2crd() { (*this)(0) = 0; (*this)(1) = 0; } + Point(coord_t x, coord_t y) { (*this)(0) = x; (*this)(1) = y; } + Point(int64_t x, int64_t y) { (*this)(0) = coord_t(x); (*this)(1) = coord_t(y); } // for Clipper + Point(double x, double y) { (*this)(0) = coord_t(lrint(x)); (*this)(1) = coord_t(lrint(y)); } + Point(const Point &rhs) { *this = rhs; } + // This constructor allows you to construct Point from Eigen expressions + template + Point(const Eigen::MatrixBase &other) : Vec2crd(other) {} static Point new_scale(coordf_t x, coordf_t y) { return Point(coord_t(scale_(x)), coord_t(scale_(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]; } + // This method allows you to assign Eigen expressions to MyVectorType + template + Point& operator=(const Eigen::MatrixBase &other) + { + this->Point::operator=(other); + return *this; + } - operator const Vec2crd& () const { return this->data; } - operator Vec2crd& () { return this->data; } - template Eigen::Matrix cast() const { return this->data.cast(); } - - Point& operator=(const Vec2crd &rhs) { this->data = rhs; return *this; } - Point& operator=(Vec2crd &&rhs) { this->data = std::move(rhs); return *this; } + const coord_t& x() const { return (*this)(0); } + coord_t& x() { return (*this)(0); } + const coord_t& y() const { return (*this)(1); } + coord_t& y() { return (*this)(1); } 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()); } + 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; } @@ -81,30 +85,30 @@ public: std::string wkt() const; std::string dump_perl() const; - void scale(double factor) { this->data *= factor; } - void translate(double x, double y) { this->data += Vec2crd(x, y); } - void translate(const Vector &vector) { this->data += vector.data; } - void rotate(double angle); - 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_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; } + void scale(double factor) { *this *= factor; } + void translate(double x, double y) { *this += Vector(x, y); } + void translate(const Vector &vector) { *this += vector; } + void rotate(double angle); + 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 &rhs) const { return *this == rhs; } + 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 (point - *this).norm(); } + double distance_to_sq(const Point &point) const { return (point - *this).squaredNorm(); } double distance_to(const Line &line) const; double perp_distance_to(const Line &line) const; double ccw(const Point &p1, const Point &p2) const; double ccw(const Line &line) const; double ccw_angle(const Point &p1, const Point &p2) const; - Point projection_onto(const MultiPoint &poly) const; - Point projection_onto(const Line &line) const; - Point negative() const { return Point(- this->data); } - Vector vector_to(const Point &point) const { return Vector(point.data - this->data); } + Point projection_onto(const MultiPoint &poly) const; + Point projection_onto(const Line &line) const; + Point negative() const { return Point(- *this); } + Vector vector_to(const Point &point) const { return Vector(point - *this); } }; inline Point operator+(const Point& point1, const Point& point2) { return Point(point1.x() + point2.x(), point1.y() + point2.y()); } @@ -223,70 +227,77 @@ private: coord_t m_grid_log2; }; -class Point3 +class Point3 : public Vec3crd { public: typedef coord_t coord_type; - Vec3crd data; - 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]; } - const coord_t& z() const { return this->data[2]; } - coord_t& z() { return this->data[2]; } - - operator const Vec3crd& () const { return this->data; } - operator Vec3crd& () { return this->data; } - template Eigen::Matrix cast() const { return this->data.cast(); } - - explicit Point3(coord_t _x = 0, coord_t _y = 0, coord_t _z = 0) { this->data[0] = _x; this->data[1] = _y; this->data[2] = _z; } - explicit Point3(const Vec3crd &rhs) { this->data = rhs; } - explicit Point3(Vec3crd &&rhs) { this->data = std::move(rhs); } + explicit Point3() { (*this)(0) = (*this)(1) = (*this)(2) = 0; } + explicit Point3(coord_t x, coord_t y, coord_t z) { (*this)(0) = x; (*this)(1) = y; (*this)(2) = z; } + // This constructor allows you to construct Point3 from Eigen expressions + template + Point3(const Eigen::MatrixBase &other) : Vec3crd(other) {} 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))); } - Point3& operator=(const Vec3crd &rhs) { this->data = rhs; return *this; } - Point3& operator=(Vec3crd &&rhs) { this->data = std::move(rhs); return *this; } - 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(); } - Point xy() const { return Point(this->x(), this->y()); } + // This method allows you to assign Eigen expressions to MyVectorType + template + Point3& operator=(const Eigen::MatrixBase &other) + { + this->Point3::operator=(other); + return *this; + } + + const coord_t& x() const { return (*this)(0); } + coord_t& x() { return (*this)(0); } + const coord_t& y() const { return (*this)(1); } + coord_t& y() { return (*this)(1); } + const coord_t& z() const { return (*this)(2); } + coord_t& z() { return (*this)(2); } + + 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); } + + Point xy() const { return Point(this->x(), this->y()); } }; std::ostream& operator<<(std::ostream &stm, const Pointf &pointf); -class Pointf +class Pointf : public Vec2d { public: typedef coordf_t coord_type; - Vec2d data; - explicit Pointf(coordf_t x = 0, coordf_t y = 0) { data(0) = x; data(1) = y; } - explicit Pointf(const Vec2d &rhs) { this->data = rhs; } - explicit Pointf(Vec2d &&rhs) { this->data = std::move(rhs); } + explicit Pointf() { (*this)(0) = (*this)(1) = 0.; } +// explicit Pointf(double x, double y) { (*this)(0) = x; (*this)(1) = y; } + explicit Pointf(coordf_t x, coordf_t y) { (*this)(0) = x; (*this)(1) = y; } + // This constructor allows you to construct Pointf from Eigen expressions + template + Pointf(const Eigen::MatrixBase &other) : Vec2d(other) {} 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())); } - Pointf& operator=(const Vec2d &rhs) { this->data = rhs; return *this; } - Pointf& operator=(Vec2d &&rhs) { this->data = std::move(rhs); return *this; } - 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]; } + // This method allows you to assign Eigen expressions to MyVectorType + template + Pointf& operator=(const Eigen::MatrixBase &other) + { + this->Pointf::operator=(other); + return *this; + } - operator const Vec2d& () const { return this->data; } - operator Vec2d& () { return this->data; } - template Eigen::Matrix cast() const { return this->data.cast(); } + const coordf_t& x() const { return (*this)(0); } + coordf_t& x() { return (*this)(0); } + const coordf_t& y() const { return (*this)(1); } + coordf_t& y() { return (*this)(1); } std::string wkt() const; std::string dump_perl() const; - void scale(double factor) { this->data *= factor; } - void translate(double x, double y) { this->data += Vec2d(x, y); } - void translate(const Vectorf &vector) { this->data += vector.data; } - void rotate(double angle); - void rotate(double angle, const Pointf ¢er); - Pointf negative() const { return Pointf(- this->data); } - Vectorf vector_to(const Pointf &point) const { return Vectorf(point.data - this->data); } + void scale(double factor) { *this *= factor; } + void translate(double x, double y) { *this += Vec2d(x, y); } + void translate(const Vectorf &vector) { *this += vector; } + void rotate(double angle); + void rotate(double angle, const Pointf ¢er); + Pointf negative() const { return Pointf(- *this); } + Vectorf vector_to(const Pointf &point) const { return point - *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; } @@ -311,37 +322,41 @@ inline Vectorf normalize(const Vectorf& v) return (len != 0.0) ? 1.0 / len * v : Vectorf(0.0, 0.0); } -class Pointf3 +class Pointf3 : public Vec3d { public: typedef coordf_t coord_type; - Vec3d data; - 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]; } - const coordf_t& z() const { return this->data[2]; } - coordf_t& z() { return this->data[2]; } - - operator const Vec3d& () const { return this->data; } - operator Vec3d& () { return this->data; } - template Eigen::Matrix cast() const { return this->data.cast(); } - - explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0) { this->data[0] = _x; this->data[1] = _y; this->data[2] = _z; } - explicit Pointf3(const Vec3d &rhs) { this->data = rhs; } - explicit Pointf3(Vec3d &&rhs) { this->data = std::move(rhs); } + explicit Pointf3() { (*this)(0) = (*this)(1) = (*this)(2) = 0.; } +// explicit Pointf3(coord_t x, coord_t y, coord_t z) { (*this)(0) = x; (*this)(1) = y; (*this)(2) = z; } + explicit Pointf3(coordf_t x, coordf_t y, coordf_t z) { (*this)(0) = x; (*this)(1) = y; (*this)(2) = z; } + // This constructor allows you to construct Pointf from Eigen expressions + template + Pointf3(const Eigen::MatrixBase &other) : Vec3d(other) {} 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())); } - Pointf3& operator=(const Vec3d &rhs) { this->data = rhs; return *this; } - Pointf3& operator=(Vec3d &&rhs) { this->data = std::move(rhs); return *this; } - void scale(double factor) { this->data *= factor; } - void translate(const Vectorf3 &vector) { this->data += vector.data; } - void translate(double x, double y, double z) { this->data += Vec3d(x, y, z); } - double distance_to(const Pointf3 &point) const { return (point.data - this->data).norm(); } - Pointf3 negative() const { return Pointf3(- this->data); } - Vectorf3 vector_to(const Pointf3 &point) const { return Vectorf3(point.data - this->data); } + // This method allows you to assign Eigen expressions to MyVectorType + template + Pointf3& operator=(const Eigen::MatrixBase &other) + { + this->Pointf3::operator=(other); + return *this; + } + + const coordf_t& x() const { return (*this)(0); } + coordf_t& x() { return (*this)(0); } + const coordf_t& y() const { return (*this)(1); } + coordf_t& y() { return (*this)(1); } + const coordf_t& z() const { return (*this)(2); } + coordf_t& z() { return (*this)(2); } + + void scale(double factor) { *this *= factor; } + void translate(const Vectorf3 &vector) { *this += vector; } + void translate(double x, double y, double z) { *this += Vec3d(x, y, z); } + double distance_to(const Pointf3 &point) const { return (point - *this).norm(); } + Pointf3 negative() const { return Pointf3(- *this); } + Vectorf3 vector_to(const Pointf3 &point) const { return point - *this; } 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); } diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index d409e8c32..dfa8f7d8e 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -44,11 +44,9 @@ Polyline Polygon::split_at_vertex(const Point &point) const { // find index of point - for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) { - if (it->coincides_with(point)) { - return this->split_at_index(it - this->points.begin()); - } - } + for (const Point &pt : this->points) + if (pt == point) + return this->split_at_index(&pt - &this->points.front()); CONFESS("Point not found"); return Polyline(); } diff --git a/xs/src/libslic3r/Polyline.cpp b/xs/src/libslic3r/Polyline.cpp index bd7b9bf98..d183f4dda 100644 --- a/xs/src/libslic3r/Polyline.cpp +++ b/xs/src/libslic3r/Polyline.cpp @@ -178,9 +178,9 @@ Polyline::split_at(const Point &point, Polyline* p1, Polyline* p2) const // create first half p1->points.clear(); - for (Lines::const_iterator line = lines.begin(); line != lines.begin() + line_idx + 1; ++line) { - if (!line->a.coincides_with(p)) p1->points.push_back(line->a); - } + for (Lines::const_iterator line = lines.begin(); line != lines.begin() + line_idx + 1; ++line) + if (line->a != p) + p1->points.push_back(line->a); // we add point instead of p because they might differ because of numerical issues // and caller might want to rely on point belonging to result polylines p1->points.push_back(point); diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 0dabfdaa7..f60fb1b62 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -1052,7 +1052,10 @@ void Print::_make_wipe_tower() return; // Get wiping matrix to get number of extruders and convert vector to vector: +#pragma warning(push) +#pragma warning(disable:4244) // disable Visual Studio's warning: conversion from 'double' to 'float', possible loss of data std::vector wiping_matrix((this->config.wiping_volumes_matrix.values).begin(),(this->config.wiping_volumes_matrix.values).end()); +#pragma warning(pop) // Extract purging volumes for each extruder pair: std::vector> wipe_volumes; const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 618cdbb1a..0c446806c 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -280,7 +280,7 @@ const Transform3f& GLVolume::world_matrix() const { m_world_mat = Transform3f::Identity(); m_world_mat.translate(Vec3f(m_origin.x(), m_origin.y(), 0)); - m_world_mat.rotate(Eigen::AngleAxisf(m_angle_z, Eigen::Vector3f::UnitZ())); + m_world_mat.rotate(Eigen::AngleAxisf(m_angle_z, Vec3f::UnitZ())); m_world_mat.scale(m_scale_factor); m_dirty = false; } diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 05feb6314..a9a76d2da 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -1947,7 +1947,7 @@ void GLCanvas3D::set_auto_bed_shape() // draw a default square bed around object center const BoundingBoxf3& bbox = volumes_bounding_box(); coordf_t max_size = bbox.max_size(); - const Pointf3& center = bbox.center(); + const Pointf3 center = bbox.center(); Pointfs bed_shape; bed_shape.reserve(4); @@ -3101,7 +3101,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { // The mouse_to_3d gets the Z coordinate from the Z buffer at the screen coordinate pos x, y, // an converts the screen space coordinate to unscaled object space. - Pointf3 pos3d = (volume_idx == -1) ? Pointf3(DBL_MAX, DBL_MAX) : _mouse_to_3d(pos); + Pointf3 pos3d = (volume_idx == -1) ? Pointf3(DBL_MAX, DBL_MAX, DBL_MAX) : _mouse_to_3d(pos); // Only accept the initial position, if it is inside the volume bounding box. BoundingBoxf3 volume_bbox = m_volumes.volumes[volume_idx]->transformed_bounding_box(); diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index af7022f2b..d1f5a8650 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -891,10 +891,13 @@ void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFl g_wiping_dialog_button->Bind(wxEVT_BUTTON, ([parent](wxCommandEvent& e) { auto &config = g_PresetBundle->project_config; - std::vector init_matrix = (config.option("wiping_volumes_matrix"))->values; - std::vector init_extruders = (config.option("wiping_volumes_extruders"))->values; + const std::vector &init_matrix = (config.option("wiping_volumes_matrix"))->values; + const std::vector &init_extruders = (config.option("wiping_volumes_extruders"))->values; +#pragma warning(push) +#pragma warning(disable:4244) // disable Visual Studio's warning: conversion from 'double' to 'float', possible loss of data WipingDialog dlg(parent,std::vector(init_matrix.begin(),init_matrix.end()),std::vector(init_extruders.begin(),init_extruders.end())); +#pragma warning(pop) if (dlg.ShowModal() == wxID_OK) { std::vector matrix = dlg.get_matrix(); diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index 26cde87ae..df4df60b7 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -48,7 +48,7 @@ Clone negative() %code{% RETVAL = new Point(THIS->negative()); %}; bool coincides_with_epsilon(Point* point) - %code{% RETVAL = THIS->coincides_with_epsilon(*point); %}; + %code{% RETVAL = (*THIS) == *point; %}; std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld", THIS->x(), THIS->y()); RETVAL = buf; %}; %{ @@ -68,7 +68,7 @@ Point::coincides_with(point_sv) CODE: Point point; from_SV_check(point_sv, &point); - RETVAL = THIS->coincides_with(point); + RETVAL = (*THIS) == point; OUTPUT: RETVAL