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

This commit is contained in:
Alessandro Ranellucci 2013-08-28 20:32:25 +02:00
parent c9f68ed28a
commit e19c6a1494
7 changed files with 18 additions and 6 deletions

View file

@ -7,10 +7,4 @@ sub new_scale {
return $class->new(map Slic3r::Geometry::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; 1;

View file

@ -30,6 +30,12 @@ Line::reverse()
std::swap(this->a, this->b); std::swap(this->a, this->b);
} }
double
Line::length() const
{
return this->a.distance_to(&(this->b));
}
void void
Line::from_SV(SV* line_sv) Line::from_SV(SV* line_sv)
{ {

View file

@ -22,6 +22,7 @@ class Line
void translate(double x, double y); void translate(double x, double y);
void rotate(double angle, Point* center); void rotate(double angle, Point* center);
void reverse(); void reverse();
double length() const;
}; };
typedef std::vector<Line> Lines; typedef std::vector<Line> Lines;

View file

@ -64,6 +64,14 @@ Point::nearest_point(Points points) const
return &(points.at(this->nearest_point_index(points))); 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* SV*
Point::to_SV_pureperl() { Point::to_SV_pureperl() {
AV* av = newAV(); AV* av = newAV();

View file

@ -25,6 +25,7 @@ class Point
bool coincides_with(const Point* point) const; bool coincides_with(const Point* point) const;
int nearest_point_index(const Points points) const; int nearest_point_index(const Points points) const;
Point* nearest_point(Points points) const; Point* nearest_point(Points points) const;
double distance_to(const Point* point) const;
}; };
} }

View file

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

View file

@ -23,6 +23,7 @@
int nearest_point_index(Points points); int nearest_point_index(Points points);
Point* nearest_point(Points points) Point* nearest_point(Points points)
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->nearest_point(points))); %}; %code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->nearest_point(points))); %};
double distance_to(Point* point);
%{ %{