mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 15:13:58 -06:00
Lots of changes and refactoring after testing with hollow objects
This commit is contained in:
parent
26b05ab155
commit
18c7aef1a7
15 changed files with 716 additions and 494 deletions
|
@ -3,69 +3,40 @@ use Moo;
|
|||
|
||||
extends 'Slic3r::Polyline';
|
||||
|
||||
has 'contour_of' => (
|
||||
is => 'rw',
|
||||
#isa => 'Slic3r::Surface',
|
||||
weak_ref => 1,
|
||||
);
|
||||
|
||||
has 'hole_of' => (
|
||||
is => 'rw',
|
||||
#isa => 'Slic3r::Surface',
|
||||
weak_ref => 1,
|
||||
);
|
||||
|
||||
sub new_from_points {
|
||||
my $class = shift;
|
||||
my $polyline = $class->SUPER::new_from_points(@_);
|
||||
sub lines {
|
||||
my $self = shift;
|
||||
my @lines = $self->SUPER::lines(@_);
|
||||
|
||||
# polylines must be always closed, otherwise it means that our object is not manifold!
|
||||
die "Polylines must be closed! Object not manifold?\n"
|
||||
if ($polyline->lines->[0]->a != $polyline->lines->[-1]->b);
|
||||
# since this is a closed polyline, we just add a line at the end,
|
||||
# connecting the last and the first point
|
||||
push @lines, Slic3r::Line->new(points => [$self->points->[-1], $self->points->[0]]);
|
||||
return @lines;
|
||||
}
|
||||
|
||||
# superclass doesn't check whether last line of our closed polyline
|
||||
# is parallel to first one, so let's do it here
|
||||
sub merge_continuous_lines {
|
||||
my $self = shift;
|
||||
$self->SUPER::merge_continuous_lines(@_);
|
||||
|
||||
return $polyline;
|
||||
my @lines = $self->lines;
|
||||
if ($lines[-1]->parallel_to($lines[0])) {
|
||||
shift @{$self->points};
|
||||
}
|
||||
}
|
||||
|
||||
sub encloses_point {
|
||||
my $self = shift;
|
||||
my ($point) = @_;
|
||||
|
||||
my @xy = map { $_->x, $_->y } $self->points; #}}
|
||||
my ($x, $y) = ($point->x, $point->y); #))
|
||||
|
||||
# Derived from the comp.graphics.algorithms FAQ,
|
||||
# courtesy of Wm. Randolph Franklin
|
||||
my $n = @xy / 2; # Number of points in polygon
|
||||
my @i = map { 2*$_ } 0..(@xy/2); # The even indices of @xy
|
||||
my @x = map { $xy[$_] } @i; # Even indices: x-coordinates
|
||||
my @y = map { $xy[$_ + 1] } @i; # Odd indices: y-coordinates
|
||||
|
||||
my ($i, $j);
|
||||
my $side = 0; # 0 = outside; 1 = inside
|
||||
for ($i = 0, $j = $n - 1; $i < $n; $j = $i++) {
|
||||
if (
|
||||
# If the y is between the (y-) borders...
|
||||
($y[$i] <= $y && $y < $y[$j]) || ($y[$j] <= $y && $y < $y[$i])
|
||||
and
|
||||
# ...the (x,y) to infinity line crosses the edge
|
||||
# from the ith point to the jth point...
|
||||
($x < ($x[$j] - $x[$i]) * ($y - $y[$i]) / ($y[$j] - $y[$i]) + $x[$i])
|
||||
) {
|
||||
$side = not $side; # Jump the fence
|
||||
}
|
||||
}
|
||||
|
||||
return $side;
|
||||
return Slic3r::Geometry::point_in_polygon($point->p, $self->p);
|
||||
}
|
||||
|
||||
sub mgp_polygon {
|
||||
my $self = shift;
|
||||
|
||||
# we need a list of ordered points
|
||||
my $points = $self->ordered_points;
|
||||
|
||||
my $p = Math::Geometry::Planar->new;
|
||||
$p->points($points);
|
||||
$p->points($self->points);
|
||||
return $p;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue