Ported same_line() to XS

This commit is contained in:
Alessandro Ranellucci 2013-11-06 19:38:10 +01:00
parent b5aaeb9b12
commit d8e098ab0e
5 changed files with 21 additions and 9 deletions

View File

@ -7,7 +7,7 @@ use warnings;
use Boost::Geometry::Utils; use Boost::Geometry::Utils;
use List::Util qw(first); use List::Util qw(first);
use Math::Geometry::Voronoi; use Math::Geometry::Voronoi;
use Slic3r::Geometry qw(X Y A B point_in_polygon same_line epsilon scaled_epsilon); use Slic3r::Geometry qw(X Y A B point_in_polygon epsilon scaled_epsilon);
use Slic3r::Geometry::Clipper qw(union_ex); use Slic3r::Geometry::Clipper qw(union_ex);
sub wkt { sub wkt {
@ -60,9 +60,9 @@ sub encloses_line {
my $clip = $self->clip_line($line); my $clip = $self->clip_line($line);
if (!defined $tolerance) { if (!defined $tolerance) {
# optimization # optimization
return @$clip == 1 && same_line($clip->[0]->pp, $line->pp); return @$clip == 1 && $clip->[0]->coincides_with($line);
} else { } else {
return @$clip == 1 && abs(Boost::Geometry::Utils::linestring_length($clip->[0]->pp) - $line->length) < $tolerance; return @$clip == 1 && abs($clip->[0]->length - $line->length) < $tolerance;
} }
} }

View File

@ -14,7 +14,7 @@ our @EXPORT_OK = qw(
polygon_has_vertex polyline_length can_connect_points deg2rad rad2deg polygon_has_vertex polyline_length can_connect_points deg2rad rad2deg
rotate_points move_points clip_segment_polygon rotate_points move_points clip_segment_polygon
sum_vectors multiply_vector subtract_vectors dot perp polygon_points_visibility sum_vectors multiply_vector subtract_vectors dot perp polygon_points_visibility
line_intersection bounding_box bounding_box_intersect same_point same_line line_intersection bounding_box bounding_box_intersect same_point
longest_segment angle3points three_points_aligned line_direction longest_segment angle3points three_points_aligned line_direction
polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices
polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges
@ -112,11 +112,6 @@ sub same_point {
return $p1->[X] == $p2->[X] && $p1->[Y] == $p2->[Y]; return $p1->[X] == $p2->[X] && $p1->[Y] == $p2->[Y];
} }
sub same_line {
my ($line1, $line2) = @_;
return same_point($line1->[A], $line2->[A]) && same_point($line1->[B], $line2->[B]);
}
sub distance_between_points { sub distance_between_points {
my ($p1, $p2) = @_; my ($p1, $p2) = @_;
return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2); return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2);

View File

@ -54,6 +54,12 @@ Line::point_at(double distance) const
return p; return p;
} }
bool
Line::coincides_with(const Line* line) const
{
return this->a.coincides_with(&line->a) && this->b.coincides_with(&line->b);
}
#ifdef SLIC3RXS #ifdef SLIC3RXS
void void
Line::from_SV(SV* line_sv) Line::from_SV(SV* line_sv)

View File

@ -20,6 +20,7 @@ class Line
double length() const; double length() const;
Point* midpoint() const; Point* midpoint() const;
Point* point_at(double distance) const; Point* point_at(double distance) const;
bool coincides_with(const Line* line) const;
#ifdef SLIC3RXS #ifdef SLIC3RXS
void from_SV(SV* line_sv); void from_SV(SV* line_sv);

View File

@ -46,5 +46,15 @@ Line::rotate(angle, center_sv)
center.from_SV_check(center_sv); center.from_SV_check(center_sv);
THIS->rotate(angle, &center); THIS->rotate(angle, &center);
bool
Line::coincides_with(line_sv)
SV* line_sv;
CODE:
Line line;
line.from_SV_check(line_sv);
RETVAL = THIS->coincides_with(&line);
OUTPUT:
RETVAL
%} %}
}; };