From 2ef565fc4d156744e7795d8b862bbbdc32e008c1 Mon Sep 17 00:00:00 2001 From: Mark Hindess Date: Sat, 16 Jun 2012 08:24:27 +0100 Subject: [PATCH] Simplify creation of $n, @x and @y in point_in_polygon test. Gives 30% speed up on simcop2387's coaster on my laptop and it cuts the maximum resident set size too. I know this is going to be replaced but thought this might be useful in the meantime. --- lib/Slic3r/Geometry.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index 8a9e5ac32..130f791fd 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -154,15 +154,16 @@ sub point_in_polygon { my ($point, $polygon) = @_; my ($x, $y) = @$point; - my @xy = map @$_, @$polygon; + my $n = @$polygon; + my @x; + my @y; + foreach (0..$n-1) { + push @x, $polygon->[$_]->[X]; + push @y, $polygon->[$_]->[Y]; + } # Derived from the comp.graphics.algorithms FAQ, # courtesy of Wm. Randolph Franklin - my $n = @xy / 2; # Number of points in polygon - my @i = map { 2*$_ } 0..(@xy/2); # The even indices of @xy - my @x = map { $xy[$_] } @i; # Even indices: x-coordinates - my @y = map { $xy[$_ + 1] } @i; # Odd indices: y-coordinates - my ($i, $j); my $side = 0; # 0 = outside; 1 = inside for ($i = 0, $j = $n - 1; $i < $n; $j = $i++) {