Skip to content

Easier way to obtain object bounds #301

@aleokdev

Description

@aleokdev

While refactoring my sokoban game to use this crate instead of my old fork, i realized a friction point that could be worked on.
Previously, to obtain an object's width or height, we could do the following:

object.width
object.height

However, since these members referred to deprecated members within the <object> tag, they were later removed. This means that to obtain the width/height of an object now, we need to match on the object's shape, check that it is an ellipse or rect, and obtain the width and height from there, something akin to:

let (width, height) = match object.shape {
    tiled::ObjectShape::Rect { width, height } | tiled::ObjectShape::Ellipse { width, height } => (width, height),
    _ => panic!(),
};

Doing this every time the user wants to obtain width/height of an object is a bit painful (and in this case also panics if the shape is anything but a rect or ellipse), so I propose a object.global_bounds() function of sorts that returns a rect including the position of the object as well as its actual width/height. I mean actual because previously width/height was not set for polygonal objects (since they are exclusively rect/ellipse members), but it could be useful to calculate them from the min/max point positions of the polygon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions