Browse Source

Changing the internal representation of Point / Pointf / Point3 / Pointf3 to Eigen Matrix types:
Changed the Point3 / Pointf3 to derive from the Eigen Vec3crd / Vec3d.
Replaced the Point::concide_with() method calls with == operator.
Reduced some compiler warnings.

bubnikv 6 years ago
parent
commit
3b89717149

+ 3 - 3
xs/src/libslic3r/BridgeDetector.cpp

@@ -182,9 +182,9 @@ std::vector<double> BridgeDetector::bridge_direction_candidates() const
     
     /*  we also test angles of each open supporting edge
         (this finds the optimal angle for C-shaped supports) */
-    for (Polylines::const_iterator edge = this->_edges.begin(); edge != this->_edges.end(); ++edge)
-        if (! edge->first_point().coincides_with(edge->last_point()))
-            angles.push_back(Line(edge->first_point(), edge->last_point()).direction());
+    for (const Polyline &edge : this->_edges)
+        if (edge.first_point() != edge.last_point())
+            angles.push_back(Line(edge.first_point(), edge.last_point()).direction());
     
     // remove duplicates
     double min_resolution = PI/180.0;  // 1 degree

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

@@ -595,26 +595,26 @@ Polylines _clipper_pl(ClipperLib::ClipType clipType, const Polygons &subject, co
        to recombine continuous polylines. */
     for (size_t i = 0; i < retval.size(); ++i) {
         for (size_t j = i+1; j < retval.size(); ++j) {
-            if (retval[i].points.back().coincides_with(retval[j].points.front())) {
+            if (retval[i].points.back() == retval[j].points.front()) {
                 /* If last point of i coincides with first point of j,
                    append points of j to i and delete j */
                 retval[i].points.insert(retval[i].points.end(), retval[j].points.begin()+1, retval[j].points.end());
                 retval.erase(retval.begin() + j);
                 --j;
-            } else if (retval[i].points.front().coincides_with(retval[j].points.back())) {
+            } else if (retval[i].points.front() == retval[j].points.back()) {
                 /* If first point of i coincides with last point of j,
                    prepend points of j to i and delete j */
                 retval[i].points.insert(retval[i].points.begin(), retval[j].points.begin(), retval[j].points.end()-1);
                 retval.erase(retval.begin() + j);
                 --j;
-            } else if (retval[i].points.front().coincides_with(retval[j].points.front())) {
+            } else if (retval[i].points.front() == retval[j].points.front()) {
                 /* Since Clipper does not preserve orientation of polylines, 
                    also check the case when first point of i coincides with first point of j. */
                 retval[j].reverse();
                 retval[i].points.insert(retval[i].points.begin(), retval[j].points.begin(), retval[j].points.end()-1);
                 retval.erase(retval.begin() + j);
                 --j;
-            } else if (retval[i].points.back().coincides_with(retval[j].points.back())) {
+            } else if (retval[i].points.back() == retval[j].points.back()) {
                 /* Since Clipper does not preserve orientation of polylines, 
                    also check the case when last point of i coincides with last point of j. */
                 retval[j].reverse();

+ 4 - 4
xs/src/libslic3r/ExPolygon.cpp

@@ -294,14 +294,14 @@ ExPolygon::medial_axis(double max_width, double min_width, ThickPolylines* polyl
             // find another polyline starting here
             for (size_t j = i+1; j < pp.size(); ++j) {
                 ThickPolyline& other = pp[j];
-                if (polyline.last_point().coincides_with(other.last_point())) {
+                if (polyline.last_point() == other.last_point()) {
                     other.reverse();
-                } else if (polyline.first_point().coincides_with(other.last_point())) {
+                } else if (polyline.first_point() == other.last_point()) {
                     polyline.reverse();
                     other.reverse();
-                } else if (polyline.first_point().coincides_with(other.first_point())) {
+                } else if (polyline.first_point() == other.first_point()) {
                     polyline.reverse();
-                } else if (!polyline.last_point().coincides_with(other.first_point())) {
+                } else if (polyline.last_point() != other.first_point()) {
                     continue;
                 }
                 

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

@@ -2213,7 +2213,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
     std::string gcode;
     
     // go to first point of extrusion path
-    if (!m_last_pos_defined || !m_last_pos.coincides_with(path.first_point())) {
+    if (!m_last_pos_defined || m_last_pos != path.first_point()) {
         gcode += this->travel_to(
             path.first_point(),
             path.role(),

+ 1 - 1
xs/src/libslic3r/GCode/WipeTower.hpp

@@ -31,7 +31,7 @@ public:
 			xy out(0,0);
 			float temp_x = x - width / 2.f;
 			float temp_y = y - depth / 2.f;
-			angle *= M_PI/180.;
+			angle *= float(M_PI/180.);
 			out.x += (temp_x - origin.x) * cos(angle)  -  (temp_y - origin.y) * sin(angle);
 			out.y += (temp_x - origin.x) * sin(angle)  +  (temp_y - origin.y) * cos(angle);
 			return out + origin;

+ 3 - 3
xs/src/libslic3r/Geometry.cpp

@@ -229,7 +229,7 @@ convex_hull(Points points)
 
         hull.points.resize(k);
         
-        assert( hull.points.front().coincides_with(hull.points.back()) );
+        assert( hull.points.front() == hull.points.back() );
         hull.points.pop_back();
     }
     
@@ -910,7 +910,7 @@ MedialAxis::build(ThickPolylines* polylines)
         assert(polyline.width.size() == polyline.points.size()*2 - 2);
         
         // prevent loop endpoints from being extended
-        if (polyline.first_point().coincides_with(polyline.last_point())) {
+        if (polyline.first_point() == polyline.last_point()) {
             polyline.endpoints.first = false;
             polyline.endpoints.second = false;
         }
@@ -1003,7 +1003,7 @@ MedialAxis::validate_edge(const VD::edge_type* edge)
     // this could maybe be optimized (checking inclusion of the endpoints
     // might give false positives as they might belong to the contour itself)
     if (this->expolygon != NULL) {
-        if (line.a.coincides_with(line.b)) {
+        if (line.a == line.b) {
             // in this case, contains(line) returns a false positive
             if (!this->expolygon->contains(line.a)) return false;
         } else {

+ 7 - 10
xs/src/libslic3r/Line.cpp

@@ -109,7 +109,7 @@ Line::intersection_infinite(const Line &other, Point* point) const
 bool
 Line::coincides_with(const Line &line) const
 {
-    return this->a.coincides_with(line.a) && this->b.coincides_with(line.b);
+    return this->a == line.a && this->b == line.b;
 }
 
 double
@@ -220,22 +220,19 @@ Line::ccw(const Point& point) const
 
 double Line3::length() const
 {
-    return (b.data - a.data).norm();
+    return (b - a).norm();
 }
 
 Vector3 Line3::vector() const
 {
-    return Vector3(b.data - a.data);
+    return Vector3(b - a);
 }
 
-Pointf3
-Linef3::intersect_plane(double z) const
+Pointf3 Linef3::intersect_plane(double z) const
 {
-    return Pointf3(
-        this->a.x() + (this->b.x() - this->a.x()) * (z - this->a.z()) / (this->b.z() - this->a.z()),
-        this->a.y() + (this->b.y() - this->a.y()) * (z - this->a.z()) / (this->b.z() - this->a.z()),
-        z
-    );
+    Vec3d  v = this->b - this->a;
+    double t = (z - this->a.z()) / v.z();
+    return Pointf3(this->a.x() + v.x() * t, this->a.y() + v.y() * t, z);
 }
 
 void

+ 1 - 0
xs/src/libslic3r/Model.hpp

@@ -210,6 +210,7 @@ public:
 
     friend class ModelObject;
 
+//    Transform3d     transform;
     double rotation;            // Rotation around the Z axis, in radians around mesh center point
     double scaling_factor;
     Pointf offset;              // in unscaled coordinates

+ 12 - 16
xs/src/libslic3r/MultiPoint.cpp

@@ -40,9 +40,9 @@ void MultiPoint::rotate(double angle, const Point &center)
     double s = sin(angle);
     double c = cos(angle);
     for (Point &pt : points) {
-        Vec2crd dif(pt.data - center.data);
-        pt.x() = (coord_t)round(double(center.x()) + c * dif[0] - s * dif[1]);
-        pt.y() = (coord_t)round(double(center.y()) + c * dif[1] + s * dif[0]);
+        Vec2crd v(pt - center);
+        pt.x() = (coord_t)round(double(center.x()) + c * v[0] - s * v[1]);
+        pt.y() = (coord_t)round(double(center.y()) + c * v[1] + s * v[0]);
     }
 }
 
@@ -70,9 +70,9 @@ MultiPoint::length() const
 int
 MultiPoint::find_point(const Point &point) const
 {
-    for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) {
-        if (it->coincides_with(point)) return it - this->points.begin();
-    }
+    for (const Point &pt : this->points)
+        if (pt == point)
+            return &pt - &this->points.front();
     return -1;  // not found
 }
 
@@ -93,7 +93,7 @@ bool
 MultiPoint::has_duplicate_points() const
 {
     for (size_t i = 1; i < points.size(); ++i)
-        if (points[i-1].coincides_with(points[i]))
+        if (points[i-1] == points[i])
             return true;
     return false;
 }
@@ -103,7 +103,7 @@ MultiPoint::remove_duplicate_points()
 {
     size_t j = 0;
     for (size_t i = 1; i < points.size(); ++i) {
-        if (points[j].coincides_with(points[i])) {
+        if (points[j] == points[i]) {
             // Just increase index i.
         } else {
             ++ j;
@@ -234,15 +234,11 @@ BoundingBox3 MultiPoint3::bounding_box() const
 bool MultiPoint3::remove_duplicate_points()
 {
     size_t j = 0;
-    for (size_t i = 1; i < points.size(); ++i)
-    {
-        if (points[j].coincides_with(points[i]))
-        {
+    for (size_t i = 1; i < points.size(); ++i) {
+        if (points[j] == points[i]) {
             // Just increase index i.
-        }
-        else
-        {
-            ++j;
+        } else {
+            ++ j;
             if (j < i)
                 points[j] = points[i];
         }

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

@@ -452,7 +452,7 @@ ExtrusionEntityCollection PerimeterGenerator::_variable_width(const ThickPolylin
             paths.emplace_back(std::move(path));        
         // Append paths to collection.
         if (! paths.empty()) {
-            if (paths.front().first_point().coincides_with(paths.back().last_point()))
+            if (paths.front().first_point() == paths.back().last_point())
                 coll.append(ExtrusionLoop(paths));
             else
                 coll.append(paths);

Some files were not shown because too many files changed in this diff