mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-18 20:28:08 -06:00
Ported Polygon->is_valid() and ExPolygon->is_valid()
This commit is contained in:
parent
da0b85c0d9
commit
fe42427a54
13 changed files with 37 additions and 54 deletions
|
@ -10,24 +10,6 @@ use Math::Geometry::Voronoi;
|
|||
use Slic3r::Geometry qw(X Y A B point_in_polygon same_line epsilon);
|
||||
use Slic3r::Geometry::Clipper qw(union_ex JT_MITER);
|
||||
|
||||
sub is_valid {
|
||||
my $self = shift;
|
||||
return (!first { !$_->is_valid } @$self)
|
||||
&& $self->contour->is_counter_clockwise
|
||||
&& (!first { $_->is_counter_clockwise } @{$self->holes});
|
||||
}
|
||||
|
||||
# returns false if the expolygon is too tight to be printed
|
||||
sub is_printable {
|
||||
my $self = shift;
|
||||
my ($width) = @_;
|
||||
|
||||
# try to get an inwards offset
|
||||
# for a distance equal to half of the extrusion width;
|
||||
# if no offset is possible, then expolygon is not printable.
|
||||
return @{Slic3r::Geometry::Clipper::offset($self, -$width / 2)} ? 1 : 0;
|
||||
}
|
||||
|
||||
sub wkt {
|
||||
my $self = shift;
|
||||
return sprintf "POLYGON(%s)",
|
||||
|
|
|
@ -692,17 +692,18 @@ sub _line_intersection2 {
|
|||
# 2D
|
||||
sub bounding_box {
|
||||
my ($points) = @_;
|
||||
|
||||
my @x = (undef, undef);
|
||||
my @y = (undef, undef);
|
||||
for (@$points) {
|
||||
$x[MIN] = $_->[X] if !defined $x[MIN] || $_->[X] < $x[MIN];
|
||||
$x[MAX] = $_->[X] if !defined $x[MAX] || $_->[X] > $x[MAX];
|
||||
$y[MIN] = $_->[Y] if !defined $y[MIN] || $_->[Y] < $y[MIN];
|
||||
$y[MAX] = $_->[Y] if !defined $y[MAX] || $_->[Y] > $y[MAX];
|
||||
use XXX; ZZZ "not" if ref($points->[0]) eq 'ARRAY';
|
||||
my @x = map $_->x, @$points;
|
||||
my @y = map $_->y, @$points; #,,
|
||||
my @bb = (undef, undef, undef, undef);
|
||||
for (0..$#x) {
|
||||
$bb[X1] = $x[$_] if !defined $bb[X1] || $x[$_] < $bb[X1];
|
||||
$bb[X2] = $x[$_] if !defined $bb[X2] || $x[$_] > $bb[X2];
|
||||
$bb[Y1] = $y[$_] if !defined $bb[Y1] || $y[$_] < $bb[Y1];
|
||||
$bb[Y2] = $y[$_] if !defined $bb[Y2] || $y[$_] > $bb[Y2];
|
||||
}
|
||||
|
||||
return ($x[0], $y[0], $x[-1], $y[-1]);
|
||||
return @bb[X1,Y1,X2,Y2];
|
||||
}
|
||||
|
||||
sub bounding_box_center {
|
||||
|
|
|
@ -68,28 +68,6 @@ sub subdivide {
|
|||
}
|
||||
}
|
||||
|
||||
# returns false if the polygon is too tight to be printed
|
||||
sub is_printable {
|
||||
my $self = shift;
|
||||
my ($width) = @_;
|
||||
|
||||
# try to get an inwards offset
|
||||
# for a distance equal to half of the extrusion width;
|
||||
# if no offset is possible, then polyline is not printable.
|
||||
# we use flow_width here because this has to be consistent
|
||||
# with the thin wall detection in Layer->make_surfaces,
|
||||
# otherwise we could lose surfaces as that logic wouldn't
|
||||
# detect them and we would be discarding them.
|
||||
my $p = $self->clone;
|
||||
$p->make_counter_clockwise;
|
||||
return @{Slic3r::Geometry::Clipper::offset([$p], -$width / 2)} ? 1 : 0;
|
||||
}
|
||||
|
||||
sub is_valid {
|
||||
my $self = shift;
|
||||
return @$self >= 3;
|
||||
}
|
||||
|
||||
# for cw polygons this will return convex points!
|
||||
sub concave_points {
|
||||
my $self = shift;
|
||||
|
|
|
@ -302,7 +302,7 @@ sub bounding_box {
|
|||
[ $copy->[X] + $object->size->[X], $copy->[Y] + $object->size->[Y] ];
|
||||
}
|
||||
}
|
||||
return Slic3r::Geometry::BoundingBox->new_from_points(\@points);
|
||||
return Slic3r::Geometry::BoundingBox->new_from_points([ map Slic3r::Point->new(@$_), @points ]);
|
||||
}
|
||||
|
||||
sub size {
|
||||
|
|
|
@ -3,7 +3,7 @@ use Moo;
|
|||
|
||||
use List::Util qw(min max sum first);
|
||||
use Slic3r::ExtrusionPath ':roles';
|
||||
use Slic3r::Geometry qw(Z PI scale unscale deg2rad rad2deg scaled_epsilon chained_path_points);
|
||||
use Slic3r::Geometry qw(X Y Z PI scale unscale deg2rad rad2deg scaled_epsilon chained_path_points);
|
||||
use Slic3r::Geometry::Clipper qw(diff diff_ex intersection intersection_ex union union_ex
|
||||
offset offset_ex offset2);
|
||||
use Slic3r::Surface ':types';
|
||||
|
@ -128,7 +128,7 @@ sub bounding_box {
|
|||
my $self = shift;
|
||||
|
||||
# since the object is aligned to origin, bounding box coincides with size
|
||||
return Slic3r::Geometry::BoundingBox->new_from_points([ [0,0], $self->size ]);
|
||||
return Slic3r::Geometry::BoundingBox->new_from_points([ map Slic3r::Point->new(@$_[X,Y]), [0,0], $self->size ]);
|
||||
}
|
||||
|
||||
sub slice {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue