From 0b5b02e0027b9994e26f5b719355d6e08bb4b2db Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 21 Aug 2018 21:05:24 +0200 Subject: [PATCH] Eradicated the Pointf class, replaced with Eigen Vector3d --- xs/src/libslic3r/BoundingBox.cpp | 18 +++++----- xs/src/libslic3r/BoundingBox.hpp | 10 +++--- xs/src/libslic3r/Config.hpp | 18 +++++----- xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp | 4 +-- xs/src/libslic3r/Fill/FillGyroid.cpp | 24 +++++++------ xs/src/libslic3r/Fill/FillPlanePath.cpp | 42 +++++++++++----------- xs/src/libslic3r/Fill/FillRectilinear3.cpp | 8 ++--- xs/src/libslic3r/Format/PRUS.cpp | 2 +- xs/src/libslic3r/GCode.cpp | 16 ++++----- xs/src/libslic3r/GCode.hpp | 12 +++---- xs/src/libslic3r/GCode/PrintExtents.cpp | 10 +++--- xs/src/libslic3r/GCodeWriter.cpp | 4 +-- xs/src/libslic3r/GCodeWriter.hpp | 4 +-- xs/src/libslic3r/Geometry.cpp | 30 ++++++++-------- xs/src/libslic3r/Geometry.hpp | 6 ++-- xs/src/libslic3r/Line.hpp | 6 ++-- xs/src/libslic3r/Model.cpp | 6 ++-- xs/src/libslic3r/Model.hpp | 4 +-- xs/src/libslic3r/ModelArrange.hpp | 2 +- xs/src/libslic3r/Point.cpp | 2 +- xs/src/libslic3r/Point.hpp | 32 ++--------------- xs/src/libslic3r/Polygon.cpp | 4 +-- xs/src/libslic3r/Polygon.hpp | 4 +-- xs/src/libslic3r/Polyline.hpp | 4 +-- xs/src/libslic3r/Print.hpp | 2 +- xs/src/libslic3r/PrintConfig.cpp | 4 +-- xs/src/libslic3r/PrintObject.cpp | 2 +- xs/src/libslic3r/SVG.cpp | 4 +-- xs/src/libslic3r/SupportMaterial.cpp | 4 +-- xs/src/perlglue.cpp | 18 +++++----- xs/src/slic3r/GUI/2DBed.cpp | 28 +++++++-------- xs/src/slic3r/GUI/2DBed.hpp | 14 ++++---- xs/src/slic3r/GUI/3DScene.cpp | 28 +++++++-------- xs/src/slic3r/GUI/BedShapeDialog.cpp | 34 +++++++++--------- xs/src/slic3r/GUI/BedShapeDialog.hpp | 4 +-- xs/src/slic3r/GUI/Field.cpp | 8 ++--- xs/src/slic3r/GUI/Field.hpp | 2 +- xs/src/slic3r/GUI/GLCanvas3D.cpp | 30 ++++++++-------- xs/src/slic3r/GUI/GLCanvas3D.hpp | 10 +++--- xs/src/slic3r/GUI/GLGizmo.cpp | 16 ++++----- xs/src/slic3r/GUI/GLGizmo.hpp | 14 ++++---- xs/src/slic3r/GUI/GUI.cpp | 4 +-- xs/src/xsinit.h | 6 ++-- xs/xsp/BoundingBox.xsp | 10 +++--- xs/xsp/GCode.xsp | 4 +-- xs/xsp/Geometry.xsp | 2 +- xs/xsp/Model.xsp | 6 ++-- xs/xsp/Point.xsp | 20 +++++------ xs/xsp/Print.xsp | 2 +- xs/xsp/my.map | 6 ++-- xs/xsp/typemap.xspt | 6 ++-- 51 files changed, 267 insertions(+), 293 deletions(-) diff --git a/xs/src/libslic3r/BoundingBox.cpp b/xs/src/libslic3r/BoundingBox.cpp index 81a748f8f..9bd2327ad 100644 --- a/xs/src/libslic3r/BoundingBox.cpp +++ b/xs/src/libslic3r/BoundingBox.cpp @@ -7,7 +7,7 @@ namespace Slic3r { template BoundingBoxBase::BoundingBoxBase(const std::vector &points); -template BoundingBoxBase::BoundingBoxBase(const std::vector &points); +template BoundingBoxBase::BoundingBoxBase(const std::vector &points); template BoundingBox3Base::BoundingBox3Base(const std::vector &points); @@ -70,7 +70,7 @@ BoundingBoxBase::scale(double factor) this->max *= factor; } template void BoundingBoxBase::scale(double factor); -template void BoundingBoxBase::scale(double factor); +template void BoundingBoxBase::scale(double factor); template void BoundingBoxBase::scale(double factor); template void @@ -86,7 +86,7 @@ BoundingBoxBase::merge(const PointClass &point) } } template void BoundingBoxBase::merge(const Point &point); -template void BoundingBoxBase::merge(const Pointf &point); +template void BoundingBoxBase::merge(const Vec2d &point); template void BoundingBoxBase::merge(const std::vector &points) @@ -94,7 +94,7 @@ BoundingBoxBase::merge(const std::vector &points) this->merge(BoundingBoxBase(points)); } template void BoundingBoxBase::merge(const Points &points); -template void BoundingBoxBase::merge(const Pointfs &points); +template void BoundingBoxBase::merge(const Pointfs &points); template void BoundingBoxBase::merge(const BoundingBoxBase &bb) @@ -112,7 +112,7 @@ BoundingBoxBase::merge(const BoundingBoxBase &bb) } } template void BoundingBoxBase::merge(const BoundingBoxBase &bb); -template void BoundingBoxBase::merge(const BoundingBoxBase &bb); +template void BoundingBoxBase::merge(const BoundingBoxBase &bb); template void BoundingBox3Base::merge(const PointClass &point) @@ -158,7 +158,7 @@ BoundingBoxBase::size() const return PointClass(this->max(0) - this->min(0), this->max(1) - this->min(1)); } template Point BoundingBoxBase::size() const; -template Pointf BoundingBoxBase::size() const; +template Vec2d BoundingBoxBase::size() const; template PointClass BoundingBox3Base::size() const @@ -175,7 +175,7 @@ template double BoundingBoxBase::radius() const return 0.5 * sqrt(x*x+y*y); } template double BoundingBoxBase::radius() const; -template double BoundingBoxBase::radius() const; +template double BoundingBoxBase::radius() const; template double BoundingBox3Base::radius() const { @@ -194,7 +194,7 @@ BoundingBoxBase::offset(coordf_t delta) this->max += v; } template void BoundingBoxBase::offset(coordf_t delta); -template void BoundingBoxBase::offset(coordf_t delta); +template void BoundingBoxBase::offset(coordf_t delta); template void BoundingBox3Base::offset(coordf_t delta) @@ -211,7 +211,7 @@ BoundingBoxBase::center() const return (this->min + this->max) / 2; } template Point BoundingBoxBase::center() const; -template Pointf BoundingBoxBase::center() const; +template Vec2d BoundingBoxBase::center() const; template PointClass BoundingBox3Base::center() const diff --git a/xs/src/libslic3r/BoundingBox.hpp b/xs/src/libslic3r/BoundingBox.hpp index cb8bc3ad9..6190d4b93 100644 --- a/xs/src/libslic3r/BoundingBox.hpp +++ b/xs/src/libslic3r/BoundingBox.hpp @@ -39,7 +39,7 @@ public: PointClass size() const; double radius() const; void translate(coordf_t x, coordf_t y) { assert(this->defined); PointClass v(x, y); this->min += v; this->max += v; } - void translate(const Pointf &v) { this->min += v; this->max += v; } + void translate(const Vec2d &v) { this->min += v; this->max += v; } void offset(coordf_t delta); PointClass center() const; bool contains(const PointClass &point) const { @@ -128,12 +128,12 @@ public: BoundingBox3(const Points3& points) : BoundingBox3Base(points) {}; }; -class BoundingBoxf : public BoundingBoxBase +class BoundingBoxf : public BoundingBoxBase { public: - BoundingBoxf() : BoundingBoxBase() {}; - BoundingBoxf(const Pointf &pmin, const Pointf &pmax) : BoundingBoxBase(pmin, pmax) {}; - BoundingBoxf(const std::vector &points) : BoundingBoxBase(points) {}; + BoundingBoxf() : BoundingBoxBase() {}; + BoundingBoxf(const Vec2d &pmin, const Vec2d &pmax) : BoundingBoxBase(pmin, pmax) {}; + BoundingBoxf(const std::vector &points) : BoundingBoxBase(points) {}; }; class BoundingBoxf3 : public BoundingBox3Base diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index a1b0f624e..7f75f815d 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -622,11 +622,11 @@ public: } }; -class ConfigOptionPoint : public ConfigOptionSingle +class ConfigOptionPoint : public ConfigOptionSingle { public: - ConfigOptionPoint() : ConfigOptionSingle(Pointf(0,0)) {} - explicit ConfigOptionPoint(const Pointf &value) : ConfigOptionSingle(value) {} + ConfigOptionPoint() : ConfigOptionSingle(Vec2d(0,0)) {} + explicit ConfigOptionPoint(const Vec2d &value) : ConfigOptionSingle(value) {} static ConfigOptionType static_type() { return coPoint; } ConfigOptionType type() const override { return static_type(); } @@ -652,13 +652,13 @@ public: } }; -class ConfigOptionPoints : public ConfigOptionVector +class ConfigOptionPoints : public ConfigOptionVector { public: - ConfigOptionPoints() : ConfigOptionVector() {} - explicit ConfigOptionPoints(size_t n, const Pointf &value) : ConfigOptionVector(n, value) {} - explicit ConfigOptionPoints(std::initializer_list il) : ConfigOptionVector(std::move(il)) {} - explicit ConfigOptionPoints(const std::vector &values) : ConfigOptionVector(values) {} + ConfigOptionPoints() : ConfigOptionVector() {} + explicit ConfigOptionPoints(size_t n, const Vec2d &value) : ConfigOptionVector(n, value) {} + explicit ConfigOptionPoints(std::initializer_list il) : ConfigOptionVector(std::move(il)) {} + explicit ConfigOptionPoints(const std::vector &values) : ConfigOptionVector(values) {} static ConfigOptionType static_type() { return coPoints; } ConfigOptionType type() const override { return static_type(); } @@ -696,7 +696,7 @@ public: std::istringstream is(str); std::string point_str; while (std::getline(is, point_str, ',')) { - Pointf point(Vec2d::Zero()); + Vec2d 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/Fill/Fill3DHoneycomb.cpp b/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp index 16ed12fb9..6a37e4369 100644 --- a/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp +++ b/xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp @@ -54,7 +54,7 @@ static std::vector 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 (Pointf &pt : pts) { + for (Vec2d &pt : pts) { pt(0) = clamp(minX, maxX, pt(0)); pt(1) = clamp(minY, maxY, pt(1)); } @@ -66,7 +66,7 @@ static inline Pointfs zip(const std::vector &x, const std::vector& one_period, double width, double height, double offset, double scaleFactor, + const std::vector& one_period, double width, double height, double offset, double scaleFactor, double z_cos, double z_sin, bool vertical) { - std::vector points = one_period; + std::vector points = one_period; double period = points.back()(0); points.pop_back(); int n = points.size(); do { - points.emplace_back(Pointf(points[points.size()-n](0) + period, points[points.size()-n](1))); + points.emplace_back(Vec2d(points[points.size()-n](0) + period, points[points.size()-n](1))); } while (points.back()(0) < width); points.back()(0) = width; @@ -55,14 +55,14 @@ static inline Polyline make_wave( return polyline; } -static std::vector make_one_period(double width, double scaleFactor, double z_cos, double z_sin, bool vertical, bool flip) +static std::vector make_one_period(double width, double scaleFactor, double z_cos, double z_sin, bool vertical, bool flip) { - std::vector points; + std::vector points; double dx = M_PI_4; // very coarse spacing to begin with double limit = std::min(2*M_PI, width); for (double x = 0.; x < limit + EPSILON; x += dx) { // so the last point is there too x = std::min(x, limit); - points.emplace_back(Pointf(x,f(x, z_sin,z_cos, vertical, flip))); + points.emplace_back(Vec2d(x,f(x, z_sin,z_cos, vertical, flip))); } // now we will check all internal points and in case some are too far from the line connecting its neighbours, @@ -77,11 +77,13 @@ static std::vector make_one_period(double width, double scaleFactor, dou double dist_mm = unscale(scaleFactor) * std::abs(cross2(rp, lp) - cross2(rp - lp, tp)) / lrv.norm(); if (dist_mm > tolerance) { // if the difference from straight line is more than this double x = 0.5f * (points[i-1](0) + points[i](0)); - points.emplace_back(Pointf(x, f(x, z_sin, z_cos, vertical, flip))); + points.emplace_back(Vec2d(x, f(x, z_sin, z_cos, vertical, flip))); x = 0.5f * (points[i+1](0) + points[i](0)); - 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 + points.emplace_back(Vec2d(x, f(x, z_sin, z_cos, vertical, flip))); + // we added the points to the end, but need them all in order + std::sort(points.begin(), points.end(), [](const Vec2d &lhs, const Vec2d &rhs){ return lhs < rhs; }); + // decrement i so we also check the first newly added point + --i; } } return points; @@ -107,7 +109,7 @@ static Polylines make_gyroid_waves(double gridZ, double density_adjusted, double std::swap(width,height); } - std::vector one_period = make_one_period(width, scaleFactor, z_cos, z_sin, vertical, flip); // creates one period of the waves, so it doesn't have to be recalculated all the time + std::vector one_period = make_one_period(width, scaleFactor, z_cos, z_sin, vertical, flip); // creates one period of the waves, so it doesn't have to be recalculated all the time Polylines result; for (double y0 = lower_bound; y0 < upper_bound+EPSILON; y0 += 2*M_PI) // creates odd polylines diff --git a/xs/src/libslic3r/Fill/FillPlanePath.cpp b/xs/src/libslic3r/Fill/FillPlanePath.cpp index bb7d5ac80..615cc6efe 100644 --- a/xs/src/libslic3r/Fill/FillPlanePath.cpp +++ b/xs/src/libslic3r/Fill/FillPlanePath.cpp @@ -86,12 +86,12 @@ Pointfs FillArchimedeanChords::_generate(coord_t min_x, coord_t min_y, coord_t m coordf_t r = 1; Pointfs out; //FIXME Vojtech: If used as a solid infill, there is a gap left at the center. - out.push_back(Pointf(0, 0)); - out.push_back(Pointf(1, 0)); + out.push_back(Vec2d(0, 0)); + out.push_back(Vec2d(1, 0)); while (r < rmax) { theta += 1. / r; r = a + b * theta; - out.push_back(Pointf(r * cos(theta), r * sin(theta))); + out.push_back(Vec2d(r * cos(theta), r * sin(theta))); } return out; } @@ -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(0) + min_x, p(1) + min_y)); + line.push_back(Vec2d(p(0) + min_x, p(1) + min_y)); } return line; } @@ -175,27 +175,27 @@ Pointfs FillOctagramSpiral::_generate(coord_t min_x, coord_t min_y, coord_t max_ coordf_t r = 0; coordf_t r_inc = sqrt(2.); Pointfs out; - out.push_back(Pointf(0, 0)); + out.push_back(Vec2d(0, 0)); while (r < rmax) { r += r_inc; coordf_t rx = r / sqrt(2.); coordf_t r2 = r + rx; - out.push_back(Pointf( r, 0.)); - out.push_back(Pointf( r2, rx)); - out.push_back(Pointf( rx, rx)); - out.push_back(Pointf( rx, r2)); - out.push_back(Pointf(0., r)); - out.push_back(Pointf(-rx, r2)); - out.push_back(Pointf(-rx, rx)); - out.push_back(Pointf(-r2, rx)); - out.push_back(Pointf(-r, 0.)); - out.push_back(Pointf(-r2, -rx)); - out.push_back(Pointf(-rx, -rx)); - out.push_back(Pointf(-rx, -r2)); - out.push_back(Pointf(0., -r)); - out.push_back(Pointf( rx, -r2)); - out.push_back(Pointf( rx, -rx)); - out.push_back(Pointf( r2+r_inc, -rx)); + out.push_back(Vec2d( r, 0.)); + out.push_back(Vec2d( r2, rx)); + out.push_back(Vec2d( rx, rx)); + out.push_back(Vec2d( rx, r2)); + out.push_back(Vec2d(0., r)); + out.push_back(Vec2d(-rx, r2)); + out.push_back(Vec2d(-rx, rx)); + out.push_back(Vec2d(-r2, rx)); + out.push_back(Vec2d(-r, 0.)); + out.push_back(Vec2d(-r2, -rx)); + out.push_back(Vec2d(-rx, -rx)); + out.push_back(Vec2d(-rx, -r2)); + out.push_back(Vec2d(0., -r)); + out.push_back(Vec2d( rx, -r2)); + out.push_back(Vec2d( rx, -rx)); + out.push_back(Vec2d( r2+r_inc, -rx)); } return out; } diff --git a/xs/src/libslic3r/Fill/FillRectilinear3.cpp b/xs/src/libslic3r/Fill/FillRectilinear3.cpp index 72c8b1ec5..8fc129eac 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear3.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear3.cpp @@ -217,11 +217,11 @@ Point SegmentIntersection::pos() const const Point &seg_start = poly.points[(this->iSegment == 0) ? poly.points.size() - 1 : this->iSegment - 1]; const Point &seg_end = poly.points[this->iSegment]; // Point, vector of the segment. - const Pointf p1(seg_start.cast()); - const Pointf v1((seg_end - seg_start).cast()); + const Vec2d p1(seg_start.cast()); + const Vec2d v1((seg_end - seg_start).cast()); // Point, vector of this hatching line. - const Pointf p2(line->pos.cast()); - const Pointf v2(line->dir.cast()); + const Vec2d p2(line->pos.cast()); + const Vec2d v2(line->dir.cast()); // Intersect the two rays. double denom = v1(0) * v2(1) - v2(0) * v1(1); Point out; diff --git a/xs/src/libslic3r/Format/PRUS.cpp b/xs/src/libslic3r/Format/PRUS.cpp index b817f8305..9f42fc151 100644 --- a/xs/src/libslic3r/Format/PRUS.cpp +++ b/xs/src/libslic3r/Format/PRUS.cpp @@ -166,7 +166,7 @@ bool load_prus(const char *path, Model *model) float trafo[3][4] = { 0 }; double instance_rotation = 0.; double instance_scaling_factor = 1.f; - Pointf instance_offset(0., 0.); + Vec2d instance_offset(0., 0.); bool trafo_set = false; unsigned int group_id = (unsigned int)-1; unsigned int extruder_id = (unsigned int)-1; diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 2f911440a..fa18ddf3f 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -207,7 +207,7 @@ std::string WipeTowerIntegration::append_tcr(GCode &gcodegen, const WipeTower::T check_add_eol(gcode); } // A phony move to the end position at the wipe tower. - gcodegen.writer().travel_to_xy(Pointf(end_pos.x, end_pos.y)); + gcodegen.writer().travel_to_xy(Vec2d(end_pos.x, end_pos.y)); gcodegen.set_last_pos(wipe_tower_point_to_object_point(gcodegen, end_pos)); // Prepare a future wipe. @@ -293,7 +293,7 @@ std::string WipeTowerIntegration::prime(GCode &gcodegen) gcodegen.writer().toolchange(current_extruder_id); gcodegen.placeholder_parser().set("current_extruder", current_extruder_id); // A phony move to the end position at the wipe tower. - gcodegen.writer().travel_to_xy(Pointf(m_priming.end_pos.x, m_priming.end_pos.y)); + gcodegen.writer().travel_to_xy(Vec2d(m_priming.end_pos.x, m_priming.end_pos.y)); gcodegen.set_last_pos(wipe_tower_point_to_object_point(gcodegen, m_priming.end_pos)); // Prepare a future wipe. gcodegen.m_wipe.path.points.clear(); @@ -783,7 +783,7 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data) Polygon outer_skirt = Slic3r::Geometry::convex_hull(skirt_points); Polygons skirts; for (unsigned int extruder_id : print.extruders()) { - const Pointf &extruder_offset = print.config.extruder_offset.get_at(extruder_id); + const Vec2d &extruder_offset = print.config.extruder_offset.get_at(extruder_id); Polygon s(outer_skirt); s.translate(Point::new_scale(- extruder_offset(0), - extruder_offset(1))); skirts.emplace_back(std::move(s)); @@ -1632,7 +1632,7 @@ void GCode::set_extruders(const std::vector &extruder_ids) } } -void GCode::set_origin(const Pointf &pointf) +void GCode::set_origin(const Vec2d &pointf) { // if origin increases (goes towards right), last_pos decreases because it goes towards left const Point translate( @@ -2618,16 +2618,16 @@ std::string GCode::set_extruder(unsigned int extruder_id) } // convert a model-space scaled point into G-code coordinates -Pointf GCode::point_to_gcode(const Point &point) const +Vec2d GCode::point_to_gcode(const Point &point) const { - Pointf extruder_offset = EXTRUDER_CONFIG(extruder_offset); + Vec2d extruder_offset = EXTRUDER_CONFIG(extruder_offset); return unscale(point) + m_origin - extruder_offset; } // convert a model-space scaled point into G-code coordinates -Point GCode::gcode_to_point(const Pointf &point) const +Point GCode::gcode_to_point(const Vec2d &point) const { - Pointf extruder_offset = EXTRUDER_CONFIG(extruder_offset); + Vec2d extruder_offset = EXTRUDER_CONFIG(extruder_offset); return Point( scale_(point(0) - m_origin(0) + extruder_offset(0)), scale_(point(1) - m_origin(1) + extruder_offset(1))); diff --git a/xs/src/libslic3r/GCode.hpp b/xs/src/libslic3r/GCode.hpp index 235ca62f0..dc8a32135 100644 --- a/xs/src/libslic3r/GCode.hpp +++ b/xs/src/libslic3r/GCode.hpp @@ -153,12 +153,12 @@ public: void do_export(Print *print, const char *path, GCodePreviewData *preview_data = nullptr); // Exported for the helper classes (OozePrevention, Wipe) and for the Perl binding for unit tests. - const Pointf& origin() const { return m_origin; } - void set_origin(const Pointf &pointf); - void set_origin(const coordf_t x, const coordf_t y) { this->set_origin(Pointf(x, y)); } + const Vec2d& origin() const { return m_origin; } + void set_origin(const Vec2d &pointf); + void set_origin(const coordf_t x, const coordf_t y) { this->set_origin(Vec2d(x, y)); } const Point& last_pos() const { return m_last_pos; } - Pointf point_to_gcode(const Point &point) const; - Point gcode_to_point(const Pointf &point) const; + Vec2d point_to_gcode(const Point &point) const; + Point gcode_to_point(const Vec2d &point) const; const FullPrintConfig &config() const { return m_config; } const Layer* layer() const { return m_layer; } GCodeWriter& writer() { return m_writer; } @@ -259,7 +259,7 @@ protected: /* Origin of print coordinates expressed in unscaled G-code coordinates. This affects the input arguments supplied to the extrude*() and travel_to() methods. */ - Pointf m_origin; + Vec2d m_origin; FullPrintConfig m_config; GCodeWriter m_writer; PlaceholderParser m_placeholder_parser; diff --git a/xs/src/libslic3r/GCode/PrintExtents.cpp b/xs/src/libslic3r/GCode/PrintExtents.cpp index dd0b18db8..2ed607769 100644 --- a/xs/src/libslic3r/GCode/PrintExtents.cpp +++ b/xs/src/libslic3r/GCode/PrintExtents.cpp @@ -148,9 +148,9 @@ 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 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); + Vec2d delta = 0.5 * Vec2d(e.width, e.width); + Vec2d p1 = trafo * Vec2d((&e - 1)->pos.x, (&e - 1)->pos.y); + Vec2d p2 = trafo * Vec2d(e.pos.x, e.pos.y); bbox.merge(p1.cwiseMin(p2) - delta); bbox.merge(p1.cwiseMax(p2) + delta); } @@ -169,8 +169,8 @@ BoundingBoxf get_wipe_tower_priming_extrusions_extents(const Print &print) 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); + Vec2d p1((&e - 1)->pos.x, (&e - 1)->pos.y); + Vec2d p2(e.pos.x, e.pos.y); 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); diff --git a/xs/src/libslic3r/GCodeWriter.cpp b/xs/src/libslic3r/GCodeWriter.cpp index 5352e9502..6ef17f4f4 100644 --- a/xs/src/libslic3r/GCodeWriter.cpp +++ b/xs/src/libslic3r/GCodeWriter.cpp @@ -276,7 +276,7 @@ std::string GCodeWriter::set_speed(double F, const std::string &comment, const s return gcode.str(); } -std::string GCodeWriter::travel_to_xy(const Pointf &point, const std::string &comment) +std::string GCodeWriter::travel_to_xy(const Vec2d &point, const std::string &comment) { m_pos(0) = point(0); m_pos(1) = point(1); @@ -358,7 +358,7 @@ bool GCodeWriter::will_move_z(double z) const return true; } -std::string GCodeWriter::extrude_to_xy(const Pointf &point, double dE, const std::string &comment) +std::string GCodeWriter::extrude_to_xy(const Vec2d &point, double dE, const std::string &comment) { m_pos(0) = point(0); m_pos(1) = point(1); diff --git a/xs/src/libslic3r/GCodeWriter.hpp b/xs/src/libslic3r/GCodeWriter.hpp index d02bbfe60..664b0e3a1 100644 --- a/xs/src/libslic3r/GCodeWriter.hpp +++ b/xs/src/libslic3r/GCodeWriter.hpp @@ -55,11 +55,11 @@ public: std::string toolchange_prefix() const; std::string toolchange(unsigned int extruder_id); std::string set_speed(double F, const std::string &comment = std::string(), const std::string &cooling_marker = std::string()) const; - std::string travel_to_xy(const Pointf &point, const std::string &comment = std::string()); + std::string travel_to_xy(const Vec2d &point, const std::string &comment = std::string()); std::string travel_to_xyz(const Vec3d &point, const std::string &comment = std::string()); std::string travel_to_z(double z, const std::string &comment = std::string()); bool will_move_z(double z) const; - std::string extrude_to_xy(const Pointf &point, double dE, const std::string &comment = std::string()); + std::string extrude_to_xy(const Vec2d &point, double dE, const std::string &comment = std::string()); std::string extrude_to_xyz(const Vec3d &point, double dE, const std::string &comment = std::string()); std::string retract(bool before_wipe = false); std::string retract_for_toolchange(bool before_wipe = false); diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index f51334155..c978d46b6 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -345,7 +345,7 @@ linint(double value, double oldmin, double oldmax, double newmin, double newmax) // If the points have the same weight, sort them lexicographically by their positions. struct ArrangeItem { ArrangeItem() {} - Pointf pos; + Vec2d pos; coordf_t weight; bool operator<(const ArrangeItem &other) const { return weight < other.weight || @@ -353,17 +353,17 @@ struct ArrangeItem { } }; -Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const BoundingBoxf* bed_bounding_box) +Pointfs arrange(size_t num_parts, const Vec2d &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(0) + gap, part_size(1) + gap); + const Vec2d cell_size(part_size(0) + gap, part_size(1) + 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(0) * num_parts, cell_size(1) * num_parts)); + Vec2d(0, 0), + Vec2d(cell_size(0) * num_parts, cell_size(1) * num_parts)); // This is how many cells we have available into which to put parts. size_t cellw = size_t(floor((bed_bbox.size()(0) + gap) / cell_size(0))); @@ -372,8 +372,8 @@ Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const B 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(0) - gap, cellh * cell_size(1) - gap); - Pointf cells_offset(bed_bbox.center() - 0.5 * cells_size); + Vec2d cells_size(cellw * cell_size(0) - gap, cellh * cell_size(1) - gap); + Vec2d cells_offset(bed_bbox.center() - 0.5 * cells_size); BoundingBoxf cells_bb(cells_offset, cells_size + cells_offset); // List of cells, sorted by distance from center. @@ -405,13 +405,13 @@ Pointfs arrange(size_t num_parts, const Pointf &part_size, coordf_t gap, const B Pointfs positions; positions.reserve(num_parts); for (std::vector::const_iterator it = cellsorder.begin(); it != cellsorder.end(); ++ it) - positions.push_back(Pointf(it->pos(0) - 0.5 * part_size(0), it->pos(1) - 0.5 * part_size(1))); + positions.push_back(Vec2d(it->pos(0) - 0.5 * part_size(0), it->pos(1) - 0.5 * part_size(1))); return positions; } #else class ArrangeItem { public: - Pointf pos = Vec2d::Zero(); + Vec2d pos = Vec2d::Zero(); size_t index_x, index_y; coordf_t dist; }; @@ -423,17 +423,17 @@ public: }; bool -arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const BoundingBoxf* bb, Pointfs &positions) +arrange(size_t total_parts, const Vec2d &part_size, coordf_t dist, const BoundingBoxf* bb, Pointfs &positions) { positions.clear(); - Pointf part = part_size; + Vec2d part = part_size; // use actual part size (the largest) plus separation distance (half on each side) in spacing algorithm part(0) += dist; part(1) += dist; - Pointf area(Vec2d::Zero()); + Vec2d area(Vec2d::Zero()); if (bb != NULL && bb->defined) { area = bb->size(); } else { @@ -449,11 +449,11 @@ arrange(size_t total_parts, const Pointf &part_size, coordf_t dist, const Boundi return false; // total space used by cells - Pointf cells(cellw * part(0), cellh * part(1)); + Vec2d cells(cellw * part(0), cellh * part(1)); // bounding box of total space used by cells BoundingBoxf cells_bb; - cells_bb.merge(Pointf(0,0)); // min + cells_bb.merge(Vec2d(0,0)); // min cells_bb.merge(cells); // max // center bounding box to area @@ -533,7 +533,7 @@ 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(0), cy * part(1))); + positions.push_back(Vec2d(cx * part(0), cy * part(1))); } if (bb != NULL && bb->defined) { diff --git a/xs/src/libslic3r/Geometry.hpp b/xs/src/libslic3r/Geometry.hpp index 95c13fcdb..194534007 100644 --- a/xs/src/libslic3r/Geometry.hpp +++ b/xs/src/libslic3r/Geometry.hpp @@ -66,7 +66,7 @@ static inline bool is_ccw(const Polygon &poly) return o == ORIENTATION_CCW; } -inline bool ray_ray_intersection(const Pointf &p1, const Vectorf &v1, const Pointf &p2, const Vectorf &v2, Pointf &res) +inline bool ray_ray_intersection(const Vec2d &p1, const Vec2d &v1, const Vec2d &p2, const Vec2d &v2, Vec2d &res) { double denom = v1(0) * v2(1) - v2(0) * v1(1); if (std::abs(denom) < EPSILON) @@ -77,7 +77,7 @@ inline bool ray_ray_intersection(const Pointf &p1, const Vectorf &v1, const Poin return true; } -inline bool segment_segment_intersection(const Pointf &p1, const Vectorf &v1, const Pointf &p2, const Vectorf &v2, Pointf &res) +inline bool segment_segment_intersection(const Vec2d &p1, const Vec2d &v1, const Vec2d &p2, const Vec2d &v2, Vec2d &res) { double denom = v1(0) * v2(1) - v2(0) * v1(1); if (std::abs(denom) < EPSILON) @@ -123,7 +123,7 @@ void simplify_polygons(const Polygons &polygons, double tolerance, Polygons* ret double linint(double value, double oldmin, double oldmax, double newmin, double newmax); bool arrange( // input - size_t num_parts, const Pointf &part_size, coordf_t gap, const BoundingBoxf* bed_bounding_box, + size_t num_parts, const Vec2d &part_size, coordf_t gap, const BoundingBoxf* bed_bounding_box, // output Pointfs &positions); diff --git a/xs/src/libslic3r/Line.hpp b/xs/src/libslic3r/Line.hpp index 65e04dc93..b1294f522 100644 --- a/xs/src/libslic3r/Line.hpp +++ b/xs/src/libslic3r/Line.hpp @@ -72,10 +72,10 @@ class Linef { public: Linef() : a(Vec2d::Zero()), b(Vec2d::Zero()) {} - explicit Linef(Pointf _a, Pointf _b): a(_a), b(_b) {} + explicit Linef(Vec2d _a, Vec2d _b): a(_a), b(_b) {} - Pointf a; - Pointf b; + Vec2d a; + Vec2d b; }; class Linef3 diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 047751ecd..e0f226476 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -243,7 +243,7 @@ BoundingBoxf3 Model::transformed_bounding_box() const return bb; } -void Model::center_instances_around_point(const Pointf &point) +void Model::center_instances_around_point(const Vec2d &point) { // BoundingBoxf3 bb = this->bounding_box(); BoundingBoxf3 bb; @@ -251,7 +251,7 @@ void Model::center_instances_around_point(const Pointf &point) for (size_t i = 0; i < o->instances.size(); ++ i) bb.merge(o->instance_bounding_box(i, false)); - Pointf shift = point - 0.5 * to_2d(bb.size()) - to_2d(bb.min); + Vec2d shift = point - 0.5 * to_2d(bb.size()) - to_2d(bb.min); for (ModelObject *o : this->objects) { for (ModelInstance *i : o->instances) i->offset += shift; @@ -343,7 +343,7 @@ void Model::duplicate(size_t copies_num, coordf_t dist, const BoundingBoxf* bb) // make a copy of the pointers in order to avoid recursion when appending their copies ModelInstancePtrs instances = o->instances; for (const ModelInstance *i : instances) { - for (const Pointf &pos : positions) { + for (const Vec2d &pos : positions) { ModelInstance *instance = o->add_instance(*i); instance->offset += pos; } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index a7597ada5..6b6db7696 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -213,7 +213,7 @@ public: // Transform3d transform; double rotation; // Rotation around the Z axis, in radians around mesh center point double scaling_factor; - Pointf offset; // in unscaled coordinates + Vec2d offset; // in unscaled coordinates // flag showing the position of this instance with respect to the print volume (set by Print::validate() using ModelObject::check_instances_print_volume_state()) EPrintVolumeState print_volume_state; @@ -288,7 +288,7 @@ public: BoundingBoxf3 bounding_box() const; // Returns tight axis aligned bounding box of this model BoundingBoxf3 transformed_bounding_box() const; - void center_instances_around_point(const Pointf &point); + void center_instances_around_point(const Vec2d &point); void translate(coordf_t x, coordf_t y, coordf_t z) { for (ModelObject *o : this->objects) o->translate(x, y, z); } TriangleMesh mesh() const; bool arrange_objects(coordf_t dist, const BoundingBoxf* bb = NULL); diff --git a/xs/src/libslic3r/ModelArrange.hpp b/xs/src/libslic3r/ModelArrange.hpp index 67825248a..db18e6731 100644 --- a/xs/src/libslic3r/ModelArrange.hpp +++ b/xs/src/libslic3r/ModelArrange.hpp @@ -468,7 +468,7 @@ void applyResult( // appropriately auto off = item.translation(); Radians rot = item.rotation(); - Pointf foff(off.X*SCALING_FACTOR + batch_offset, + Vec2d foff(off.X*SCALING_FACTOR + batch_offset, off.Y*SCALING_FACTOR); // write the tranformation data into the model instance diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp index 0fe76c611..ec6c28fe8 100644 --- a/xs/src/libslic3r/Point.cpp +++ b/xs/src/libslic3r/Point.cpp @@ -148,7 +148,7 @@ Point Point::projection_onto(const Line &line) const return ((line.a - *this).cast().squaredNorm() < (line.b - *this).cast().squaredNorm()) ? line.a : line.b; } -std::ostream& operator<<(std::ostream &stm, const Pointf &pointf) +std::ostream& operator<<(std::ostream &stm, const Vec2d &pointf) { return stm << pointf(0) << "," << pointf(1); } diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index b5af3b1de..2d0304f4e 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -17,10 +17,8 @@ class Line; class MultiPoint; class Point; class Point3; -class Pointf; typedef Point Vector; typedef Point3 Vector3; -typedef Pointf Vectorf; // Eigen types, to replace the Slic3r's own types in the future. // Vector types with a fixed point coordinate base type. @@ -39,7 +37,7 @@ typedef std::vector Points; typedef std::vector PointPtrs; typedef std::vector PointConstPtrs; typedef std::vector Points3; -typedef std::vector Pointfs; +typedef std::vector Pointfs; typedef std::vector Pointf3s; typedef Eigen::Transform Transform2f; @@ -244,33 +242,7 @@ public: } }; -std::ostream& operator<<(std::ostream &stm, const Pointf &pointf); - -class Pointf : public Vec2d -{ -public: - typedef coordf_t coord_type; - -// 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 - Pointf(const Eigen::MatrixBase &other) : Vec2d(other) {} - - // This method allows you to assign Eigen expressions to MyVectorType - template - Pointf& operator=(const Eigen::MatrixBase &other) - { - this->Vec2d::operator=(other); - return *this; - } - -// void rotate(double angle); -// void rotate(double angle, const Pointf ¢er); - -private: -}; +std::ostream& operator<<(std::ostream &stm, const Vec2d &pointf); } // namespace Slic3r diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index f9c82d198..14248d84f 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -297,10 +297,10 @@ Point Polygon::point_projection(const Point &point) const dmin = d; proj = pt1; } - Pointf v1(coordf_t(pt1(0) - pt0(0)), coordf_t(pt1(1) - pt0(1))); + Vec2d v1(coordf_t(pt1(0) - pt0(0)), coordf_t(pt1(1) - pt0(1))); coordf_t div = v1.squaredNorm(); if (div > 0.) { - Pointf v2(coordf_t(point(0) - pt0(0)), coordf_t(point(1) - pt0(1))); + Vec2d v2(coordf_t(point(0) - pt0(0)), coordf_t(point(1) - pt0(1))); coordf_t t = v1.dot(v2) / div; if (t > 0. && t < 1.) { Point foot(coord_t(floor(coordf_t(pt0(0)) + t * v1(0) + 0.5)), coord_t(floor(coordf_t(pt0(1)) + t * v1(1) + 0.5))); diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index 18a2d2b95..54909352c 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -24,10 +24,10 @@ 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(const std::vector &points) { + static Polygon new_scale(const std::vector &points) { Polygon pgn; pgn.points.reserve(points.size()); - for (const Pointf &pt : points) + for (const Vec2d &pt : points) pgn.points.emplace_back(Point::new_scale(pt(0), pt(1))); return pgn; } diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index f61e46717..0c934e074 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -23,10 +23,10 @@ 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(const std::vector &points) { + static Polyline new_scale(const std::vector &points) { Polyline pl; pl.points.reserve(points.size()); - for (const Pointf &pt : points) + for (const Vec2d &pt : points) pl.points.emplace_back(Point::new_scale(pt(0), pt(1))); return pl; } diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 734b04e3f..ef43033da 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -138,7 +138,7 @@ public: const ModelObject* model_object() const { return this->_model_object; } const Points& copies() const { return this->_copies; } - bool add_copy(const Pointf &point); + bool add_copy(const Vec2d &point); bool delete_last_copy(); bool delete_all_copies() { return this->set_copies(Points()); } bool set_copies(const Points &points); diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 840096c74..56a24a6f7 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -35,7 +35,7 @@ PrintConfigDef::PrintConfigDef() def = this->add("bed_shape", coPoints); def->label = L("Bed shape"); - def->default_value = new ConfigOptionPoints { Pointf(0,0), Pointf(200,0), Pointf(200,200), Pointf(0,200) }; + def->default_value = new ConfigOptionPoints { Vec2d(0,0), Vec2d(200,0), Vec2d(200,200), Vec2d(0,200) }; def = this->add("bed_temperature", coInts); def->label = L("Other layers"); @@ -392,7 +392,7 @@ PrintConfigDef::PrintConfigDef() "from the XY coordinate)."); def->sidetext = L("mm"); def->cli = "extruder-offset=s@"; - def->default_value = new ConfigOptionPoints { Pointf(0,0) }; + def->default_value = new ConfigOptionPoints { Vec2d(0,0) }; def = this->add("extrusion_axis", coString); def->label = L("Extrusion axis"); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 10ebcb18e..54f7cb30a 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -59,7 +59,7 @@ PrintObject::PrintObject(Print* print, ModelObject* model_object, const Bounding this->layer_height_profile = model_object->layer_height_profile; } -bool PrintObject::add_copy(const Pointf &point) +bool PrintObject::add_copy(const Vec2d &point) { Points points = this->_copies; points.push_back(Point::new_scale(point(0), point(1))); diff --git a/xs/src/libslic3r/SVG.cpp b/xs/src/libslic3r/SVG.cpp index 2113acc43..03f55802e 100644 --- a/xs/src/libslic3r/SVG.cpp +++ b/xs/src/libslic3r/SVG.cpp @@ -58,8 +58,8 @@ 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(0)-line.a(0), line.b(1)-line.a(1)); - Pointf perp(-dir(1), dir(0)); + Vec2d dir(line.b(0)-line.a(0), line.b(1)-line.a(1)); + Vec2d perp(-dir(1), dir(0)); coordf_t len = sqrt(perp(0)*perp(0) + perp(1)*perp(1)); coordf_t da = coordf_t(0.5)*line.a_width/len; coordf_t db = coordf_t(0.5)*line.b_width/len; diff --git a/xs/src/libslic3r/SupportMaterial.cpp b/xs/src/libslic3r/SupportMaterial.cpp index 98f41a663..4b7e78976 100644 --- a/xs/src/libslic3r/SupportMaterial.cpp +++ b/xs/src/libslic3r/SupportMaterial.cpp @@ -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(0)) - coordf_t(p1(0)), coordf_t(p2(1)) - coordf_t(p1(1))); - const Pointf v_cntr(coordf_t(p1(0) - center_last(0)), coordf_t(p1(1) - center_last(1))); + const Vec2d v_seg(coordf_t(p2(0)) - coordf_t(p1(0)), coordf_t(p2(1)) - coordf_t(p1(1))); + const Vec2d v_cntr(coordf_t(p1(0) - center_last(0)), coordf_t(p1(1) - center_last(1))); coordf_t a = v_seg.squaredNorm(); coordf_t b = 2. * v_seg.dot(v_cntr); coordf_t c = v_cntr.squaredNorm() - circle_distance * circle_distance; diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index 693221f84..1ad31c8f8 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -42,7 +42,7 @@ REGISTER_CLASS(BoundingBoxf3, "Geometry::BoundingBoxf3"); REGISTER_CLASS(BridgeDetector, "BridgeDetector"); REGISTER_CLASS(Point, "Point"); REGISTER_CLASS(Point3, "Point3"); -REGISTER_CLASS(Pointf, "Pointf"); +__REGISTER_CLASS(Vec2d, "Pointf"); __REGISTER_CLASS(Vec3d, "Pointf3"); REGISTER_CLASS(DynamicPrintConfig, "Config"); REGISTER_CLASS(StaticPrintConfig, "Config::Static"); @@ -133,7 +133,7 @@ SV* ConfigOption_to_SV(const ConfigOption &opt, const ConfigOptionDef &def) auto optv = static_cast(&opt); AV* av = newAV(); av_fill(av, optv->values.size()-1); - for (const Pointf &v : optv->values) + for (const Vec2d &v : optv->values) av_store(av, &v - optv->values.data(), perl_to_SV_clone_ref(v)); return newRV_noinc((SV*)av); } @@ -263,14 +263,14 @@ bool ConfigBase__set(ConfigBase* THIS, const t_config_option_key &opt_key, SV* v return from_SV_check(value, &static_cast(opt)->value); case coPoints: { - std::vector &values = static_cast(opt)->values; + std::vector &values = static_cast(opt)->values; AV* av = (AV*)SvRV(value); const size_t len = av_len(av)+1; values.clear(); values.reserve(len); for (size_t i = 0; i < len; i++) { SV** elem = av_fetch(av, i, 0); - Pointf point(Vec2d::Zero()); + Vec2d point(Vec2d::Zero()); if (elem == NULL || !from_SV_check(*elem, &point)) return false; values.emplace_back(point); } @@ -509,7 +509,7 @@ void from_SV_check(SV* point_sv, Point* point) } } -SV* to_SV_pureperl(const Pointf* point) +SV* to_SV_pureperl(const Vec2d* point) { AV* av = newAV(); av_fill(av, 1); @@ -518,23 +518,23 @@ SV* to_SV_pureperl(const Pointf* point) return newRV_noinc((SV*)av); } -bool from_SV(SV* point_sv, Pointf* point) +bool from_SV(SV* point_sv, Vec2d* point) { AV* point_av = (AV*)SvRV(point_sv); SV* sv_x = *av_fetch(point_av, 0, 0); SV* sv_y = *av_fetch(point_av, 1, 0); if (!looks_like_number(sv_x) || !looks_like_number(sv_y)) return false; - *point = Pointf(SvNV(sv_x), SvNV(sv_y)); + *point = Vec2d(SvNV(sv_x), SvNV(sv_y)); return true; } -bool from_SV_check(SV* point_sv, Pointf* point) +bool from_SV_check(SV* point_sv, Vec2d* point) { if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) { if (!sv_isa(point_sv, perl_class_name(point)) && !sv_isa(point_sv, perl_class_name_ref(point))) CONFESS("Not a valid %s object (got %s)", perl_class_name(point), HvNAME(SvSTASH(SvRV(point_sv)))); - *point = *(Pointf*)SvIV((SV*)SvRV( point_sv )); + *point = *(Vec2d*)SvIV((SV*)SvRV( point_sv )); return true; } else { return from_SV(point_sv, point); diff --git a/xs/src/slic3r/GUI/2DBed.cpp b/xs/src/slic3r/GUI/2DBed.cpp index ccca4320c..e19f839cd 100644 --- a/xs/src/slic3r/GUI/2DBed.cpp +++ b/xs/src/slic3r/GUI/2DBed.cpp @@ -32,7 +32,7 @@ void Bed_2D::repaint() cw--; ch--; - auto cbb = BoundingBoxf(Pointf(0, 0),Pointf(cw, ch)); + auto cbb = BoundingBoxf(Vec2d(0, 0),Vec2d(cw, ch)); // leave space for origin point cbb.min(0) += 4; cbb.max -= Vec2d(4., 4.); @@ -50,19 +50,19 @@ void Bed_2D::repaint() auto bed_shape = m_bed_shape; 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 + bb.merge(Vec2d(0, 0)); // origin needs to be in the visible area auto bw = bb.size()(0); auto bh = bb.size()(1); 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( + auto shift = Vec2d( ccenter(0) - bcenter(0) * sfactor, ccenter(1) - bcenter(1) * sfactor ); m_scale_factor = sfactor; - m_shift = Pointf(shift(0) + cbb.min(0), + m_shift = Vec2d(shift(0) + cbb.min(0), shift(1) - (cbb.max(1) - GetSize().GetHeight())); // draw bed fill @@ -79,10 +79,10 @@ 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) { - polylines.push_back(Polyline::new_scale({ Pointf(x, bb.min(1)), Pointf(x, bb.max(1)) })); + polylines.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(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) })); + polylines.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) })); } polylines = intersection_pl(polylines, bed_polygon); @@ -101,14 +101,14 @@ void Bed_2D::repaint() dc.SetBrush(wxBrush(wxColour(0, 0, 0), wxTRANSPARENT)); dc.DrawPolygon(&pt_list, 0, 0); - auto origin_px = to_pixels(Pointf(0, 0)); + auto origin_px = to_pixels(Vec2d(0, 0)); // draw axes auto axes_len = 50; 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(0) + axes_len, origin_px(1)); + auto x_end = Vec2d(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 = Eigen::Translation2d(x_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- x_end) * Eigen::Vector2d(x_end(0) - arrow_len, x_end(1)); @@ -116,7 +116,7 @@ void Bed_2D::repaint() } dc.SetPen(wxPen(wxColour(0, 255, 0), 2, wxSOLID)); // green - auto y_end = Pointf(origin_px(0), origin_px(1) - axes_len); + auto y_end = Vec2d(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 = Eigen::Translation2d(y_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- y_end) * Eigen::Vector2d(y_end(0), y_end(1) + arrow_len); @@ -137,7 +137,7 @@ void Bed_2D::repaint() dc.DrawText(origin_label, origin_label_x, origin_label_y); // draw current position - if (m_pos!= Pointf(0, 0)) { + if (m_pos!= Vec2d(0, 0)) { auto pos_px = to_pixels(m_pos); dc.SetPen(wxPen(wxColour(200, 0, 0), 2, wxSOLID)); dc.SetBrush(wxBrush(wxColour(200, 0, 0), wxTRANSPARENT)); @@ -151,7 +151,7 @@ void Bed_2D::repaint() } // convert G - code coordinates into pixels -Point Bed_2D::to_pixels(Pointf point){ +Point Bed_2D::to_pixels(Vec2d point){ auto p = point * m_scale_factor + m_shift; return Point(p(0), GetSize().GetHeight() - p(1)); } @@ -170,11 +170,11 @@ void Bed_2D::mouse_event(wxMouseEvent event){ } // convert pixels into G - code coordinates -Pointf Bed_2D::to_units(Point point){ - return (Pointf(point(0), GetSize().GetHeight() - point(1)) - m_shift) * (1. / m_scale_factor); +Vec2d Bed_2D::to_units(Point point){ + return (Vec2d(point(0), GetSize().GetHeight() - point(1)) - m_shift) * (1. / m_scale_factor); } -void Bed_2D::set_pos(Pointf pos){ +void Bed_2D::set_pos(Vec2d pos){ m_pos = pos; Refresh(); } diff --git a/xs/src/slic3r/GUI/2DBed.hpp b/xs/src/slic3r/GUI/2DBed.hpp index 399be6f12..d7a7f4260 100644 --- a/xs/src/slic3r/GUI/2DBed.hpp +++ b/xs/src/slic3r/GUI/2DBed.hpp @@ -14,15 +14,15 @@ class Bed_2D : public wxPanel bool m_painted = false; bool m_interactive = false; double m_scale_factor; - Pointf m_shift = Vec2d::Zero(); - Pointf m_pos = Vec2d::Zero(); - std::function m_on_move = nullptr; + Vec2d m_shift = Vec2d::Zero(); + Vec2d m_pos = Vec2d::Zero(); + std::function m_on_move = nullptr; - Point to_pixels(Pointf point); - Pointf to_units(Point point); + Point to_pixels(Vec2d point); + Vec2d to_units(Point point); void repaint(); void mouse_event(wxMouseEvent event); - void set_pos(Pointf pos); + void set_pos(Vec2d pos); public: Bed_2D(wxWindow* parent) @@ -41,7 +41,7 @@ public: } ~Bed_2D(){} - std::vector m_bed_shape; + std::vector m_bed_shape; }; diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 43d79a7a9..e516ffbb5 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(Vec2d::Zero()); - Vectorf v_prev(Vec2d::Zero()); + Vec2d b1_prev(Vec2d::Zero()); + Vec2d v_prev(Vec2d::Zero()); int idx_initial[4] = { -1, -1, -1, -1 }; double width_initial = 0.; double bottom_z_initial = 0.0; @@ -973,23 +973,23 @@ static void thick_lines_to_indexed_vertex_array( bool is_last = (ii == lines_end - 1); bool is_closing = closed && is_last; - Vectorf v = unscale(line.vector()); + Vec2d v = unscale(line.vector()); v *= inv_len; - Pointf a = unscale(line.a); - Pointf b = unscale(line.b); - Pointf a1 = a; - Pointf a2 = a; - Pointf b1 = b; - Pointf b2 = b; + Vec2d a = unscale(line.a); + Vec2d b = unscale(line.b); + Vec2d a1 = a; + Vec2d a2 = a; + Vec2d b1 = b; + Vec2d b2 = b; { double dist = 0.5 * width; // scaled double dx = dist * v(0); double dy = dist * v(1); - a1 += Vectorf(+dy, -dx); - a2 += Vectorf(-dy, +dx); - b1 += Vectorf(+dy, -dx); - b2 += Vectorf(-dy, +dx); + a1 += Vec2d(+dy, -dx); + a2 += Vec2d(-dy, +dx); + b1 += Vec2d(+dy, -dx); + b2 += Vec2d(-dy, +dx); } // calculate new XY normals @@ -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(Vec2d::Zero()); + Vec2d 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 c47de94aa..e04f2b370 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.cpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.cpp @@ -48,14 +48,14 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt) auto optgroup = init_shape_options_page(_(L("Rectangular"))); ConfigOptionDef def; def.type = coPoints; - def.default_value = new ConfigOptionPoints{ Pointf(200, 200) }; + def.default_value = new ConfigOptionPoints{ Vec2d(200, 200) }; def.label = L("Size"); def.tooltip = L("Size in X and Y of the rectangular plate."); Option option(def, "rect_size"); optgroup->append_single_option_line(option); def.type = coPoints; - def.default_value = new ConfigOptionPoints{ Pointf(0, 0) }; + def.default_value = new ConfigOptionPoints{ Vec2d(0, 0) }; def.label = L("Origin"); def.tooltip = L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle."); option = Option(def, "rect_origin"); @@ -159,11 +159,11 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) y_max = std::max(y_max, pt(1)); } - auto origin = new ConfigOptionPoints{ Pointf(-x_min, -y_min) }; + auto origin = new ConfigOptionPoints{ Vec2d(-x_min, -y_min) }; m_shape_options_book->SetSelection(SHAPE_RECTANGULAR); auto optgroup = m_optgroups[SHAPE_RECTANGULAR]; - optgroup->set_value("rect_size", new ConfigOptionPoints{ Pointf(x_max - x_min, y_max - y_min) });//[x_max - x_min, y_max - y_min]); + optgroup->set_value("rect_size", new ConfigOptionPoints{ Vec2d(x_max - x_min, y_max - y_min) });//[x_max - x_min, y_max - y_min]); optgroup->set_value("rect_origin", origin); update_shape(); return; @@ -206,8 +206,8 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points) // Invalid polygon.Revert to default bed dimensions. m_shape_options_book->SetSelection(SHAPE_RECTANGULAR); auto optgroup = m_optgroups[SHAPE_RECTANGULAR]; - optgroup->set_value("rect_size", new ConfigOptionPoints{ Pointf(200, 200) }); - optgroup->set_value("rect_origin", new ConfigOptionPoints{ Pointf(0, 0) }); + optgroup->set_value("rect_size", new ConfigOptionPoints{ Vec2d(200, 200) }); + optgroup->set_value("rect_origin", new ConfigOptionPoints{ Vec2d(0, 0) }); update_shape(); return; } @@ -230,15 +230,15 @@ void BedShapePanel::update_shape() { auto page_idx = m_shape_options_book->GetSelection(); if (page_idx == SHAPE_RECTANGULAR) { - Pointf rect_size(Vec2d::Zero()); - Pointf rect_origin(Vec2d::Zero()); + Vec2d rect_size(Vec2d::Zero()); + Vec2d rect_origin(Vec2d::Zero()); try{ - rect_size = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); } + rect_size = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_size")); } catch (const std::exception &e){ return; } try{ - rect_origin = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin")); + rect_origin = boost::any_cast(m_optgroups[SHAPE_RECTANGULAR]->get_value("rect_origin")); } catch (const std::exception &e){ return;} @@ -259,10 +259,10 @@ void BedShapePanel::update_shape() x1 -= dx; y0 -= dy; y1 -= dy; - m_canvas->m_bed_shape = { Pointf(x0, y0), - Pointf(x1, y0), - Pointf(x1, y1), - Pointf(x0, y1)}; + m_canvas->m_bed_shape = { Vec2d(x0, y0), + Vec2d(x1, y0), + Vec2d(x1, y1), + Vec2d(x0, y1)}; } else if(page_idx == SHAPE_CIRCULAR) { double diameter; @@ -276,10 +276,10 @@ void BedShapePanel::update_shape() auto r = diameter / 2; auto twopi = 2 * PI; auto edges = 60; - std::vector points; + std::vector points; for (size_t i = 1; i <= 60; ++i){ auto angle = i * twopi / edges; - points.push_back(Pointf(r*cos(angle), r*sin(angle))); + points.push_back(Vec2d(r*cos(angle), r*sin(angle))); } m_canvas->m_bed_shape = points; } @@ -332,7 +332,7 @@ void BedShapePanel::load_stl() } auto polygon = expolygons[0].contour; - std::vector points; + std::vector points; for (auto pt : polygon.points) points.push_back(unscale(pt)); m_canvas->m_bed_shape = points; diff --git a/xs/src/slic3r/GUI/BedShapeDialog.hpp b/xs/src/slic3r/GUI/BedShapeDialog.hpp index 5ff488063..d8ba5a912 100644 --- a/xs/src/slic3r/GUI/BedShapeDialog.hpp +++ b/xs/src/slic3r/GUI/BedShapeDialog.hpp @@ -34,7 +34,7 @@ public: void load_stl(); // Returns the resulting bed shape polygon. This value will be stored to the ini file. - std::vector GetValue() { return m_canvas->m_bed_shape; } + std::vector GetValue() { return m_canvas->m_bed_shape; } }; class BedShapeDialog : public wxDialog @@ -46,7 +46,7 @@ public: ~BedShapeDialog(){ } void build_dialog(ConfigOptionPoints* default_pt); - std::vector GetValue() { return m_panel->GetValue(); } + std::vector GetValue() { return m_panel->GetValue(); } }; } // GUI diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 32688ec3c..b36afda4f 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -653,7 +653,7 @@ void PointCtrl::BUILD() y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y)); } -void PointCtrl::set_value(const Pointf& value, bool change_event) +void PointCtrl::set_value(const Vec2d& value, bool change_event) { m_disable_change_event = !change_event; @@ -667,8 +667,8 @@ void PointCtrl::set_value(const Pointf& value, bool change_event) void PointCtrl::set_value(const boost::any& value, bool change_event) { - Pointf pt(Vec2d::Zero()); - const Pointf *ptf = boost::any_cast(&value); + Vec2d pt(Vec2d::Zero()); + const Vec2d *ptf = boost::any_cast(&value); if (!ptf) { ConfigOptionPoints* pts = boost::any_cast(value); @@ -684,7 +684,7 @@ boost::any& PointCtrl::get_value() double x, y; x_textctrl->GetValue().ToDouble(&x); y_textctrl->GetValue().ToDouble(&y); - return m_value = Pointf(x, y); + return m_value = Vec2d(x, y); } void StaticText::BUILD() diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index db8d2a408..e19c47d68 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -372,7 +372,7 @@ public: void BUILD() override; - void set_value(const Pointf& value, bool change_event = false); + void set_value(const Vec2d& value, bool change_event = false); void set_value(const boost::any& value, bool change_event = false); boost::any& get_value() override; diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index a9ef69357..015f7e6cc 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -317,7 +317,7 @@ bool GLCanvas3D::Bed::set_shape(const Pointfs& shape) _calc_bounding_box(); ExPolygon poly; - for (const Pointf& p : m_shape) + for (const Vec2d& p : m_shape) { poly.contour.append(Point(scale_(p(0)), scale_(p(1)))); } @@ -373,7 +373,7 @@ void GLCanvas3D::Bed::render(float theta) const void GLCanvas3D::Bed::_calc_bounding_box() { m_bounding_box = BoundingBoxf3(); - for (const Pointf& p : m_shape) + for (const Vec2d& p : m_shape) { m_bounding_box.merge(Vec3d(p(0), p(1), 0.0)); } @@ -1168,7 +1168,7 @@ void GLCanvas3D::Gizmos::set_enabled(bool enable) m_enabled = enable; } -void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Pointf& mouse_pos) +void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos) { if (!m_enabled) return; @@ -1187,14 +1187,14 @@ void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Poin // we currently use circular icons for gizmo, so we check the radius if (it->second->get_state() != GLGizmoBase::On) { - bool inside = (mouse_pos - Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size; + bool inside = (mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size; it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off); } top_y += (tex_size + OverlayGapY); } } -void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Pointf& mouse_pos) +void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos) { if (!m_enabled) return; @@ -1211,7 +1211,7 @@ void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Poi float half_tex_size = 0.5f * tex_size; // we currently use circular icons for gizmo, so we check the radius - if ((mouse_pos - Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size) + if ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size) { if ((it->second->get_state() == GLGizmoBase::On)) { @@ -1260,7 +1260,7 @@ void GLCanvas3D::Gizmos::set_hover_id(int id) } } -bool GLCanvas3D::Gizmos::overlay_contains_mouse(const GLCanvas3D& canvas, const Pointf& mouse_pos) const +bool GLCanvas3D::Gizmos::overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const { if (!m_enabled) return false; @@ -1277,7 +1277,7 @@ bool GLCanvas3D::Gizmos::overlay_contains_mouse(const GLCanvas3D& canvas, const float half_tex_size = 0.5f * tex_size; // we currently use circular icons for gizmo, so we check the radius - if ((mouse_pos - Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size) + if ((mouse_pos - Vec2d(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size) return true; top_y += (tex_size + OverlayGapY); @@ -1295,7 +1295,7 @@ bool GLCanvas3D::Gizmos::grabber_contains_mouse() const return (curr != nullptr) ? (curr->get_hover_id() != -1) : false; } -void GLCanvas3D::Gizmos::update(const Pointf& mouse_pos) +void GLCanvas3D::Gizmos::update(const Vec2d& mouse_pos) { if (!m_enabled) return; @@ -2719,7 +2719,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else if (evt.Leaving()) { // to remove hover on objects when the mouse goes out of this canvas - m_mouse.position = Pointf(-1.0, -1.0); + m_mouse.position = Vec2d(-1.0, -1.0); m_dirty = true; } else if (evt.LeftDClick() && (m_hover_volume_id != -1)) @@ -2880,7 +2880,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_mouse.dragging = true; const Vec3d& cur_pos = _mouse_to_bed_3d(pos); - m_gizmos.update(Pointf(cur_pos(0), cur_pos(1))); + m_gizmos.update(Vec2d(cur_pos(0), cur_pos(1))); std::vector volumes; if (m_mouse.drag.gizmo_volume_idx != -1) @@ -3052,7 +3052,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } else if (evt.Moving()) { - m_mouse.position = Pointf((coordf_t)pos(0), (coordf_t)pos(1)); + m_mouse.position = Vec2d((coordf_t)pos(0), (coordf_t)pos(1)); // 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; @@ -3396,9 +3396,9 @@ void GLCanvas3D::_camera_tranform() const void GLCanvas3D::_picking_pass() const { - const Pointf& pos = m_mouse.position; + const Vec2d& pos = m_mouse.position; - if (m_picking_enabled && !m_mouse.dragging && (pos != Pointf(DBL_MAX, DBL_MAX))) + if (m_picking_enabled && !m_mouse.dragging && (pos != Vec2d(DBL_MAX, DBL_MAX))) { // Render the object for picking. // FIXME This cannot possibly work in a multi - sampled context as the color gets mangled by the anti - aliasing. @@ -4870,7 +4870,7 @@ void GLCanvas3D::_on_move(const std::vector& volume_idxs) // Move a regular object. ModelObject* model_object = m_model->objects[obj_idx]; const Vec3d& origin = volume->get_origin(); - model_object->instances[instance_idx]->offset = Pointf(origin(0), origin(1)); + model_object->instances[instance_idx]->offset = Vec2d(origin(0), origin(1)); model_object->invalidate_bounding_box(); object_moved = true; } diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 3d35495b4..3c317ba51 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -314,7 +314,7 @@ public: }; bool dragging; - Pointf position; + Vec2d position; Drag drag; Mouse(); @@ -357,15 +357,15 @@ public: bool is_enabled() const; void set_enabled(bool enable); - void update_hover_state(const GLCanvas3D& canvas, const Pointf& mouse_pos); - void update_on_off_state(const GLCanvas3D& canvas, const Pointf& mouse_pos); + void update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos); + void update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos); void reset_all_states(); void set_hover_id(int id); - bool overlay_contains_mouse(const GLCanvas3D& canvas, const Pointf& mouse_pos) const; + bool overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const; bool grabber_contains_mouse() const; - void update(const Pointf& mouse_pos); + void update(const Vec2d& mouse_pos); void refresh(); EType get_current_type() const; diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 62242ea8a..107759e54 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -16,7 +16,7 @@ const float GLGizmoBase::BaseColor[3] = { 1.0f, 1.0f, 1.0f }; const float GLGizmoBase::HighlightColor[3] = { 1.0f, 0.38f, 0.0f }; GLGizmoBase::Grabber::Grabber() - : center(Pointf(0.0, 0.0)) + : center(Vec2d(0.0, 0.0)) , angle_z(0.0f) { color[0] = 1.0f; @@ -124,7 +124,7 @@ void GLGizmoBase::stop_dragging() on_stop_dragging(); } -void GLGizmoBase::update(const Pointf& mouse_pos) +void GLGizmoBase::update(const Vec2d& mouse_pos) { if (m_hover_id != -1) on_update(mouse_pos); @@ -187,7 +187,7 @@ const float GLGizmoRotate::GrabberOffset = 5.0f; GLGizmoRotate::GLGizmoRotate() : GLGizmoBase() , m_angle_z(0.0f) - , m_center(Pointf(0.0, 0.0)) + , m_center(Vec2d(0.0, 0.0)) , m_radius(0.0f) , m_keep_radius(false) { @@ -232,10 +232,10 @@ void GLGizmoRotate::on_set_state() m_keep_radius = (m_state == On) ? false : true; } -void GLGizmoRotate::on_update(const Pointf& mouse_pos) +void GLGizmoRotate::on_update(const Vec2d& mouse_pos) { - Vectorf orig_dir(1.0, 0.0); - Vectorf new_dir = (mouse_pos - m_center).normalized(); + Vec2d orig_dir(1.0, 0.0); + Vec2d new_dir = (mouse_pos - m_center).normalized(); coordf_t theta = ::acos(clamp(-1.0, 1.0, new_dir.dot(orig_dir))); if (cross2(orig_dir, new_dir) < 0.0) theta = 2.0 * (coordf_t)PI - theta; @@ -440,9 +440,9 @@ void GLGizmoScale::on_start_dragging() m_starting_drag_position = m_grabbers[m_hover_id].center; } -void GLGizmoScale::on_update(const Pointf& mouse_pos) +void GLGizmoScale::on_update(const Vec2d& mouse_pos) { - Pointf center(0.5 * (m_grabbers[1].center(0) + m_grabbers[0].center(0)), 0.5 * (m_grabbers[3].center(1) + m_grabbers[0].center(1))); + Vec2d center(0.5 * (m_grabbers[1].center(0) + m_grabbers[0].center(0)), 0.5 * (m_grabbers[3].center(1) + m_grabbers[0].center(1))); coordf_t orig_len = (m_starting_drag_position - center).norm(); coordf_t new_len = (mouse_pos - center).norm(); diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index d6223a14d..19d93bd30 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -23,7 +23,7 @@ protected: static const float HalfSize; static const float HoverOffset; - Pointf center; + Vec2d center; float angle_z; float color[3]; @@ -64,7 +64,7 @@ public: void start_dragging(); void stop_dragging(); - void update(const Pointf& mouse_pos); + void update(const Vec2d& mouse_pos); void refresh(); void render(const BoundingBoxf3& box) const; @@ -75,7 +75,7 @@ protected: virtual void on_set_state(); virtual void on_start_dragging(); virtual void on_stop_dragging(); - virtual void on_update(const Pointf& mouse_pos) = 0; + virtual void on_update(const Vec2d& mouse_pos) = 0; virtual void on_refresh(); virtual void on_render(const BoundingBoxf3& box) const = 0; virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0; @@ -98,7 +98,7 @@ class GLGizmoRotate : public GLGizmoBase float m_angle_z; - mutable Pointf m_center; + mutable Vec2d m_center; mutable float m_radius; mutable bool m_keep_radius; @@ -111,7 +111,7 @@ public: protected: virtual bool on_init(); virtual void on_set_state(); - virtual void on_update(const Pointf& mouse_pos); + virtual void on_update(const Vec2d& mouse_pos); virtual void on_refresh(); virtual void on_render(const BoundingBoxf3& box) const; virtual void on_render_for_picking(const BoundingBoxf3& box) const; @@ -132,7 +132,7 @@ class GLGizmoScale : public GLGizmoBase float m_scale; float m_starting_scale; - Pointf m_starting_drag_position; + Vec2d m_starting_drag_position; public: GLGizmoScale(); @@ -143,7 +143,7 @@ public: protected: virtual bool on_init(); virtual void on_start_dragging(); - virtual void on_update(const Pointf& mouse_pos); + virtual void on_update(const Vec2d& mouse_pos); virtual void on_render(const BoundingBoxf3& box) const; virtual void on_render_for_picking(const BoundingBoxf3& box) const; }; diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index e5dca948c..e0a8aa59d 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -608,10 +608,10 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt break; case coPoints:{ if (opt_key.compare("bed_shape") == 0){ - config.option(opt_key)->values = boost::any_cast>(value); + config.option(opt_key)->values = boost::any_cast>(value); break; } - ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast(value) }; + ConfigOptionPoints* vec_new = new ConfigOptionPoints{ boost::any_cast(value) }; config.option(opt_key)->set_at(vec_new, opt_index, 0); } break; diff --git a/xs/src/xsinit.h b/xs/src/xsinit.h index e32717532..c9e363602 100644 --- a/xs/src/xsinit.h +++ b/xs/src/xsinit.h @@ -197,9 +197,9 @@ void from_SV_check(SV* poly_sv, Polyline* THIS); SV* to_SV_pureperl(const Point* THIS); void from_SV(SV* point_sv, Point* point); void from_SV_check(SV* point_sv, Point* point); -SV* to_SV_pureperl(const Pointf* point); -bool from_SV(SV* point_sv, Pointf* point); -bool from_SV_check(SV* point_sv, Pointf* point); +SV* to_SV_pureperl(const Vec2d* point); +bool from_SV(SV* point_sv, Vec2d* point); +bool from_SV_check(SV* point_sv, Vec2d* point); void from_SV_check(SV* surface_sv, Surface* THIS); SV* to_SV(TriangleMesh* THIS); diff --git a/xs/xsp/BoundingBox.xsp b/xs/xsp/BoundingBox.xsp index 46a6da98c..a34cad0bc 100644 --- a/xs/xsp/BoundingBox.xsp +++ b/xs/xsp/BoundingBox.xsp @@ -56,15 +56,15 @@ new_from_points(CLASS, points) Clone clone() %code{% RETVAL = THIS; %}; void merge(BoundingBoxf* bb) %code{% THIS->merge(*bb); %}; - void merge_point(Pointf* point) %code{% THIS->merge(*point); %}; + void merge_point(Vec2d* point) %code{% THIS->merge(*point); %}; void scale(double factor); void translate(double x, double y); - Clone size(); - Clone center(); + Clone size(); + Clone center(); double radius(); bool empty() %code{% RETVAL = empty(*THIS); %}; - Clone min_point() %code{% RETVAL = THIS->min; %}; - Clone max_point() %code{% RETVAL = THIS->max; %}; + Clone min_point() %code{% RETVAL = THIS->min; %}; + Clone max_point() %code{% RETVAL = THIS->max; %}; double x_min() %code{% RETVAL = THIS->min(0); %}; double x_max() %code{% RETVAL = THIS->max(0); %}; double y_min() %code{% RETVAL = THIS->min(1); %}; diff --git a/xs/xsp/GCode.xsp b/xs/xsp/GCode.xsp index c1856ccf7..9e04edd4c 100644 --- a/xs/xsp/GCode.xsp +++ b/xs/xsp/GCode.xsp @@ -35,9 +35,9 @@ } %}; - Ref origin() + Ref origin() %code{% RETVAL = &(THIS->origin()); %}; - void set_origin(Pointf* pointf) + void set_origin(Vec2d* pointf) %code{% THIS->set_origin(*pointf); %}; Ref last_pos() %code{% RETVAL = &(THIS->last_pos()); %}; diff --git a/xs/xsp/Geometry.xsp b/xs/xsp/Geometry.xsp index b23bbeffa..b7e92ba69 100644 --- a/xs/xsp/Geometry.xsp +++ b/xs/xsp/Geometry.xsp @@ -8,7 +8,7 @@ %package{Slic3r::Geometry}; -Pointfs arrange(size_t total_parts, Pointf* part, coordf_t dist, BoundingBoxf* bb = NULL) +Pointfs arrange(size_t total_parts, Vec2d* part, coordf_t dist, BoundingBoxf* bb = NULL) %code{% Pointfs points; if (! Slic3r::Geometry::arrange(total_parts, *part, dist, bb, points)) diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index d8e509527..ac265a3b3 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -81,7 +81,7 @@ bool add_default_instances(); Clone bounding_box(); - void center_instances_around_point(Pointf* point) + void center_instances_around_point(Vec2d* point) %code%{ THIS->center_instances_around_point(*point); %}; void translate(double x, double y, double z); Clone mesh(); @@ -357,14 +357,14 @@ ModelMaterial::attributes() %code%{ RETVAL = THIS->rotation; %}; double scaling_factor() %code%{ RETVAL = THIS->scaling_factor; %}; - Ref offset() + Ref offset() %code%{ RETVAL = &THIS->offset; %}; void set_rotation(double val) %code%{ THIS->rotation = val; THIS->get_object()->invalidate_bounding_box(); %}; void set_scaling_factor(double val) %code%{ THIS->scaling_factor = val; THIS->get_object()->invalidate_bounding_box(); %}; - void set_offset(Pointf *offset) + void set_offset(Vec2d *offset) %code%{ THIS->offset = *offset; %}; void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index 7671b7d03..209f1c298 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -91,10 +91,10 @@ Point::coincides_with(point_sv) std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld,%ld", (*THIS)(0), (*THIS)(1), (*THIS)(2)); RETVAL = buf; %}; }; -%name{Slic3r::Pointf} class Pointf { - Pointf(double _x = 0, double _y = 0); - ~Pointf(); - Clone clone() +%name{Slic3r::Pointf} class Vec2d { + Vec2d(double _x = 0, double _y = 0); + ~Vec2d(); + Clone clone() %code{% RETVAL = THIS; %}; SV* arrayref() %code{% RETVAL = to_SV_pureperl(THIS); %}; @@ -109,15 +109,15 @@ Point::coincides_with(point_sv) void set_y(double val) %code{% (*THIS)(1) = val; %}; void translate(double x, double y) - %code{% *THIS += Pointf(x, y); %}; + %code{% *THIS += Vec2d(x, y); %}; void scale(double factor) %code{% *THIS *= factor; %}; - void rotate(double angle, Pointf* center) + void rotate(double angle, Vec2d* 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) - %code{% RETVAL = new Pointf(*point - *THIS); %}; + Vec2d* negative() + %code{% RETVAL = new Vec2d(- *THIS); %}; + Vec2d* vector_to(Vec2d* point) + %code{% RETVAL = new Vec2d(*point - *THIS); %}; std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf", (*THIS)(0), (*THIS)(1)); RETVAL = buf; %}; }; diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index a6fb4f1b2..9005e6e90 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -72,7 +72,7 @@ _constant() void set_shifted_copies(Points value) %code%{ THIS->_shifted_copies = value; %}; - bool add_copy(Pointf* point) + bool add_copy(Vec2d* point) %code%{ RETVAL = THIS->add_copy(*point); %}; bool delete_last_copy(); bool delete_all_copies(); diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 4c3cc3522..b59853198 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -66,9 +66,9 @@ Point3* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T -Pointf* O_OBJECT_SLIC3R -Ref O_OBJECT_SLIC3R_T -Clone O_OBJECT_SLIC3R_T +Vec2d* O_OBJECT_SLIC3R +Ref O_OBJECT_SLIC3R_T +Clone O_OBJECT_SLIC3R_T Vec3d* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index 714148794..9cacb3d55 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -22,9 +22,9 @@ %typemap{Point3*}; %typemap{Ref}{simple}; %typemap{Clone}{simple}; -%typemap{Pointf*}; -%typemap{Ref}{simple}; -%typemap{Clone}{simple}; +%typemap{Vec2d*}; +%typemap{Ref}{simple}; +%typemap{Clone}{simple}; %typemap{Vec3d*}; %typemap{Ref}{simple}; %typemap{Clone}{simple};