implemented contains
Breno G. de Oliveira [Sun, 4 Oct 2009 07:16:27 +0000 (04:16 -0300)]
lib/SDL/Game/Rect.pm

index 01368f0..a74413f 100644 (file)
@@ -572,6 +572,23 @@ sub normalize {
     return;
 }
 
+sub contains {
+    my ($self, $rect) = (@_);
+    
+    unless ($rect->isa('SDL::Rect')) {
+        croak "must receive an SDL::Rect-based object";
+    }
+    
+    my $contained = ($self->x <= $rect->x) 
+                 && ($self->y <= $rect->y) 
+                 && ($self->x + $self->w >= $rect->x + $rect->w) 
+                 && ($self->y + $self->h >= $rect->y + $rect->h) 
+                 && ($self->x + $self->w > $rect->x) 
+                 && ($self->y + $self->h > $rect->y)
+                 ;
+                 
+    return $contained;
+}
 
 42;
 __END__