Modified implementation of Line::parallel_to(const Line& line) and Line::perpendicular_to(const Line& line)

This commit is contained in:
enricoturri1966 2021-10-22 13:51:33 +02:00
parent b6b5bdb592
commit decdaa82d3
2 changed files with 16 additions and 2 deletions

View File

@ -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<double>();
const Vec2d v2 = (line.b - line.a).cast<double>();
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<double>();
const Vec2d v2 = (line.b - line.a).cast<double>();
return std::fabs(v1.dot(v2)) < EPSILON;
}
#endif // ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
bool Line::intersection(const Line &l2, Point *intersection) const

View File

@ -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;