Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_math/src/bounding/bounded2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ pub struct BoundingCircle {
impl BoundingCircle {
/// Constructs a bounding circle from its center and radius.
#[inline]
pub fn new(center: Vec2, radius: f32) -> Self {
pub const fn new(center: Vec2, radius: f32) -> Self {
debug_assert!(radius >= 0.);
Self {
center,
Expand Down Expand Up @@ -525,7 +525,7 @@ impl BoundingCircle {

/// Get the radius of the bounding circle
#[inline]
pub fn radius(&self) -> f32 {
pub const fn radius(&self) -> f32 {
self.circle.radius
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/bounding/bounded3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl BoundingSphere {

/// Get the radius of the bounding sphere
#[inline]
pub fn radius(&self) -> f32 {
pub const fn radius(&self) -> f32 {
self.sphere.radius
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/bounding/raycast2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl RayCast2d {
}

/// Get the cached multiplicative inverse of the direction of the ray.
pub fn direction_recip(&self) -> Vec2 {
pub const fn direction_recip(&self) -> Vec2 {
self.direction_recip
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/bounding/raycast3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl RayCast3d {
}

/// Get the cached multiplicative inverse of the direction of the ray.
pub fn direction_recip(&self) -> Vec3A {
pub const fn direction_recip(&self) -> Vec3A {
self.direction_recip
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_math/src/cubic_splines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<P: VectorSpace> CubicHermite<P> {
/// combination of `p_i`, `v_i`, `p_{i+1}`, and `v_{i+1}`, where `(p_i, v_i)` and
/// `(p_{i+1}, v_{i+1})` are consecutive control points with tangents.
#[inline]
fn char_matrix(&self) -> [[f32; 4]; 4] {
const fn char_matrix(&self) -> [[f32; 4]; 4] {
[
[1., 0., 0., 0.],
[0., 1., 0., 0.],
Expand Down Expand Up @@ -300,7 +300,7 @@ impl<P: VectorSpace> CubicCardinalSpline<P> {
/// Each row of this matrix expresses the coefficients of a [`CubicSegment`] as a linear
/// combination of four consecutive control points.
#[inline]
fn char_matrix(&self) -> [[f32; 4]; 4] {
const fn char_matrix(&self) -> [[f32; 4]; 4] {
let s = self.tension;
[
[0., 1., 0., 0.],
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/curve/adaptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
{
/// Create a constant curve, which has the given `domain` and always produces the given `value`
/// when sampled.
pub fn new(domain: Interval, value: T) -> Self {
pub const fn new(domain: Interval, value: T) -> Self {
Self { domain, value }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/curve/cores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ impl<T> ChunkedUnevenCore<T> {

/// The sample width: the number of values that are contained in each sample.
#[inline]
pub fn width(&self) -> usize {
pub const fn width(&self) -> usize {
self.values.len() / self.times.len()
}

Expand Down
28 changes: 14 additions & 14 deletions crates/bevy_math/src/curve/easing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<T> EasingCurve<T> {
///
/// [the unit interval]: Interval::UNIT
/// [ease function]: EaseFunction
pub fn new(start: T, end: T, ease_fn: EaseFunction) -> Self {
pub const fn new(start: T, end: T, ease_fn: EaseFunction) -> Self {
Self {
start,
end,
Expand Down Expand Up @@ -1050,7 +1050,7 @@ mod easing_functions {
use crate::{ops, FloatPow};

#[inline]
pub(crate) fn linear(t: f32) -> f32 {
pub(crate) const fn linear(t: f32) -> f32 {
t
}

Expand Down Expand Up @@ -1089,15 +1089,15 @@ mod easing_functions {
}

#[inline]
pub(crate) fn quartic_in(t: f32) -> f32 {
pub(crate) const fn quartic_in(t: f32) -> f32 {
t * t * t * t
}
#[inline]
pub(crate) fn quartic_out(t: f32) -> f32 {
pub(crate) const fn quartic_out(t: f32) -> f32 {
1.0 - (1.0 - t) * (1.0 - t) * (1.0 - t) * (1.0 - t)
}
#[inline]
pub(crate) fn quartic_in_out(t: f32) -> f32 {
pub(crate) const fn quartic_in_out(t: f32) -> f32 {
if t < 0.5 {
8.0 * t * t * t * t
} else {
Expand All @@ -1106,15 +1106,15 @@ mod easing_functions {
}

#[inline]
pub(crate) fn quintic_in(t: f32) -> f32 {
pub(crate) const fn quintic_in(t: f32) -> f32 {
t * t * t * t * t
}
#[inline]
pub(crate) fn quintic_out(t: f32) -> f32 {
pub(crate) const fn quintic_out(t: f32) -> f32 {
1.0 - (1.0 - t) * (1.0 - t) * (1.0 - t) * (1.0 - t) * (1.0 - t)
}
#[inline]
pub(crate) fn quintic_in_out(t: f32) -> f32 {
pub(crate) const fn quintic_in_out(t: f32) -> f32 {
if t < 0.5 {
16.0 * t * t * t * t * t
} else {
Expand All @@ -1128,32 +1128,32 @@ mod easing_functions {
}

#[inline]
pub(crate) fn smoothstep_in(t: f32) -> f32 {
pub(crate) const fn smoothstep_in(t: f32) -> f32 {
((1.5 - 0.5 * t) * t) * t
}

#[inline]
pub(crate) fn smoothstep_out(t: f32) -> f32 {
pub(crate) const fn smoothstep_out(t: f32) -> f32 {
(1.5 + (-0.5 * t) * t) * t
}

#[inline]
pub(crate) fn smoothstep(t: f32) -> f32 {
pub(crate) const fn smoothstep(t: f32) -> f32 {
((3.0 - 2.0 * t) * t) * t
}

#[inline]
pub(crate) fn smootherstep_in(t: f32) -> f32 {
pub(crate) const fn smootherstep_in(t: f32) -> f32 {
(((2.5 + (-1.875 + 0.375 * t) * t) * t) * t) * t
}

#[inline]
pub(crate) fn smootherstep_out(t: f32) -> f32 {
pub(crate) const fn smootherstep_out(t: f32) -> f32 {
(1.875 + ((-1.25 + (0.375 * t) * t) * t) * t) * t
}

#[inline]
pub(crate) fn smootherstep(t: f32) -> f32 {
pub(crate) const fn smootherstep(t: f32) -> f32 {
(((10.0 + (-15.0 + 6.0 * t) * t) * t) * t) * t
}

Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_math/src/curve/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ impl Interval {
/// Get the linear function which maps this interval onto the `other` one. Returns an error if either
/// interval is unbounded.
#[inline]
pub(super) fn linear_map_to(self, other: Self) -> Result<impl Fn(f32) -> f32, LinearMapError> {
pub(super) const fn linear_map_to(
self,
other: Self,
) -> Result<impl Fn(f32) -> f32, LinearMapError> {
if !self.is_bounded() {
return Err(LinearMapError::SourceUnbounded);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum InvalidDirectionError {

impl InvalidDirectionError {
/// Creates an [`InvalidDirectionError`] from the length of an invalid direction vector.
pub fn from_length(length: f32) -> Self {
pub const fn from_length(length: f32) -> Self {
if length.is_nan() {
InvalidDirectionError::NaN
} else if !length.is_finite() {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_math/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ mod std_ops_for_no_std {
///
/// This function always returns the precise result.
#[inline]
pub fn abs(x: f32) -> f32 {
pub const fn abs(x: f32) -> f32 {
f32::abs(x)
}

Expand All @@ -569,39 +569,39 @@ mod std_ops_for_no_std {
/// `NaN`, then a `NaN` with the sign bit of `y` is returned. Note, however, that conserving the
/// sign bit on `NaN` across arithmetical operations is not generally guaranteed.
#[inline]
pub fn copysign(x: f32, y: f32) -> f32 {
pub const fn copysign(x: f32, y: f32) -> f32 {
f32::copysign(x, y)
}

/// Returns the nearest integer to `x`. If a value is half-way between two integers, round away from `0.0`.
///
/// This function always returns the precise result.
#[inline]
pub fn round(x: f32) -> f32 {
pub const fn round(x: f32) -> f32 {
f32::round(x)
}

/// Returns the largest integer less than or equal to `x`.
///
/// This function always returns the precise result.
#[inline]
pub fn floor(x: f32) -> f32 {
pub const fn floor(x: f32) -> f32 {
f32::floor(x)
}

/// Returns the smallest integer greater than or equal to `x`.
///
/// This function always returns the precise result.
#[inline]
pub fn ceil(x: f32) -> f32 {
pub const fn ceil(x: f32) -> f32 {
f32::ceil(x)
}

/// Returns the fractional part of `x`.
///
/// This function always returns the precise result.
#[inline]
pub fn fract(x: f32) -> f32 {
pub const fn fract(x: f32) -> f32 {
f32::fract(x)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_math/src/primitives/dim2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ impl Segment2d {

/// Reverses the direction of the line segment by swapping the endpoints.
#[inline]
pub fn reverse(&mut self) {
pub const fn reverse(&mut self) {
let [point1, point2] = &mut self.vertices;
core::mem::swap(point1, point2);
}
Expand Down Expand Up @@ -1759,7 +1759,7 @@ impl Triangle2d {
/// Reverse the [`WindingOrder`] of the triangle
/// by swapping the first and last vertices.
#[inline]
pub fn reverse(&mut self) {
pub const fn reverse(&mut self) {
self.vertices.swap(0, 2);
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_math/src/primitives/dim3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl Segment3d {

/// Reverses the direction of the line segment by swapping the endpoints.
#[inline]
pub fn reverse(&mut self) {
pub const fn reverse(&mut self) {
let [point1, point2] = &mut self.vertices;
core::mem::swap(point1, point2);
}
Expand Down Expand Up @@ -1338,14 +1338,14 @@ impl Triangle3d {

/// Reverse the triangle by swapping the first and last vertices.
#[inline]
pub fn reverse(&mut self) {
pub const fn reverse(&mut self) {
self.vertices.swap(0, 2);
}

/// This triangle but reversed.
#[inline]
#[must_use]
pub fn reversed(mut self) -> Triangle3d {
pub const fn reversed(mut self) -> Triangle3d {
self.reverse();
self
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/primitives/half_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl HalfSpace {
/// Returns the bisecting plane's unit normal vector and the signed distance
/// from the plane to the origin.
#[inline]
pub fn normal_d(&self) -> Vec4 {
pub const fn normal_d(&self) -> Vec4 {
self.normal_d
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/src/primitives/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct SweepLineEvent {

#[cfg(feature = "alloc")]
impl SweepLineEvent {
fn position(&self) -> Vec2 {
const fn position(&self) -> Vec2 {
match self.endpoint {
Endpoint::Left => self.segment.left,
Endpoint::Right => self.segment.right,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_math/src/rects/irect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl IRect {
/// assert_eq!(r.width(), 5);
/// ```
#[inline]
pub fn width(&self) -> i32 {
pub const fn width(&self) -> i32 {
self.max.x - self.min.x
}

Expand All @@ -170,7 +170,7 @@ impl IRect {
/// assert_eq!(r.height(), 1);
/// ```
#[inline]
pub fn height(&self) -> i32 {
pub const fn height(&self) -> i32 {
self.max.y - self.min.y
}

Expand Down
Loading