Просмотр исходного кода

Removed Point::scale(),translate(),coincides_with(),distance_to(),
distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.

bubnikv 6 лет назад
Родитель
Сommit
1ba64da3fe

+ 8 - 6
xs/src/libslic3r/BoundingBox.cpp

@@ -68,8 +68,8 @@ BoundingBox BoundingBox::rotated(double angle, const Point &center) const
 template <class PointClass> void
 BoundingBoxBase<PointClass>::scale(double factor)
 {
-    this->min.scale(factor);
-    this->max.scale(factor);
+    this->min *= factor;
+    this->max *= factor;
 }
 template void BoundingBoxBase<Point>::scale(double factor);
 template void BoundingBoxBase<Pointf>::scale(double factor);
@@ -188,8 +188,9 @@ template double BoundingBox3Base<Pointf3>::radius() const;
 template <class PointClass> void
 BoundingBoxBase<PointClass>::offset(coordf_t delta)
 {
-    this->min.translate(-delta, -delta);
-    this->max.translate(delta, delta);
+    PointClass v(delta, delta);
+    this->min -= v;
+    this->max += v;
 }
 template void BoundingBoxBase<Point>::offset(coordf_t delta);
 template void BoundingBoxBase<Pointf>::offset(coordf_t delta);
@@ -197,8 +198,9 @@ template void BoundingBoxBase<Pointf>::offset(coordf_t delta);
 template <class PointClass> void
 BoundingBox3Base<PointClass>::offset(coordf_t delta)
 {
-    this->min.translate(-delta, -delta, -delta);
-    this->max.translate(delta, delta, delta);
+    PointClass v(delta, delta, delta);
+    this->min -= v;
+    this->max += v;
 }
 template void BoundingBox3Base<Pointf3>::offset(coordf_t delta);
 

+ 4 - 4
xs/src/libslic3r/BoundingBox.hpp

@@ -46,8 +46,8 @@ public:
     void scale(double factor);
     PointClass size() const;
     double radius() const;
