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-15 13:36:05 +0400
committerAlessandro Ranellucci <aar@cpan.org>2011-10-15 23:14:13 +0400
commit5090ae561c2727b6022ea1f293b1036de7aa271e (patch)
tree4406812581747650c3b0c8e421267b1d0a8b401d /lib/Slic3r/ExPolygon.pm
parent2d784fac9b503b5d246886e2c62289d83ee63e26 (diff)
Refactored Perimeter code with new Slic3r::Polygon and Slic3r::ExPolygon objects
Large refactoring. Speed gains. Removed convex hull for bridges.
Diffstat (limited to 'lib/Slic3r/ExPolygon.pm')
-rw-r--r--lib/Slic3r/ExPolygon.pm66
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm
new file mode 100644
index 000000000..d267e3205
--- /dev/null
+++ b/lib/Slic3r/ExPolygon.pm
@@ -0,0 +1,66 @@
+package Slic3r::ExPolygon;
+use strict;
+use warnings;
+
+# an ExPolygon is a polygon with holes
+
+use Math::Clipper qw(CT_UNION PFT_NONZERO JT_MITER);
+use Slic3r::Geometry::Clipper qw(union_ex);
+
+# the constructor accepts an array of polygons
+# or a Math::Clipper ExPolygon (hashref)
+sub new {
+ my $class = shift;
+ my $self;
+ if (@_ == 1 && ref $_[0] eq 'HASH') {
+ $self = [
+ Slic3r::Polygon->new($_[0]{outer}),
+ map Slic3r::Polygon->new($_), @{$_[0]{holes}},
+ ];
+ } else {
+ $self = [@_];
+ }
+ bless $self, $class;
+ $self;
+}
+
+# this class method accepts an array of polygons and returns
+# an array of expolygons with the right holes applied to the
+# right contours
+sub make {
+ my $class = shift;
+ return map $class->new($_), @{ union_ex(\@_) };
+}
+
+sub contour {
+ my $self = shift;
+ return $self->[0];
+}
+
+sub holes {
+ my $self = shift;
+ return @$self[1..$#$self];
+}
+
+sub clipper_expolygon {
+ my $self = shift;
+ return {
+ outer => $self->contour,
+ holes => [ $self->holes ],
+ };
+}
+
+sub offset {
+ my $self = shift;
+ my ($distance, $scale, $joinType, $miterLimit) = @_;
+ $scale ||= $Slic3r::resolution * 1000000;
+ $joinType = JT_MITER if !defined $joinType;
+ $miterLimit ||= 2;
+
+ my $offsets = Math::Clipper::offset($self, $distance, $scale, $joinType, $miterLimit);
+
+ # apply holes to the right contours
+ return (ref $self)->make(@$offsets);
+}
+
+1;