Don't try to align rectilinear infill if solid, otherwise there will be a gap at one side
This commit is contained in:
parent
51de3ce14f
commit
948b43fe0d
4 changed files with 73 additions and 50 deletions
|
@ -173,6 +173,14 @@ sub translate {
|
||||||
$self;
|
$self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub align_to_origin {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my $bb = $self->bounding_box;
|
||||||
|
$self->translate(-$bb->x_min, -$bb->y_min);
|
||||||
|
$self;
|
||||||
|
}
|
||||||
|
|
||||||
sub rotate {
|
sub rotate {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$_->rotate(@_) for @$self;
|
$_->rotate(@_) for @$self;
|
||||||
|
|
|
@ -165,7 +165,6 @@ sub make_fill {
|
||||||
$surface,
|
$surface,
|
||||||
density => $density,
|
density => $density,
|
||||||
flow_spacing => $flow_spacing,
|
flow_spacing => $flow_spacing,
|
||||||
dont_adjust => $is_bridge,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
my $params = shift @paths;
|
my $params = shift @paths;
|
||||||
|
|
|
@ -5,7 +5,7 @@ extends 'Slic3r::Fill::Base';
|
||||||
|
|
||||||
has 'cache' => (is => 'rw', default => sub {{}});
|
has 'cache' => (is => 'rw', default => sub {{}});
|
||||||
|
|
||||||
use Slic3r::Geometry qw(A B X Y scale unscale scaled_epsilon);
|
use Slic3r::Geometry qw(A B X Y MIN scale unscale scaled_epsilon);
|
||||||
|
|
||||||
sub fill_surface {
|
sub fill_surface {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -16,72 +16,63 @@ sub fill_surface {
|
||||||
my $rotate_vector = $self->infill_direction($surface);
|
my $rotate_vector = $self->infill_direction($surface);
|
||||||
$self->rotate_points($expolygon, $rotate_vector);
|
$self->rotate_points($expolygon, $rotate_vector);
|
||||||
|
|
||||||
my ($expolygon_off) = $expolygon->offset_ex(scale $params{flow_spacing}/2);
|
my $flow_spacing = $params{flow_spacing};
|
||||||
return {} if !$expolygon_off; # skip some very small polygons (which shouldn't arrive here)
|
my $min_spacing = scale $params{flow_spacing};
|
||||||
|
my $line_spacing = $min_spacing / $params{density};
|
||||||
|
my $line_oscillation = $line_spacing - $min_spacing;
|
||||||
|
my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
|
||||||
|
my $bounding_box = $expolygon->bounding_box;
|
||||||
|
|
||||||
my $flow_spacing = $params{flow_spacing};
|
# define flow spacing according to requested density
|
||||||
my $min_spacing = scale $params{flow_spacing};
|
if ($params{density} == 1 && !$params{dont_adjust}) {
|
||||||
my $distance_between_lines = $min_spacing / $params{density};
|
$line_spacing = $self->adjust_solid_spacing(
|
||||||
my $line_oscillation = $distance_between_lines - $min_spacing;
|
width => $bounding_box->size->[X],
|
||||||
my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
|
distance => $line_spacing,
|
||||||
|
);
|
||||||
|
$flow_spacing = unscale $line_spacing;
|
||||||
|
} else {
|
||||||
|
# extend bounding box so that our pattern will be aligned with other layers
|
||||||
|
# $bounding_box->[X1] and [Y1] represent the displacement between new bounding box offset and old one
|
||||||
|
$bounding_box->extents->[X][MIN] -= $bounding_box->x_min;
|
||||||
|
$bounding_box->extents->[Y][MIN] -= $bounding_box->y_min;
|
||||||
|
}
|
||||||
|
|
||||||
my $cache_id = sprintf "d%s_s%.2f_a%.2f",
|
# generate the basic pattern
|
||||||
$params{density}, $params{flow_spacing}, $rotate_vector->[0][0];
|
my $i = 0;
|
||||||
|
my $x = $bounding_box->x_min;
|
||||||
if (!$self->cache->{$cache_id}) {
|
my $x_max = $bounding_box->x_max + scaled_epsilon;
|
||||||
# compute bounding box
|
my @vertical_lines = ();
|
||||||
my $bounding_box;
|
while ($x <= $x_max) {
|
||||||
{
|
my $vertical_line = Slic3r::Line->new([$x, $bounding_box->y_max], [$x, $bounding_box->y_min]);
|
||||||
my $bb_polygon = $self->bounding_box->polygon;
|
if ($is_line_pattern && $i % 2) {
|
||||||
$bb_polygon->scale(sqrt 2);
|
$vertical_line->[A][X] += $line_oscillation;
|
||||||
$self->rotate_points($bb_polygon, $rotate_vector);
|
$vertical_line->[B][X] -= $line_oscillation;
|
||||||
$bounding_box = $bb_polygon->bounding_box;
|
|
||||||
}
|
}
|
||||||
|
push @vertical_lines, $vertical_line;
|
||||||
# define flow spacing according to requested density
|
$i++;
|
||||||
if ($params{density} == 1 && !$params{dont_adjust}) {
|
$x += $line_spacing;
|
||||||
$distance_between_lines = $self->adjust_solid_spacing(
|
|
||||||
width => $bounding_box->size->[X],
|
|
||||||
distance => $distance_between_lines,
|
|
||||||
);
|
|
||||||
$flow_spacing = unscale $distance_between_lines;
|
|
||||||
}
|
|
||||||
|
|
||||||
# generate the basic pattern
|
|
||||||
my $x = $bounding_box->x_min;
|
|
||||||
my @vertical_lines = ();
|
|
||||||
for (my $i = 0; $x <= $bounding_box->x_max + scaled_epsilon; $i++) {
|
|
||||||
my $vertical_line = Slic3r::Line->new([$x, $bounding_box->y_max], [$x, $bounding_box->y_min]);
|
|
||||||
if ($is_line_pattern && $i % 2) {
|
|
||||||
$vertical_line->[A][X] += $line_oscillation;
|
|
||||||
$vertical_line->[B][X] -= $line_oscillation;
|
|
||||||
}
|
|
||||||
push @vertical_lines, $vertical_line;
|
|
||||||
$x += $distance_between_lines;
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->cache->{$cache_id} = [@vertical_lines];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# clip paths against a slightly offsetted expolygon, so that the first and last paths
|
# clip paths against a slightly offsetted expolygon, so that the first and last paths
|
||||||
# are kept even if the expolygon has vertical sides
|
# are kept even if the expolygon has vertical sides
|
||||||
my @paths = @{ Boost::Geometry::Utils::polygon_multi_linestring_intersection(
|
my @paths = @{ Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection(
|
||||||
+($expolygon->offset_ex(scaled_epsilon))[0], # TODO: we should use all the resulting expolygons and clip the linestrings to a multipolygon object
|
[ $expolygon->offset_ex(scaled_epsilon) ],
|
||||||
[ @{ $self->cache->{$cache_id} } ],
|
[ @vertical_lines ],
|
||||||
) };
|
) };
|
||||||
|
|
||||||
# connect lines
|
# connect lines
|
||||||
unless ($params{dont_connect}) {
|
unless ($params{dont_connect}) {
|
||||||
|
my ($expolygon_off) = $expolygon->offset_ex(scale $params{flow_spacing}/2);
|
||||||
my $collection = Slic3r::Polyline::Collection->new(
|
my $collection = Slic3r::Polyline::Collection->new(
|
||||||
polylines => [ map Slic3r::Polyline->new(@$_), @paths ],
|
polylines => [ map Slic3r::Polyline->new(@$_), @paths ],
|
||||||
);
|
);
|
||||||
@paths = ();
|
@paths = ();
|
||||||
|
|
||||||
my $tolerance = 10 * scaled_epsilon;
|
my $tolerance = 10 * scaled_epsilon;
|
||||||
my $diagonal_distance = $distance_between_lines * 2;
|
my $diagonal_distance = $line_spacing * 2;
|
||||||
my $can_connect = $is_line_pattern
|
my $can_connect = $is_line_pattern
|
||||||
? sub {
|
? sub {
|
||||||
($_[X] >= ($distance_between_lines - $line_oscillation) - $tolerance) && ($_[X] <= ($distance_between_lines + $line_oscillation) + $tolerance)
|
($_[X] >= ($line_spacing - $line_oscillation) - $tolerance) && ($_[X] <= ($line_spacing + $line_oscillation) + $tolerance)
|
||||||
&& $_[Y] <= $diagonal_distance
|
&& $_[Y] <= $diagonal_distance
|
||||||
}
|
}
|
||||||
: sub { $_[X] <= $diagonal_distance && $_[Y] <= $diagonal_distance };
|
: sub { $_[X] <= $diagonal_distance && $_[Y] <= $diagonal_distance };
|
||||||
|
|
27
t/fill.t
27
t/fill.t
|
@ -2,7 +2,7 @@ use Test::More;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
plan tests => 10;
|
plan tests => 11;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
use FindBin;
|
use FindBin;
|
||||||
|
@ -11,6 +11,7 @@ BEGIN {
|
||||||
|
|
||||||
use Slic3r;
|
use Slic3r;
|
||||||
use Slic3r::Geometry qw(scale X Y);
|
use Slic3r::Geometry qw(scale X Y);
|
||||||
|
use Slic3r::Geometry::Clipper qw(diff_ex);
|
||||||
use Slic3r::Surface qw(:types);
|
use Slic3r::Surface qw(:types);
|
||||||
use Slic3r::Test;
|
use Slic3r::Test;
|
||||||
|
|
||||||
|
@ -48,6 +49,30 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $expolygon = Slic3r::ExPolygon->new([
|
||||||
|
[6883102, 9598327.01296997],
|
||||||
|
[6883102, 20327272.01297],
|
||||||
|
[3116896, 20327272.01297],
|
||||||
|
[3116896, 9598327.01296997],
|
||||||
|
]);
|
||||||
|
$expolygon->align_to_origin;
|
||||||
|
my $filler = Slic3r::Fill::Rectilinear->new(
|
||||||
|
bounding_box => $expolygon->bounding_box,
|
||||||
|
angle => 0,
|
||||||
|
);
|
||||||
|
my $surface = Slic3r::Surface->new(
|
||||||
|
surface_type => S_TYPE_BOTTOM,
|
||||||
|
expolygon => $expolygon,
|
||||||
|
);
|
||||||
|
my ($params, @paths) = $filler->fill_surface($surface, flow_spacing => 0.55, density => 1);
|
||||||
|
|
||||||
|
# check whether any part was left uncovered
|
||||||
|
my @grown_paths = map Slic3r::Polyline->new(@$_)->grow(scale $params->{flow_spacing}/2), @paths;
|
||||||
|
my $uncovered = diff_ex([ @$expolygon ], [ @grown_paths ]);
|
||||||
|
is scalar(@$uncovered), 0, 'solid surface is fully filled';
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
my $collection = Slic3r::Polyline::Collection->new(polylines => [
|
my $collection = Slic3r::Polyline::Collection->new(polylines => [
|
||||||
Slic3r::Polyline->new([0,15], [0,18], [0,20]),
|
Slic3r::Polyline->new([0,15], [0,18], [0,20]),
|
||||||
|
|
Loading…
Add table
Reference in a new issue