diff options
Diffstat (limited to 'src/libslic3r/Line.cpp')
-rw-r--r-- | src/libslic3r/Line.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/libslic3r/Line.cpp b/src/libslic3r/Line.cpp index 05cbfee4e..8a2a2875b 100644 --- a/src/libslic3r/Line.cpp +++ b/src/libslic3r/Line.cpp @@ -33,24 +33,6 @@ bool Line::intersection_infinite(const Line &other, Point* point) const return true; } -// Distance to the closest point of line. -double Line::distance_to_squared(const Point &point, const Point &a, const Point &b) -{ - const Vec2d v = (b - a).cast<double>(); - const Vec2d va = (point - a).cast<double>(); - const double l2 = v.squaredNorm(); // avoid a sqrt - if (l2 == 0.0) - // a == b case - return va.squaredNorm(); - // Consider the line extending the segment, parameterized as a + t (b - a). - // We find projection of this point onto the line. - // It falls where t = [(this-a) . (b-a)] / |b-a|^2 - const double t = va.dot(v) / l2; - if (t < 0.0) return va.squaredNorm(); // beyond the 'a' end of the segment - else if (t > 1.0) return (point - b).cast<double>().squaredNorm(); // beyond the 'b' end of the segment - return (t * v - va).squaredNorm(); -} - double Line::perp_distance_to(const Point &point) const { const Line &line = *this; @@ -118,6 +100,13 @@ bool Line::clip_with_bbox(const BoundingBox &bbox) return result; } +void Line::extend(double offset) +{ + Vector offset_vector = (offset * this->vector().cast<double>().normalized()).cast<coord_t>(); + this->a -= offset_vector; + this->b += offset_vector; +} + Vec3d Linef3::intersect_plane(double z) const { auto v = (this->b - this->a).cast<double>(); @@ -125,4 +114,14 @@ Vec3d Linef3::intersect_plane(double z) const return Vec3d(this->a(0) + v(0) * t, this->a(1) + v(1) * t, z); } +BoundingBox get_extents(const Lines &lines) +{ + BoundingBox bbox; + for (const Line &line : lines) { + bbox.merge(line.a); + bbox.merge(line.b); + } + return bbox; } + +} // namespace Slic3r |