Make the motionplanner work again after recent changes to approximation
This commit is contained in:
parent
0eadc5adba
commit
27090f83bd
3 changed files with 20 additions and 7 deletions
|
@ -6,7 +6,7 @@ use warnings;
|
|||
|
||||
use Boost::Geometry::Utils;
|
||||
use Math::Geometry::Voronoi;
|
||||
use Slic3r::Geometry qw(X Y A B point_in_polygon same_line);
|
||||
use Slic3r::Geometry qw(X Y A B point_in_polygon same_line scale epsilon);
|
||||
use Slic3r::Geometry::Clipper qw(union_ex JT_MITER);
|
||||
|
||||
# the constructor accepts an array of polygons
|
||||
|
@ -113,7 +113,7 @@ sub encloses_line {
|
|||
my ($line) = @_;
|
||||
|
||||
my $clip = $self->clip_line($line);
|
||||
return @$clip == 1 && same_line($clip->[0], $line);
|
||||
return @$clip == 1 && abs($line->length - Slic3r::Geometry::line_length($clip->[0])) < scale epsilon;
|
||||
}
|
||||
|
||||
sub point_on_segment {
|
||||
|
|
|
@ -38,6 +38,7 @@ sub BUILD {
|
|||
my $crossing_edges = $self->_crossing_edges;
|
||||
my $tolerance = scale epsilon;
|
||||
|
||||
# given an expolygon, this subroutine connects all its visible points
|
||||
my $add_expolygon = sub {
|
||||
my ($expolygon, $crosses_perimeter) = @_;
|
||||
my @points = map @$_, @$expolygon;
|
||||
|
@ -55,13 +56,25 @@ sub BUILD {
|
|||
}
|
||||
};
|
||||
|
||||
# process individual islands
|
||||
for my $i (0 .. $#{$self->islands}) {
|
||||
# simplify the island's contours
|
||||
$self->islands->[$i]->simplify($self->_inner_margin);
|
||||
|
||||
# offset the island inwards to make the boundaries for internal movements
|
||||
# so that no motion along external perimeters happens
|
||||
$self->_inner->[$i] = [ $self->islands->[$i]->offset_ex(-$self->_inner_margin) ]
|
||||
if !$self->no_internal;
|
||||
|
||||
# offset the island outwards to make the boundaries for external movements
|
||||
$self->_outer->[$i] = [ $self->islands->[$i]->contour->offset($self->_outer_margin) ];
|
||||
|
||||
# further simplification (isn't this a duplication of the one above?)
|
||||
$_->simplify($self->_inner_margin) for @{$self->_inner->[$i]}, @{$self->_outer->[$i]};
|
||||
|
||||
# if internal motion is enabled, build a set of utility expolygons representing
|
||||
# the outer boundaries (as contours) and the inner boundaries (as holes). whenever
|
||||
# we jump from a hole to a contour or viceversa, we know we're crossing a perimeter
|
||||
if (!$self->no_internal) {
|
||||
$self->_contours_ex->[$i] = diff_ex(
|
||||
$self->_outer->[$i],
|
||||
|
@ -81,7 +94,7 @@ sub BUILD {
|
|||
my ($polygon, $line) = @_;
|
||||
@{Boost::Geometry::Utils::polygon_linestring_intersection(
|
||||
$polygon->boost_polygon,
|
||||
Boost::Geometry::Utils::linestring($line),
|
||||
$line->boost_linestring,
|
||||
)} > 0;
|
||||
};
|
||||
|
||||
|
@ -148,10 +161,11 @@ sub BUILD {
|
|||
require "Slic3r/SVG.pm";
|
||||
Slic3r::SVG::output(undef, "space.svg",
|
||||
lines => \@lines,
|
||||
points => [ values %{$self->_pointmap} ],
|
||||
no_arrows => 1,
|
||||
polygons => [ map @$_, @{$self->islands} ],
|
||||
red_polygons => [ map $_->holes, map @$_, @{$self->_inner} ],
|
||||
white_polygons => [ map @$_, @{$self->_outer} ],
|
||||
#polygons => [ map @$_, @{$self->islands} ],
|
||||
#red_polygons => [ map $_->holes, map @$_, @{$self->_inner} ],
|
||||
#white_polygons => [ map @$_, @{$self->_outer} ],
|
||||
);
|
||||
printf "%d islands\n", scalar @{$self->islands};
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ sub factor {
|
|||
|
||||
sub svg {
|
||||
my ($print) = @_;
|
||||
$print ||= Slic3r::Print->new(x_length => 200 / &Slic3r::SCALING_FACTOR, y_length => 200 / &Slic3r::SCALING_FACTOR);
|
||||
my $svg = SVG->new(width => 200 * 10, height => 200 * 10);
|
||||
|
||||
my $marker_end = $svg->marker(
|
||||
|
|
Loading…
Reference in a new issue