Optimizations for better usage of XS code
This commit is contained in:
parent
9254ff9704
commit
5d6fd7f4d9
@ -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);
|
||||
}
|
||||
|
||||
# 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;
|
||||
}
|
||||
|
@ -14,6 +14,12 @@ ExtrusionPath::first_point() const
|
||||
return &(this->polyline.points.front());
|
||||
}
|
||||
|
||||
const Point*
|
||||
ExtrusionPath::last_point() const
|
||||
{
|
||||
return &(this->polyline.points.back());
|
||||
}
|
||||
|
||||
ExtrusionPath*
|
||||
ExtrusionLoop::split_at_index(int index)
|
||||
{
|
||||
|
@ -39,6 +39,7 @@ class ExtrusionPath : public ExtrusionEntity
|
||||
Polyline polyline;
|
||||
void reverse();
|
||||
const Point* first_point() const;
|
||||
const Point* last_point() const;
|
||||
};
|
||||
|
||||
class ExtrusionLoop : public ExtrusionEntity
|
||||
|
@ -36,6 +36,12 @@ Line::length() const
|
||||
return this->a.distance_to(&(this->b));
|
||||
}
|
||||
|
||||
Point*
|
||||
Line::midpoint() const
|
||||
{
|
||||
return new Point ((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0);
|
||||
}
|
||||
|
||||
void
|
||||
Line::from_SV(SV* line_sv)
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ class Line
|
||||
void rotate(double angle, Point* center);
|
||||
void reverse();
|
||||
double length() const;
|
||||
Point* midpoint() const;
|
||||
};
|
||||
|
||||
typedef std::vector<Line> Lines;
|
||||
|
@ -38,6 +38,12 @@ MultiPoint::first_point() const
|
||||
return &(this->points.front());
|
||||
}
|
||||
|
||||
const Point*
|
||||
MultiPoint::last_point() const
|
||||
{
|
||||
return &(this->points.back());
|
||||
}
|
||||
|
||||
void
|
||||
MultiPoint::from_SV(SV* poly_sv)
|
||||
{
|
||||
|
@ -20,6 +20,7 @@ class MultiPoint
|
||||
void rotate(double angle, Point* center);
|
||||
void reverse();
|
||||
const Point* first_point() const;
|
||||
const Point* last_point() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 4;
|
||||
use Test::More tests => 5;
|
||||
|
||||
my $points = [
|
||||
[100, 100],
|
||||
@ -24,4 +24,7 @@ is_deeply [ map $_->pp, @$lines ], [
|
||||
[ [200, 100], [200, 200] ],
|
||||
], 'polyline lines';
|
||||
|
||||
$polyline->append_polyline($polyline->clone);
|
||||
is_deeply $polyline->pp, [ @$points, @$points ], 'append_polyline';
|
||||
|
||||
__END__
|
||||
|
@ -18,6 +18,8 @@
|
||||
%code{% RETVAL = THIS->polyline.lines(); %};
|
||||
Point* first_point()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->first_point())); %};
|
||||
Point* last_point()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->last_point())); %};
|
||||
%{
|
||||
|
||||
ExtrusionPath*
|
||||
|
@ -21,6 +21,8 @@
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
double length();
|
||||
Point* midpoint()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->midpoint(); %};
|
||||
%{
|
||||
|
||||
Line*
|
||||
|
@ -21,6 +21,8 @@
|
||||
Lines lines();
|
||||
Point* first_point()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->first_point())); %};
|
||||
Point* last_point()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->last_point())); %};
|
||||
%{
|
||||
|
||||
Polyline*
|
||||
@ -44,6 +46,14 @@ Polyline::append(...)
|
||||
THIS->points.push_back(p);
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::append_polyline(polyline)
|
||||
Polyline* polyline;
|
||||
CODE:
|
||||
for (Points::const_iterator it = polyline->points.begin(); it != polyline->points.end(); ++it) {
|
||||
THIS->points.push_back((*it));
|
||||
}
|
||||
|
||||
void
|
||||
Polyline::rotate(angle, center_sv)
|
||||
double angle;
|
||||
|
Loading…
Reference in New Issue
Block a user