From: Breno G. de Oliveira Date: Sun, 4 Oct 2009 07:16:27 +0000 (-0300) Subject: implemented contains X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b6eea8bc8d821ff717eeb1c057248000a6f02a69;p=sdlgit%2FSDL_perl.git implemented contains --- diff --git a/lib/SDL/Game/Rect.pm b/lib/SDL/Game/Rect.pm index 01368f0..a74413f 100644 --- a/lib/SDL/Game/Rect.pm +++ b/lib/SDL/Game/Rect.pm @@ -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__