mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 11:17:51 -06:00
XS interface completed, including new Line class
This commit is contained in:
parent
9af2a1c007
commit
ab6b3d41a7
33 changed files with 435 additions and 257 deletions
|
@ -1,4 +1,4 @@
|
|||
package Slic3r::ExPolygon;
|
||||
gpackage Slic3r::ExPolygon;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
@ -34,7 +34,7 @@ sub clone {
|
|||
|
||||
# no-op for legacy with ::XS
|
||||
sub arrayref { $_[0] }
|
||||
sub arrayref_pp { [ map $_->arrayref_pp, @{$_[0]} ] }
|
||||
sub pp { [ map $_->pp, @{$_[0]} ] }
|
||||
|
||||
sub contour {
|
||||
my $self = shift;
|
||||
|
@ -108,7 +108,7 @@ sub noncollapsing_offset_ex {
|
|||
sub encloses_point {
|
||||
my $self = shift;
|
||||
my ($point) = @_;
|
||||
return Boost::Geometry::Utils::point_covered_by_polygon($point->arrayref, $self->arrayref_pp);
|
||||
return Boost::Geometry::Utils::point_covered_by_polygon($point->arrayref, $self->pp);
|
||||
}
|
||||
|
||||
# A version of encloses_point for use when hole borders do not matter.
|
||||
|
@ -141,7 +141,7 @@ sub clip_line {
|
|||
my $self = shift;
|
||||
my ($line) = @_; # line must be a Slic3r::Line object
|
||||
|
||||
return Boost::Geometry::Utils::polygon_multi_linestring_intersection($self->arrayref_pp, [$line->arrayref_pp]);
|
||||
return Boost::Geometry::Utils::polygon_multi_linestring_intersection($self->pp, [$line->pp]);
|
||||
}
|
||||
|
||||
sub simplify {
|
||||
|
@ -150,7 +150,7 @@ sub simplify {
|
|||
|
||||
# it would be nice to have a multilinestring_simplify method in B::G::U
|
||||
my @simplified = Slic3r::Geometry::Clipper::simplify_polygons(
|
||||
[ map Boost::Geometry::Utils::linestring_simplify($_, $tolerance), @{$self->arrayref_pp} ],
|
||||
[ map Boost::Geometry::Utils::linestring_simplify($_, $tolerance), @{$self->pp} ],
|
||||
);
|
||||
return @{ Slic3r::Geometry::Clipper::union_ex([ @simplified ]) };
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ sub fill_surface {
|
|||
# path is more straight
|
||||
@paths = map Slic3r::Polyline->new(@$_),
|
||||
@{ Boost::Geometry::Utils::polygon_multi_linestring_intersection(
|
||||
$surface->expolygon->arrayref_pp,
|
||||
$surface->expolygon->pp,
|
||||
\@polygons,
|
||||
) };
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ sub fill_surface {
|
|||
# clip paths against a slightly offsetted expolygon, so that the first and last paths
|
||||
# are kept even if the expolygon has vertical sides
|
||||
my @paths = @{ Boost::Geometry::Utils::polygon_multi_linestring_intersection(
|
||||
+($expolygon->offset_ex(scaled_epsilon))[0]->arrayref_pp, # TODO: we should use all the resulting expolygons and clip the linestrings to a multipolygon object
|
||||
+($expolygon->offset_ex(scaled_epsilon))[0]->pp, # TODO: we should use all the resulting expolygons and clip the linestrings to a multipolygon object
|
||||
[ @{ $self->cache->{$cache_id} } ],
|
||||
) };
|
||||
|
||||
|
|
|
@ -891,7 +891,7 @@ sub repaint {
|
|||
|
||||
# if sequential printing is enabled and we have more than one object
|
||||
if ($parent->{config}->complete_objects && (map @{$_->instances}, @{$parent->{objects}}) > 1) {
|
||||
my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @{$_->contour->arrayref_pp}, @{$parent->{object_previews}->[-1][2]} ])});
|
||||
my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @{$_->contour->pp}, @{$parent->{object_previews}->[-1][2]} ])});
|
||||
my ($clearance) = @{offset([$convex_hull], $parent->{config}->extruder_clearance_radius / 2 * $parent->{scaling_factor}, 100, JT_ROUND)};
|
||||
$dc->SetPen($parent->{clearance_pen});
|
||||
$dc->SetBrush($parent->{transparent_brush});
|
||||
|
|
|
@ -179,8 +179,8 @@ sub traverse_pt {
|
|||
|
||||
sub _convert {
|
||||
my $polygons = shift;
|
||||
$polygons = $polygons->arrayref_pp if ref $polygons eq 'Slic3r::ExPolygon::XS';
|
||||
$polygons = [ map $_->arrayref_pp, @$polygons ] if @$polygons && ref $polygons->[0] eq 'Slic3r::Polygon';
|
||||
$polygons = $polygons->pp if ref $polygons eq 'Slic3r::ExPolygon::XS';
|
||||
$polygons = [ map $_->pp, @$polygons ] if @$polygons && ref $polygons->[0] eq 'Slic3r::Polygon';
|
||||
return $polygons;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ sub wkt {
|
|||
|
||||
sub is_counter_clockwise {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::Clipper::is_counter_clockwise($self->arrayref_pp);
|
||||
return Slic3r::Geometry::Clipper::is_counter_clockwise($self->pp);
|
||||
}
|
||||
|
||||
sub make_counter_clockwise {
|
||||
|
@ -57,12 +57,12 @@ sub remove_acute_vertices {
|
|||
sub encloses_point {
|
||||
my $self = shift;
|
||||
my ($point) = @_;
|
||||
return Boost::Geometry::Utils::point_covered_by_polygon($point->arrayref, [$self->arrayref_pp]);
|
||||
return Boost::Geometry::Utils::point_covered_by_polygon($point->arrayref, [$self->pp]);
|
||||
}
|
||||
|
||||
sub area {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::Clipper::area($self->arrayref_pp);
|
||||
return Slic3r::Geometry::Clipper::area($self->pp);
|
||||
}
|
||||
|
||||
sub grow {
|
||||
|
|
|
@ -18,7 +18,7 @@ sub new {
|
|||
}
|
||||
|
||||
sub arrayref { $_[0] }
|
||||
sub arrayref_pp {
|
||||
sub pp {
|
||||
my $self = shift;
|
||||
if (ref($self->[0]) eq 'Slic3r::Point') {
|
||||
return [ map $_->arrayref, @$self ];
|
||||
|
@ -68,7 +68,7 @@ sub simplify {
|
|||
my $self = shift;
|
||||
my $tolerance = shift || 10;
|
||||
|
||||
my $simplified = Boost::Geometry::Utils::linestring_simplify($self->arrayref_pp, $tolerance);
|
||||
my $simplified = Boost::Geometry::Utils::linestring_simplify($self->pp, $tolerance);
|
||||
return (ref $self)->new(@$simplified);
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ sub reverse {
|
|||
|
||||
sub length {
|
||||
my $self = shift;
|
||||
return Boost::Geometry::Utils::linestring_length($self->arrayref_pp);
|
||||
return Boost::Geometry::Utils::linestring_length($self->pp);
|
||||
}
|
||||
|
||||
sub grow {
|
||||
|
@ -119,7 +119,7 @@ sub clip_with_expolygon {
|
|||
my $self = shift;
|
||||
my ($expolygon) = @_;
|
||||
|
||||
my $result = Boost::Geometry::Utils::polygon_multi_linestring_intersection($expolygon->arrayref_pp, [$self->arrayref_pp]);
|
||||
my $result = Boost::Geometry::Utils::polygon_multi_linestring_intersection($expolygon->pp, [$self->pp]);
|
||||
bless $_, 'Slic3r::Polyline' for @$result;
|
||||
return @$result;
|
||||
}
|
||||
|
|
|
@ -763,7 +763,7 @@ sub write_gcode {
|
|||
my @islands = ();
|
||||
foreach my $obj_idx (0 .. $#{$self->objects}) {
|
||||
my $convex_hull = convex_hull([
|
||||
map @{$_->contour->arrayref_pp}, map @{$_->slices}, @{$self->objects->[$obj_idx]->layers},
|
||||
map @{$_->contour->pp}, map @{$_->slices}, @{$self->objects->[$obj_idx]->layers},
|
||||
]);
|
||||
# discard layers only containing thin walls (offset would fail on an empty polygon)
|
||||
if (@$convex_hull) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue