From 667a121ddbbe9732c3831166792128a901c01315 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 19 Dec 2015 14:49:29 +0100 Subject: [PATCH] Fixed error in porting causing wrong moves with avoid_crossing_perimeters --- xs/src/libslic3r/GCode.cpp | 7 +++---- xs/src/libslic3r/GCode.hpp | 2 +- xs/src/libslic3r/MotionPlanner.cpp | 2 +- xs/src/libslic3r/Point.cpp | 8 ++++++++ xs/src/libslic3r/Point.hpp | 1 + xs/src/libslic3r/libslic3r.h | 4 ++-- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index f94784450..1069555a4 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -203,8 +203,8 @@ GCode::GCode() { } -Point& -GCode::last_pos() +const Point& +GCode::last_pos() const { return this->_last_pos; } @@ -249,13 +249,12 @@ void GCode::set_origin(const Pointf &pointf) { // if origin increases (goes towards right), last_pos decreases because it goes towards left - Point translate( + const Point translate( scale_(this->origin.x - pointf.x), scale_(this->origin.y - pointf.y) ); this->_last_pos.translate(translate); this->wipe.path.translate(translate); - this->origin = pointf; } diff --git a/xs/src/libslic3r/GCode.hpp b/xs/src/libslic3r/GCode.hpp index 29aa7633a..7aa0143a3 100644 --- a/xs/src/libslic3r/GCode.hpp +++ b/xs/src/libslic3r/GCode.hpp @@ -86,7 +86,7 @@ class GCode { double volumetric_speed; GCode(); - Point& last_pos(); + const Point& last_pos() const; void set_last_pos(const Point &pos); bool last_pos_defined() const; void apply_print_config(const PrintConfig &print_config); diff --git a/xs/src/libslic3r/MotionPlanner.cpp b/xs/src/libslic3r/MotionPlanner.cpp index c61737ad6..7211100c3 100644 --- a/xs/src/libslic3r/MotionPlanner.cpp +++ b/xs/src/libslic3r/MotionPlanner.cpp @@ -171,7 +171,7 @@ MotionPlanner::shortest_path(const Point &from, const Point &to) svg.draw(inner_from, "red"); svg.draw(to); svg.draw(inner_to, "red"); - svg.draw(*polyline, "red"); + svg.draw(polyline, "red"); svg.Close(); */ diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp index 35948b7d8..dc9d510c6 100644 --- a/xs/src/libslic3r/Point.cpp +++ b/xs/src/libslic3r/Point.cpp @@ -305,6 +305,14 @@ operator<<(std::ostream &stm, const Pointf &pointf) return stm << pointf.x << "," << pointf.y; } +std::string +Pointf::wkt() const +{ + std::ostringstream ss; + ss << "POINT(" << this->x << " " << this->y << ")"; + return ss.str(); +} + void Pointf::scale(double factor) { diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index 1a5bd641e..af0f59af9 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -86,6 +86,7 @@ class Pointf static Pointf new_unscale(const Point &p) { return Pointf(unscale(p.x), unscale(p.y)); }; + std::string wkt() const; void scale(double factor); void translate(double x, double y); void translate(const Vectorf &vector); diff --git a/xs/src/libslic3r/libslic3r.h b/xs/src/libslic3r/libslic3r.h index f4dfdfe23..eb3fb8f03 100644 --- a/xs/src/libslic3r/libslic3r.h +++ b/xs/src/libslic3r/libslic3r.h @@ -17,8 +17,8 @@ #define SMALL_PERIMETER_LENGTH (6.5 / SCALING_FACTOR) * 2 * PI #define INSET_OVERLAP_TOLERANCE 0.4 #define EXTERNAL_INFILL_MARGIN 3 -#define scale_(val) (val / SCALING_FACTOR) -#define unscale(val) (val * SCALING_FACTOR) +#define scale_(val) ((val) / SCALING_FACTOR) +#define unscale(val) ((val) * SCALING_FACTOR) #define SCALED_EPSILON scale_(EPSILON) typedef long coord_t; typedef double coordf_t;