mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-09 06:45:25 -06:00
Optimizations for better usage of XS code
This commit is contained in:
parent
9254ff9704
commit
5d6fd7f4d9
22 changed files with 68 additions and 42 deletions
|
@ -210,7 +210,7 @@ sub medial_axis {
|
|||
# cleanup
|
||||
$polyline = Slic3r::Geometry::douglas_peucker($polyline, $width / 7);
|
||||
|
||||
if (Slic3r::Geometry::same_point($polyline->[0], $polyline->[-1])) {
|
||||
if (Slic3r::Geometry::same_point($polyline->first_point, $polyline->last_point)) {
|
||||
next if @$polyline == 2;
|
||||
push @result, Slic3r::Polygon->new(@$polyline[0..$#$polyline-1]);
|
||||
} else {
|
||||
|
|
|
@ -13,11 +13,6 @@ sub split_at {
|
|||
);
|
||||
}
|
||||
|
||||
sub first_point {
|
||||
my $self = shift;
|
||||
return $self->polygon->[0];
|
||||
}
|
||||
|
||||
sub make_counter_clockwise {
|
||||
my $self = shift;
|
||||
if (!$self->polygon->is_counter_clockwise) {
|
||||
|
|
|
@ -65,11 +65,6 @@ sub points {
|
|||
return $self->polyline;
|
||||
}
|
||||
|
||||
sub last_point {
|
||||
my $self = shift;
|
||||
return $self->polyline->[-1];
|
||||
}
|
||||
|
||||
sub is_perimeter {
|
||||
my $self = shift;
|
||||
return $self->role == EXTR_ROLE_PERIMETER
|
||||
|
|
|
@ -33,7 +33,7 @@ sub chained_path {
|
|||
}
|
||||
push @paths, splice @my_paths, $path_index, 1;
|
||||
splice @$endpoints, $path_index*2, 2;
|
||||
$start_near = $paths[-1][-1];
|
||||
$start_near = $paths[-1]->last_point;
|
||||
}
|
||||
return @paths;
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ sub make_fill {
|
|||
flow_spacing => $params->{flow_spacing} || (warn "Warning: no flow_spacing was returned by the infill engine, please report this to the developer\n"),
|
||||
), @polylines,
|
||||
);
|
||||
push @fills_ordering_points, $polylines[0][0];
|
||||
push @fills_ordering_points, $polylines[0]->first_point;
|
||||
}
|
||||
|
||||
# add thin fill regions
|
||||
|
|
|
@ -101,10 +101,10 @@ sub fill_surface {
|
|||
foreach my $path ($collection->chained_path) {
|
||||
if (@paths) {
|
||||
# distance between first point of this path and last point of last path
|
||||
my $distance = $paths[-1][-1]->distance_to($path->[0]);
|
||||
my $distance = $paths[-1]->last_point->distance_to($path->first_point);
|
||||
|
||||
if ($distance <= $m->{hex_width}) {
|
||||
$paths[-1]->append(@$path);
|
||||
$paths[-1]->append_polyline($path);
|
||||
next;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ sub fill_surface {
|
|||
my $x_max = $bounding_box->x_max + scaled_epsilon;
|
||||
my @vertical_lines = ();
|
||||
while ($x <= $x_max) {
|
||||
my $vertical_line = Slic3r::Line->new([$x, $bounding_box->y_max], [$x, $bounding_box->y_min]);
|
||||
my $vertical_line = [ [$x, $bounding_box->y_max], [$x, $bounding_box->y_min] ];
|
||||
if ($is_line_pattern && $i % 2) {
|
||||
$vertical_line->[A][X] += $line_oscillation;
|
||||
$vertical_line->[B][X] -= $line_oscillation;
|
||||
|
@ -60,7 +60,7 @@ sub fill_surface {
|
|||
my @polylines = map Slic3r::Polyline->new(@$_),
|
||||
@{ Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection(
|
||||
[ map $_->pp, @{$expolygon->offset_ex($line_spacing*0.05)} ],
|
||||
[ map $_->pp, @vertical_lines ],
|
||||
[ @vertical_lines ],
|
||||
) };
|
||||
|
||||
# connect lines
|
||||
|
@ -82,13 +82,14 @@ sub fill_surface {
|
|||
|
||||
foreach my $polyline ($collection->chained_path) {
|
||||
if (@polylines) {
|
||||
my $last_point = $polylines[-1][-1]->pp;
|
||||
my @distance = map abs($polyline->[0][$_] - $last_point->[$_]), (X,Y);
|
||||
my $first_point = $polyline->first_point;
|
||||
my $last_point = $polylines[-1]->last_point;
|
||||
my @distance = map abs($first_point->$_ - $last_point->$_), qw(x y);
|
||||
|
||||
# TODO: we should also check that both points are on a fill_boundary to avoid
|
||||
# connecting paths on the boundaries of internal regions
|
||||
if ($can_connect->(@distance) && $expolygon_off->encloses_line(Slic3r::Line->new($last_point, $polyline->[0]), $tolerance)) {
|
||||
$polylines[-1]->append(@$polyline);
|
||||
if ($can_connect->(@distance) && $expolygon_off->encloses_line(Slic3r::Line->new($last_point, $first_point), $tolerance)) {
|
||||
$polylines[-1]->append_polyline($polyline);
|
||||
next;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -274,9 +274,11 @@ sub extrude_path {
|
|||
|
||||
# go to first point of extrusion path
|
||||
my $gcode = "";
|
||||
my $first_point = $path->first_point;
|
||||
$gcode .= $self->travel_to($first_point, $path->role, "move to first $description point")
|
||||
if !defined $self->last_pos || !$self->last_pos->coincides_with($first_point);
|
||||
{
|
||||
my $first_point = $path->first_point;
|
||||
$gcode .= $self->travel_to($first_point, $path->role, "move to first $description point")
|
||||
if !defined $self->last_pos || !$self->last_pos->coincides_with($first_point);
|
||||
}
|
||||
|
||||
# compensate retraction
|
||||
$gcode .= $self->unretract;
|
||||
|
@ -330,9 +332,10 @@ sub extrude_path {
|
|||
$E = $self->extruder->extrude($e * $line_length) if $e;
|
||||
|
||||
# compose G-code line
|
||||
my $point = $line->b;
|
||||
$gcode .= sprintf "G1 X%.3f Y%.3f",
|
||||
($line->[B]->x * &Slic3r::SCALING_FACTOR) + $self->shift_x - $self->extruder->extruder_offset->[X],
|
||||
($line->[B]->y * &Slic3r::SCALING_FACTOR) + $self->shift_y - $self->extruder->extruder_offset->[Y]; #**
|
||||
($point->x * &Slic3r::SCALING_FACTOR) + $self->shift_x - $self->extruder->extruder_offset->[X],
|
||||
($point->y * &Slic3r::SCALING_FACTOR) + $self->shift_y - $self->extruder->extruder_offset->[Y]; #**
|
||||
$gcode .= sprintf(" %s%.5f", $self->config->extrusion_axis, $E)
|
||||
if $E;
|
||||
$gcode .= " F$local_F"
|
||||
|
@ -344,8 +347,10 @@ sub extrude_path {
|
|||
# only include F in the first line
|
||||
$local_F = 0;
|
||||
}
|
||||
$self->wipe_path(Slic3r::Polyline->new(reverse @{$path->points}))
|
||||
if $self->enable_wipe;
|
||||
if ($self->enable_wipe) {
|
||||
$self->wipe_path($path->polyline);
|
||||
$self->wipe_path->reverse;
|
||||
}
|
||||
}
|
||||
$gcode .= ";_BRIDGE_FAN_END\n" if $path->is_bridge;
|
||||
$self->last_pos($path->last_point);
|
||||
|
|
|
@ -80,8 +80,8 @@ sub BUILD {
|
|||
for my $i (0 .. $#outer) {
|
||||
foreach my $line ($outer[$i]->lines) {
|
||||
my $dist = $line->length;
|
||||
$edges->{$line->[A]}{$line->[B]} = $dist;
|
||||
$edges->{$line->[B]}{$line->[A]} = $dist;
|
||||
$edges->{$line->a}{$line->b} = $dist;
|
||||
$edges->{$line->b}{$line->a} = $dist;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -589,8 +589,8 @@ sub _detect_bridge_direction {
|
|||
# remove any line not having both endpoints within anchors
|
||||
@clipped_lines = grep {
|
||||
my $line = $_;
|
||||
!(first { $_->encloses_point_quick($line->[A]) } @$anchors)
|
||||
&& !(first { $_->encloses_point_quick($line->[B]) } @$anchors);
|
||||
!(first { $_->encloses_point_quick($line->a) } @$anchors)
|
||||
&& !(first { $_->encloses_point_quick($line->b) } @$anchors);
|
||||
} @clipped_lines;
|
||||
|
||||
# sum length of bridged lines
|
||||
|
|
|
@ -37,14 +37,6 @@ sub point_on_left {
|
|||
return Slic3r::Geometry::point_is_on_left_of_segment($point, $self);
|
||||
}
|
||||
|
||||
sub midpoint {
|
||||
my $self = shift;
|
||||
return Slic3r::Point->new(
|
||||
($self->[A][X] + $self->[B][X]) / 2,
|
||||
($self->[A][Y] + $self->[B][Y]) / 2,
|
||||
);
|
||||
}
|
||||
|
||||
sub grow {
|
||||
my $self = shift;
|
||||
return Slic3r::Polyline->new(@$self[0,1,0])->grow(@_);
|
||||
|
|
|
@ -192,7 +192,7 @@ sub chained_path {
|
|||
}
|
||||
push @paths, splice @my_paths, $path_index, 1;
|
||||
splice @$endpoints, $path_index*2, 2;
|
||||
$start_near = $paths[-1][-1];
|
||||
$start_near = $paths[-1]->last_point;
|
||||
}
|
||||
return @paths;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue