diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index 8aba26fcb..5a59828f6 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -7,7 +7,7 @@ use warnings; use Boost::Geometry::Utils; use List::Util qw(first); 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); sub wkt { @@ -60,9 +60,9 @@ sub encloses_line { my $clip = $self->clip_line($line); if (!defined $tolerance) { # optimization - return @$clip == 1 && same_line($clip->[0]->pp, $line->pp); + return @$clip == 1 && $clip->[0]->coincides_with($line); } 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; } } diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index 17383f18a..15ee3d26d 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -14,7 +14,7 @@ our @EXPORT_OK = qw( polygon_has_vertex polyline_length can_connect_points deg2rad rad2deg rotate_points move_points clip_segment_polygon 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 polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices 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]; } -sub same_line { - my ($line1, $line2) = @_; - return same_point($line1->[A], $line2->[A]) && same_point($line1->[B], $line2->[B]); -} - sub distance_between_points { my ($p1, $p2) = @_; return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2); diff --git a/xs/src/Line.cpp b/xs/src/Line.cpp index 4f60a2304..612116091 100644 --- a/xs/src/Line.cpp +++ b/xs/src/Line.cpp @@ -54,6 +54,12 @@ Line::point_at(double distance) const 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 void Line::from_SV(SV* line_sv) diff --git a/xs/src/Line.hpp b/xs/src/Line.hpp index 795590d5e..2545cc564 100644 --- a/xs/src/Line.hpp +++ b/xs/src/Line.hpp @@ -20,6 +20,7 @@ class Line double length() const; Point* midpoint() const; Point* point_at(double distance) const; + bool coincides_with(const Line* line) const; #ifdef SLIC3RXS void from_SV(SV* line_sv); diff --git a/xs/xsp/Line.xsp b/xs/xsp/Line.xsp index 39c54b48c..57ff19a39 100644 --- a/xs/xsp/Line.xsp +++ b/xs/xsp/Line.xsp @@ -46,5 +46,15 @@ Line::rotate(angle, center_sv) center.from_SV_check(center_sv); THIS->rotate(angle, ¢er); +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 + %} };