Skip to content

Implement bounding boxes for SDL::Game::Rect #140

@kthakore

Description

@kthakore

The minimum bounding rectangle (MBR), also known as bounding box or envelope, is an expression of the maximum extents of a 2-dimensional object (e.g. point, line, polygon) within its 2-D (x, y) coordinate system, in other words min(x), max(x), min(y), max(y). The MBR is a 2-dimensional case of the minimum bounding box.

SDL::Game::Rect could have bounding values for coordinates and size. Something like:

$rect->min_x(0);
$rect->max_x(100);
$rect->min_height(3);
$rect->max_height(7);

they should probably be "paired" methods as well:

$rect->min_pos(0, 0); # x, y
$rect->max_pos(102, 109); # x, y

$rect->min_size(10, 18); # width, height
$rect->max_size(42, 42); # width, height

I don't like this API:

$rect->min_boundbox(2, 2, undef, 7); # x, y, w, h
$rect->max_boundbox(2, 2, undef, 7); # x, y, w, h

I like this one better (or something like that):

$rect->size_boundbox(2, 2, undef, 7); # min_w, min_h, max_w, max_h
$rect->pos_boundbox (2, 2, undef, 7); # min_x, min_y, max_w, max_h

There should also be a way to do this inside the constructor, something like:

my $rect = SDL::Game::Rect->new(
-top => 0,
-left => 0,
-width => 10,
-height => 10,
-min_x => 0,
-max_width => 42,
);

or something like that. Since there are several things to be done on SDL Perl before tackling this, just feel free to comment on the suggested API, or suggest your own while we're not there yet.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions