Speed optimization in avoid_crossing_perimeters

This commit is contained in:
Alessandro Ranellucci 2013-05-19 10:35:11 +02:00
parent f599ed00c6
commit 7180e7cb30
2 changed files with 4 additions and 8 deletions

View file

@ -75,6 +75,7 @@ sub BUILD {
{
my @outer = (map @$_, @{$self->_outer});
my @outer_ex = map [$_], @outer; # as ExPolygons
# lines of outer polygons connect visible points
for my $i (0 .. $#outer) {
@ -91,7 +92,7 @@ sub BUILD {
for my $m (0 .. $#{$outer[$i]}) {
for my $n (0 .. $#{$outer[$j]}) {
my $line = Slic3r::Line->new($outer[$i][$m], $outer[$j][$n]);
if (!first { $_->intersects_line($line) } @outer) {
if (!@{Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection(\@outer_ex, [$line])}) {
# this line does not cross any polygon
my $dist = $line->length;
$edges->{$outer[$i][$m]}{$outer[$j][$n]} = $dist;
@ -106,12 +107,13 @@ sub BUILD {
# lines connecting inner polygons contours are visible but discouraged
if (!$self->no_internal) {
my @inner = (map $_->contour, map @$_, @{$self->_inner});
my @inner_ex = map [$_], @inner; # as ExPolygons
for my $i (0 .. $#inner) {
for my $j (($i+1) .. $#inner) {
for my $m (0 .. $#{$inner[$i]}) {
for my $n (0 .. $#{$inner[$j]}) {
my $line = Slic3r::Line->new($inner[$i][$m], $inner[$j][$n]);
if (!first { $_->intersects_line($line) } @inner) {
if (!@{Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection(\@inner_ex, [$line])}) {
# this line does not cross any polygon
my $dist = $line->length * CROSSING_FACTOR;
$edges->{$inner[$i][$m]}{$inner[$j][$n]} = $dist;

View file

@ -172,10 +172,4 @@ sub split_at_first_point {
return $self->split_at_index(0);
}
sub intersects_line {
my $self = shift;
my ($line) = @_;
return @{Boost::Geometry::Utils::polygon_multi_linestring_intersection([$self], [$line])} > 0;
}
1;