| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Collision::Util; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
45682
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
38
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
113
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
BEGIN { |
|
7
|
1
|
|
|
1
|
|
6
|
require Exporter; |
|
8
|
1
|
|
|
|
|
20
|
our @ISA = qw(Exporter); |
|
9
|
1
|
|
|
|
|
4
|
our @EXPORT_OK = qw( |
|
10
|
|
|
|
|
|
|
check_contains check_contains_rect |
|
11
|
|
|
|
|
|
|
check_collision check_collision_rect |
|
12
|
|
|
|
|
|
|
); |
|
13
|
1
|
|
|
|
|
32
|
our %EXPORT_TAGS = ( |
|
14
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
|
15
|
|
|
|
|
|
|
std => [qw( check_contains check_collision )], |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
7
|
use Carp (); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1426
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub check_contains { |
|
25
|
0
|
|
|
0
|
1
|
|
my ($self, $target) = (@_); |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
Carp::croak "must receive a target" |
|
28
|
|
|
|
|
|
|
unless $target; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my @ret = (); |
|
31
|
0
|
|
|
|
|
|
my $ref = ref $target; |
|
32
|
0
|
0
|
|
|
|
|
if ( $ref eq 'ARRAY' ) { |
|
|
|
0
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $id = 0; |
|
34
|
0
|
|
|
|
|
|
foreach ( @{$target} ) { |
|
|
0
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$id++; |
|
36
|
0
|
0
|
|
|
|
|
if (check_contains_rect($self, $_) ) { |
|
37
|
0
|
|
|
|
|
|
push @ret, $id; |
|
38
|
0
|
0
|
|
|
|
|
last unless wantarray; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
elsif ( $ref eq 'HASH' ) { |
|
43
|
0
|
|
|
|
|
|
foreach ( keys %{$target} ) { |
|
|
0
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if (check_contains_rect($self, $target->{$_}) ) { |
|
45
|
0
|
|
|
|
|
|
push @ret, $_; |
|
46
|
0
|
0
|
|
|
|
|
last unless wantarray; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
else { |
|
51
|
0
|
|
|
|
|
|
return check_contains_rect($self, $target); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
0
|
0
|
|
|
|
|
return wantarray ? @ret : $ret[0]; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub check_contains_rect { |
|
57
|
0
|
0
|
|
0
|
0
|
|
Carp::croak "must receive a target" |
|
58
|
|
|
|
|
|
|
unless $_[1]; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $contains; |
|
61
|
0
|
|
|
|
|
|
eval { |
|
62
|
0
|
|
0
|
|
|
|
$contains = ($_[0]->x <= $_[1]->x) |
|
63
|
|
|
|
|
|
|
&& ($_[0]->y <= $_[1]->y) |
|
64
|
|
|
|
|
|
|
&& ($_[0]->x + $_[0]->w >= $_[1]->x + $_[1]->w) |
|
65
|
|
|
|
|
|
|
&& ($_[0]->y + $_[0]->h >= $_[1]->y + $_[1]->h) |
|
66
|
|
|
|
|
|
|
&& ($_[0]->x + $_[0]->w > $_[1]->x) |
|
67
|
|
|
|
|
|
|
&& ($_[0]->y + $_[0]->h > $_[1]->y) |
|
68
|
|
|
|
|
|
|
; |
|
69
|
|
|
|
|
|
|
}; |
|
70
|
0
|
0
|
|
|
|
|
Carp::croak "elements should have x, y, w, h accessors" if $@; |
|
71
|
0
|
|
|
|
|
|
return $contains; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub check_collision { |
|
75
|
0
|
|
|
0
|
1
|
|
my ($self, $target) = (@_); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
Carp::croak "must receive a target" |
|
78
|
|
|
|
|
|
|
unless $target; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my @ret = (); |
|
81
|
0
|
|
|
|
|
|
my $ref = ref $target; |
|
82
|
0
|
0
|
|
|
|
|
if ( $ref eq 'ARRAY' ) { |
|
|
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $id = 0; |
|
84
|
0
|
|
|
|
|
|
foreach ( @{$target} ) { |
|
|
0
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$id++; |
|
86
|
0
|
0
|
|
|
|
|
if (check_collision_rect($self, $_) ) { |
|
87
|
0
|
|
|
|
|
|
push @ret, $id; |
|
88
|
0
|
0
|
|
|
|
|
last unless wantarray; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
elsif ( $ref eq 'HASH' ) { |
|
93
|
0
|
|
|
|
|
|
foreach ( keys %{$target} ) { |
|
|
0
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
if (check_collision_rect($self, $target->{$_}) ) { |
|
95
|
0
|
|
|
|
|
|
push @ret, $_; |
|
96
|
0
|
0
|
|
|
|
|
last unless wantarray; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
else { |
|
101
|
0
|
|
|
|
|
|
return check_collision_rect($self, $target); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
0
|
0
|
|
|
|
|
return wantarray ? @ret : $ret[0]; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub check_collision_rect { |
|
107
|
0
|
0
|
|
0
|
0
|
|
Carp::croak "must receive a target" |
|
108
|
|
|
|
|
|
|
unless $_[1]; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $collide; |
|
111
|
0
|
|
|
|
|
|
eval { |
|
112
|
0
|
|
0
|
|
|
|
$collide = ( |
|
113
|
|
|
|
|
|
|
($_[0]->x >= $_[1]->x && $_[0]->x < $_[1]->x + $_[1]->w) |
|
114
|
|
|
|
|
|
|
|| ($_[1]->x >= $_[0]->x && $_[1]->x < $_[0]->x + $_[0]->w) |
|
115
|
|
|
|
|
|
|
) |
|
116
|
|
|
|
|
|
|
&& |
|
117
|
|
|
|
|
|
|
( |
|
118
|
|
|
|
|
|
|
($_[0]->y >= $_[1]->y && $_[0]->y < $_[1]->y + $_[1]->h) |
|
119
|
|
|
|
|
|
|
|| ($_[1]->y >= $_[0]->y && $_[1]->y < $_[0]->y + $_[0]->h) |
|
120
|
|
|
|
|
|
|
) |
|
121
|
|
|
|
|
|
|
; |
|
122
|
|
|
|
|
|
|
}; |
|
123
|
0
|
0
|
|
|
|
|
Carp::croak "elements should have x, y, w, h accessors" if $@; |
|
124
|
0
|
|
|
|
|
|
return $collide; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
42; |
|
129
|
|
|
|
|
|
|
__END__ |