feat: mark some functions in bevy_math as const (#16439)

# Objective

Mark simple functions as const in `bevy_math`
https://github.com/bevyengine/bevy/issues/16124

## Solution

- Make them const

## Testing

`cargo test -p bevy_math --all-features`
This commit is contained in:
DAA 2024-11-22 19:26:47 +01:00 committed by GitHub
parent d82bbd8370
commit 7ff47a111f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -45,31 +45,31 @@ impl AspectRatio {
/// Returns the aspect ratio as a f32 value. /// Returns the aspect ratio as a f32 value.
#[inline] #[inline]
pub fn ratio(&self) -> f32 { pub const fn ratio(&self) -> f32 {
self.0 self.0
} }
/// Returns the inverse of this aspect ratio (height/width). /// Returns the inverse of this aspect ratio (height/width).
#[inline] #[inline]
pub fn inverse(&self) -> Self { pub const fn inverse(&self) -> Self {
Self(1.0 / self.0) Self(1.0 / self.0)
} }
/// Returns true if the aspect ratio represents a landscape orientation. /// Returns true if the aspect ratio represents a landscape orientation.
#[inline] #[inline]
pub fn is_landscape(&self) -> bool { pub const fn is_landscape(&self) -> bool {
self.0 > 1.0 self.0 > 1.0
} }
/// Returns true if the aspect ratio represents a portrait orientation. /// Returns true if the aspect ratio represents a portrait orientation.
#[inline] #[inline]
pub fn is_portrait(&self) -> bool { pub const fn is_portrait(&self) -> bool {
self.0 < 1.0 self.0 < 1.0
} }
/// Returns true if the aspect ratio is exactly square. /// Returns true if the aspect ratio is exactly square.
#[inline] #[inline]
pub fn is_square(&self) -> bool { pub const fn is_square(&self) -> bool {
self.0 == 1.0 self.0 == 1.0
} }
} }

View File

@ -350,7 +350,7 @@ impl Rot2 {
#[inline] #[inline]
#[must_use] #[must_use]
#[doc(alias = "conjugate")] #[doc(alias = "conjugate")]
pub fn inverse(self) -> Self { pub const fn inverse(self) -> Self {
Self { Self {
cos: self.cos, cos: self.cos,
sin: -self.sin, sin: -self.sin,