2011-09-05 10:21:27 +00:00
|
|
|
package Slic3r::Fill::Rectilinear;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-05 10:21:27 +00:00
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
extends 'Slic3r::Fill::Base';
|
|
|
|
|
2011-12-13 16:34:31 +00:00
|
|
|
use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y scale unscale epsilon);
|
2011-09-05 10:21:27 +00:00
|
|
|
use XXX;
|
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
sub fill_surface {
|
2011-09-05 10:21:27 +00:00
|
|
|
my $self = shift;
|
2011-10-06 11:43:32 +00:00
|
|
|
my ($surface, %params) = @_;
|
|
|
|
|
|
|
|
# rotate polygons so that we can work with vertical lines here
|
2011-11-13 17:14:02 +00:00
|
|
|
my $expolygon = $surface->expolygon;
|
2011-10-07 17:07:57 +00:00
|
|
|
my $rotate_vector = $self->infill_direction($surface);
|
2011-11-13 17:14:02 +00:00
|
|
|
$self->rotate_points($expolygon, $rotate_vector);
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2011-11-13 17:14:02 +00:00
|
|
|
my $bounding_box = [ $expolygon->bounding_box ];
|
2011-12-04 15:24:46 +00:00
|
|
|
$bounding_box->[X1] += scale 0.1;
|
|
|
|
$bounding_box->[X2] -= scale 0.1;
|
|
|
|
|
2011-12-13 16:34:31 +00:00
|
|
|
my $min_spacing = scale $params{flow_width};
|
2011-12-04 15:24:46 +00:00
|
|
|
my $distance_between_lines = $min_spacing / $params{density};
|
|
|
|
my $line_oscillation = $distance_between_lines - $min_spacing;
|
|
|
|
|
|
|
|
my $number_of_lines = int(($bounding_box->[X2] - $bounding_box->[X1]) / $distance_between_lines) + 1;
|
2011-12-13 16:34:31 +00:00
|
|
|
my $flow_width = undef;
|
|
|
|
if ($params{density} == 1) {
|
|
|
|
my $extra_space = ($bounding_box->[X2] - $bounding_box->[X1]) % $distance_between_lines;
|
|
|
|
$distance_between_lines += $extra_space / ($number_of_lines - 1) if $number_of_lines > 1;
|
|
|
|
$flow_width = unscale $distance_between_lines;
|
|
|
|
}
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2011-10-06 13:24:21 +00:00
|
|
|
my @paths = ();
|
|
|
|
my $x = $bounding_box->[X1];
|
2011-11-14 09:31:07 +00:00
|
|
|
my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
|
2011-12-04 15:24:46 +00:00
|
|
|
for (my $i = 0; $i < $number_of_lines; $i++) {
|
2011-10-06 13:24:21 +00:00
|
|
|
my $vertical_line = [ [$x, $bounding_box->[Y2]], [$x, $bounding_box->[Y1]] ];
|
2011-11-14 09:31:07 +00:00
|
|
|
if ($is_line_pattern && $i % 2) {
|
2011-12-04 15:24:46 +00:00
|
|
|
$vertical_line->[A][X] -= $line_oscillation;
|
|
|
|
$vertical_line->[B][X] += $line_oscillation;
|
2011-11-14 09:31:07 +00:00
|
|
|
}
|
2011-11-13 17:14:02 +00:00
|
|
|
push @paths, @{ $expolygon->clip_line($vertical_line) };
|
2011-12-04 15:24:46 +00:00
|
|
|
$x += $distance_between_lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
# connect lines
|
2011-12-13 16:36:03 +00:00
|
|
|
if ($params{density} < 1) {
|
2011-12-04 15:24:46 +00:00
|
|
|
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
|
|
|
paths => [ map Slic3r::ExtrusionPath->cast([ @$_ ], role => 'bogus'), @paths ],
|
|
|
|
);
|
|
|
|
@paths = ();
|
|
|
|
|
|
|
|
my $can_connect = $is_line_pattern
|
|
|
|
? sub { $_[X] <= (abs((($_[2][Y] - $bounding_box->[Y1])*(2 * $line_oscillation)/($bounding_box->[Y2] - $bounding_box->[Y1])) - $line_oscillation) + $distance_between_lines) && $_[Y] <= $distance_between_lines * 5 }
|
|
|
|
: sub { ($_[X] <= $distance_between_lines) && ($_[Y] <= $distance_between_lines * 5) };
|
|
|
|
|
|
|
|
foreach my $path ($collection->shortest_path) {
|
|
|
|
if (@paths) {
|
|
|
|
my @distance = map abs($paths[-1][-1][$_] - $path->points->[0][$_]), (X,Y);
|
|
|
|
|
|
|
|
# TODO: we should also check that both points are on a fill_boundary to avoid
|
|
|
|
# connecting paths on the boundaries of internal regions
|
|
|
|
if ($can_connect->(@distance, $paths[-1][-1])) {
|
|
|
|
push @{$paths[-1]}, @{$path->points};
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
push @paths, [@{$path->points}];
|
|
|
|
}
|
2011-09-25 18:09:30 +00:00
|
|
|
}
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
|
|
# paths must be rotated back
|
|
|
|
$self->rotate_points_back(\@paths, $rotate_vector);
|
|
|
|
|
2011-12-13 16:34:31 +00:00
|
|
|
return { flow_width => $flow_width }, @paths;
|
2011-09-05 10:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|