New logic for connecting honeycomb loops
This commit is contained in:
parent
9ff85898b1
commit
258842b845
@ -6,7 +6,7 @@ extends 'Slic3r::Fill::Base';
|
|||||||
has 'cache' => (is => 'rw', default => sub {{}});
|
has 'cache' => (is => 'rw', default => sub {{}});
|
||||||
|
|
||||||
use Slic3r::Geometry qw(PI X Y MIN MAX scale scaled_epsilon);
|
use Slic3r::Geometry qw(PI X Y MIN MAX scale scaled_epsilon);
|
||||||
use Slic3r::Geometry::Clipper qw(intersection_ex);
|
use Slic3r::Geometry::Clipper qw(intersection);
|
||||||
|
|
||||||
sub angles () { [0, PI/3, PI/3*2] }
|
sub angles () { [0, PI/3, PI/3*2] }
|
||||||
|
|
||||||
@ -77,40 +77,49 @@ sub fill_surface {
|
|||||||
$_->rotate(-$rotate_vector->[0][0], $m->{hex_center}) for @polygons;
|
$_->rotate(-$rotate_vector->[0][0], $m->{hex_center}) for @polygons;
|
||||||
}
|
}
|
||||||
|
|
||||||
# consider polygons as polylines without re-appending the initial point:
|
my @paths;
|
||||||
# this cuts the last segment on purpose, so that the jump to the next
|
if ($params{complete}) {
|
||||||
# path is more straight
|
# we were requested to complete each loop;
|
||||||
my @paths = map Slic3r::Polyline->new($_),
|
# in this case we don't try to make more continuous paths
|
||||||
@{ Boost::Geometry::Utils::polygon_multi_linestring_intersection(
|
@paths = map $_->split_at_first_point,
|
||||||
$surface->expolygon,
|
@{intersection($surface->expolygon, \@polygons)};
|
||||||
\@polygons,
|
|
||||||
) };
|
} else {
|
||||||
|
# consider polygons as polylines without re-appending the initial point:
|
||||||
# connect paths
|
# this cuts the last segment on purpose, so that the jump to the next
|
||||||
{
|
# path is more straight
|
||||||
my $collection = Slic3r::Polyline::Collection->new(polylines => [@paths]);
|
@paths = map Slic3r::Polyline->new($_),
|
||||||
@paths = ();
|
@{ Boost::Geometry::Utils::polygon_multi_linestring_intersection(
|
||||||
foreach my $path ($collection->chained_path) {
|
$surface->expolygon,
|
||||||
if (@paths) {
|
\@polygons,
|
||||||
# distance between first point of this path and last point of last path
|
) };
|
||||||
my $distance = $paths[-1][-1]->distance_to($path->[0]);
|
|
||||||
|
# connect paths
|
||||||
if ($distance <= $m->{hex_width}) {
|
{
|
||||||
push @{$paths[-1]}, @$path;
|
my $collection = Slic3r::Polyline::Collection->new(polylines => [@paths]);
|
||||||
next;
|
@paths = ();
|
||||||
|
foreach my $path ($collection->chained_path) {
|
||||||
|
if (@paths) {
|
||||||
|
# distance between first point of this path and last point of last path
|
||||||
|
my $distance = $paths[-1][-1]->distance_to($path->[0]);
|
||||||
|
|
||||||
|
if ($distance <= $m->{hex_width}) {
|
||||||
|
push @{$paths[-1]}, @$path;
|
||||||
|
next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
push @paths, $path;
|
||||||
}
|
}
|
||||||
push @paths, $path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# clip paths again to prevent connection segments from crossing the expolygon boundaries
|
||||||
|
@paths = map Slic3r::Polyline->new($_),
|
||||||
|
@{ Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection(
|
||||||
|
[ $surface->expolygon->offset_ex(scaled_epsilon) ],
|
||||||
|
[ @paths ],
|
||||||
|
) };
|
||||||
}
|
}
|
||||||
|
|
||||||
# clip paths again to prevent connection segments from crossing the expolygon boundaries
|
|
||||||
@paths = map Slic3r::Polyline->new($_),
|
|
||||||
@{ Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection(
|
|
||||||
[ $surface->expolygon->offset_ex(scaled_epsilon) ],
|
|
||||||
[ @paths ],
|
|
||||||
) };
|
|
||||||
|
|
||||||
return { flow_spacing => $params{flow_spacing} }, @paths;
|
return { flow_spacing => $params{flow_spacing} }, @paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user