diff --git a/xs/src/libslic3r/BoundingBox.hpp b/xs/src/libslic3r/BoundingBox.hpp index 7a02878607..cb8bc3ad96 100644 --- a/xs/src/libslic3r/BoundingBox.hpp +++ b/xs/src/libslic3r/BoundingBox.hpp @@ -18,7 +18,7 @@ public: BoundingBoxBase() : defined(false), min(PointClass::Zero()), max(PointClass::Zero()) {} BoundingBoxBase(const PointClass &pmin, const PointClass &pmax) : min(pmin), max(pmax), defined(pmin(0) < pmax(0) && pmin(1) < pmax(1)) {} - BoundingBoxBase(const std::vector& points) + BoundingBoxBase(const std::vector& points) : min(PointClass::Zero()), max(PointClass::Zero()) { if (points.empty()) CONFESS("Empty point set supplied to BoundingBoxBase constructor"); diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index ef54b12648..a1b0f624ea 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -696,7 +696,7 @@ public: std::istringstream is(str); std::string point_str; while (std::getline(is, point_str, ',')) { - Pointf point; + Pointf point(Vec2d::Zero()); std::istringstream iss(point_str); std::string coord_str; if (std::getline(iss, coord_str, 'x')) { diff --git a/xs/src/libslic3r/GCode.hpp b/xs/src/libslic3r/GCode.hpp index 4953c39fef..235ca62f0b 100644 --- a/xs/src/libslic3r/GCode.hpp +++ b/xs/src/libslic3r/GCode.hpp @@ -125,6 +125,7 @@ private: class GCode { public: GCode() : + m_origin(Vec2d::Zero()), m_enable_loop_clipping(true), m_enable_cooling_markers(false), m_enable_extrusion_role_markers(false), diff --git a/xs/src/libslic3r/GCode/PrintExtents.cpp b/xs/src/libslic3r/GCode/PrintExtents.cpp index a1cd0cde9f..dd0b18db84 100644 --- a/xs/src/libslic3r/GCode/PrintExtents.cpp +++ b/xs/src/libslic3r/GCode/PrintExtents.cpp @@ -136,8 +136,9 @@ BoundingBoxf get_wipe_tower_extrusions_extents(const Print &print, const coordf_ { // Wipe tower extrusions are saved as if the tower was at the origin with no rotation // We need to get position and angle of the wipe tower to transform them to actual position. - Pointf wipe_tower_pos(print.config.wipe_tower_x.value, print.config.wipe_tower_y.value); - float wipe_tower_angle = print.config.wipe_tower_rotation_angle.value; + Transform2d trafo = + Eigen::Translation2d(print.config.wipe_tower_x.value, print.config.wipe_tower_y.value) * + Eigen::Rotation2Dd(print.config.wipe_tower_rotation_angle.value); BoundingBoxf bbox; for (const std::vector &tool_changes : print.m_wipe_tower_tool_changes) { @@ -147,19 +148,11 @@ BoundingBoxf get_wipe_tower_extrusions_extents(const Print &print, const coordf_ for (size_t i = 1; i < tcr.extrusions.size(); ++ i) { const WipeTower::Extrusion &e = tcr.extrusions[i]; if (e.width > 0) { - Pointf p1((&e - 1)->pos.x, (&e - 1)->pos.y); - Pointf p2(e.pos.x, e.pos.y); - p1.rotate(wipe_tower_angle); - p1 += wipe_tower_pos; - p2.rotate(wipe_tower_angle); - p2 += wipe_tower_pos; - - bbox.merge(p1); - coordf_t radius = 0.5 * e.width; - bbox.min(0) = std::min(bbox.min(0), std::min(p1(0), p2(0)) - radius); - bbox.min(1) = std::min(bbox.min(1), std::min(p1(1), p2(1)) - radius); - bbox.max(0) = std::max(bbox.max(0), std::max(p1(0), p2(0)) + radius); - bbox.max(1) = std::max(bbox.max(1), std::max(p1(1), p2(1)) + radius); + Pointf delta = 0.5 * Vec2d(e.width, e.width); + Pointf p1 = trafo * Vec2d((&e - 1)->pos.x, (&e - 1)->pos.y); + Pointf p2 = trafo * Vec2d(e.pos.x, e.pos.y); + bbox.merge(p1.cwiseMin(p2) - delta); + bbox.merge(p1.cwiseMax(p2) + delta); } } } diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index b4813be14a..f513341551 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -410,13 +410,13 @@ Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const B } #else class ArrangeItem { - public: - Pointf pos; +public: + Pointf pos = Vec2d::Zero(); size_t index_x, index_y; coordf_t dist; }; class ArrangeItemIndex { - public: +public: coordf_t index; ArrangeItem item; ArrangeItemIndex(coordf_t _index, ArrangeItem _item) : index(_index), item(_item) {}; @@ -433,7 +433,7 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi part(0) += dist; part(1) += dist; - Pointf area; + Pointf area(Vec2d::Zero()); if (bb != NULL && bb->defined) { area = bb->size(); } else { diff --git a/xs/src/libslic3r/Line.hpp b/xs/src/libslic3r/Line.hpp index 39a7c2223b..65e04dc930 100644 --- a/xs/src/libslic3r/Line.hpp +++ b/xs/src/libslic3r/Line.hpp @@ -71,7 +71,7 @@ public: class Linef { public: - Linef() {} + Linef() : a(Vec2d::Zero()), b(Vec2d::Zero()) {} explicit Linef(Pointf _a, Pointf _b): a(_a), b(_b) {} Pointf a; diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index cc59b65588..047751ecd6 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -726,24 +726,22 @@ void ModelObject::center_around_origin() if (! v->modifier) bb.merge(v->mesh.bounding_box()); - // first align to origin on XYZ - Vec3d vector(-bb.min(0), -bb.min(1), -bb.min(2)); - - // then center it on XY + // First align to origin on XYZ, then center it on XY. Vec3d size = bb.size(); - vector(0) -= size(0)/2; - vector(1) -= size(1)/2; + size(2) = 0.; + Vec3d shift3 = - bb.min - 0.5 * size; + // Unaligned vector, for the Rotation2D to work on Visual Studio 2013. + Eigen::Vector2d shift2 = to_2d(shift3); - this->translate(vector); - this->origin_translation += vector; + this->translate(shift3); + this->origin_translation += shift3; if (!this->instances.empty()) { for (ModelInstance *i : this->instances) { // apply rotation and scaling to vector as well before translating instance, // in order to leave final position unaltered - Vectorf v = - to_2d(vector); - v.rotate(i->rotation); - i->offset += v * i->scaling_factor; + Eigen::Rotation2Dd rot(i->rotation); + i->offset -= rot * shift2 * i->scaling_factor; } this->invalidate_bounding_box(); } @@ -762,7 +760,7 @@ void ModelObject::scale(const Vec3d &versor) for (ModelVolume *v : this->volumes) v->mesh.scale(versor); // reset origin translation since it doesn't make sense anymore - this->origin_translation = Vec3d(0,0,0); + this->origin_translation = Vec3d::Zero(); this->invalidate_bounding_box(); } @@ -784,7 +782,7 @@ void ModelObject::rotate(float angle, const Axis &axis) } } - this->origin_translation = Vec3d(0, 0, 0); + this->origin_translation = Vec3d::Zero(); this->invalidate_bounding_box(); } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index dfe391b0e8..a7597ada51 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -235,7 +235,7 @@ private: // Parent object, owning this instance. ModelObject* object; - ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), object(object), print_volume_state(PVS_Inside) {} + ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), offset(Vec2d::Zero()), object(object), print_volume_state(PVS_Inside) {} ModelInstance(ModelObject *object, const ModelInstance &other) : rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset), object(object), print_volume_state(PVS_Inside) {} }; diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp index 10578641e0..0fe76c6113 100644 --- a/xs/src/libslic3r/Point.cpp +++ b/xs/src/libslic3r/Point.cpp @@ -153,28 +153,6 @@ std::ostream& operator<<(std::ostream &stm, const Pointf &pointf) return stm << pointf(0) << "," << pointf(1); } -void Pointf::rotate(double angle) -{ - double cur_x = (*this)(0); - double cur_y = (*this)(1); - double s = ::sin(angle); - double c = ::cos(angle); - (*this)(0) = c * cur_x - s * cur_y; - (*this)(1) = c * cur_y + s * cur_x; -} - -void Pointf::rotate(double angle, const Pointf ¢er) -{ - double cur_x = (*this)(0); - double cur_y = (*this)(1); - double s = ::sin(angle); - double c = ::cos(angle); - double dx = cur_x - center(0); - double dy = cur_y - center(1); - (*this)(0) = center(0) + c * dx - s * dy; - (*this)(1) = center(1) + c * dy + s * dx; -} - namespace int128 { int orient(const Vec2crd &p1, const Vec2crd &p2, const Vec2crd &p3) diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index e189e22eec..b5af3b1def 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -47,6 +47,8 @@ typedef Eigen::Transform Transform2d typedef Eigen::Transform Transform3f; typedef Eigen::Transform Transform3d; +inline bool operator<(const Vec2d &lhs, const Vec2d &rhs) { return lhs(0) < rhs(0) || (lhs(0) == rhs(0) && lhs(1) < rhs(1)); } + inline int64_t cross2(const Vec2i64 &v1, const Vec2i64 &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } inline coord_t cross2(const Vec2crd &v1, const Vec2crd &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } inline float cross2(const Vec2f &v1, const Vec2f &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } @@ -249,7 +251,8 @@ class Pointf : public Vec2d public: typedef coordf_t coord_type; - explicit Pointf() { (*this)(0) = (*this)(1) = 0.; } +// explicit Pointf() { (*this)(0) = (*this)(1) = 0.; } + explicit Pointf() { } 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 @@ -263,10 +266,10 @@ public: return *this; } - void rotate(double angle); - void rotate(double angle, const Pointf ¢er); +// void rotate(double angle); +// void rotate(double angle, const Pointf ¢er); - bool operator< (const Pointf& rhs) const { return (*this)(0) < rhs(0) || ((*this)(0) == rhs(0) && (*this)(1) < rhs(1)); } +private: }; } // namespace Slic3r diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index 0091846206..18a2d2b950 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -24,11 +24,12 @@ public: explicit Polygon(const Points &points): MultiPoint(points) {} Polygon(const Polygon &other) : MultiPoint(other.points) {} Polygon(Polygon &&other) : MultiPoint(std::move(other.points)) {} - static Polygon new_scale(std::vector points) { - Points int_points; - for (auto pt : points) - int_points.push_back(Point::new_scale(pt(0), pt(1))); - return Polygon(int_points); + static Polygon new_scale(const std::vector &points) { + Polygon pgn; + pgn.points.reserve(points.size()); + for (const Pointf &pt : points) + pgn.points.emplace_back(Point::new_scale(pt(0), pt(1))); + return pgn; } Polygon& operator=(const Polygon &other) { points = other.points; return *this; } Polygon& operator=(Polygon &&other) { points = std::move(other.points); return *this; } diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index edd27aaf68..f61e467178 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -23,12 +23,11 @@ public: explicit Polyline(const Point &p1, const Point &p2) { points.reserve(2); points.emplace_back(p1); points.emplace_back(p2); } Polyline& operator=(const Polyline &other) { points = other.points; return *this; } Polyline& operator=(Polyline &&other) { points = std::move(other.points); return *this; } - static Polyline new_scale(std::vector points) { + static Polyline new_scale(const std::vector &points) { Polyline pl; - Points int_points; - for (auto pt : points) - int_points.push_back(Point::new_scale(pt(0), pt(1))); - pl.append(int_points); + pl.points.reserve(points.size()); + for (const Pointf &pt : points) + pl.points.emplace_back(Point::new_scale(pt(0), pt(1))); return pl; } diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index ff226ad9ee..b1d88f2c61 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -1575,8 +1575,7 @@ TriangleMesh make_cylinder(double r, double h, double fa) { vertices.emplace_back(Vec3d(sin(0) * r , cos(0) * r, 0)); vertices.emplace_back(Vec3d(sin(0) * r , cos(0) * r, h)); for (double i = 0; i < 2*PI; i+=angle) { - Pointf p(0, r); - p.rotate(i); + Vec2d p = Eigen::Rotation2Dd(i) * Eigen::Vector2d(0, r); vertices.emplace_back(Vec3d(p(0), p(1), 0.)); vertices.emplace_back(Vec3d(p(0), p(1), h)); id = vertices.size() - 1; @@ -1626,8 +1625,7 @@ TriangleMesh make_sphere(double rho, double fa) { const double z = -rho + increment*rho*2.0; // radius of the circle for this step. const double r = sqrt(abs(rho*rho - z*z)); - Pointf b(0, r); - b.rotate(ring[i]); + Vec2d b = Eigen::Rotation2Dd(ring[i]) * Eigen::Vector2d(0, r); vertices.emplace_back(Vec3d(b(0), b(1), z)); facets.emplace_back((i == 0) ? Point3(1, 0, ring.size()) : Point3(id, 0, id - 1)); ++ id; @@ -1639,8 +1637,7 @@ TriangleMesh make_sphere(double rho, double fa) { const double r = sqrt(abs(rho*rho - z*z)); for (size_t i = 0; i < ring.size(); i++) { - Pointf b(0, r); - b.rotate(ring[i]); + Vec2d b = Eigen::Rotation2Dd(ring[i]) * Eigen::Vector2d(0, r); vertices.emplace_back(Vec3d(b(0), b(1), z)); if (i == 0) { // wrap around diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index 46d8d1618a..693221f84f 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -270,7 +270,7 @@ bool ConfigBase__set(ConfigBase* THIS, const t_config_option_key &opt_key, SV* v values.reserve(len); for (size_t i = 0; i < len; i++) { SV** elem = av_fetch(av, i, 0); - Pointf point; + Pointf point(Vec2d::Zero()); if (elem == NULL || !from_SV_check(*elem, &point)) return false; values.emplace_back(point); } diff --git a/xs/src/slic3r/GUI/2DBed.cpp b/xs/src/slic3r/GUI/2DBed.cpp index 35c23272e6..ccca4320ca 100644 --- a/xs/src/slic3r/GUI/2DBed.cpp +++ b/xs/src/slic3r/GUI/2DBed.cpp @@ -79,8 +79,7 @@ void Bed_2D::repaint() auto step = 10; // 1cm grid Polylines polylines; for (auto x = bb.min(0) - fmod(bb.min(0), step) + step; x < bb.max(0); x += step) { - Polyline pl = Polyline::new_scale({ Pointf(x, bb.min(1)), Pointf(x, bb.max(1)) }); - polylines.push_back(pl); + polylines.push_back(Polyline::new_scale({ Pointf(x, bb.min(1)), Pointf(x, bb.max(1)) })); } for (auto y = bb.min(1) - fmod(bb.min(1), step) + step; y < bb.max(1); y += step) { polylines.push_back(Polyline::new_scale({ Pointf(bb.min(0), y), Pointf(bb.max(0), y) })); @@ -112,9 +111,7 @@ void Bed_2D::repaint() auto x_end = Pointf(origin_px(0) + axes_len, origin_px(1)); dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(x_end(0), x_end(1))); for (auto angle : { -arrow_angle, arrow_angle }){ - auto end = x_end; - end(0) -= arrow_len; - end.rotate(angle, x_end); + auto end = Eigen::Translation2d(x_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- x_end) * Eigen::Vector2d(x_end(0) - arrow_len, x_end(1)); dc.DrawLine(wxPoint(x_end(0), x_end(1)), wxPoint(end(0), end(1))); } @@ -122,9 +119,7 @@ void Bed_2D::repaint() auto y_end = Pointf(origin_px(0), origin_px(1) - axes_len); dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(y_end(0), y_end(1))); for (auto angle : { -arrow_angle, arrow_angle }) { - auto end = y_end; - end(1) += arrow_len; - end.rotate(angle, y_end); + auto end = Eigen::Translation2d(y_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- y_end) * Eigen::Vector2d(y_end(0), y_end(1) + arrow_len); dc.DrawLine(wxPoint(y_end(0), y_end(1)), wxPoint(end(0), end(1))); } diff --git a/xs/src/slic3r/GUI/2DBed.hpp b/xs/src/slic3r/GUI/2DBed.hpp index 4b14986a2b..399be6f120 100644 --- a/xs/src/slic3r/GUI/2DBed.hpp +++ b/xs/src/slic3r/GUI/2DBed.hpp @@ -14,8 +14,8 @@ class Bed_2D : public wxPanel bool m_painted = false; bool m_interactive = false; double m_scale_factor; - Pointf m_shift; - Pointf m_pos; + Pointf m_shift = Vec2d::Zero(); + Pointf m_pos = Vec2d::Zero(); std::function m_on_move = nullptr; Point to_pixels(Pointf point); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 86cbe1b6fb..43d79a7a9c 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -952,8 +952,8 @@ static void thick_lines_to_indexed_vertex_array( // right, left, top, bottom int idx_prev[4] = { -1, -1, -1, -1 }; double bottom_z_prev = 0.; - Pointf b1_prev; - Vectorf v_prev; + Pointf b1_prev(Vec2d::Zero()); + Vectorf v_prev(Vec2d::Zero()); int idx_initial[4] = { -1, -1, -1, -1 }; double width_initial = 0.; double bottom_z_initial = 0.0; @@ -1064,7 +1064,7 @@ static void thick_lines_to_indexed_vertex_array( { // Create a sharp corner with an overshot and average the left / right normals. // At the crease angle of 45 degrees, the overshot at the corner will be less than (1-1/cos(PI/8)) = 8.2% over an arc. - Pointf intersection; + Pointf intersection(Vec2d::Zero()); Geometry::ray_ray_intersection(b1_prev, v_prev, a1, v, intersection); a1 = intersection; a2 = 2. * a - intersection; diff --git a/xs/src/slic3r/GUI/BedShapeDialog.cpp b/xs/src/slic3r/GUI/BedShapeDialog.cpp index b8a57a0c55..c47de94aa6 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.cpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.cpp @@ -230,11 +230,13 @@ void BedShapePanel::update_shape() { auto page_idx = m_shape_options_book->GetSelection(); if (page_idx == SHAPE_RECTANGULAR) { - Pointf rect_size, rect_origin; + Pointf rect_size(Vec2d::Zero()); + Pointf rect_origin(Vec2d::Zero()); try{ rect_size = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); } catch (const std::exception &e){ - return;} + return; + } try{ rect_origin = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin")); } diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 942b134400..32688ec3c3 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -667,7 +667,7 @@ void PointCtrl::set_value(const Pointf& value, bool change_event) void PointCtrl::set_value(const boost::any& value, bool change_event) { - Pointf pt; + Pointf pt(Vec2d::Zero()); const Pointf *ptf = boost::any_cast(&value); if (!ptf) { @@ -681,13 +681,10 @@ void PointCtrl::set_value(const boost::any& value, bool change_event) boost::any& PointCtrl::get_value() { - Pointf ret_point; - double val; - x_textctrl->GetValue().ToDouble(&val); - ret_point(0) = val; - y_textctrl->GetValue().ToDouble(&val); - ret_point(1) = val; - return m_value = ret_point; + double x, y; + x_textctrl->GetValue().ToDouble(&x); + y_textctrl->GetValue().ToDouble(&y); + return m_value = Pointf(x, y); } void StaticText::BUILD() diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index eaf24c8bc7..62242ea8a0 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -396,6 +396,7 @@ GLGizmoScale::GLGizmoScale() : GLGizmoBase() , m_scale(1.0f) , m_starting_scale(1.0f) + , m_starting_drag_position(Vec2d::Zero()) { } diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index dc4f592cd2..7671b7d033 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -113,7 +113,7 @@ Point::coincides_with(point_sv) void scale(double factor) %code{% *THIS *= factor; %}; void rotate(double angle, Pointf* center) - %code{% THIS->rotate(angle, *center); %}; + %code{% *THIS = Eigen::Translation2d(*center) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- *center) * Eigen::Vector2d((*THIS)(0), (*THIS)(1)); %}; Pointf* negative() %code{% RETVAL = new Pointf(- *THIS); %}; Pointf* vector_to(Pointf* point)