File Coverage

blib/lib/SDLx/Rect.pm
Criterion Covered Total %
statement 83 330 25.1
branch 32 170 18.8
condition 22 107 20.5
subroutine 21 53 39.6
pod 0 42 0.0
total 158 702 22.5


line stmt bran cond sub pod time code
1             package SDLx::Rect;
2 7     7   1523 use strict;
  7         7  
  7         179  
3 7     7   21 use warnings;
  7         5  
  7         117  
4 7     7   20 use Carp;
  7         7  
  7         271  
5 7     7   22 use base 'SDL::Rect';
  7         7  
  7         4579  
6              
7             our $VERSION = '0.01';
8              
9             sub new {
10 18     18 0 3899 my $class = shift;
11 18   100     66 my $x = shift || 0;
12 18   100     59 my $y = shift || 0;
13 18   100     51 my $w = shift || 0;
14 18   100     57 my $h = shift || 0;
15              
16 18   66     52 $class = ref($class) || $class;
17 18         104 my $self = $class->SUPER::new( $x, $y, $w, $h );
18 18 50       62 unless ($$self) {
19              
20             #require Carp;
21 0         0 Carp::confess SDL::get_error();
22             }
23 18         61 return bless $self, $class;
24             }
25              
26             #############################
27             ## extra accessors
28             #############################
29              
30             sub left {
31 44     44 0 711 my $self = shift;
32 44         122 $self->x(@_);
33             }
34              
35             sub top {
36 206     206 0 1213 my $self = shift;
37 206         610 $self->y(@_);
38             }
39              
40             sub width {
41 109     109 0 871 my $self = shift;
42 109         475 $self->w(@_);
43             }
44              
45             sub height {
46 279     279 0 754 my $self = shift;
47 279         1309 $self->h(@_);
48             }
49              
50             sub bottom {
51 5     5 0 989 my ( $self, $val ) = (@_);
52 5 100       14 if ( defined $val ) {
53 1         3 $self->top( $val - $self->height ); # y = val - height
54             }
55 5         10 return $self->top + $self->height; # y + height
56             }
57              
58             sub right {
59 5     5 0 326 my ( $self, $val ) = (@_);
60 5 100       12 if ( defined $val ) {
61 1         4 $self->left( $val - $self->width ); # x = val - width
62             }
63 5         13 return $self->left + $self->width; # x + width
64             }
65              
66             sub centerx {
67 8     8 0 352 my ( $self, $val ) = (@_);
68 8 100       16 if ( defined $val ) {
69 1         2 $self->left( $val - ( $self->width >> 1 ) ); # x = val - (width/2)
70             }
71 8         12 return $self->left + ( $self->width >> 1 ); # x + (width/2)
72             }
73              
74             sub centery {
75 93     93 0 845488 my ( $self, $val ) = (@_);
76 93 100       422 if ( defined $val ) {
77 82         318 $self->top( $val - ( $self->height >> 1 ) ); # y = val - (height/2)
78             }
79 93         228 return $self->top + ( $self->height >> 1 ); # y + (height/2)
80             }
81              
82             sub size {
83 81     81 0 659 my ( $self, $w, $h ) = (@_);
84              
85 81 50 33     283 return ( $self->width, $self->height ) # (width, height)
86             unless ( defined $w or defined $h );
87              
88 81 50       216 if ( defined $w ) {
89 81         190 $self->width($w); # width
90             }
91 81 50       157 if ( defined $h ) {
92 81         163 $self->height($h); # height
93             }
94             }
95              
96             sub topleft {
97 5     5 0 8 my ( $self, $y, $x ) = (@_);
98              
99 5 100 100     25 return ( $self->top, $self->left ) # (top, left)
100             unless ( defined $y or defined $x );
101              
102 3 100       4 if ( defined $x ) {
103 2         4 $self->left($x); # left
104             }
105 3 100       5 if ( defined $y ) {
106 2         4 $self->top($y); # top
107             }
108 3         4 return;
109             }
110              
111             sub midleft {
112 5     5 0 7 my ( $self, $centery, $x ) = (@_);
113              
114             return (
115 5 100 100     20 $self->top + ( $self->height >> 1 ),
116             $self->left
117             ) # (centery, left)
118             unless ( defined $centery or defined $x );
119              
120 3 100       5 if ( defined $x ) {
121 2         3 $self->left($x); # left
122             }
123 3 100       5 if ( defined $centery ) {
124 2         3 $self->top( $centery - ( $self->height >> 1 ) ); # y = centery - (height/2)
125             }
126 3         4 return;
127             }
128              
129             sub bottomleft {
130 0     0 0 0 my ( $self, $bottom, $x ) = (@_);
131              
132 0 0 0     0 return ( $self->top + $self->height, $self->left ) # (bottom, left)
133             unless ( defined $bottom or defined $x );
134              
135 0 0       0 if ( defined $x ) {
136 0         0 $self->left($x); # left
137             }
138 0 0       0 if ( defined $bottom ) {
139 0         0 $self->top( $bottom - $self->height ); # y = bottom - height
140             }
141 0         0 return;
142             }
143              
144             sub center {
145 5     5 0 7 my ( $self, $centerx, $centery ) = (@_);
146              
147             return (
148 5 100 100     18 $self->left + ( $self->width >> 1 ),
149             $self->top + ( $self->height >> 1 )
150             ) unless ( defined $centerx or defined $centery );
151              
152 3 100       6 if ( defined $centerx ) {
153 2         5 $self->left( $centerx - ( $self->width >> 1 ) ); # x = centerx - (width/2)
154             }
155 3 100       10 if ( defined $centery ) {
156 2         4 $self->top( $centery - ( $self->height >> 1 ) ); # y = centery - (height/2)
157             }
158 3         4 return;
159             }
160              
161             sub topright {
162 0     0 0 0 my ( $self, $y, $right ) = (@_);
163              
164 0 0 0     0 return ( $self->top, $self->left + $self->width ) # (top, right)
165             unless ( defined $y or defined $right );
166              
167 0 0       0 if ( defined $right ) {
168 0         0 $self->left( $right - $self->width ); # x = right - width
169             }
170 0 0       0 if ( defined $y ) {
171 0         0 $self->top($y); # top
172             }
173 0         0 return;
174             }
175              
176             sub midright {
177 0     0 0 0 my ( $self, $centery, $right ) = (@_);
178              
179             return (
180 0 0 0     0 $self->top + ( $self->height >> 1 ),
181             $self->left + $self->width
182             ) # (centery, right)
183             unless ( defined $centery or defined $right );
184              
185 0 0       0 if ( defined $right ) {
186 0         0 $self->left( $right - $self->width ); # x = right - width
187             }
188 0 0       0 if ( defined $centery ) {
189 0         0 $self->top( $centery - ( $self->height >> 1 ) ); # y = centery - (height/2)
190             }
191 0         0 return;
192             }
193              
194             sub bottomright {
195 0     0 0 0 my ( $self, $bottom, $right ) = (@_);
196              
197             return (
198 0 0 0     0 $self->top + $self->height,
199             $self->left + $self->width
200             ) # (bottom, right)
201             unless ( defined $bottom or defined $right );
202              
203 0 0       0 if ( defined $right ) {
204 0         0 $self->left( $right - $self->width ); # x = right - width
205             }
206 0 0       0 if ( defined $bottom ) {
207 0         0 $self->top( $bottom - $self->height ); # y = bottom - height
208             }
209 0         0 return;
210             }
211              
212             sub midtop {
213 0     0 0 0 my ( $self, $centerx, $y ) = (@_);
214              
215 0 0 0     0 return ( $self->left + ( $self->width >> 1 ), $self->top ) # (centerx, top)
216             unless ( defined $centerx or defined $y );
217              
218 0 0       0 if ( defined $y ) {
219 0         0 $self->top($y); # top
220             }
221 0 0       0 if ( defined $centerx ) {
222 0         0 $self->left( $centerx - ( $self->width >> 1 ) ); # x = centerx - (width/2)
223             }
224 0         0 return;
225             }
226              
227             sub midbottom {
228 0     0 0 0 my ( $self, $centerx, $bottom ) = (@_);
229              
230             return (
231 0 0 0     0 $self->left + ( $self->width >> 1 ),
232             $self->top + $self->height
233             ) # (centerx, bottom)
234             unless ( defined $centerx or defined $bottom );
235              
236 0 0       0 if ( defined $bottom ) {
237 0         0 $self->top( $bottom - $self->height ); # y = bottom - height
238             }
239 0 0       0 if ( defined $centerx ) {
240 0         0 $self->left( $centerx - ( $self->width >> 1 ) ); # x = centerx - (width/2)
241             }
242 0         0 return;
243             }
244              
245             ###############################
246             ## methods ##
247             ###############################
248              
249             {
250 7     7   29 no strict 'refs';
  7         10  
  7         12672  
251             *{'duplicate'} = *{copy};
252             }
253              
254             sub copy {
255 1     1 0 1 my $self = shift;
256 1         8 return $self->new(
257             $self->x,
258             $self->y,
259             $self->w,
260             $self->h,
261             );
262             }
263              
264             sub move {
265 1     1 0 1000 my ( $self, $x, $y ) = (@_);
266 1 50 33     10 if ( not defined $x or not defined $y ) {
267              
268             #require Carp;
269 0         0 Carp::confess "must receive x and y positions as argument";
270             }
271 1         4 return $self->new(
272             $self->left + $x,
273             $self->top + $y,
274             $self->width,
275             $self->height,
276             );
277             }
278              
279             sub move_ip {
280 0     0 0 0 my ( $self, $x, $y ) = (@_);
281 0 0 0     0 if ( not defined $x or not defined $y ) {
282              
283             #require Carp;
284 0         0 Carp::confess "must receive x and y positions as argument";
285             }
286 0         0 $self->x( $self->x + $x );
287 0         0 $self->y( $self->y + $y );
288              
289 0         0 return;
290             }
291              
292             sub inflate {
293 1     1 0 1014 my ( $self, $x, $y ) = (@_);
294 1 50 33     7 if ( not defined $x or not defined $y ) {
295              
296             #require Carp;
297 0         0 Carp::confess "must receive x and y positions as argument";
298             }
299              
300 1         2 return $self->new(
301             $self->left - ( $x / 2 ),
302             $self->top - ( $y / 2 ),
303             $self->width + $x,
304             $self->height + $y,
305             );
306             }
307              
308             sub inflate_ip {
309 0     0 0   my ( $self, $x, $y ) = (@_);
310 0 0 0       if ( not defined $x or not defined $y ) {
311              
312             #require Carp;
313 0           Carp::confess "must receive x and y positions as argument";
314             }
315              
316 0           $self->x( $self->x - ( $x / 2 ) );
317 0           $self->y( $self->y - ( $y / 2 ) );
318              
319 0           $self->w( $self->w + $x );
320 0           $self->h( $self->h + $y );
321             }
322              
323             sub _get_clamp_coordinates {
324 0     0     my ( $self_pos, $self_len, $rect_pos, $rect_len ) = (@_);
325              
326 0 0         if ( $self_len >= $rect_len ) {
    0          
    0          
327 0           return $rect_pos + ( $rect_len / 2 ) - ( $self_len / 2 );
328             } elsif ( $self_pos < $rect_pos ) {
329 0           return $rect_pos;
330             } elsif ( ( $self_pos + $self_len ) > ( $rect_pos + $rect_len ) ) {
331 0           return $rect_pos + $rect_len - $self_len;
332             } else {
333 0           return $self_pos;
334             }
335             }
336              
337             sub clamp {
338 0     0 0   my ( $self, $rect ) = (@_);
339              
340 0 0         unless ( $rect->isa('SDL::Rect') ) {
341 0           Carp::confess "must receive an SDL::Rect-based object";
342             }
343              
344 0           my $x = _get_clamp_coordinates( $self->x, $self->w, $rect->x, $rect->w );
345 0           my $y = _get_clamp_coordinates( $self->y, $self->h, $rect->y, $rect->h );
346              
347 0           return $self->new( $x, $y, $self->w, $self->h );
348             }
349              
350             sub clamp_ip {
351 0     0 0   my ( $self, $rect ) = (@_);
352              
353 0 0         unless ( $rect->isa('SDL::Rect') ) {
354 0           Carp::confess "must receive an SDL::Rect-based object";
355             }
356              
357 0           my $x = _get_clamp_coordinates( $self->x, $self->w, $rect->x, $rect->w );
358 0           my $y = _get_clamp_coordinates( $self->y, $self->h, $rect->y, $rect->h );
359              
360 0           $self->x($x);
361 0           $self->y($y);
362              
363 0           return;
364             }
365              
366             sub _get_intersection_coordinates {
367 0     0     my ( $self, $rect ) = (@_);
368 0           my ( $x, $y, $w, $h );
369              
370             INTERSECTION:
371             {
372             ### Left
373 0 0 0       if ( ( $self->x >= $rect->x )
  0 0 0        
374             && ( $self->x < ( $rect->x + $rect->w ) ) )
375             {
376 0           $x = $self->x;
377             } elsif ( ( $rect->x >= $self->x )
378             && ( $rect->x < ( $self->x + $self->w ) ) )
379             {
380 0           $x = $rect->x;
381             } else {
382 0           last INTERSECTION;
383             }
384              
385             ## Right
386 0 0 0       if ( ( ( $self->x + $self->w ) > $rect->x )
    0 0        
387             && ( ( $self->x + $self->w ) <= ( $rect->x + $rect->w ) ) )
388             {
389 0           $w = ( $self->x + $self->w ) - $x;
390             } elsif ( ( ( $rect->x + $rect->w ) > $self->x )
391             && ( ( $rect->x + $rect->w ) <= ( $self->x + $self->w ) ) )
392             {
393 0           $w = ( $rect->x + $rect->w ) - $x;
394             } else {
395 0           last INTERSECTION;
396             }
397              
398             ## Top
399 0 0 0       if ( ( $self->y >= $rect->y )
    0 0        
400             && ( $self->y < ( $rect->y + $rect->h ) ) )
401             {
402 0           $y = $self->y;
403             } elsif ( ( $rect->y >= $self->y )
404             && ( $rect->y < ( $self->y + $self->h ) ) )
405             {
406 0           $y = $rect->y;
407             } else {
408 0           last INTERSECTION;
409             }
410              
411             ## Bottom
412 0 0 0       if ( ( ( $self->y + $self->h ) > $rect->y )
    0 0        
413             && ( ( $self->y + $self->h ) <= ( $rect->y + $rect->h ) ) )
414             {
415 0           $h = ( $self->y + $self->h ) - $y;
416             } elsif ( ( ( $rect->y + $rect->h ) > $self->y )
417             && ( ( $rect->y + $rect->h ) <= ( $self->y + $self->h ) ) )
418             {
419 0           $h = ( $rect->y + $rect->h ) - $y;
420             } else {
421 0           last INTERSECTION;
422             }
423              
424 0           return ( $x, $y, $w, $h );
425             }
426              
427             # if we got here, the two rects do not intersect
428 0           return ( $self->x, $self->y, 0, 0 );
429              
430             }
431              
432             sub clip {
433 0     0 0   my ( $self, $rect ) = (@_);
434              
435 0 0         unless ( $rect->isa('SDL::Rect') ) {
436 0           Carp::confess "must receive an SDL::Rect-based object";
437             }
438              
439 0           my ( $x, $y, $w, $h ) = _get_intersection_coordinates( $self, $rect );
440              
441 0           return $self->new( $x, $y, $w, $h );
442             }
443              
444             sub clip_ip {
445 0     0 0   my ( $self, $rect ) = (@_);
446              
447 0 0         unless ( $rect->isa('SDL::Rect') ) {
448 0           Carp::confess "must receive an SDL::Rect-based object";
449             }
450              
451 0           my ( $x, $y, $w, $h ) = _get_intersection_coordinates( $self, $rect );
452              
453 0           $self->x($x);
454 0           $self->y($y);
455 0           $self->w($w);
456 0           $self->h($h);
457              
458 0           return;
459             }
460              
461             sub _test_union {
462 0     0     my ( $self, $rect ) = (@_);
463 0           my ( $x, $y, $w, $h );
464              
465 0 0         $x = $self->x < $rect->x ? $self->x : $rect->x; # MIN
466 0 0         $y = $self->y < $rect->y ? $self->y : $rect->y; # MIN
467              
468 0 0         $w =
469             ( $self->x + $self->w ) > ( $rect->x + $rect->w )
470             ? ( $self->x + $self->w ) - $x
471             : ( $rect->x + $rect->w ) - $x; # MAX
472              
473 0 0         $h =
474             ( $self->y + $self->h ) > ( $rect->y + $rect->h )
475             ? ( $self->y + $self->h ) - $y
476             : ( $rect->y + $rect->h ) - $y; # MAX
477              
478 0           return ( $x, $y, $w, $h );
479             }
480              
481             sub union {
482 0     0 0   my ( $self, $rect ) = (@_);
483              
484 0 0         unless ( $rect->isa('SDL::Rect') ) {
485 0           Carp::confess "must receive an SDL::Rect-based object";
486             }
487              
488 0           my ( $x, $y, $w, $h ) = _test_union( $self, $rect );
489 0           return $self->new( $x, $y, $w, $h );
490             }
491              
492             sub union_ip {
493 0     0 0   my ( $self, $rect ) = (@_);
494              
495 0 0         unless ( $rect->isa('SDL::Rect') ) {
496 0           Carp::confess "must receive an SDL::Rect-based object";
497             }
498              
499 0           my ( $x, $y, $w, $h ) = _test_union( $self, $rect );
500              
501 0           $self->x($x);
502 0           $self->y($y);
503 0           $self->w($w);
504 0           $self->y($h);
505              
506 0           return;
507             }
508              
509             sub _test_unionall {
510 0     0     my ( $self, $rects ) = (@_);
511              
512             # initial values for union rect
513 0           my $left = $self->x;
514 0           my $top = $self->y;
515 0           my $right = $self->x + $self->w;
516 0           my $bottom = $self->y + $self->h;
517              
518 0           foreach my $rect ( @{$rects} ) {
  0            
519 0 0         unless ( $rect->isa('SDL::Rect') ) {
520              
521             # TODO: better error message, maybe saying which item
522             # is the bad one (by list position)
523 0           Carp::confess "must receive an array reference of SDL::Rect-based objects";
524             }
525              
526 0 0         $left = $rect->x if $rect->x < $left; # MIN
527 0 0         $top = $rect->y if $rect->y < $top; # MIN
528 0 0         $right = ( $rect->x + $rect->w )
529             if ( $rect->x + $rect->w ) > $right; # MAX
530 0 0         $bottom = ( $rect->y + $rect->h )
531             if ( $rect->y + $rect->h ) > $bottom; # MAX
532             }
533              
534 0           return ( $left, $top, $right - $left, $bottom - $top );
535             }
536              
537             sub unionall {
538 0     0 0   my ( $self, $rects ) = (@_);
539              
540 0 0 0       unless ( defined $rects and ref $rects eq 'ARRAY' ) {
541 0           Carp::confess "must receive an array reference of SDL::Rect-based objects";
542             }
543              
544 0           my ( $x, $y, $w, $h ) = _test_unionall( $self, $rects );
545              
546 0           return $self->new( $x, $y, $w, $h );
547             }
548              
549             sub unionall_ip {
550 0     0 0   my ( $self, $rects ) = (@_);
551              
552 0 0 0       unless ( defined $rects and ref $rects eq 'ARRAY' ) {
553 0           Carp::confess "must receive an array reference of SDL::Rect-based objects";
554             }
555              
556 0           my ( $x, $y, $w, $h ) = _test_unionall( $self, $rects );
557              
558 0           $self->x($x);
559 0           $self->y($y);
560 0           $self->w($w);
561 0           $self->h($h);
562              
563 0           return;
564             }
565              
566             sub _check_fit {
567 0     0     my ( $self, $rect ) = (@_);
568              
569 0           my $x_ratio = $self->w / $rect->w;
570 0           my $y_ratio = $self->h / $rect->h;
571 0 0         my $max_ratio = ( $x_ratio > $y_ratio ) ? $x_ratio : $y_ratio;
572              
573 0           my $w = int( $self->w / $max_ratio );
574 0           my $h = int( $self->h / $max_ratio );
575              
576 0           my $x = $rect->x + int( ( $rect->w - $w ) / 2 );
577 0           my $y = $rect->y + int( ( $rect->h - $h ) / 2 );
578              
579 0           return ( $x, $y, $w, $h );
580             }
581              
582             sub fit {
583 0     0 0   my ( $self, $rect ) = (@_);
584              
585 0 0         unless ( $rect->isa('SDL::Rect') ) {
586 0           Carp::confess "must receive an SDL::Rect-based object";
587             }
588              
589 0           my ( $x, $y, $w, $h ) = _check_fit( $self, $rect );
590              
591 0           return $self->new( $x, $y, $w, $h );
592             }
593              
594             sub fit_ip {
595 0     0 0   my ( $self, $rect ) = (@_);
596              
597 0 0         unless ( $rect->isa('SDL::Rect') ) {
598 0           Carp::confess "must receive an SDL::Rect-based object";
599             }
600              
601 0           my ( $x, $y, $w, $h ) = _check_fit( $self, $rect );
602              
603 0           $self->x($x);
604 0           $self->y($y);
605 0           $self->w($w);
606 0           $self->h($h);
607              
608 0           return;
609             }
610              
611             sub normalize {
612 0     0 0   my $self = shift;
613              
614 0 0         if ( $self->w < 0 ) {
615 0           $self->x( $self->x + $self->w );
616 0           $self->w( -$self->w );
617             }
618              
619 0 0         if ( $self->h < 0 ) {
620 0           $self->y( $self->y + $self->h );
621 0           $self->h( -$self->h );
622             }
623 0           return;
624             }
625              
626             sub contains {
627 0     0 0   my ( $self, $rect ) = (@_);
628              
629 0 0         unless ( $rect->isa('SDL::Rect') ) {
630 0           Carp::confess "must receive an SDL::Rect-based object";
631             }
632              
633 0   0       my $contained =
634             ( $self->x <= $rect->x )
635             && ( $self->y <= $rect->y )
636             && ( $self->x + $self->w >= $rect->x + $rect->w )
637             && ( $self->y + $self->h >= $rect->y + $rect->h )
638             && ( $self->x + $self->w > $rect->x )
639             && ( $self->y + $self->h > $rect->y );
640              
641 0           return $contained;
642             }
643              
644             sub collidepoint {
645 0     0 0   my ( $self, $x, $y ) = (@_);
646              
647 0 0 0       unless ( defined $x and defined $y ) {
648 0           Carp::confess "must receive (x,y) as arguments";
649             }
650              
651 0   0       my $inside =
652             $x >= $self->x
653             && $x < $self->x + $self->w
654             && $y >= $self->y
655             && $y < $self->y + $self->h;
656              
657 0           return $inside;
658             }
659              
660             sub _do_rects_intersect {
661 0     0     my ( $rect_A, $rect_B ) = (@_);
662              
663             return (
664 0   0       ( $rect_A->x >= $rect_B->x && $rect_A->x < $rect_B->x + $rect_B->w ) || ( $rect_B->x >= $rect_A->x
665             && $rect_B->x < $rect_A->x + $rect_A->w )
666             )
667             && ( ( $rect_A->y >= $rect_B->y && $rect_A->y < $rect_B->y + $rect_B->h )
668             || ( $rect_B->y >= $rect_A->y && $rect_B->y < $rect_A->y + $rect_A->h ) );
669             }
670              
671             sub colliderect {
672 0     0 0   my ( $self, $rect ) = (@_);
673              
674 0 0         unless ( $rect->isa('SDL::Rect') ) {
675 0           Carp::confess "must receive an SDL::Rect-based object";
676             }
677              
678 0           return _do_rects_intersect( $self, $rect );
679             }
680              
681             sub collidelist {
682 0     0 0   my ( $self, $rects ) = (@_);
683              
684 0 0 0       unless ( defined $rects and ref $rects eq 'ARRAY' ) {
685 0           Carp::confess "must receive an array reference of SDL::Rect-based objects";
686             }
687              
688 0           for ( my $i = 0; $i < @{$rects}; $i++ ) {
  0            
689 0 0         if ( _do_rects_intersect( $self, $rects->[$i] ) ) {
690 0           return $i;
691             }
692             }
693 0           return;
694             }
695              
696             sub collidelistall {
697 0     0 0   my ( $self, $rects ) = (@_);
698              
699 0 0 0       unless ( defined $rects and ref $rects eq 'ARRAY' ) {
700 0           Carp::confess "must receive an array reference of SDL::Rect-based objects";
701             }
702              
703 0           my @collisions = ();
704 0           for ( my $i = 0; $i < @{$rects}; $i++ ) {
  0            
705 0 0         if ( _do_rects_intersect( $self, $rects->[$i] ) ) {
706 0           push @collisions, $i;
707             }
708             }
709 0           return \@collisions;
710             }
711              
712             sub collidehash {
713 0     0 0   my ( $self, $rects ) = (@_);
714              
715 0 0 0       unless ( defined $rects and ref $rects eq 'HASH' ) {
716 0           Carp::confess "must receive an hash reference of SDL::Rect-based objects";
717             }
718              
719 0           while ( my ( $key, $value ) = each %{$rects} ) {
  0            
720 0 0         unless ( $value->isa('SDL::Rect') ) {
721 0           Carp::confess "hash element of key '$key' is not an SDL::Rect-based object";
722             }
723              
724 0 0         if ( _do_rects_intersect( $self, $value ) ) {
725 0           return ( $key, $value );
726             }
727             }
728 0           return ( undef, undef );
729             }
730              
731             sub collidehashall {
732 0     0 0   my ( $self, $rects ) = (@_);
733              
734 0 0 0       unless ( defined $rects and ref $rects eq 'HASH' ) {
735 0           Carp::confess "must receive an hash reference of SDL::Rect-based objects";
736             }
737              
738 0           my %collisions = ();
739 0           while ( my ( $key, $value ) = each %{$rects} ) {
  0            
740 0 0         unless ( $value->isa('SDL::Rect') ) {
741 0           Carp::confess "hash element of key '$key' is not an SDL::Rect-based object";
742             }
743              
744 0 0         if ( _do_rects_intersect( $self, $value ) ) {
745 0           $collisions{$key} = $value;
746             }
747             }
748 0           return \%collisions;
749             }
750              
751             1; #NOT 42!
752