1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
use strict;
use warnings;
use Test::More tests => 1+6+3*2;
use constant EPS => 1.e-9;
sub approx_eq {
return ($_[0]+EPS() < $_[1] && $_[0]-EPS() > $_[1]);
}
use Math::Clipper qw/:all/;
pass();
foreach my $const (
qw/CT_INTERSECTION CT_UNION CT_DIFFERENCE CT_XOR/,
#qw/PT_SUBJECT PT_CLIP/,
qw/PFT_EVENODD PFT_NONZERO/,
)
{
ok(defined eval $const);
}
SCOPE: {
my $c = Math::Clipper->new;
isa_ok($c, 'Math::Clipper');
$c->add_subject_polygon(
[
[0, 0],
[10, 0],
[10, 10],
[0, 10],
],
);
$c->add_clip_polygon(
my $clip = [
[0, 0],
[5, 0],
[5, 10],
[0, 10],
],
);
my $ppoly = $c->execute(CT_INTERSECTION);
ok(ref($ppoly) eq 'ARRAY');
is area($ppoly->[0]), area($clip);
}
SCOPE: {
my $c = Math::Clipper->new;
isa_ok($c, 'Math::Clipper');
$c->add_subject_polygon(
[
[0, 0],
[10, 0],
[10, 10],
[0, 10],
],
);
$c->add_clip_polygon(
[
[50, 0.],
[55, 0.],
[55, 10],
[50, 10],
[60, 20],
[80, 30],
[100, 40],
[120, 50],
[140, 60],
[160, 70],
],
);
my $ppoly = $c->execute(CT_INTERSECTION);
ok(ref($ppoly) eq 'ARRAY');
is_deeply($ppoly, [] );
}
|