From 840752194fd4847cfb66c69128f7884b18c04eb4 Mon Sep 17 00:00:00 2001 From: Mark Hindess Date: Tue, 26 Jun 2012 23:11:46 +0100 Subject: [PATCH] Speed up encloses_point calls from medial_axis code. The points shouldn't be on hole borders so we can make the check much quicker. Gives over 50% speed up slicing reprap shot glass (thing:11944) with default settings and 0.3 layer height. --- lib/Slic3r/ExPolygon.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index 4f0b2e27f..d39aa7291 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -99,6 +99,15 @@ sub encloses_point { || grep($_->point_on_segment($point), $self->holes)); } +# A version of encloses_point for use when hole borders do not matter. +# Useful because point_on_segment is slow +sub encloses_point_quick { + my $self = shift; + my ($point) = @_; + return $self->contour->encloses_point($point) + && !grep($_->encloses_point($point), $self->holes); +} + sub encloses_line { my $self = shift; my ($line) = @_; @@ -200,7 +209,7 @@ sub medial_axis { $a = $vertices->[$edge->[1]]; $b = $vertices->[$edge->[2]]; - next if !$self->encloses_point($a) || !$self->encloses_point($b); + next if !$self->encloses_point_quick($a) || !$self->encloses_point_quick($b); push @skeleton_lines, [$edge->[1], $edge->[2]]; }