bevyengine / bevyengine/bevy

Bevy has too many rectangle / box types

Open
#13,455 7 comments 0 reactions 0 assignees View on GitHub
A-Gizmos A-Math A-Rendering A-UI C-Code-Quality C-Usability S-Needs-Design X-Needs-SME
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

# Problem

In Bevy, there are currently:

1. https://dev-docs.bevyengine.org/bevy/a11y/accesskit/struct.Rect.html: f64, re-exported as part of our a11y work
2. https://dev-docs.bevyengine.org/bevy/math/struct.Rect.html: f32, used in UI
3. https://dev-docs.bevyengine.org/bevy/math/struct.URect.html: u32, used in UI
4. https://dev-docs.bevyengine.org/bevy/render/primitives/struct.Aabb.html: f32 3 dimensional axis-aligned bounding box, used in rendering
5. https://dev-docs.bevyengine.org/bevy/math/bounding/struct.Aabb2d.html: f32, 2 dimensional axis-aligned bounding box
6. https://dev-docs.bevyengine.org/bevy/math/bounding/struct.Aabb3d.html: f32, 3 dimensional axis-aligned bounding box
7. https://dev-docs.bevyengine.org/bevy/math/prelude/struct.Rectangle.html: f32, a mathematical primitive 2d shape w
8. https://dev-docs.bevyengine.org/bevy/math/prelude/struct.Cuboid.html: f32, a mathematical primitive 3d shape
9. https://dev-docs.bevyengine.org/bevy/ui/struct.UiRect.html: not a rectangle! Instead, used for things like padding

Please let me know if I've missed any.

We don't need this many distinct types for a rectangle! This results in user confusion, inconsistencies, duplicated API surfaces and more.

## Proposed changes

1. Don't re-export a11y types.
2. Eliminate bevy_render::Aabb in favor of the bevy_math types. Needs benchmarking.
3. Remove the `Rect` used by `bevy_ui` in favor of `Rectangle`.
4. Consider how we want to handle integer versions of geometric primitives and do so cohesively.
5. Investigate if we need distinct Aabb types, and if we do clearly document on them why just using a `Rectangle` or `Cuboid` isn't good enough.

Contributor guide

Open the contributing guide

Research direction

Start by comparing the listed types in bevy_a11y/accesskit, bevy_math, bevy_render/primitives, and bevy_ui, including their documented purposes and duplicated APIs. Investigate whether bevy_render::Aabb, the UI Rect, integer primitives, and the distinct Aabb types can be consolidated without losing required behavior; benchmark the proposed render change. Done means the type set is coherent, unnecessary re-exports or duplicates are removed, and remaining distinctions are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, game-dev
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.