diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index 27aa1a59b..6adb650c2 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -7,18 +7,6 @@ use warnings; use List::Util qw(first); use Slic3r::Geometry::Clipper qw(union_ex diff_pl); -sub wkt { - my $self = shift; - return sprintf "POLYGON(%s)", - join ',', map "($_)", map { join ',', map "$_->[0] $_->[1]", @$_ } @$self; -} - -sub dump_perl { - my $self = shift; - return sprintf "[%s]", - join ',', map "[$_]", map { join ',', map "[$_->[0],$_->[1]]", @$_ } @$self; -} - sub offset { my $self = shift; return Slic3r::Geometry::Clipper::offset(\@$self, @_); diff --git a/lib/Slic3r/Point.pm b/lib/Slic3r/Point.pm index 535a97194..1134138ea 100644 --- a/lib/Slic3r/Point.pm +++ b/lib/Slic3r/Point.pm @@ -7,11 +7,6 @@ sub new_scale { return $class->new(map Slic3r::Geometry::scale($_), @_); } -sub dump_perl { - my $self = shift; - return sprintf "[%s,%s]", @$self; -} - package Slic3r::Pointf; use strict; use warnings; diff --git a/lib/Slic3r/Polyline.pm b/lib/Slic3r/Polyline.pm index 9cc142409..a42b5d1c4 100644 --- a/lib/Slic3r/Polyline.pm +++ b/lib/Slic3r/Polyline.pm @@ -10,9 +10,4 @@ sub new_scale { return $class->new(map [ Slic3r::Geometry::scale($_->[X]), Slic3r::Geometry::scale($_->[Y]) ], @points); } -sub dump_perl { - my $self = shift; - return sprintf "[%s]", join ',', map "[$_->[0],$_->[1]]", @$self; -} - 1; diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index c252b448e..4294fe543 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -505,17 +505,6 @@ ExPolygon::lines() const return lines; } -std::string -ExPolygon::dump_perl() const -{ - std::ostringstream ret; - ret << "[" << this->contour.dump_perl(); - for (Polygons::const_iterator h = this->holes.begin(); h != this->holes.end(); ++h) - ret << "," << h->dump_perl(); - ret << "]"; - return ret.str(); -} - BoundingBox get_extents(const ExPolygon &expolygon) { return get_extents(expolygon.contour); diff --git a/xs/src/libslic3r/ExPolygon.hpp b/xs/src/libslic3r/ExPolygon.hpp index f4782ba55..4833ee49e 100644 --- a/xs/src/libslic3r/ExPolygon.hpp +++ b/xs/src/libslic3r/ExPolygon.hpp @@ -63,7 +63,6 @@ public: void triangulate_pp(Polygons* polygons) const; void triangulate_p2t(Polygons* polygons) const; Lines lines() const; - std::string dump_perl() const; }; // Count a nuber of polygons stored inside the vector of expolygons. diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index 9007754fe..93e888efa 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/xs/src/libslic3r/Line.cpp @@ -7,14 +7,6 @@ namespace Slic3r { -std::string Line::wkt() const -{ - std::ostringstream ss; - ss << "LINESTRING(" << this->a(0) << " " << this->a(1) << "," - << this->b(0) << " " << this->b(1) << ")"; - return ss.str(); -} - bool Line::intersection_infinite(const Line &other, Point* point) const { Vec2d a1 = this->a.cast(); diff --git a/xs/src/libslic3r/Line.hpp b/xs/src/libslic3r/Line.hpp index feeb1d266..7c5e16ca4 100644 --- a/xs/src/libslic3r/Line.hpp +++ b/xs/src/libslic3r/Line.hpp @@ -20,7 +20,6 @@ class Line public: Line() {} explicit Line(Point _a, Point _b): a(_a), b(_b) {} - std::string wkt() const; explicit operator Lines() const { Lines lines; lines.emplace_back(*this); return lines; } void scale(double factor) { this->a *= factor; this->b *= factor; } void translate(double x, double y) { Vector v(x, y); this->a += v; this->b += v; } diff --git a/xs/src/libslic3r/MultiPoint.cpp b/xs/src/libslic3r/MultiPoint.cpp index 0fbad58c2..0be95fd55 100644 --- a/xs/src/libslic3r/MultiPoint.cpp +++ b/xs/src/libslic3r/MultiPoint.cpp @@ -153,19 +153,6 @@ bool MultiPoint::first_intersection(const Line& line, Point* intersection) const return found; } -std::string -MultiPoint::dump_perl() const -{ - std::ostringstream ret; - ret << "["; - for (Points::const_iterator p = this->points.begin(); p != this->points.end(); ++p) { - ret << p->dump_perl(); - if (p != this->points.end()-1) ret << ","; - } - ret << "]"; - return ret.str(); -} - //FIXME This is very inefficient in term of memory use. // The recursive algorithm shall run in place, not allocating temporary data in each recursion. Points diff --git a/xs/src/libslic3r/MultiPoint.hpp b/xs/src/libslic3r/MultiPoint.hpp index e8e275c65..c5d35050d 100644 --- a/xs/src/libslic3r/MultiPoint.hpp +++ b/xs/src/libslic3r/MultiPoint.hpp @@ -76,7 +76,6 @@ public: bool intersection(const Line& line, Point* intersection) const; bool first_intersection(const Line& line, Point* intersection) const; - std::string dump_perl() const; static Points _douglas_peucker(const Points &points, const double tolerance); }; diff --git a/xs/src/libslic3r/PlaceholderParser.cpp b/xs/src/libslic3r/PlaceholderParser.cpp index 80740b20d..1cfd51141 100644 --- a/xs/src/libslic3r/PlaceholderParser.cpp +++ b/xs/src/libslic3r/PlaceholderParser.cpp @@ -693,7 +693,7 @@ namespace client case coInts: output.set_i(static_cast(opt.opt)->values[idx]); break; case coStrings: output.set_s(static_cast(opt.opt)->values[idx]); break; case coPercents: output.set_d(static_cast(opt.opt)->values[idx]); break; - case coPoints: output.set_s(static_cast(opt.opt)->values[idx].dump_perl()); break; + case coPoints: output.set_s(to_string(static_cast(opt.opt)->values[idx])); break; case coBools: output.set_b(static_cast(opt.opt)->values[idx] != 0); break; default: ctx->throw_exception("Unknown vector variable type", opt.it_range); diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp index 4b49106df..7c008be9d 100644 --- a/xs/src/libslic3r/Point.cpp +++ b/xs/src/libslic3r/Point.cpp @@ -6,20 +6,6 @@ namespace Slic3r { -std::string Point::wkt() const -{ - std::ostringstream ss; - ss << "POINT(" << (*this)(0) << " " << (*this)(1) << ")"; - return ss.str(); -} - -std::string Point::dump_perl() const -{ - std::ostringstream ss; - ss << "[" << (*this)(0) << "," << (*this)(1) << "]"; - return ss.str(); -} - void Point::rotate(double angle) { double cur_x = (double)(*this)(0); @@ -172,20 +158,6 @@ std::ostream& operator<<(std::ostream &stm, const Pointf &pointf) return stm << pointf(0) << "," << pointf(1); } -std::string Pointf::wkt() const -{ - std::ostringstream ss; - ss << "POINT(" << (*this)(0) << " " << (*this)(1) << ")"; - return ss.str(); -} - -std::string Pointf::dump_perl() const -{ - std::ostringstream ss; - ss << "[" << (*this)(0) << "," << (*this)(1) << "]"; - return ss.str(); -} - void Pointf::rotate(double angle) { double cur_x = (*this)(0); @@ -210,14 +182,14 @@ void Pointf::rotate(double angle, const Pointf ¢er) namespace int128 { -int orient(const Point &p1, const Point &p2, const Point &p3) +int orient(const Vec2crd &p1, const Vec2crd &p2, const Vec2crd &p3) { Slic3r::Vector v1(p2 - p1); Slic3r::Vector v2(p3 - p1); return Int128::sign_determinant_2x2_filtered(v1(0), v1(1), v2(0), v2(1)); } -int cross(const Point &v1, const Point &v2) +int cross(const Vec2crd &v1, const Vec2crd &v2) { return Int128::sign_determinant_2x2_filtered(v1(0), v1(1), v2(0), v2(1)); } diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index 60e053f16..c53c10f4d 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -14,22 +14,21 @@ namespace Slic3r { class Line; -class Linef; class MultiPoint; class Point; class Point3; class Pointf; class Pointf3; -typedef Point Vector; -typedef Point3 Vector3; -typedef Pointf Vectorf; -typedef Pointf3 Vectorf3; -typedef std::vector Points; -typedef std::vector PointPtrs; -typedef std::vector PointConstPtrs; -typedef std::vector Points3; -typedef std::vector Pointfs; -typedef std::vector Pointf3s; +typedef Point Vector; +typedef Point3 Vector3; +typedef Pointf Vectorf; +typedef Pointf3 Vectorf3; +typedef std::vector Points; +typedef std::vector PointPtrs; +typedef std::vector PointConstPtrs; +typedef std::vector Points3; +typedef std::vector Pointfs; +typedef std::vector Pointf3s; // Eigen types, to replace the Slic3r's own types in the future. // Vector types with a fixed point coordinate base type. @@ -54,6 +53,11 @@ inline coord_t cross2(const Vec2crd &v1, const Vec2crd &v2) { return v1(0) * v2( inline float cross2(const Vec2f &v1, const Vec2f &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } inline double cross2(const Vec2d &v1, const Vec2d &v2) { return v1(0) * v2(1) - v1(1) * v2(0); } +inline std::string to_string(const Vec2crd &pt) { return std::string("[") + std::to_string(pt(0)) + ", " + std::to_string(pt(1)) + "]"; } +inline std::string to_string(const Vec2d &pt) { return std::string("[") + std::to_string(pt(0)) + ", " + std::to_string(pt(1)) + "]"; } +inline std::string to_string(const Vec3crd &pt) { return std::string("[") + std::to_string(pt(0)) + ", " + std::to_string(pt(1)) + ", " + std::to_string(pt(2)) + "]"; } +inline std::string to_string(const Vec3d &pt) { return std::string("[") + std::to_string(pt(0)) + ", " + std::to_string(pt(1)) + ", " + std::to_string(pt(2)) + "]"; } + class Point : public Vec2crd { public: @@ -77,16 +81,12 @@ public: return *this; } - bool operator==(const Point& rhs) const { return (*this)(0) == rhs(0) && (*this)(1) == rhs(1); } - bool operator!=(const Point& rhs) const { return ! (*this == rhs); } bool operator< (const Point& rhs) const { return (*this)(0) < rhs(0) || ((*this)(0) == rhs(0) && (*this)(1) < rhs(1)); } Point& operator+=(const Point& rhs) { (*this)(0) += rhs(0); (*this)(1) += rhs(1); return *this; } Point& operator-=(const Point& rhs) { (*this)(0) -= rhs(0); (*this)(1) -= rhs(1); return *this; } Point& operator*=(const double &rhs) { (*this)(0) *= rhs; (*this)(1) *= rhs; return *this; } - std::string wkt() const; - std::string dump_perl() const; void rotate(double angle); void rotate(double angle, const Point ¢er); Point rotated(double angle) const { Point res(*this); res.rotate(angle); return res; } @@ -106,15 +106,15 @@ public: namespace int128 { // Exact orientation predicate, // returns +1: CCW, 0: collinear, -1: CW. - int orient(const Point &p1, const Point &p2, const Point &p3); + int orient(const Vec2crd &p1, const Vec2crd &p2, const Vec2crd &p3); // Exact orientation predicate, // returns +1: CCW, 0: collinear, -1: CW. - int cross(const Point &v1, const Slic3r::Point &v2); + int cross(const Vec2crd &v1, const Vec2crd &v2); } // To be used by std::unordered_map, std::unordered_multimap and friends. struct PointHash { - size_t operator()(const Point &pt) const { + size_t operator()(const Vec2crd &pt) const { return std::hash()(pt(0)) ^ std::hash()(pt(1)); } }; @@ -159,34 +159,34 @@ public: } void insert(const ValueType &value) { - const Point *pt = m_point_accessor(value); + const Vec2crd *pt = m_point_accessor(value); if (pt != nullptr) - m_map.emplace(std::make_pair(Point(pt->x()>>m_grid_log2, pt->y()>>m_grid_log2), value)); + m_map.emplace(std::make_pair(Vec2crd(pt->x()>>m_grid_log2, pt->y()>>m_grid_log2), value)); } void insert(ValueType &&value) { - const Point *pt = m_point_accessor(value); + const Vec2crd *pt = m_point_accessor(value); if (pt != nullptr) - m_map.emplace(std::make_pair(Point(pt->x()>>m_grid_log2, pt->y()>>m_grid_log2), std::move(value))); + m_map.emplace(std::make_pair(Vec2crd(pt->x()>>m_grid_log2, pt->y()>>m_grid_log2), std::move(value))); } // Return a pair of - std::pair find(const Point &pt) { + std::pair find(const Vec2crd &pt) { // Iterate over 4 closest grid cells around pt, // find the closest start point inside these cells to pt. const ValueType *value_min = nullptr; double dist_min = std::numeric_limits::max(); // Round pt to a closest grid_cell corner. - Point grid_corner((pt(0)+(m_grid_resolution>>1))>>m_grid_log2, (pt(1)+(m_grid_resolution>>1))>>m_grid_log2); + Vec2crd grid_corner((pt(0)+(m_grid_resolution>>1))>>m_grid_log2, (pt(1)+(m_grid_resolution>>1))>>m_grid_log2); // For four neighbors of grid_corner: for (coord_t neighbor_y = -1; neighbor_y < 1; ++ neighbor_y) { for (coord_t neighbor_x = -1; neighbor_x < 1; ++ neighbor_x) { // Range of fragment starts around grid_corner, close to pt. - auto range = m_map.equal_range(Point(grid_corner(0) + neighbor_x, grid_corner(1) + neighbor_y)); + auto range = m_map.equal_range(Vec2crd(grid_corner(0) + neighbor_x, grid_corner(1) + neighbor_y)); // Find the map entry closest to pt. for (auto it = range.first; it != range.second; ++it) { const ValueType &value = it->second; - const Point *pt2 = m_point_accessor(value); + const Vec2crd *pt2 = m_point_accessor(value); if (pt2 != nullptr) { const double d2 = (pt - *pt2).squaredNorm(); if (d2 < dist_min) { @@ -203,7 +203,7 @@ public: } private: - typedef typename std::unordered_multimap map_type; + typedef typename std::unordered_multimap map_type; PointAccessor m_point_accessor; map_type m_map; coord_t m_search_radius; @@ -231,10 +231,7 @@ public: return *this; } - bool operator==(const Point3 &rhs) const { return (*this)(0) == rhs(0) && (*this)(1) == rhs(1) && (*this)(2) == rhs(2); } - bool operator!=(const Point3 &rhs) const { return ! (*this == rhs); } - - Point xy() const { return Point((*this)(0), (*this)(1)); } + Point xy() const { return Point((*this)(0), (*this)(1)); } }; std::ostream& operator<<(std::ostream &stm, const Pointf &pointf); @@ -260,13 +257,9 @@ public: return *this; } - std::string wkt() const; - std::string dump_perl() const; void rotate(double angle); void rotate(double angle, const Pointf ¢er); - bool operator==(const Pointf &rhs) const { return (*this)(0) == rhs(0) && (*this)(1) == rhs(1); } - bool operator!=(const Pointf &rhs) const { return ! (*this == rhs); } bool operator< (const Pointf& rhs) const { return (*this)(0) < rhs(0) || ((*this)(0) == rhs(0) && (*this)(1) < rhs(1)); } }; @@ -292,9 +285,6 @@ public: return *this; } - bool operator==(const Pointf3 &rhs) const { return (*this)(0) == rhs(0) && (*this)(1) == rhs(1) && (*this)(2) == rhs(2); } - bool operator!=(const Pointf3 &rhs) const { return ! (*this == rhs); } - Pointf xy() const { return Pointf((*this)(0), (*this)(1)); } }; diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index ce9cc66dc..f9c82d198 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -230,19 +230,6 @@ Polygon::centroid() const return Point(x_temp/(6*area_temp), y_temp/(6*area_temp)); } -std::string -Polygon::wkt() const -{ - std::ostringstream wkt; - wkt << "POLYGON(("; - for (Points::const_iterator p = this->points.begin(); p != this->points.end(); ++p) { - wkt << p->x() << " " << p->y(); - if (p != this->points.end()-1) wkt << ","; - } - wkt << "))"; - return wkt.str(); -} - // find all concave vertices (i.e. having an internal angle greater than the supplied angle) // (external = right side, thus we consider ccw orientation) Points diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index d618644e9..009184620 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -54,7 +54,6 @@ public: void simplify(double tolerance, Polygons &polygons) const; void triangulate_convex(Polygons* polygons) const; Point centroid() const; - std::string wkt() const; Points concave_points(double angle = PI) const; Points convex_points(double angle = PI) const; // Projection of a point onto the polygon. diff --git a/xs/src/libslic3r/Polyline.cpp b/xs/src/libslic3r/Polyline.cpp index 75c6203e1..b2e50bca3 100644 --- a/xs/src/libslic3r/Polyline.cpp +++ b/xs/src/libslic3r/Polyline.cpp @@ -196,18 +196,6 @@ bool Polyline::is_straight() const return true; } -std::string Polyline::wkt() const -{ - std::ostringstream wkt; - wkt << "LINESTRING(("; - for (Points::const_iterator p = this->points.begin(); p != this->points.end(); ++p) { - wkt << p->x() << " " << p->y(); - if (p != this->points.end()-1) wkt << ","; - } - wkt << "))"; - return wkt.str(); -} - BoundingBox get_extents(const Polyline &polyline) { return polyline.bounding_box(); diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index d977c771e..edd27aaf6 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -73,7 +73,6 @@ public: template void simplify_by_visibility(const T &area); void split_at(const Point &point, Polyline* p1, Polyline* p2) const; bool is_straight() const; - std::string wkt() const; }; extern BoundingBox get_extents(const Polyline &polyline); diff --git a/xs/src/xsinit.h b/xs/src/xsinit.h index 02a8d9e80..c07e50b9d 100644 --- a/xs/src/xsinit.h +++ b/xs/src/xsinit.h @@ -73,10 +73,10 @@ extern "C" { #undef malloc #undef realloc #undef free - #undef Zero - #undef Packet #undef select #endif /* _MSC_VER */ +#undef Zero +#undef Packet } #endif diff --git a/xs/xsp/Polygon.xsp b/xs/xsp/Polygon.xsp index f5db9f515..a94425477 100644 --- a/xs/xsp/Polygon.xsp +++ b/xs/xsp/Polygon.xsp @@ -39,7 +39,6 @@ %code{% THIS->triangulate_convex(&RETVAL); %}; Clone centroid(); Clone bounding_box(); - std::string wkt(); Points concave_points(double angle); Points convex_points(double angle); Clone point_projection(Point* point) diff --git a/xs/xsp/Polyline.xsp b/xs/xsp/Polyline.xsp index 60d7c6aca..0dbd0e572 100644 --- a/xs/xsp/Polyline.xsp +++ b/xs/xsp/Polyline.xsp @@ -38,7 +38,6 @@ bool is_straight(); Clone bounding_box(); void remove_duplicate_points(); - std::string wkt(); %{ Polyline*