diff --git a/lib/Slic3r/Point.pm b/lib/Slic3r/Point.pm index 0a3d7ec02..6ec4e60bc 100644 --- a/lib/Slic3r/Point.pm +++ b/lib/Slic3r/Point.pm @@ -7,10 +7,4 @@ sub new_scale { return $class->new(map Slic3r::Geometry::scale($_), @_); } -sub distance_to { - my $self = shift; - my ($point) = @_; - return Slic3r::Geometry::distance_between_points($self, $point); -} - 1; diff --git a/xs/src/Line.cpp b/xs/src/Line.cpp index 2c4d63250..e7b5da558 100644 --- a/xs/src/Line.cpp +++ b/xs/src/Line.cpp @@ -30,6 +30,12 @@ Line::reverse() std::swap(this->a, this->b); } +double +Line::length() const +{ + return this->a.distance_to(&(this->b)); +} + void Line::from_SV(SV* line_sv) { diff --git a/xs/src/Line.hpp b/xs/src/Line.hpp index 6b5cba260..0006e929d 100644 --- a/xs/src/Line.hpp +++ b/xs/src/Line.hpp @@ -22,6 +22,7 @@ class Line void translate(double x, double y); void rotate(double angle, Point* center); void reverse(); + double length() const; }; typedef std::vector Lines; diff --git a/xs/src/Point.cpp b/xs/src/Point.cpp index e534df089..350911b94 100644 --- a/xs/src/Point.cpp +++ b/xs/src/Point.cpp @@ -64,6 +64,14 @@ Point::nearest_point(Points points) const return &(points.at(this->nearest_point_index(points))); } +double +Point::distance_to(const Point* point) const +{ + double dx = ((double)point->x - this->x); + double dy = ((double)point->y - this->y); + return sqrt(dx*dx + dy*dy); +} + SV* Point::to_SV_pureperl() { AV* av = newAV(); diff --git a/xs/src/Point.hpp b/xs/src/Point.hpp index fdb405097..686558d63 100644 --- a/xs/src/Point.hpp +++ b/xs/src/Point.hpp @@ -25,6 +25,7 @@ class Point bool coincides_with(const Point* point) const; int nearest_point_index(const Points points) const; Point* nearest_point(Points points) const; + double distance_to(const Point* point) const; }; } diff --git a/xs/xsp/Line.xsp b/xs/xsp/Line.xsp index 68e451832..8dc8943ea 100644 --- a/xs/xsp/Line.xsp +++ b/xs/xsp/Line.xsp @@ -20,6 +20,7 @@ void reverse(); void scale(double factor); void translate(double x, double y); + double length(); %{ Line* diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index 3ff35fac3..ac0eb8dfc 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -23,6 +23,7 @@ int nearest_point_index(Points points); Point* nearest_point(Points points) %code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->nearest_point(points))); %}; + double distance_to(Point* point); %{