Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2011-10-10 00:18:06 +0400
committerAlessandro Ranellucci <aar@cpan.org>2011-10-10 00:18:06 +0400
commit84abd41cf454bcc9bccaa0c3921263d519106d97 (patch)
tree76a4f389ba15fa0aab363157fe374dd5e262e22b /lib/Slic3r/Geometry.pm
parent459577f9a2ee4b6a751ba735cf23a023bcd68ce8 (diff)
Fixes for bridges
Diffstat (limited to 'lib/Slic3r/Geometry.pm')
-rw-r--r--lib/Slic3r/Geometry.pm37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm
index 30104e109..d53193677 100644
--- a/lib/Slic3r/Geometry.pm
+++ b/lib/Slic3r/Geometry.pm
@@ -15,6 +15,8 @@ our @EXPORT_OK = qw(
sum_vectors multiply_vector subtract_vectors dot perp polygon_points_visibility
line_intersection bounding_box bounding_box_intersect
clip_segment_complex_polygon longest_segment angle3points
+ polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices
+ polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges
);
use Slic3r::Geometry::DouglasPeucker qw(Douglas_Peucker);
@@ -575,4 +577,39 @@ sub angle3points {
return $angle <= 0 ? $angle + 2*PI() : $angle;
}
+sub polyline_remove_parallel_continuous_edges {
+ my ($points, $isPolygon) = @_;
+
+ for (my $i = $isPolygon ? 0 : 2; $i <= $#$points; $i++) {
+ if (Slic3r::Geometry::lines_parallel([$points->[$i-2], $points->[$i-1]], [$points->[$i-1], $points->[$i]])) {
+ # we can remove $points->[$i-1]
+ splice @$points, $i-1, 1;
+ $i--;
+ }
+ }
+}
+
+sub polygon_remove_parallel_continuous_edges {
+ my ($points) = @_;
+ return polyline_remove_parallel_continuous_edges($points, 1);
+}
+
+sub polyline_remove_acute_vertices {
+ my ($points, $isPolygon) = @_;
+
+ for (my $i = $isPolygon ? -1 : 1; $i < $#$points; $i++) {
+ my $angle = angle3points($points->[$i], $points->[$i-1], $points->[$i+1]);
+ if ($angle < 0.01 || $angle >= 2*PI - 0.01) {
+ # we can remove $points->[$i]
+ splice @$points, $i, 1;
+ $i--;
+ }
+ }
+}
+
+sub polygon_remove_acute_vertices {
+ my ($points) = @_;
+ return polyline_remove_acute_vertices($points, 1);
+}
+
1;