From 12b06b0ab0c463c73ed3e894f3c3dc39a180e093 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 14 Nov 2011 10:54:04 +0100 Subject: [PATCH] Speed boost for new infill patterns. #20 --- lib/Slic3r/Fill/PlanePath.pm | 11 +++++++++-- lib/Slic3r/Polyline.pm | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Slic3r/Fill/PlanePath.pm b/lib/Slic3r/Fill/PlanePath.pm index d0e3ce6c2..43ad82398 100644 --- a/lib/Slic3r/Fill/PlanePath.pm +++ b/lib/Slic3r/Fill/PlanePath.pm @@ -3,7 +3,7 @@ use Moo; extends 'Slic3r::Fill::Base'; -use Slic3r::Geometry qw(bounding_box); +use Slic3r::Geometry qw(bounding_box X1 Y1 X2 Y2); use XXX; sub multiplier () { 1 } @@ -29,6 +29,12 @@ sub fill_surface { my $distance_between_lines = $params{flow_width} / $Slic3r::resolution / $params{density} * $self->multiplier; my $bounding_box = [ bounding_box(map @$_, $expolygon) ]; + my $bounding_box_polygon = Slic3r::Polygon->new([ + [ $bounding_box->[X1], $bounding_box->[Y1] ], + [ $bounding_box->[X2], $bounding_box->[Y1] ], + [ $bounding_box->[X2], $bounding_box->[Y2] ], + [ $bounding_box->[X1], $bounding_box->[Y2] ], + ]); (ref $self) =~ /::([^:]+)$/; my $path = "Math::PlanePath::$1"->new; @@ -41,7 +47,8 @@ sub fill_surface { $self->process_polyline($polyline, $bounding_box); - my @paths = ($polyline->clip_with_expolygon($expolygon)); + my @paths = map $_->clip_with_expolygon($expolygon), + $polyline->clip_with_polygon($bounding_box_polygon); if (0) { require "Slic3r/SVG.pm"; diff --git a/lib/Slic3r/Polyline.pm b/lib/Slic3r/Polyline.pm index f85a45ba7..980426044 100644 --- a/lib/Slic3r/Polyline.pm +++ b/lib/Slic3r/Polyline.pm @@ -118,6 +118,13 @@ sub has_segment { return 0; } +sub clip_with_polygon { + my $self = shift; + my ($polygon) = @_; + + return $self->clip_with_expolygon(Slic3r::ExPolygon->new($polygon)); +} + sub clip_with_expolygon { my $self = shift; my ($expolygon) = @_;