Ported Point->distance_to() and Line->length()
This commit is contained in:
parent
c9f68ed28a
commit
e19c6a1494
7 changed files with 18 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
void reverse();
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
double length();
|
||||
%{
|
||||
|
||||
Line*
|
||||
|
|
|
@ -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);
|
||||
|
||||
%{
|
||||
|
||||
|
|
Loading…
Reference in a new issue