2011-09-05 12:21:27 +02:00
|
|
|
package Slic3r::Fill::Rectilinear;
|
2011-09-06 11:50:43 +02:00
|
|
|
use Moo;
|
2011-09-05 12:21:27 +02:00
|
|
|
|
2011-10-06 13:43:32 +02:00
|
|
|
extends 'Slic3r::Fill::Base';
|
2014-07-26 16:28:38 +02:00
|
|
|
with qw(Slic3r::Fill::WithDirection);
|
2011-10-06 13:43:32 +02:00
|
|
|
|
2014-12-22 17:25:52 +01:00
|
|
|
has '_min_spacing' => (is => 'rw');
|
|
|
|
has '_line_spacing' => (is => 'rw');
|
|
|
|
has '_diagonal_distance' => (is => 'rw');
|
|
|
|
has '_line_oscillation' => (is => 'rw');
|
2013-04-18 17:34:21 +02:00
|
|
|
|
2014-12-22 17:25:52 +01:00
|
|
|
use Slic3r::Geometry qw(scale unscale scaled_epsilon);
|
|
|
|
use Slic3r::Geometry::Clipper qw(intersection_pl);
|
2011-09-05 12:21:27 +02:00
|
|
|
|
2011-10-06 13:43:32 +02:00
|
|
|
sub fill_surface {
|
2011-09-05 12:21:27 +02:00
|
|
|
my $self = shift;
|
2011-10-06 13:43:32 +02:00
|
|
|
my ($surface, %params) = @_;
|
|
|
|
|
|
|
|
# rotate polygons so that we can work with vertical lines here
|
2012-04-09 22:04:57 +02:00
|
|
|
my $expolygon = $surface->expolygon->clone;
|
2011-10-07 19:07:57 +02:00
|
|
|
my $rotate_vector = $self->infill_direction($surface);
|
2011-11-13 18:14:02 +01:00
|
|
|
$self->rotate_points($expolygon, $rotate_vector);
|
2011-10-06 13:43:32 +02:00
|
|
|
|
2014-12-22 17:25:52 +01:00
|
|
|
$self->_min_spacing(scale $self->spacing);
|
|
|
|
$self->_line_spacing($self->_min_spacing / $params{density});
|
|
|
|
$self->_diagonal_distance($self->_line_spacing * 2);
|
|
|
|
$self->_line_oscillation($self->_line_spacing - $self->_min_spacing); # only for Line infill
|
|
|
|
my $bounding_box = $expolygon->bounding_box;
|
2011-12-04 16:24:46 +01:00
|
|
|
|
2013-07-29 11:05:04 +02:00
|
|
|
# define flow spacing according to requested density
|
|
|
|
if ($params{density} == 1 && !$params{dont_adjust}) {
|
2014-12-22 17:25:52 +01:00
|
|
|
$self->_line_spacing($self->adjust_solid_spacing(
|
|
|
|
width => $bounding_box->size->x,
|
|
|
|
distance => $self->_line_spacing,
|
|
|
|
));
|
|
|
|
$self->spacing(unscale $self->_line_spacing);
|
2013-07-29 11:05:04 +02:00
|
|
|
} else {
|
|
|
|
# extend bounding box so that our pattern will be aligned with other layers
|
2014-01-07 12:48:09 +01:00
|
|
|
$bounding_box->merge_point(Slic3r::Point->new(
|
2014-12-22 17:25:52 +01:00
|
|
|
$bounding_box->x_min - ($bounding_box->x_min % $self->_line_spacing),
|
|
|
|
$bounding_box->y_min - ($bounding_box->y_min % $self->_line_spacing),
|
2014-01-07 12:48:09 +01:00
|
|
|
));
|
2013-07-29 11:05:04 +02:00
|
|
|
}
|
2011-12-17 20:29:06 +01:00
|
|
|
|
2013-07-29 11:05:04 +02:00
|
|
|
# generate the basic pattern
|
2014-12-22 17:25:52 +01:00
|
|
|
my $x_max = $bounding_box->x_max + scaled_epsilon;
|
2013-07-29 11:05:04 +02:00
|
|
|
my @vertical_lines = ();
|
2014-12-22 17:25:52 +01:00
|
|
|
for (my $x = $bounding_box->x_min; $x <= $x_max; $x += $self->_line_spacing) {
|
|
|
|
push @vertical_lines, $self->_line($#vertical_lines, $x, $bounding_box->y_min, $bounding_box->y_max);
|
2011-12-04 16:24:46 +01:00
|
|
|
}
|
2012-08-24 18:59:23 +02:00
|
|
|
|
2014-01-11 21:34:26 +01:00
|
|
|
# clip paths against a slightly larger expolygon, so that the first and last paths
|
2012-08-24 18:59:23 +02:00
|
|
|
# are kept even if the expolygon has vertical sides
|
2013-07-29 13:36:22 +02:00
|
|
|
# the minimum offset for preventing edge lines from being clipped is scaled_epsilon;
|
|
|
|
# however we use a larger offset to support expolygons with slightly skewed sides and
|
|
|
|
# not perfectly straight
|
2014-01-11 21:34:26 +01:00
|
|
|
my @polylines = @{intersection_pl(\@vertical_lines, $expolygon->offset(scale 0.02))};
|
2011-12-04 16:24:46 +01:00
|
|
|
|
|
|
|
# connect lines
|
2013-11-21 16:21:42 +01:00
|
|
|
unless ($params{dont_connect} || !@polylines) { # prevent calling leftmost_point() on empty collections
|
2014-12-22 17:25:52 +01:00
|
|
|
my ($expolygon_off) = @{$expolygon->offset_ex($self->_min_spacing/2)};
|
2013-08-30 00:06:10 +02:00
|
|
|
my $collection = Slic3r::Polyline::Collection->new(@polylines);
|
2013-07-16 17:13:01 +02:00
|
|
|
@polylines = ();
|
2011-12-04 16:24:46 +01:00
|
|
|
|
2013-11-21 14:15:38 +01:00
|
|
|
foreach my $polyline (@{$collection->chained_path_from($collection->leftmost_point, 0)}) {
|
2013-07-16 17:13:01 +02:00
|
|
|
if (@polylines) {
|
2013-08-29 01:36:42 +02:00
|
|
|
my $first_point = $polyline->first_point;
|
|
|
|
my $last_point = $polylines[-1]->last_point;
|
|
|
|
my @distance = map abs($first_point->$_ - $last_point->$_), qw(x y);
|
2011-12-04 16:24:46 +01:00
|
|
|
|
|
|
|
# TODO: we should also check that both points are on a fill_boundary to avoid
|
|
|
|
# connecting paths on the boundaries of internal regions
|
2014-12-22 17:25:52 +01:00
|
|
|
if ($self->_can_connect(@distance) && $expolygon_off->contains_line(Slic3r::Line->new($last_point, $first_point))) {
|
2013-08-29 01:36:42 +02:00
|
|
|
$polylines[-1]->append_polyline($polyline);
|
2011-12-04 16:24:46 +01:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
2013-09-02 20:22:20 +02:00
|
|
|
|
|
|
|
# make a clone before $collection goes out of scope
|
|
|
|
push @polylines, $polyline->clone;
|
2011-12-04 16:24:46 +01:00
|
|
|
}
|
2011-09-25 20:09:30 +02:00
|
|
|
}
|
2011-10-06 13:43:32 +02:00
|
|
|
|
|
|
|
# paths must be rotated back
|
2013-07-16 17:13:01 +02:00
|
|
|
$self->rotate_points_back(\@polylines, $rotate_vector);
|
2011-10-06 13:43:32 +02:00
|
|
|
|
2014-12-22 16:47:35 +01:00
|
|
|
return @polylines;
|
2011-09-05 12:21:27 +02:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:25:52 +01:00
|
|
|
sub _line {
|
|
|
|
my ($self, $i, $x, $y_min, $y_max) = @_;
|
|
|
|
|
|
|
|
return Slic3r::Polyline->new(
|
|
|
|
[$x, $y_min],
|
|
|
|
[$x, $y_max],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _can_connect {
|
|
|
|
my ($self, $dist_X, $dist_Y) = @_;
|
|
|
|
|
|
|
|
return $dist_X <= $self->_diagonal_distance
|
|
|
|
&& $dist_Y <= $self->_diagonal_distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
package Slic3r::Fill::Line;
|
|
|
|
use Moo;
|
|
|
|
extends 'Slic3r::Fill::Rectilinear';
|
|
|
|
|
|
|
|
use Slic3r::Geometry qw(scaled_epsilon);
|
|
|
|
|
|
|
|
sub _line {
|
|
|
|
my ($self, $i, $x, $y_min, $y_max) = @_;
|
|
|
|
|
|
|
|
if ($i % 2) {
|
|
|
|
return Slic3r::Polyline->new(
|
|
|
|
[$x - $self->_line_oscillation, $y_min],
|
|
|
|
[$x + $self->_line_oscillation, $y_max],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Slic3r::Polyline->new(
|
|
|
|
[$x, $y_min],
|
|
|
|
[$x, $y_max],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _can_connect {
|
|
|
|
my ($self, $dist_X, $dist_Y) = @_;
|
|
|
|
|
|
|
|
my $TOLERANCE = 10 * scaled_epsilon;
|
|
|
|
return ($dist_X >= ($self->_line_spacing - $self->_line_oscillation) - $TOLERANCE)
|
|
|
|
&& ($dist_X <= ($self->_line_spacing + $self->_line_oscillation) + $TOLERANCE)
|
|
|
|
&& $dist_Y <= $self->_diagonal_distance;
|
|
|
|
}
|
|
|
|
|
2011-09-05 12:21:27 +02:00
|
|
|
1;
|