From decdaa82d3db9619b45d3c59d5106526cf65d57d Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 22 Oct 2021 13:51:33 +0200 Subject: [PATCH] Modified implementation of Line::parallel_to(const Line& line) and Line::perpendicular_to(const Line& line) --- src/libslic3r/Line.cpp | 14 ++++++++++++++ src/libslic3r/Line.hpp | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Line.cpp b/src/libslic3r/Line.cpp index 1a96b8b1f..78ca2b9af 100644 --- a/src/libslic3r/Line.cpp +++ b/src/libslic3r/Line.cpp @@ -63,11 +63,25 @@ bool Line::parallel_to(double angle) const return Slic3r::Geometry::directions_parallel(this->direction(), angle); } +bool Line::parallel_to(const Line& line) const +{ + const Vec2d v1 = (this->b - this->a).cast(); + const Vec2d v2 = (line.b - line.a).cast(); + return std::fabs(cross2(v1, v2)) < EPSILON; +} + #if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS bool Line::perpendicular_to(double angle) const { return Slic3r::Geometry::directions_perpendicular(this->direction(), angle); } + +bool Line::perpendicular_to(const Line& line) const +{ + const Vec2d v1 = (this->b - this->a).cast(); + const Vec2d v2 = (line.b - line.a).cast(); + return std::fabs(v1.dot(v2)) < EPSILON; +} #endif // ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS bool Line::intersection(const Line &l2, Point *intersection) const diff --git a/src/libslic3r/Line.hpp b/src/libslic3r/Line.hpp index 4a33c7c9c..a4dcd827c 100644 --- a/src/libslic3r/Line.hpp +++ b/src/libslic3r/Line.hpp @@ -104,10 +104,10 @@ public: double distance_to(const Point &point) const { return distance_to(point, this->a, this->b); } double perp_distance_to(const Point &point) const; bool parallel_to(double angle) const; - bool parallel_to(const Line &line) const { return this->parallel_to(line.direction()); } + bool parallel_to(const Line& line) const; #if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS bool perpendicular_to(double angle) const; - bool perpendicular_to(const Line& line) const { return this->perpendicular_to(line.direction()); } + bool perpendicular_to(const Line& line) const; #endif // ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS double atan2_() const { return atan2(this->b(1) - this->a(1), this->b(0) - this->a(0)); } double orientation() const;