Some reduction of Perl dependencies on ClipperLib,

ported some ClipperLib polyline clipping tests to C++.
This commit is contained in:
Vojtech Bubnik 2022-04-28 15:59:13 +02:00
parent 7f7d229178
commit 3687bc28d5
9 changed files with 82 additions and 235 deletions

View file

@ -12,11 +12,6 @@ sub offset {
return Slic3r::Geometry::Clipper::offset(\@$self, @_);
}
sub offset_ex {
my $self = shift;
return Slic3r::Geometry::Clipper::offset_ex(\@$self, @_);
}
sub noncollapsing_offset_ex {
my $self = shift;
my ($distance, @params) = @_;

View file

@ -14,10 +14,8 @@ our @EXPORT_OK = qw(
dot
line_intersection
normalize
point_in_segment
polyline_lines
polygon_is_convex
polygon_segment_having_point
scale
unscale
scaled_epsilon
@ -45,30 +43,6 @@ sub scaled_epsilon () { epsilon / &Slic3r::SCALING_FACTOR }
sub scale ($) { $_[0] / &Slic3r::SCALING_FACTOR }
sub unscale ($) { $_[0] * &Slic3r::SCALING_FACTOR }
# used by geometry.t, polygon_segment_having_point
sub point_in_segment {
my ($point, $line) = @_;
my ($x, $y) = @$point;
my $line_p = $line->pp;
my @line_x = sort { $a <=> $b } $line_p->[A][X], $line_p->[B][X];
my @line_y = sort { $a <=> $b } $line_p->[A][Y], $line_p->[B][Y];
# check whether the point is in the segment bounding box
return 0 unless $x >= ($line_x[0] - epsilon) && $x <= ($line_x[1] + epsilon)
&& $y >= ($line_y[0] - epsilon) && $y <= ($line_y[1] + epsilon);
# if line is vertical, check whether point's X is the same as the line
if ($line_p->[A][X] == $line_p->[B][X]) {
return abs($x - $line_p->[A][X]) < epsilon ? 1 : 0;
}
# calculate the Y in line at X of the point
my $y3 = $line_p->[A][Y] + ($line_p->[B][Y] - $line_p->[A][Y])
* ($x - $line_p->[A][X]) / ($line_p->[B][X] - $line_p->[A][X]);
return abs($y3 - $y) < epsilon ? 1 : 0;
}
# used by geometry.t
sub polyline_lines {
my ($polyline) = @_;
@ -76,17 +50,6 @@ sub polyline_lines {
return map Slic3r::Line->new(@points[$_, $_+1]), 0 .. $#points-1;
}
# given a $polygon, return the (first) segment having $point
# used by geometry.t
sub polygon_segment_having_point {
my ($polygon, $point) = @_;
foreach my $line (@{ $polygon->lines }) {
return $line if point_in_segment($point, $line);
}
return undef;
}
# polygon must be simple (non complex) and ccw
sub polygon_is_convex {
my ($points) = @_;

View file

@ -6,9 +6,9 @@ require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(
offset
offset_ex offset2_ex
offset2_ex
diff_ex diff union_ex intersection_ex
JT_ROUND JT_MITER JT_SQUARE
intersection intersection_pl diff_pl union);
intersection diff_pl union);
1;

View file

@ -7,7 +7,7 @@ use List::Util qw(min max sum first);
use Slic3r::Flow ':roles';
use Slic3r::Geometry qw(scale epsilon);
use Slic3r::Geometry::Clipper qw(diff diff_ex intersection intersection_ex union union_ex
offset offset_ex offset2_ex JT_MITER);
offset offset2_ex JT_MITER);
use Slic3r::Print::State ':steps';
use Slic3r::Surface ':types';