Skip to content

Commit

Permalink
Move sprite::Rect into bevy_math (bevyengine#5686)
Browse files Browse the repository at this point in the history
# Objective

Promote the `Rect` utility of `sprite::Rect`, which defines a rectangle
by its minimum and maximum corners, to the `bevy_math` crate to make it
available as a general math type to all crates without the need to
depend on the `bevy_sprite` crate.

Fixes bevyengine#5575

## Solution

Move `sprite::Rect` into `bevy_math` and fix all uses.

Implement `Reflect` for `Rect` directly into the `bevy_reflect` crate by
having `bevy_reflect` depend on `bevy_math`. This looks like a new
dependency, but the `bevy_reflect` was "cheating" for other math types
by directly depending on `glam` to reflect other math types, thereby
giving the illusion that there was no dependency on `bevy_math`. In
practice conceptually Bevy's math types are reflected into the
`bevy_reflect` crate to avoid a dependency of that crate to a "lower
level" utility crate like `bevy_math` (which in turn would make
`bevy_reflect` be a dependency of most other crates, and increase the
risk of circular dependencies). So this change simply formalizes that
dependency in `Cargo.toml`.

The `Rect` struct is also augmented in this change with a collection of
utility methods to improve its usability. A few uses cases are updated
to use those new methods, resulting is more clear and concise syntax.

---

## Changelog

### Changed

- Moved the `sprite::Rect` type into `bevy_math`.

### Added

- Added several utility methods to the `math::Rect` type.

## Migration Guide

The `bevy::sprite::Rect` type moved to the math utility crate as
`bevy::math::Rect`. You should change your imports from `use
bevy::sprite::Rect` to `use bevy::math::Rect`.
  • Loading branch information
djeedai authored and ItsDoot committed Feb 1, 2023
1 parent b0025d8 commit b81ee7d
Show file tree
Hide file tree
Showing 15 changed files with 485 additions and 81 deletions.
1 change: 1 addition & 0 deletions crates/bevy_math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ keywords = ["bevy"]

[dependencies]
glam = { version = "0.21", features = ["serde", "bytemuck"] }
serde = "1"
8 changes: 6 additions & 2 deletions crates/bevy_math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
#![warn(missing_docs)]

mod rect;

pub use rect::Rect;

/// The `bevy_math` prelude.
pub mod prelude {
#[doc(hidden)]
pub use crate::{
BVec2, BVec3, BVec4, EulerRot, IVec2, IVec3, IVec4, Mat2, Mat3, Mat4, Quat, UVec2, UVec3,
UVec4, Vec2, Vec3, Vec4,
BVec2, BVec3, BVec4, EulerRot, IVec2, IVec3, IVec4, Mat2, Mat3, Mat4, Quat, Rect, UVec2,
UVec3, UVec4, Vec2, Vec3, Vec4,
};
}

Expand Down
Loading

0 comments on commit b81ee7d

Please sign in to comment.