diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2015-01-16 18:25:39 +0300 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2015-01-16 18:25:39 +0300 |
commit | e749f6040f3ff9e81b19de47800cac1a90d549e5 (patch) | |
tree | 1d43c4c303692a94d522eb1f4fe8f0e2f393d07a /xs/src/libslic3r/Line.cpp | |
parent | aa69ae11a84c500d3c76d808e625611b42684a44 (diff) |
New +Line::intersection_infinite() method
Diffstat (limited to 'xs/src/libslic3r/Line.cpp')
-rw-r--r-- | xs/src/libslic3r/Line.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index b98208325..15771ea7c 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/xs/src/libslic3r/Line.cpp @@ -90,6 +90,23 @@ Line::point_at(double distance) const } bool +Line::intersection_infinite(const Line &other, Point* point) const +{ + Vector x = this->a.vector_to(other.a); + Vector d1 = this->vector(); + Vector d2 = other.vector(); + + double cross = d1.x * d2.y - d1.y * d2.x; + if (std::fabs(cross) < EPSILON) + return false; + + double t1 = (x.x * d2.y - x.y * d2.x)/cross; + point->x = this->a.x + d1.x * t1; + point->y = this->a.y + d1.y * t1; + return true; +} + +bool Line::coincides_with(const Line &line) const { return this->a.coincides_with(line.a) && this->b.coincides_with(line.b); |