Просмотр исходного кода

Ported Point->distance_to() and Line->length()

Alessandro Ranellucci 11 лет назад
Родитель
Сommit
e19c6a1494
7 измененных файлов с 18 добавлено и 6 удалено
  1. 0 6
      lib/Slic3r/Point.pm
  2. 6 0
      xs/src/Line.cpp
  3. 1 0
      xs/src/Line.hpp
  4. 8 0
      xs/src/Point.cpp
  5. 1 0
      xs/src/Point.hpp
  6. 1 0
      xs/xsp/Line.xsp
  7. 1 0
      xs/xsp/Point.xsp

+ 0 - 6
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;

+ 6 - 0
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)
 {

+ 1 - 0
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<Line> Lines;

+ 8 - 0
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();

+ 1 - 0
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;
 };
 
 }

+ 1 - 0
xs/xsp/Line.xsp

@@ -20,6 +20,7 @@
     void reverse();
     void scale(double factor);
     void translate(double x, double y);
+    double length();
 %{
 
 Line*

+ 1 - 0
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);
 
 %{