Renamed encloses_line() to contains_line() and implemented it using diff_pl()

This commit is contained in:
Alessandro Ranellucci 2013-11-21 14:35:28 +01:00
parent 3025c77675
commit bd62de7653
4 changed files with 10 additions and 18 deletions

View file

@ -54,16 +54,11 @@ sub encloses_point_quick {
return Boost::Geometry::Utils::point_within_polygon($point->pp, $self->pp); return Boost::Geometry::Utils::point_within_polygon($point->pp, $self->pp);
} }
sub encloses_line { sub contains_line {
my $self = shift; my $self = shift;
my ($line, $tolerance) = @_; my ($line) = @_;
my $clip = $self->clip_line($line);
if (!defined $tolerance) { return @{Slic3r::Geometry::Clipper::diff_pl([$line->as_polyline], \@$self)} ? 0 : 1;
# optimization
return @$clip == 1 && $clip->[0]->coincides_with($line);
} else {
return @$clip == 1 && abs($clip->[0]->length - $line->length) < $tolerance;
}
} }
sub bounding_box { sub bounding_box {

View file

@ -83,7 +83,7 @@ sub fill_surface {
# TODO: we should also check that both points are on a fill_boundary to avoid # TODO: we should also check that both points are on a fill_boundary to avoid
# connecting paths on the boundaries of internal regions # connecting paths on the boundaries of internal regions
if ($can_connect->(@distance) && $expolygon_off->encloses_line(Slic3r::Line->new($last_point, $first_point), $tolerance)) { if ($can_connect->(@distance) && $expolygon_off->contains_line(Slic3r::Line->new($last_point, $first_point))) {
$polylines[-1]->append_polyline($polyline); $polylines[-1]->append_polyline($polyline);
next; next;
} }

View file

@ -389,9 +389,9 @@ sub travel_to {
# *and* in an island in the upper layer (so that the ooze will not be visible) # *and* in an island in the upper layer (so that the ooze will not be visible)
if ($travel->length < scale $self->extruder->retract_before_travel if ($travel->length < scale $self->extruder->retract_before_travel
|| ($self->config->only_retract_when_crossing_perimeters || ($self->config->only_retract_when_crossing_perimeters
&& (first { $_->encloses_line($travel, scaled_epsilon) } @{$self->_upper_layer_islands}) && (first { $_->contains_line($travel) } @{$self->_upper_layer_islands})
&& (first { $_->encloses_line($travel, scaled_epsilon) } @{$self->_layer_islands})) && (first { $_->contains_line($travel) } @{$self->_layer_islands}))
|| (defined $role && $role == EXTR_ROLE_SUPPORTMATERIAL && (first { $_->encloses_line($travel, scaled_epsilon) } @{$self->layer->support_islands})) || (defined $role && $role == EXTR_ROLE_SUPPORTMATERIAL && (first { $_->contains_line($travel) } @{$self->layer->support_islands}))
) { ) {
$self->straight_once(0); $self->straight_once(0);
$self->speed('travel'); $self->speed('travel');
@ -434,7 +434,7 @@ sub _plan {
$need_retract = 1; $need_retract = 1;
foreach my $island (@{$self->_upper_layer_islands}) { foreach my $island (@{$self->_upper_layer_islands}) {
# discard the island if at any line is not enclosed in it # discard the island if at any line is not enclosed in it
next if first { !$island->encloses_line($_, scaled_epsilon) } @travel; next if first { !$island->contains_line($_) } @travel;
# okay, this island encloses the full travel path # okay, this island encloses the full travel path
$need_retract = 0; $need_retract = 0;
last; last;

View file

@ -10,7 +10,6 @@ has '_contours_ex' => (is => 'rw', default => sub { [] }); # arrayref of array
has '_pointmap' => (is => 'rw', default => sub { {} }); # { id => $point } has '_pointmap' => (is => 'rw', default => sub { {} }); # { id => $point }
has '_edges' => (is => 'rw', default => sub { {} }); # node_idx => { node_idx => distance, ... } has '_edges' => (is => 'rw', default => sub { {} }); # node_idx => { node_idx => distance, ... }
has '_crossing_edges' => (is => 'rw', default => sub { {} }); # edge_idx => bool has '_crossing_edges' => (is => 'rw', default => sub { {} }); # edge_idx => bool
has '_tolerance' => (is => 'lazy');
use List::Util qw(first); use List::Util qw(first);
use Slic3r::Geometry qw(A B scale epsilon); use Slic3r::Geometry qw(A B scale epsilon);
@ -31,8 +30,6 @@ use constant CROSSING_FACTOR => 20;
use constant INFINITY => 'inf'; use constant INFINITY => 'inf';
sub _build__tolerance { scale epsilon }
# setup our configuration space # setup our configuration space
sub BUILD { sub BUILD {
my $self = shift; my $self = shift;
@ -175,7 +172,7 @@ sub _add_expolygon {
for my $i (0 .. $#points) { for my $i (0 .. $#points) {
for my $j (($i+1) .. $#points) { for my $j (($i+1) .. $#points) {
my $line = Slic3r::Line->new($points[$i], $points[$j]); my $line = Slic3r::Line->new($points[$i], $points[$j]);
if ($expolygon->encloses_line($line, $self->_tolerance)) { if ($expolygon->contains_line($line)) {
my $dist = $line->length * ($crosses_perimeter ? CROSSING_FACTOR : 1); my $dist = $line->length * ($crosses_perimeter ? CROSSING_FACTOR : 1);
$edges->{$points[$i]}{$points[$j]} = $dist; $edges->{$points[$i]}{$points[$j]} = $dist;
$edges->{$points[$j]}{$points[$i]} = $dist; $edges->{$points[$j]}{$points[$i]} = $dist;