Make ray casting test work
This commit is contained in:
parent
91df62d461
commit
6883b40e1e
1 changed files with 11 additions and 9 deletions
|
|
@ -10,7 +10,7 @@ sub create_polygon
|
|||
for(my $i = 0; $i < $#$sides; $i += 2) {
|
||||
push @poly, [ $pts->[$sides->[$i]-1], $pts->[$sides->[$i+1]-1] ];
|
||||
}
|
||||
@poly;
|
||||
\@poly;
|
||||
}
|
||||
|
||||
my @pts = ( point(0,0), point(10,0), point(10,10), point(0,10),
|
||||
|
|
@ -18,20 +18,22 @@ my @pts = ( point(0,0), point(10,0), point(10,10), point(0,10),
|
|||
point(0,5), point(10,5),
|
||||
point(3,0), point(7,0), point(7,10), point(3,10) );
|
||||
|
||||
my @squared = create_polygon(\@pts, [ 1,2, 2,3, 3,4, 4,1 ] );
|
||||
my @squaredhole = create_polygon(\@pts, [ 1,2, 2,3, 3,4, 4,1, 5,6, 6,7, 7,8, 8,5 ] );
|
||||
my @strange = create_polygon(\@pts, [ 1,5, 5,4, 4,8, 8,7, 7,3, 3,2, 2,5 ] );
|
||||
my @exagon = create_polygon(\@pts, [ 11,12, 12,10, 10,13, 13,14, 14,9, 9,11 ]) ;
|
||||
my %pgs = (
|
||||
squared => create_polygon(\@pts, [ 1,2, 2,3, 3,4, 4,1 ] ),
|
||||
squaredhole => create_polygon(\@pts, [ 1,2, 2,3, 3,4, 4,1, 5,6, 6,7, 7,8, 8,5 ] ),
|
||||
strange => create_polygon(\@pts, [ 1,5, 5,4, 4,8, 8,7, 7,3, 3,2, 2,5 ] ),
|
||||
exagon => create_polygon(\@pts, [ 11,12, 12,10, 10,13, 13,14, 14,9, 9,11 ]),
|
||||
);
|
||||
|
||||
|
||||
my @p = ( point(5,5), point(5, 8), point(-10, 5), point(0,5), point(10,5), &
|
||||
point(8,5), point(10,10) );
|
||||
|
||||
foreach my $pol ( qw(squared squaredhole strange exagon) ) {
|
||||
no strict 'refs';
|
||||
foreach my $pol ( sort keys %pgs ) {
|
||||
print "$pol\n";
|
||||
my @rp = @{$pol};
|
||||
my $rp = $pgs{$pol};
|
||||
foreach my $tp ( @p ) {
|
||||
print "\t($tp->[0],$tp->[1]) " .
|
||||
( point_in_polygon($tp, \@rp) ? "INSIDE" : "OUTSIDE" ) . "\n";
|
||||
( point_in_polygon($tp, $rp) ? "INSIDE" : "OUTSIDE" ) . "\n";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue