Skip to content

Commit

Permalink
feat: mark some functions in bevy_math as const (#16439)
Browse files Browse the repository at this point in the history
# Objective

Mark simple functions as const in `bevy_math`
#16124

## Solution

- Make them const

## Testing

`cargo test -p bevy_math --all-features`
  • Loading branch information
DaAlbrecht authored Nov 22, 2024
1 parent d82bbd8 commit 7ff47a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions crates/bevy_math/src/aspect_ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,31 @@ impl AspectRatio {

/// Returns the aspect ratio as a f32 value.
#[inline]
pub fn ratio(&self) -> f32 {
pub const fn ratio(&self) -> f32 {
self.0
}

/// Returns the inverse of this aspect ratio (height/width).
#[inline]
pub fn inverse(&self) -> Self {
pub const fn inverse(&self) -> Self {
Self(1.0 / self.0)
}

/// Returns true if the aspect ratio represents a landscape orientation.
#[inline]
pub fn is_landscape(&self) -> bool {
pub const fn is_landscape(&self) -> bool {
self.0 > 1.0
}

/// Returns true if the aspect ratio represents a portrait orientation.
#[inline]
pub fn is_portrait(&self) -> bool {
pub const fn is_portrait(&self) -> bool {
self.0 < 1.0
}

/// Returns true if the aspect ratio is exactly square.
#[inline]
pub fn is_square(&self) -> bool {
pub const fn is_square(&self) -> bool {
self.0 == 1.0
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/rotation2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl Rot2 {
#[inline]
#[must_use]
#[doc(alias = "conjugate")]
pub fn inverse(self) -> Self {
pub const fn inverse(self) -> Self {
Self {
cos: self.cos,
sin: -self.sin,
Expand Down

0 comments on commit 7ff47a1

Please sign in to comment.