-    void translate(coordf_t x, coordf_t y) { assert(this->defined); this->min.translate(x, y); this->max.translate(x, y); }
-    void translate(const Pointf &pos) { this->translate(pos.x(), pos.y()); }
+    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 offset(coordf_t delta);
     PointClass center() const;
     bool contains(const PointClass &point) const {
@@ -90,8 +90,8 @@ public:
     void merge(const BoundingBox3Base<PointClass> &bb);
     PointClass size() const;
     double radius() const;
-    void translate(coordf_t x, coordf_t y, coordf_t z) { this->min.translate(x, y, z); this->max.translate(x, y, z); }
-    void translate(const Pointf3 &pos) { this->translate(pos.x(), pos.y(), pos.z()); }
+    void translate(coordf_t x, coordf_t y, coordf_t z) { assert(this->defined); PointClass v(x, y, z); this->min += v; this->max += v; }
+    void translate(const Pointf3 &v) { this->min += v; this->max += v; }
     void offset(coordf_t delta);
     PointClass center() const;
     coordf_t max_size() const;

+ 6 - 4
xs/src/libslic3r/BridgeDetector.cpp

@@ -282,10 +282,12 @@ BridgeDetector::unsupported_edges(double angle, Polylines* unsupported) const
             extrusions would be anchored within such length (i.e. a slightly non-parallel bridging
             direction might still benefit from anchors if long enough)
             double angle_tolerance = PI / 180.0 * 5.0; */
-        for (Lines::const_iterator line = unsupported_lines.begin(); line != unsupported_lines.end(); ++line) {
-            if (!Slic3r::Geometry::directions_parallel(line->direction(), angle))
-                unsupported->push_back(*line);
-        }
+        for (const Line &line : unsupported_lines)
+            if (! Slic3r::Geometry::directions_parallel(line.direction(), angle)) {
+                unsupported->emplace_back(Polyline());
+                unsupported->back().points.emplace_back(line.a);
+                unsupported->back().points.emplace_back(line.b);
+            }
     }
     
     /*

+ 2 - 2
xs/src/libslic3r/ClipperUtils.cpp

@@ -634,8 +634,8 @@ _clipper_ln(ClipperLib::ClipType clipType, const Lines &subject, const Polygons
     // convert Lines to Polylines
     Polylines polylines;
     polylines.reserve(subject.size());
-    for (Lines::const_iterator line = subject.begin(); line != subject.end(); ++line)
-        polylines.push_back(*line);
+    for (const Line &line : subject)
+        polylines.emplace_back(Polyline(line.a, line.b));
     
     // perform operation
     polylines = _clipper_pl(clipType, polylines, clip, safety_offset_);

+ 6 - 6
xs/src/libslic3r/EdgeGrid.cpp

@@ -767,7 +767,7 @@ void EdgeGrid::Grid::calculate_sdf()
 				const Slic3r::Point &p1 = pts[ipt];
 				const Slic3r::Point &p2 = pts[(ipt + 1 == pts.size()) ? 0 : ipt + 1];
 				// Segment vector
-				const Slic3r::Point v_seg = p1.vector_to(p2);
+				const Slic3r::Point v_seg = p2 - p1;
 				// l2 of v_seg
 				const int64_t l2_seg = int64_t(v_seg.x()) * int64_t(v_seg.x()) + int64_t(v_seg.y()) * int64_t(v_seg.y());
 				// For each corner of this cell and its 1 ring neighbours:
@@ -781,7 +781,7 @@ void EdgeGrid::Grid::calculate_sdf()
 							continue;
 						float  &d_min = m_signed_distance_field[corner_r * ncols + corner_c];
 						Slic3r::Point pt(m_bbox.min.x() + corner_c * m_resolution, m_bbox.min.y() + corner_r * m_resolution);
-						Slic3r::Point v_pt = p1.vector_to(pt);
+						Slic3r::Point v_pt = pt - p1;
 						// dot(p2-p1, pt-p1)
 						int64_t t_pt = int64_t(v_seg.x()) * int64_t(v_pt.x()) + int64_t(v_seg.y()) * int64_t(v_pt.y());
 						if (t_pt < 0) {
@@ -790,7 +790,7 @@ void EdgeGrid::Grid::calculate_sdf()
 							if (dabs < d_min) {
 								// Previous point.
 								const Slic3r::Point &p0 = pts[(ipt == 0) ? (pts.size() - 1) : ipt - 1];
-								Slic3r::Point v_seg_prev = p0.vector_to(p1);
+								Slic3r::Point v_seg_prev = p1 - p0;
 								int64_t t2_pt = int64_t(v_seg_prev.x()) * int64_t(v_pt.x()) + int64_t(v_seg_prev.y()) * int64_t(v_pt.y());
 								if (t2_pt > 0) {
 									// Inside the wedge between the previous and the next segment.
@@ -1164,8 +1164,8 @@ bool EdgeGrid::Grid::signed_distance_edges(const Point &pt, coord_t search_radiu
 				// End points of the line segment.
 				const Slic3r::Point &p1 = pts[ipt];
 				const Slic3r::Point &p2 = pts[(ipt + 1 == pts.size()) ? 0 : ipt + 1];
-				Slic3r::Point v_seg = p1.vector_to(p2);
-				Slic3r::Point v_pt = p1.vector_to(pt);
+				Slic3r::Point v_seg = p2 - p1;
+				Slic3r::Point v_pt  = pt - p1;
 				// dot(p2-p1, pt-p1)
 				int64_t t_pt = int64_t(v_seg.x()) * int64_t(v_pt.x()) + int64_t(v_seg.y()) * int64_t(v_pt.y());
 				// l2 of seg
@@ -1176,7 +1176,7 @@ bool EdgeGrid::Grid::signed_distance_edges(const Point &pt, coord_t search_radiu
 					if (dabs < d_min) {
 						// Previous point.
 						const Slic3r::Point &p0 = pts[(ipt == 0) ? (pts.size() - 1) : ipt - 1];
-						Slic3r::Point v_seg_prev = p0.vector_to(p1);
+						Slic3r::Point v_seg_prev = p1 - p0;
 						int64_t t2_pt = int64_t(v_seg_prev.x()) * int64_t(v_pt.x()) + int64_t(v_seg_prev.y()) * int64_t(v_pt.y());
 						if (t2_pt > 0) {
 							// Inside the wedge between the previous and the next segment.

+ 36 - 53
xs/src/libslic3r/ExPolygon.cpp

@@ -34,54 +34,43 @@ ExPolygon::operator Polylines() const
     return to_polylines(*this);
 }
 
-void
-ExPolygon::scale(double factor)
+void ExPolygon::scale(double factor)
 {
     contour.scale(factor);
-    for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
-        (*it).scale(factor);
-    }
+    for (Polygon &hole : holes)
+        hole.scale(factor);
 }
 
-void
-ExPolygon::translate(double x, double y)
+void ExPolygon::translate(double x, double y)
 {
     contour.translate(x, y);
-    for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
-        (*it).translate(x, y);
-    }
+    for (Polygon &hole : holes)
+        hole.translate(x, y);
 }
 
-void
-ExPolygon::rotate(double angle)
+void ExPolygon::rotate(double angle)
 {
     contour.rotate(angle);
-    for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
-        (*it).rotate(angle);
-    }
+    for (Polygon &hole : holes)
+        hole.rotate(angle);
 }
 
-void
-ExPolygon::rotate(double angle, const Point &center)
+void ExPolygon::rotate(double angle, const Point &center)
 {
     contour.rotate(angle, center);
-    for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
-        (*it).rotate(angle, center);
-    }
+    for (Polygon &hole : holes)
+        hole.rotate(angle, center);
 }
 
-double
-ExPolygon::area() const
+double ExPolygon::area() const
 {
     double a = this->contour.area();
-    for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
-        a -= -(*it).area();  // holes have negative area
-    }
+    for (const Polygon &hole : holes)
+        a -= - hole.area();  // holes have negative area
     return a;
 }
 
-bool
-ExPolygon::is_valid() const
+bool ExPolygon::is_valid() const
 {
     if (!this->contour.is_valid() || !this->contour.is_counter_clockwise()) return false;
     for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
@@ -90,20 +79,17 @@ ExPolygon::is_valid() const
     return true;
 }
 
-bool
-ExPolygon::contains(const Line &line) const
+bool ExPolygon::contains(const Line &line) const
 {
-    return this->contains((Polyline)line);
+    return this->contains(Polyline(line.a, line.b));
 }
 
-bool
-ExPolygon::contains(const Polyline &polyline) const
+bool ExPolygon::contains(const Polyline &polyline) const
 {
     return diff_pl((Polylines)polyline, *this).empty();
 }
 
-bool
-ExPolygon::contains(const Polylines &polylines) const
+bool ExPolygon::contains(const Polylines &polylines) const
 {
     #if 0
     BoundingBox bbox = get_extents(polylines);
@@ -120,8 +106,7 @@ ExPolygon::contains(const Polylines &polylines) const
     return pl_out.empty();
 }
 
-bool
-ExPolygon::contains(const Point &point) const
+bool ExPolygon::contains(const Point &point) const
 {
     if (!this->contour.contains(point)) return false;
     for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
@@ -131,8 +116,7 @@ ExPolygon::contains(const Point &point) const
 }
 
 // inclusive version of contains() that also checks whether point is on boundaries
-bool
-ExPolygon::contains_b(const Point &point) const
+bool ExPolygon::contains_b(const Point &point) const
 {
     return this->contains(point) || this->has_boundary_point(point);
 }
@@ -243,25 +227,24 @@ ExPolygon::medial_axis(double max_width, double min_width, ThickPolylines* polyl
         Point new_front = polyline.points.front();
         Point new_back  = polyline.points.back();
         if (polyline.endpoints.first && !this->has_boundary_point(new_front)) {
-            Line line(polyline.points.front(), polyline.points[1]);
-            
+            Vec2d p1 = polyline.points.front().cast<double>();
+            Vec2d p2 = polyline.points[1].cast<double>();
             // prevent the line from touching on the other side, otherwise intersection() might return that solution
-            if (polyline.points.size() == 2) line.b = line.midpoint();
-            
-            line.extend_start(max_width);
-            (void)this->contour.intersection(line, &new_front);
+            if (polyline.points.size() == 2)
+                p2 = (p1 + p2) * 0.5;
+            // Extend the start of the segment.
+            p1 -= (p2 - p1).normalized() * max_width;
+            this->contour.intersection(Line(p1.cast<coord_t>(), p2.cast<coord_t>()), &new_front);
         }
         if (polyline.endpoints.second && !this->has_boundary_point(new_back)) {
-            Line line(
-                *(polyline.points.end() - 2),
-                polyline.points.back()
-            );
-            
+            Vec2d p1 = (polyline.points.end() - 2)->cast<double>();
+            Vec2d p2 = polyline.points.back().cast<double>();
             // prevent the line from touching on the other side, otherwise intersection() might return that solution
-            if (polyline.points.size() == 2) line.a = line.midpoint();
-            line.extend_end(max_width);
-            
-            (void)this->contour.intersection(line, &new_back);
+            if (polyline.points.size() == 2)
+                p1 = (p1 + p2) * 0.5;
+            // Extend the start of the segment.
+            p2 += (p2 - p1).normalized() * max_width;
+            this->contour.intersection(Line(p1.cast<coord_t>(), p2.cast<coord_t>()), &new_back);
         }
         polyline.points.front() = new_front;
         polyline.points.back()  = new_back;

+ 1 - 1
xs/src/libslic3r/ExtrusionEntity.cpp

@@ -220,7 +220,7 @@ void ExtrusionLoop::split_at(const Point &point, bool prefer_non_overhang)
         double min_non_overhang = std::numeric_limits<double>::max();
         for (ExtrusionPaths::const_iterator path = this->paths.begin(); path != this->paths.end(); ++path) {
             Point p_tmp = point.projection_onto(path->polyline);
-            double dist = point.distance_to(p_tmp);
+            double dist = (p_tmp - point).cast<double>().norm();
             if (dist < min) {
                 p = p_tmp;
                 min = dist;

+ 8 - 3
xs/src/libslic3r/ExtrusionEntityCollection.hpp

@@ -50,10 +50,15 @@ public:
             src.clear();
         }
     }
-    void append(const ExtrusionPaths &paths) { 
+    void append(const ExtrusionPaths &paths) {
         this->entities.reserve(this->entities.size() + paths.size());
-        for (ExtrusionPaths::const_iterator path = paths.begin(); path != paths.end(); ++path)
-            this->entities.push_back(path->clone());
+        for (const ExtrusionPath &path : paths)
+            this->entities.emplace_back(path.clone());
+    }
+    void append(ExtrusionPaths &&paths) {
+        this->entities.reserve(this->entities.size() + paths.size());
+        for (ExtrusionPath &path : paths)
+            this->entities.emplace_back(new ExtrusionPath(std::move(path)));
     }
     void replace(size_t i, const ExtrusionEntity &entity);
     void remove(size_t i);

+ 1 - 1
xs/src/libslic3r/Fill/Fill3DHoneycomb.cpp

@@ -187,7 +187,7 @@ void Fill3DHoneycomb::_fill_surface_single(
                 const Point &last_point = pts_end.back();
                 // TODO: we should also check that both points are on a fill_boundary to avoid 
                 // connecting paths on the boundaries of internal regions
-                if (first_point.distance_to(last_point) <= 1.5 * distance && 
+                if ((last_point - first_point).cast<double>().norm() <= 1.5 * distance && 
                     expolygon_off.contains(Line(last_point, first_point))) {
                     // Append the polyline.
                     pts_end.insert(pts_end.end(), it_polyline->points.begin(), it_polyline->points.end());

+ 2 - 2
xs/src/libslic3r/Fill/FillGyroid.cpp

@@ -49,7 +49,7 @@ static inline Polyline make_wave(
         point.y() = clamp(0., height, double(point.y()));
         if (vertical)
             std::swap(point.x(), point.y());
-        polyline.points.emplace_back(convert_to<Point>(point * scaleFactor));
+        polyline.points.emplace_back((point * scaleFactor).cast<coord_t>());
     }
 
     return polyline;
@@ -177,7 +177,7 @@ void FillGyroid::_fill_surface_single(
                 // TODO: we should also check that both points are on a fill_boundary to avoid 
                 // connecting paths on the boundaries of internal regions
                 // TODO: avoid crossing current infill path
-                if (first_point.distance_to(last_point) <= 5 * distance && 
+                if ((last_point - first_point).cast<double>().norm() <= 5 * distance && 
                     expolygon_off.contains(Line(last_point, first_point))) {
                     // Append the polyline.
                     pts_end.insert(pts_end.end(), polyline.points.begin(), polyline.points.end());

Некоторые файлы не были показаны из-за большого количества измененных файлов