NAME
Math::Shape::Rectangle - an axis-aligned 2d rectangle
VERSION
version 0.15
METHODS
new
Constructor, requires 4 values: the x,y values for the origin and the x,y values for the size.
my $rectangle = Math::Shape::Rectangle->new(1, 1, 2, 4);
my $width = $rectangle->{size}->{x}; # 2
clamp
Takes a vector object and returns a new vector object whose x & y coordinates are "clamped" to the size of the rectangle. Requires a Math::Shape::Vector object as an argument.
my $clamped_vector = $rectangle->clamp($vector);
corner
Returns a Math::Shape::Vector object representing a corner point of the rectangle. Requires a number between 0 and 3.
my $corner = $rectangle->corner(2); # get the 3rd corner
separating_axis
Boolean method that returns 1 if the axis is outside of the rectangle, or 0 if not. Requires a Math::Shape::LineSegment object as an argument.
enlarge
Returns a new rectangle object increased to the size of a vector. Requires a Math::Shape::Vector object as an argument.
my $larger_rectangle = $rectangle->enlarge($vector);
collides
Boolean method returns 1 if the rectangle collides with another object, else returns 0. Requires another Math::Shape::Vector library object as an argument.
my $is_collision = $rectangle->collides($other_rectangle);
my $circle = Math::Shape::Circle->new(54, 19, 30);
if ($rectangle->collides($circle))
{
...
}
AUTHOR
David Farrell <dfarrell@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by David Farrell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.