Removed dependency on Math::Clipper
This commit is contained in:
parent
b11b595c97
commit
fb763b0187
1
Build.PL
1
Build.PL
@ -12,7 +12,6 @@ my %prereqs = qw(
|
|||||||
File::Basename 0
|
File::Basename 0
|
||||||
File::Spec 0
|
File::Spec 0
|
||||||
Getopt::Long 0
|
Getopt::Long 0
|
||||||
Math::Clipper 1.22
|
|
||||||
Math::ConvexHull::MonotoneChain 0.01
|
Math::ConvexHull::MonotoneChain 0.01
|
||||||
Math::Geometry::Voronoi 1.3
|
Math::Geometry::Voronoi 1.3
|
||||||
Math::PlanePath 53
|
Math::PlanePath 53
|
||||||
|
@ -8,7 +8,7 @@ use Boost::Geometry::Utils;
|
|||||||
use List::Util qw(first);
|
use List::Util qw(first);
|
||||||
use Math::Geometry::Voronoi;
|
use Math::Geometry::Voronoi;
|
||||||
use Slic3r::Geometry qw(X Y A B point_in_polygon same_line epsilon);
|
use Slic3r::Geometry qw(X Y A B point_in_polygon same_line epsilon);
|
||||||
use Slic3r::Geometry::Clipper qw(union_ex JT_MITER);
|
use Slic3r::Geometry::Clipper qw(union_ex);
|
||||||
|
|
||||||
sub wkt {
|
sub wkt {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -4,7 +4,7 @@ use Moo;
|
|||||||
extends 'Slic3r::Fill::Base';
|
extends 'Slic3r::Fill::Base';
|
||||||
|
|
||||||
use Slic3r::Geometry qw(scale unscale X);
|
use Slic3r::Geometry qw(scale unscale X);
|
||||||
use Slic3r::Geometry::Clipper qw(offset offset2 union_pt traverse_pt PFT_EVENODD);
|
use Slic3r::Geometry::Clipper qw(offset offset2 union_pt traverse_pt);
|
||||||
|
|
||||||
sub fill_surface {
|
sub fill_surface {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -14,7 +14,7 @@ has '_tolerance' => (is => 'lazy');
|
|||||||
|
|
||||||
use List::Util qw(first);
|
use List::Util qw(first);
|
||||||
use Slic3r::Geometry qw(A B scale epsilon);
|
use Slic3r::Geometry qw(A B scale epsilon);
|
||||||
use Slic3r::Geometry::Clipper qw(diff_ex offset JT_MITER);
|
use Slic3r::Geometry::Clipper qw(diff_ex offset);
|
||||||
|
|
||||||
# clearance (in mm) from the perimeters
|
# clearance (in mm) from the perimeters
|
||||||
has '_inner_margin' => (is => 'ro', default => sub { scale 0.5 });
|
has '_inner_margin' => (is => 'ro', default => sub { scale 0.5 });
|
||||||
|
@ -5,7 +5,7 @@ use utf8;
|
|||||||
|
|
||||||
use File::Basename qw(basename dirname);
|
use File::Basename qw(basename dirname);
|
||||||
use List::Util qw(max sum first);
|
use List::Util qw(max sum first);
|
||||||
use Math::Clipper qw(offset JT_ROUND);
|
use Slic3r::Geometry::Clipper qw(offset JT_ROUND);
|
||||||
use Math::ConvexHull::MonotoneChain qw(convex_hull);
|
use Math::ConvexHull::MonotoneChain qw(convex_hull);
|
||||||
use Slic3r::Geometry qw(X Y Z MIN MAX);
|
use Slic3r::Geometry qw(X Y Z MIN MAX);
|
||||||
use threads::shared qw(shared_clone);
|
use threads::shared qw(shared_clone);
|
||||||
@ -681,7 +681,6 @@ sub export_gcode {
|
|||||||
sub export_gcode2 {
|
sub export_gcode2 {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($print, $output_file, %params) = @_;
|
my ($print, $output_file, %params) = @_;
|
||||||
$Slic3r::Geometry::Clipper::clipper = Math::Clipper->new;
|
|
||||||
local $SIG{'KILL'} = sub {
|
local $SIG{'KILL'} = sub {
|
||||||
Slic3r::debugf "Exporting cancelled; exiting thread...\n";
|
Slic3r::debugf "Exporting cancelled; exiting thread...\n";
|
||||||
threads->exit();
|
threads->exit();
|
||||||
@ -822,7 +821,6 @@ sub make_thumbnail {
|
|||||||
my $object = $self->{objects}[$obj_idx];
|
my $object = $self->{objects}[$obj_idx];
|
||||||
$object->thumbnail_scaling_factor($self->{scaling_factor});
|
$object->thumbnail_scaling_factor($self->{scaling_factor});
|
||||||
my $cb = sub {
|
my $cb = sub {
|
||||||
$Slic3r::Geometry::Clipper::clipper = Math::Clipper->new if $Slic3r::have_threads;
|
|
||||||
my $thumbnail = $object->make_thumbnail;
|
my $thumbnail = $object->make_thumbnail;
|
||||||
|
|
||||||
if ($Slic3r::have_threads) {
|
if ($Slic3r::have_threads) {
|
||||||
|
@ -792,14 +792,13 @@ sub chained_path {
|
|||||||
my %indices = map { $points[$_] => $_ } 0 .. $#points;
|
my %indices = map { $points[$_] => $_ } 0 .. $#points;
|
||||||
|
|
||||||
my @result = ();
|
my @result = ();
|
||||||
my $last_point;
|
if (!$start_near && @points) {
|
||||||
if (!$start_near) {
|
|
||||||
$start_near = shift @points;
|
$start_near = shift @points;
|
||||||
push @result, $indices{$start_near} if $start_near;
|
push @result, $indices{$start_near};
|
||||||
}
|
}
|
||||||
while (@points) {
|
while (@points) {
|
||||||
$start_near = $start_near->nearest_point(\@points);
|
my $idx = $start_near->nearest_point_index(\@points);
|
||||||
@points = grep $_ ne $start_near, @points;
|
my ($start_near) = splice @points, $idx, 1;
|
||||||
push @result, $indices{$start_near};
|
push @result, $indices{$start_near};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,13 +5,11 @@ use warnings;
|
|||||||
require Exporter;
|
require Exporter;
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT_OK = qw(offset offset_ex
|
our @EXPORT_OK = qw(offset offset_ex
|
||||||
diff_ex diff union_ex intersection_ex xor_ex PFT_EVENODD JT_MITER JT_ROUND
|
diff_ex diff union_ex intersection_ex xor_ex JT_ROUND
|
||||||
JT_SQUARE is_counter_clockwise union_pt offset2 offset2_ex traverse_pt
|
JT_SQUARE is_counter_clockwise union_pt offset2 offset2_ex traverse_pt
|
||||||
intersection union);
|
intersection union);
|
||||||
|
|
||||||
use Math::Clipper 1.22 qw(:cliptypes :polyfilltypes :jointypes is_counter_clockwise area);
|
|
||||||
use Slic3r::Geometry qw(scale);
|
use Slic3r::Geometry qw(scale);
|
||||||
our $clipper = Math::Clipper->new;
|
|
||||||
|
|
||||||
sub traverse_pt {
|
sub traverse_pt {
|
||||||
my ($polynodes) = @_;
|
my ($polynodes) = @_;
|
||||||
|
@ -5,7 +5,7 @@ use List::Util qw(sum first);
|
|||||||
use Slic3r::ExtrusionPath ':roles';
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(PI A B scale chained_path_items points_coincide);
|
use Slic3r::Geometry qw(PI A B scale chained_path_items points_coincide);
|
||||||
use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex
|
use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex
|
||||||
offset offset2 offset2_ex PFT_EVENODD union_pt traverse_pt diff intersection
|
offset offset2 offset2_ex union_pt traverse_pt diff intersection
|
||||||
union diff);
|
union diff);
|
||||||
use Slic3r::Surface ':types';
|
use Slic3r::Surface ':types';
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use Math::ConvexHull::MonotoneChain qw(convex_hull);
|
|||||||
use Slic3r::ExtrusionPath ':roles';
|
use Slic3r::ExtrusionPath ':roles';
|
||||||
use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX PI scale unscale move_points chained_path);
|
use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX PI scale unscale move_points chained_path);
|
||||||
use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex offset
|
use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex offset
|
||||||
offset2 traverse_pt JT_ROUND JT_SQUARE PFT_EVENODD);
|
offset2 traverse_pt JT_ROUND JT_SQUARE);
|
||||||
use Time::HiRes qw(gettimeofday tv_interval);
|
use Time::HiRes qw(gettimeofday tv_interval);
|
||||||
|
|
||||||
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => 1);
|
has 'config' => (is => 'rw', default => sub { Slic3r::Config->new_from_defaults }, trigger => 1);
|
||||||
@ -403,7 +403,6 @@ sub export_gcode {
|
|||||||
},
|
},
|
||||||
thread_cb => sub {
|
thread_cb => sub {
|
||||||
my $q = shift;
|
my $q = shift;
|
||||||
$Slic3r::Geometry::Clipper::clipper = Math::Clipper->new;
|
|
||||||
while (defined (my $obj_layer = $q->dequeue)) {
|
while (defined (my $obj_layer = $q->dequeue)) {
|
||||||
my ($obj_idx, $layer_id, $region_id) = @$obj_layer;
|
my ($obj_idx, $layer_id, $region_id) = @$obj_layer;
|
||||||
my $object = $self->objects->[$obj_idx];
|
my $object = $self->objects->[$obj_idx];
|
||||||
|
@ -330,7 +330,6 @@ sub make_perimeters {
|
|||||||
items => sub { 0 .. ($self->layer_count-1) },
|
items => sub { 0 .. ($self->layer_count-1) },
|
||||||
thread_cb => sub {
|
thread_cb => sub {
|
||||||
my $q = shift;
|
my $q = shift;
|
||||||
$Slic3r::Geometry::Clipper::clipper = Math::Clipper->new;
|
|
||||||
while (defined (my $layer_id = $q->dequeue)) {
|
while (defined (my $layer_id = $q->dequeue)) {
|
||||||
$self->layers->[$layer_id]->make_perimeters;
|
$self->layers->[$layer_id]->make_perimeters;
|
||||||
}
|
}
|
||||||
@ -1235,7 +1234,6 @@ sub generate_support_material {
|
|||||||
items => [ 0 .. $#{$self->support_layers} ],
|
items => [ 0 .. $#{$self->support_layers} ],
|
||||||
thread_cb => sub {
|
thread_cb => sub {
|
||||||
my $q = shift;
|
my $q = shift;
|
||||||
$Slic3r::Geometry::Clipper::clipper = Math::Clipper->new;
|
|
||||||
my $result = {};
|
my $result = {};
|
||||||
while (defined (my $layer_id = $q->dequeue)) {
|
while (defined (my $layer_id = $q->dequeue)) {
|
||||||
$result->{$layer_id} = $process_layer->($layer_id);
|
$result->{$layer_id} = $process_layer->($layer_id);
|
||||||
|
57
t/clipper.t
57
t/clipper.t
@ -4,8 +4,13 @@ use warnings;
|
|||||||
|
|
||||||
plan tests => 3;
|
plan tests => 3;
|
||||||
|
|
||||||
use Math::Clipper ':all';
|
BEGIN {
|
||||||
|
use FindBin;
|
||||||
|
use lib "$FindBin::Bin/../lib";
|
||||||
|
}
|
||||||
|
|
||||||
|
use Slic3r;
|
||||||
|
use Slic3r::Geometry::Clipper qw(intersection_ex union_ex diff_ex);
|
||||||
|
|
||||||
{
|
{
|
||||||
my $square = [ # ccw
|
my $square = [ # ccw
|
||||||
@ -26,29 +31,22 @@ use Math::Clipper ':all';
|
|||||||
[25, 18],
|
[25, 18],
|
||||||
[5, 18],
|
[5, 18],
|
||||||
];
|
];
|
||||||
my $clipper = Math::Clipper->new;
|
my $intersection = intersection_ex([ $square, $hole_in_square ], [ $square2 ]);
|
||||||
$clipper->add_subject_polygons([ $square, $hole_in_square ]);
|
|
||||||
$clipper->add_clip_polygons([ $square2 ]);
|
|
||||||
my $intersection = $clipper->ex_execute(CT_INTERSECTION, PFT_NONZERO, PFT_NONZERO);
|
|
||||||
|
|
||||||
is_deeply $intersection, [
|
is_deeply [ map $_->pp, @$intersection ], [[
|
||||||
{
|
[
|
||||||
holes => [
|
[20, 12],
|
||||||
[
|
[20, 18],
|
||||||
[14, 14],
|
[10, 18],
|
||||||
[14, 16],
|
[10, 12],
|
||||||
[16, 16],
|
],
|
||||||
[16, 14],
|
[
|
||||||
],
|
[14, 14],
|
||||||
],
|
[14, 16],
|
||||||
outer => [
|
[16, 16],
|
||||||
[20, 12],
|
[16, 14],
|
||||||
[20, 18],
|
],
|
||||||
[10, 18],
|
]], 'hole is preserved after intersection';
|
||||||
[10, 12],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
], 'hole is preserved after intersection';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#==========================================================
|
#==========================================================
|
||||||
@ -58,18 +56,13 @@ use Math::Clipper ':all';
|
|||||||
my $contour2 = [ [10,10], [30,10], [30,30], [10,30] ]; # ccw
|
my $contour2 = [ [10,10], [30,10], [30,30], [10,30] ]; # ccw
|
||||||
my $hole = [ [15,15], [15,25], [25,25], [25,15] ]; # cw
|
my $hole = [ [15,15], [15,25], [25,25], [25,15] ]; # cw
|
||||||
|
|
||||||
my $clipper = Math::Clipper->new;
|
my $union = union_ex([ $contour1, $contour2, $hole ]);
|
||||||
$clipper->add_subject_polygons([ $contour1, $contour2, $hole ]);
|
|
||||||
my $union = $clipper->ex_execute(CT_UNION, PFT_NONZERO, PFT_NONZERO);
|
|
||||||
|
|
||||||
is_deeply $union, [{ holes => [], outer => [ [40,0], [40,40], [0,40], [0,0] ] }],
|
is_deeply [ map $_->pp, @$union ], [[ [ [40,0], [40,40], [0,40], [0,0] ] ]],
|
||||||
'union of two ccw and one cw is a contour with no holes';
|
'union of two ccw and one cw is a contour with no holes';
|
||||||
|
|
||||||
$clipper->clear;
|
my $diff = diff_ex([ $contour1, $contour2 ], [ $hole ]);
|
||||||
$clipper->add_subject_polygons([ $contour1, $contour2 ]);
|
is_deeply [ map $_->pp, @$diff ], [[ [ [40,0], [40,40], [0,40], [0,0] ], [ [15,15], [15,25], [25,25], [25,15] ] ]],
|
||||||
$clipper->add_clip_polygons([ $hole ]);
|
|
||||||
my $diff = $clipper->ex_execute(CT_DIFFERENCE, PFT_NONZERO, PFT_NONZERO);
|
|
||||||
is_deeply $diff, [{ holes => [[ [15,15], [15,25], [25,25], [25,15] ]], outer => [ [40,0], [40,40], [0,40], [0,0] ] }],
|
|
||||||
'difference of a cw from two ccw is a contour with one hole';
|
'difference of a cw from two ccw is a contour with one hole';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ use Slic3r::Geometry qw(collinear);
|
|||||||
|
|
||||||
{
|
{
|
||||||
my @lines = (
|
my @lines = (
|
||||||
[ [0,4], [4,2] ],
|
Slic3r::Line->new([0,4], [4,2]),
|
||||||
[ [2,3], [8,0] ],
|
Slic3r::Line->new([2,3], [8,0]),
|
||||||
[ [6,1], [8,0] ],
|
Slic3r::Line->new([6,1], [8,0]),
|
||||||
);
|
);
|
||||||
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
||||||
is collinear($lines[1], $lines[2]), 1, 'collinear';
|
is collinear($lines[1], $lines[2]), 1, 'collinear';
|
||||||
@ -30,8 +30,8 @@ use Slic3r::Geometry qw(collinear);
|
|||||||
{
|
{
|
||||||
# horizontal
|
# horizontal
|
||||||
my @lines = (
|
my @lines = (
|
||||||
[ [0,1], [5,1] ],
|
Slic3r::Line->new([0,1], [5,1]),
|
||||||
[ [2,1], [8,1] ],
|
Slic3r::Line->new([2,1], [8,1]),
|
||||||
);
|
);
|
||||||
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
||||||
}
|
}
|
||||||
@ -41,8 +41,8 @@ use Slic3r::Geometry qw(collinear);
|
|||||||
{
|
{
|
||||||
# vertical
|
# vertical
|
||||||
my @lines = (
|
my @lines = (
|
||||||
[ [1,0], [1,5] ],
|
Slic3r::Line->new([1,0], [1,5]),
|
||||||
[ [1,2], [1,8] ],
|
Slic3r::Line->new([1,2], [1,8]),
|
||||||
);
|
);
|
||||||
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
is collinear($lines[0], $lines[1]), 1, 'collinear';
|
||||||
}
|
}
|
||||||
@ -52,8 +52,8 @@ use Slic3r::Geometry qw(collinear);
|
|||||||
{
|
{
|
||||||
# non overlapping
|
# non overlapping
|
||||||
my @lines = (
|
my @lines = (
|
||||||
[ [0,1], [5,1] ],
|
Slic3r::Line->new([0,1], [5,1]),
|
||||||
[ [7,1], [10,1] ],
|
Slic3r::Line->new([7,1], [10,1]),
|
||||||
);
|
);
|
||||||
is collinear($lines[0], $lines[1], 1), 0, 'non overlapping';
|
is collinear($lines[0], $lines[1], 1), 0, 'non overlapping';
|
||||||
is collinear($lines[0], $lines[1], 0), 1, 'overlapping';
|
is collinear($lines[0], $lines[1], 0), 1, 'overlapping';
|
||||||
@ -64,8 +64,8 @@ use Slic3r::Geometry qw(collinear);
|
|||||||
{
|
{
|
||||||
# with one common point
|
# with one common point
|
||||||
my @lines = (
|
my @lines = (
|
||||||
[ [0,4], [4,2] ],
|
Slic3r::Line->new([0,4], [4,2]),
|
||||||
[ [4,2], [8,0] ],
|
Slic3r::Line->new([4,2], [8,0]),
|
||||||
);
|
);
|
||||||
is collinear($lines[0], $lines[1], 1), 1, 'one common point';
|
is collinear($lines[0], $lines[1], 1), 1, 'one common point';
|
||||||
is collinear($lines[0], $lines[1], 0), 1, 'one common point';
|
is collinear($lines[0], $lines[1], 0), 1, 'one common point';
|
||||||
@ -76,8 +76,8 @@ use Slic3r::Geometry qw(collinear);
|
|||||||
{
|
{
|
||||||
# not collinear
|
# not collinear
|
||||||
my @lines = (
|
my @lines = (
|
||||||
[ [290000000,690525600], [285163380,684761540] ],
|
Slic3r::Line->new([290000000,690525600], [285163380,684761540]),
|
||||||
[ [285163380,684761540], [193267599,575244400] ],
|
Slic3r::Line->new([285163380,684761540], [193267599,575244400]),
|
||||||
);
|
);
|
||||||
is collinear($lines[0], $lines[1], 0), 0, 'not collinear';
|
is collinear($lines[0], $lines[1], 0), 0, 'not collinear';
|
||||||
is collinear($lines[0], $lines[1], 1), 0, 'not collinear';
|
is collinear($lines[0], $lines[1], 1), 0, 'not collinear';
|
||||||
|
2
t/fill.t
2
t/fill.t
@ -22,7 +22,7 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
|
|||||||
$print->init_extruders;
|
$print->init_extruders;
|
||||||
my $filler = Slic3r::Fill::Rectilinear->new(
|
my $filler = Slic3r::Fill::Rectilinear->new(
|
||||||
print => $print,
|
print => $print,
|
||||||
bounding_box => Slic3r::Geometry::BoundingBox->new_from_points([ [0, 0], [10, 10] ]),
|
bounding_box => Slic3r::Geometry::BoundingBox->new_from_points([ Slic3r::Point->new(0, 0), Slic3r::Point->new(10, 10) ]),
|
||||||
);
|
);
|
||||||
my $surface_width = 250;
|
my $surface_width = 250;
|
||||||
my $distance = $filler->adjust_solid_spacing(
|
my $distance = $filler->adjust_solid_spacing(
|
||||||
|
@ -177,7 +177,7 @@ is Slic3r::Geometry::can_connect_points(@$points, $polygons), 0, 'can_connect_po
|
|||||||
#==========================================================
|
#==========================================================
|
||||||
|
|
||||||
{
|
{
|
||||||
my $bb = Slic3r::Geometry::BoundingBox->new_from_points([ [0, 1], [10, 2], [20, 2] ]);
|
my $bb = Slic3r::Geometry::BoundingBox->new_from_points([ map Slic3r::Point->new(@$_), [0, 1], [10, 2], [20, 2] ]);
|
||||||
$bb->scale(2);
|
$bb->scale(2);
|
||||||
is_deeply $bb->extents, [ [0,40], [2,4] ], 'bounding box is scaled correctly';
|
is_deeply $bb->extents, [ [0,40], [2,4] ], 'bounding box is scaled correctly';
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ use Slic3r::Test;
|
|||||||
push @$cur_loop, [ @$info{qw(new_X new_Y)} ];
|
push @$cur_loop, [ @$info{qw(new_X new_Y)} ];
|
||||||
} else {
|
} else {
|
||||||
if ($cur_loop) {
|
if ($cur_loop) {
|
||||||
$has_cw_loops = 1 if !Slic3r::Geometry::Clipper::is_counter_clockwise($cur_loop);
|
$has_cw_loops = 1 if Slic3r::Polygon->new(@$cur_loop)->is_clockwise;
|
||||||
$cur_loop = undef;
|
$cur_loop = undef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ use Slic3r::Test;
|
|||||||
push @$cur_loop, [ @$info{qw(new_X new_Y)} ];
|
push @$cur_loop, [ @$info{qw(new_X new_Y)} ];
|
||||||
} else {
|
} else {
|
||||||
if ($cur_loop) {
|
if ($cur_loop) {
|
||||||
$has_cw_loops = 1 if !Slic3r::Geometry::Clipper::is_counter_clockwise($cur_loop);
|
$has_cw_loops = 1 if Slic3r::Polygon->new(@$cur_loop)->is_clockwise;
|
||||||
if ($self->F == $config->external_perimeter_speed*60) {
|
if ($self->F == $config->external_perimeter_speed*60) {
|
||||||
my $move_dest = Slic3r::Point->new_scale(@$info{qw(new_X new_Y)});
|
my $move_dest = Slic3r::Point->new_scale(@$info{qw(new_X new_Y)});
|
||||||
$external_loops{$self->Z}++;
|
$external_loops{$self->Z}++;
|
||||||
|
13
t/polyclip.t
13
t/polyclip.t
@ -9,7 +9,6 @@ BEGIN {
|
|||||||
use lib "$FindBin::Bin/../lib";
|
use lib "$FindBin::Bin/../lib";
|
||||||
}
|
}
|
||||||
|
|
||||||
use Math::Clipper qw(is_counter_clockwise);
|
|
||||||
use Slic3r;
|
use Slic3r;
|
||||||
|
|
||||||
#==========================================================
|
#==========================================================
|
||||||
@ -115,7 +114,7 @@ is_deeply $intersection, [ [120, 120], [180, 160] ], 'internal lines are preserv
|
|||||||
#==========================================================
|
#==========================================================
|
||||||
|
|
||||||
{
|
{
|
||||||
my $large_circle = [ # ccw
|
my $large_circle = Slic3r::Polygon->new( # ccw
|
||||||
[151.8639,288.1192], [133.2778,284.6011], [115.0091,279.6997], [98.2859,270.8606], [82.2734,260.7933],
|
[151.8639,288.1192], [133.2778,284.6011], [115.0091,279.6997], [98.2859,270.8606], [82.2734,260.7933],
|
||||||
[68.8974,247.4181], [56.5622,233.0777], [47.7228,216.3558], [40.1617,199.0172], [36.6431,180.4328],
|
[68.8974,247.4181], [56.5622,233.0777], [47.7228,216.3558], [40.1617,199.0172], [36.6431,180.4328],
|
||||||
[34.932,165.2312], [37.5567,165.1101], [41.0547,142.9903], [36.9056,141.4295], [40.199,124.1277],
|
[34.932,165.2312], [37.5567,165.1101], [41.0547,142.9903], [36.9056,141.4295], [40.199,124.1277],
|
||||||
@ -125,10 +124,10 @@ is_deeply $intersection, [ [120, 120], [180, 160] ], 'internal lines are preserv
|
|||||||
[275.6832,106.6636], [281.9225,124.52], [286.8064,142.795], [287.5061,161.696], [286.7874,180.5972],
|
[275.6832,106.6636], [281.9225,124.52], [286.8064,142.795], [287.5061,161.696], [286.7874,180.5972],
|
||||||
[281.8856,198.8664], [275.6283,216.7169], [265.5604,232.7294], [254.3211,247.942], [239.9802,260.2776],
|
[281.8856,198.8664], [275.6283,216.7169], [265.5604,232.7294], [254.3211,247.942], [239.9802,260.2776],
|
||||||
[224.757,271.5022], [207.4179,279.0635], [189.5605,285.3035], [170.7649,287.4188],
|
[224.757,271.5022], [207.4179,279.0635], [189.5605,285.3035], [170.7649,287.4188],
|
||||||
];
|
);
|
||||||
is is_counter_clockwise($large_circle), 1, "contour is counter-clockwise";
|
ok $large_circle->is_counter_clockwise, "contour is counter-clockwise";
|
||||||
|
|
||||||
my $small_circle = [ # cw
|
my $small_circle = Slic3r::Polygon->new( # cw
|
||||||
[158.227,215.9007], [164.5136,215.9007], [175.15,214.5007], [184.5576,210.6044], [190.2268,207.8743],
|
[158.227,215.9007], [164.5136,215.9007], [175.15,214.5007], [184.5576,210.6044], [190.2268,207.8743],
|
||||||
[199.1462,201.0306], [209.0146,188.346], [213.5135,177.4829], [214.6979,168.4866], [216.1025,162.3325],
|
[199.1462,201.0306], [209.0146,188.346], [213.5135,177.4829], [214.6979,168.4866], [216.1025,162.3325],
|
||||||
[214.6463,151.2703], [213.2471,145.1399], [209.0146,134.9203], [199.1462,122.2357], [189.8944,115.1366],
|
[214.6463,151.2703], [213.2471,145.1399], [209.0146,134.9203], [199.1462,122.2357], [189.8944,115.1366],
|
||||||
@ -136,8 +135,8 @@ is_deeply $intersection, [ [120, 120], [180, 160] ], 'internal lines are preserv
|
|||||||
[138.183,112.6616], [132.5135,115.3919], [123.5943,122.2357], [113.7259,134.92], [109.2269,145.7834],
|
[138.183,112.6616], [132.5135,115.3919], [123.5943,122.2357], [113.7259,134.92], [109.2269,145.7834],
|
||||||
[108.0426,154.7799], [106.638,160.9339], [108.0941,171.9957], [109.4933,178.1264], [113.7259,188.3463],
|
[108.0426,154.7799], [106.638,160.9339], [108.0941,171.9957], [109.4933,178.1264], [113.7259,188.3463],
|
||||||
[123.5943,201.0306], [132.8461,208.1296], [141.4901,211.7094], [147.172,214.4458],
|
[123.5943,201.0306], [132.8461,208.1296], [141.4901,211.7094], [147.172,214.4458],
|
||||||
];
|
);
|
||||||
is is_counter_clockwise($small_circle), 0, "hole is clockwise";
|
ok $small_circle->is_clockwise, "hole is clockwise";
|
||||||
|
|
||||||
my $expolygon = Slic3r::ExPolygon->new($large_circle, $small_circle);
|
my $expolygon = Slic3r::ExPolygon->new($large_circle, $small_circle);
|
||||||
$line = Slic3r::Line->new([152.742,288.086671142818], [152.742,34.166466971035]);
|
$line = Slic3r::Line->new([152.742,288.086671142818], [152.742,34.166466971035]);
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
#include "ExPolygon.hpp"
|
#include "ExPolygon.hpp"
|
||||||
#include "Polygon.hpp"
|
#include "Polygon.hpp"
|
||||||
|
|
||||||
|
// import these wherever we're included
|
||||||
|
using ClipperLib::jtMiter;
|
||||||
|
using ClipperLib::jtRound;
|
||||||
|
using ClipperLib::jtSquare;
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
#define CLIPPER_OFFSET_SCALE 100000.0
|
#define CLIPPER_OFFSET_SCALE 100000.0
|
||||||
|
@ -72,6 +72,12 @@ Polygon::is_counter_clockwise() const
|
|||||||
return orientation;
|
return orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Polygon::is_clockwise() const
|
||||||
|
{
|
||||||
|
return !this->is_counter_clockwise();
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Polygon::make_counter_clockwise()
|
Polygon::make_counter_clockwise()
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@ class Polygon : public MultiPoint {
|
|||||||
Polyline* split_at_first_point();
|
Polyline* split_at_first_point();
|
||||||
double area() const;
|
double area() const;
|
||||||
bool is_counter_clockwise() const;
|
bool is_counter_clockwise() const;
|
||||||
|
bool is_clockwise() const;
|
||||||
bool make_counter_clockwise();
|
bool make_counter_clockwise();
|
||||||
bool make_clockwise();
|
bool make_clockwise();
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
|
@ -10,6 +10,16 @@
|
|||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
||||||
|
IV
|
||||||
|
_constant()
|
||||||
|
ALIAS:
|
||||||
|
JT_MITER = jtMiter
|
||||||
|
JT_ROUND = jtRound
|
||||||
|
JT_SQUARE = jtSquare
|
||||||
|
CODE:
|
||||||
|
RETVAL = ix;
|
||||||
|
OUTPUT: RETVAL
|
||||||
|
|
||||||
Polygons
|
Polygons
|
||||||
offset(polygons, delta, scale = CLIPPER_OFFSET_SCALE, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
offset(polygons, delta, scale = CLIPPER_OFFSET_SCALE, joinType = ClipperLib::jtMiter, miterLimit = 3)
|
||||||
Polygons polygons
|
Polygons polygons
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_first_point(); %};
|
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_first_point(); %};
|
||||||
double area();
|
double area();
|
||||||
bool is_counter_clockwise();
|
bool is_counter_clockwise();
|
||||||
|
bool is_clockwise();
|
||||||
bool make_counter_clockwise();
|
bool make_counter_clockwise();
|
||||||
bool make_clockwise();
|
bool make_clockwise();
|
||||||
bool is_valid();
|
bool is_valid();
|
||||||
|
Loading…
Reference in New Issue
Block a user