diff options
author | Alessandro Ranellucci <aar@cpan.org> | 2016-03-19 17:33:58 +0300 |
---|---|---|
committer | Alessandro Ranellucci <aar@cpan.org> | 2016-03-19 21:20:04 +0300 |
commit | 6dc42ee902ec630ef21c1f50c96b726a8b56105b (patch) | |
tree | b25c4a5c0468905c92c46202526d863b4cac8859 /xs/src/libslic3r/Line.cpp | |
parent | 5ff7511a148bcfcd42c579f5c8e80306376c97d7 (diff) |
Variable-width gap fill. Yay! #2960
Diffstat (limited to 'xs/src/libslic3r/Line.cpp')
-rw-r--r-- | xs/src/libslic3r/Line.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index f3b8ff43c..1940402ed 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/xs/src/libslic3r/Line.cpp @@ -163,6 +163,55 @@ Line::normal() const return Vector((this->b.y - this->a.y), -(this->b.x - this->a.x)); } +void +Line::extend_end(double distance) +{ + // relocate last point by extending the segment by the specified length + Line line = *this; + line.reverse(); + this->b = line.point_at(-distance); +} + +void +Line::extend_start(double distance) +{ + // relocate first point by extending the first segment by the specified length + this->a = this->point_at(-distance); +} + +bool +Line::intersection(const Line& line, Point* intersection) const +{ + double denom = ((line.b.y - line.a.y)*(this->b.x - this->a.x)) - + ((line.b.x - line.a.x)*(this->b.y - this->a.y)); + + double nume_a = ((line.b.x - line.a.x)*(this->a.y - line.a.y)) - + ((line.b.y - line.a.y)*(this->a.x - line.a.x)); + + double nume_b = ((this->b.x - this->a.x)*(this->a.y - line.a.y)) - + ((this->b.y - this->a.y)*(this->a.x - line.a.x)); + + if (fabs(denom) < EPSILON) { + if (fabs(nume_a) < EPSILON && fabs(nume_b) < EPSILON) { + return false; // coincident + } + return false; // parallel + } + + double ua = nume_a / denom; + double ub = nume_b / denom; + + if (ua >= 0 && ua <= 1.0f && ub >= 0 && ub <= 1.0f) + { + // Get the intersection point. + intersection->x = this->a.x + ua*(this->b.x - this->a.x); + intersection->y = this->a.y + ua*(this->b.y - this->a.y); + return true; + } + + return false; // not intersecting +} + Pointf3 Linef3::intersect_plane(double z) const { |