mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-05-15 15:38:09 +08:00
Bugfix: fill escapes perimeters. #139
This commit is contained in:
parent
4a4c4b4e7d
commit
be9886eac3
@ -5,7 +5,7 @@ use warnings;
|
|||||||
# an ExPolygon is a polygon with holes
|
# an ExPolygon is a polygon with holes
|
||||||
|
|
||||||
use Math::Geometry::Voronoi;
|
use Math::Geometry::Voronoi;
|
||||||
use Slic3r::Geometry qw(X Y A B point_in_polygon);
|
use Slic3r::Geometry qw(X Y A B point_in_polygon same_line);
|
||||||
use Slic3r::Geometry::Clipper qw(union_ex JT_MITER);
|
use Slic3r::Geometry::Clipper qw(union_ex JT_MITER);
|
||||||
|
|
||||||
# the constructor accepts an array of polygons
|
# the constructor accepts an array of polygons
|
||||||
@ -93,6 +93,14 @@ sub encloses_point {
|
|||||||
|| grep($_->point_on_segment($point), $self->holes));
|
|| grep($_->point_on_segment($point), $self->holes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub encloses_line {
|
||||||
|
my $self = shift;
|
||||||
|
my ($line) = @_;
|
||||||
|
|
||||||
|
my $clip = $self->clip_line($line);
|
||||||
|
return @$clip == 1 && same_line($clip->[0], $line);
|
||||||
|
}
|
||||||
|
|
||||||
sub point_on_segment {
|
sub point_on_segment {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($point) = @_;
|
my ($point) = @_;
|
||||||
|
@ -15,9 +15,8 @@ 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 $bounding_box = [ $expolygon->bounding_box ];
|
my ($expolygon_off) = $expolygon->offset_ex(scale 0.2);
|
||||||
$bounding_box->[X1] += scale 0.1;
|
my $bounding_box = [ $expolygon_off->bounding_box ];
|
||||||
$bounding_box->[X2] -= scale 0.1;
|
|
||||||
|
|
||||||
my $min_spacing = scale $params{flow_spacing};
|
my $min_spacing = scale $params{flow_spacing};
|
||||||
my $distance_between_lines = $min_spacing / $params{density};
|
my $distance_between_lines = $min_spacing / $params{density};
|
||||||
@ -59,11 +58,9 @@ sub fill_surface {
|
|||||||
);
|
);
|
||||||
@paths = ();
|
@paths = ();
|
||||||
|
|
||||||
# the 1 below disables the fix for connection lines being extruded outside $expolygon
|
|
||||||
# (this happens to gears, for example). it works, but it's 30% slower with it enabled
|
|
||||||
my $can_connect = $is_line_pattern
|
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] <= (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 - epsilon) && ($_[X] <= $distance_between_lines + epsilon) && ($_[Y] <= $distance_between_lines * 5) && (1 || $expolygon->encloses_point(Slic3r::Line->new(@_[2,3])->midpoint)) };
|
: sub { ($_[X] >= $distance_between_lines - epsilon) && ($_[X] <= $distance_between_lines + epsilon) && ($_[Y] <= $distance_between_lines * 5) };
|
||||||
|
|
||||||
foreach my $path ($collection->shortest_path) {
|
foreach my $path ($collection->shortest_path) {
|
||||||
if (@paths) {
|
if (@paths) {
|
||||||
@ -71,7 +68,8 @@ sub fill_surface {
|
|||||||
|
|
||||||
# TODO: we should also check that both points are on a fill_boundary to avoid
|
# TODO: we should also check that both points are on a fill_boundary to avoid
|
||||||
# connecting paths on the boundaries of internal regions
|
# connecting paths on the boundaries of internal regions
|
||||||
if ($can_connect->(@distance, $paths[-1][-1], $path->points->[0])) {
|
if ($can_connect->(@distance, $paths[-1][-1], $path->points->[0])
|
||||||
|
&& $expolygon_off->encloses_line([ $paths[-1][-1], $path->points->[0] ])) {
|
||||||
push @{$paths[-1]}, @{$path->points};
|
push @{$paths[-1]}, @{$path->points};
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ our @EXPORT_OK = qw(
|
|||||||
polygon_has_vertex polyline_length can_connect_points deg2rad rad2deg
|
polygon_has_vertex polyline_length can_connect_points deg2rad rad2deg
|
||||||
rotate_points move_points remove_coinciding_points clip_segment_polygon
|
rotate_points move_points remove_coinciding_points clip_segment_polygon
|
||||||
sum_vectors multiply_vector subtract_vectors dot perp polygon_points_visibility
|
sum_vectors multiply_vector subtract_vectors dot perp polygon_points_visibility
|
||||||
line_intersection bounding_box bounding_box_intersect same_point
|
line_intersection bounding_box bounding_box_intersect same_point same_line
|
||||||
longest_segment angle3points three_points_aligned line_direction
|
longest_segment angle3points three_points_aligned line_direction
|
||||||
polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices
|
polyline_remove_parallel_continuous_edges polyline_remove_acute_vertices
|
||||||
polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges
|
polygon_remove_acute_vertices polygon_remove_parallel_continuous_edges
|
||||||
@ -103,6 +103,11 @@ sub same_point {
|
|||||||
return $p1->[X] == $p2->[X] && $p1->[Y] == $p2->[Y];
|
return $p1->[X] == $p2->[X] && $p1->[Y] == $p2->[Y];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub same_line {
|
||||||
|
my ($line1, $line2) = @_;
|
||||||
|
return same_point($line1->[A], $line2->[A]) && same_point($line1->[B], $line2->[B]);
|
||||||
|
}
|
||||||
|
|
||||||
sub distance_between_points {
|
sub distance_between_points {
|
||||||
my ($p1, $p2) = @_;
|
my ($p1, $p2) = @_;
|
||||||
return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2);
|
return sqrt((($p1->[X] - $p2->[X])**2) + ($p1->[Y] - $p2->[Y])**2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user