Math::Shape::Rectangle - an axis-aligned 2d rectangle
version 0.15
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
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);
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
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.
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);
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)) { ... }
David Farrell <dfarrell@cpan.org>
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.
To install Math::Shape::Vector, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::Shape::Vector
CPAN shell
perl -MCPAN -e shell install Math::Shape::Vector
For more information on module installation, please visit the detailed CPAN module installation guide.