From 56ac25fd75ddc858a2c5e6df49a949c835a02e56 Mon Sep 17 00:00:00 2001 From: Talin Date: Wed, 22 Oct 2025 20:27:31 -0700 Subject: [PATCH 01/10] Implement `TryStableInterpolate`. Fixes: #20579 --- crates/bevy_color/src/color.rs | 19 ++++++ crates/bevy_math/src/common_traits.rs | 64 ++++++++++++++++++- crates/bevy_ui/src/geometry.rs | 24 ++++++- .../release-notes/fallible_interpolation.md | 26 ++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 release-content/release-notes/fallible_interpolation.md diff --git a/crates/bevy_color/src/color.rs b/crates/bevy_color/src/color.rs index 832394449bc4f..5c91ecf0e5f77 100644 --- a/crates/bevy_color/src/color.rs +++ b/crates/bevy_color/src/color.rs @@ -2,6 +2,7 @@ use crate::{ color_difference::EuclideanDistance, Alpha, Hsla, Hsva, Hue, Hwba, Laba, Lcha, LinearRgba, Luminance, Mix, Oklaba, Oklcha, Saturation, Srgba, StandardColor, Xyza, }; +use bevy_math::{InterpolationError, TryStableInterpolate}; #[cfg(feature = "bevy_reflect")] use bevy_reflect::prelude::*; use derive_more::derive::From; @@ -889,3 +890,21 @@ impl EuclideanDistance for Color { } } } + +impl TryStableInterpolate for Color { + fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { + match (self, other) { + (Color::Srgba(a), Color::Srgba(b)) => Ok(Color::Srgba(a.mix(b, t))), + (Color::LinearRgba(a), Color::LinearRgba(b)) => Ok(Color::LinearRgba(a.mix(b, t))), + (Color::Hsla(a), Color::Hsla(b)) => Ok(Color::Hsla(a.mix(b, t))), + (Color::Hsva(a), Color::Hsva(b)) => Ok(Color::Hsva(a.mix(b, t))), + (Color::Hwba(a), Color::Hwba(b)) => Ok(Color::Hwba(a.mix(b, t))), + (Color::Laba(a), Color::Laba(b)) => Ok(Color::Laba(a.mix(b, t))), + (Color::Lcha(a), Color::Lcha(b)) => Ok(Color::Lcha(a.mix(b, t))), + (Color::Oklaba(a), Color::Oklaba(b)) => Ok(Color::Oklaba(a.mix(b, t))), + (Color::Oklcha(a), Color::Oklcha(b)) => Ok(Color::Oklcha(a.mix(b, t))), + (Color::Xyza(a), Color::Xyza(b)) => Ok(Color::Xyza(a.mix(b, t))), + _ => Err(InterpolationError::MismatchedUnits), + } + } +} diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index b249b34618ae9..dc7288399593a 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -396,7 +396,7 @@ impl NormedVectorSpace for f64 { /// ```text /// top curve = u.interpolate_stable(v, t) /// -/// t0 => p t1 => q +/// t0 => p t1 => q /// |-------------|---------|-------------| /// 0 => u / \ 1 => v /// / \ @@ -538,6 +538,68 @@ all_tuples_enumerated!( T ); +/// Why the interpolation failed. +#[derive(Clone, Debug)] +pub enum InterpolationError { + /// The values to be interpolated are not in the same units. + MismatchedUnits, + /// Data type cannot be interpolated because it is not contiguous + NonContiguous, +} + +/// A trait that indicates that a value _may_ be interpolable via [`StableInterpolate`]. An +/// interpolation may fail if the values have different units - for example, attempting to +/// interpolate between [`Val::Px`] and [`Val::Percent`] will fail, +/// even though they are the same Rust type. +/// +/// The motivating case for this trait is animating UI entities with [`Val`] +/// properties, which, because they are enums, cannot be interpolated in the normal way. This same +/// concept can be extended to other types as well. +/// +/// Fallible interpolation can be used for animated transitions, which can be set up to fail +/// gracefully if there's a mismatch of units. For example, the a transition could smoothly +/// go from `Val::Px(10)` to `Val::Px(20)`, but if the user attempts to go from `Val::Px(10)` to +/// `Val::Percent(10)`, the animation player can detect the failure and simply snap to the new +/// value without interpolating. +/// +/// An animation clip system can incorporate fallible interpolation to support a broad set of +/// sequenced parameter values. This can include numeric types, which always interpolate, +/// enum types, which may or may not interpolate depending on the units, and non-interpolable +/// types, which always jump immediately to the new value without interpolation. This meaas, for +/// example, that you can have an animation track whose value type is a boolean or a string. +/// +/// Interpolation for simple number and coordinate types will always succeed, as will any type +/// that implements [`StableInterpolate`]. Types which have different variants such as +/// [`Val`] and [`Color`] will only fail if the units are different. +/// Note that [`Color`] has its own, non-fallible mixing methods, but those entail +/// automatically converting between different color spaces, and is both expensive and complex. +/// [`TryStableInterpolate`] is more conservative, and doesn't automatically convert between +/// color spaces. This produces a color interpolation that is has more predictable performance. +/// +/// [`Val::Px`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html +/// [`Val::Percent`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html +/// [`Val`]: https://docs.rs/bevy/latest/bevy/ui/struct.enum.html +/// [`Color`]: https://docs.rs/bevy/latest/bevy/color/enum.Color.html +pub trait TryStableInterpolate: Clone { + /// Attempt to interpolate the value. This may fail if the two interpolation values have + /// different units, or if the type is not interpolable. + fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result; +} + +impl TryStableInterpolate for T { + fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { + Ok(self.interpolate_stable(other, t)) + } +} + +/// Boolean values can never be interpolated, but they can be animatable parameters (for things +/// like enabling and disabling lighting). +impl TryStableInterpolate for bool { + fn try_interpolate_stable(&self, _other: &Self, _t: f32) -> Result { + Err(InterpolationError::NonContiguous) + } +} + /// A type that has tangents. pub trait HasTangent { /// The tangent type. diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 36296e748fa9f..3f37c87da0c90 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -1,4 +1,4 @@ -use bevy_math::Vec2; +use bevy_math::{InterpolationError, StableInterpolate as _, TryStableInterpolate, Vec2}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_utils::default; use core::ops::{Div, DivAssign, Mul, MulAssign, Neg}; @@ -418,6 +418,28 @@ impl Val { } } +impl TryStableInterpolate for Val { + /// # Example + /// + /// ``` + /// # use bevy_ui::Val; + /// # use bevy_math::TryStableInterpolate; + /// assert!(matches!(Val::Px(0.0).try_interpolate_stable(&Val::Px(10.0), 0.5), Ok(Val::Px(5.0)))); + /// ``` + fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { + match (self, other) { + (Val::Px(a), Val::Px(b)) => Ok(Val::Px(a.interpolate_stable(b, t))), + (Val::Percent(a), Val::Percent(b)) => Ok(Val::Percent(a.interpolate_stable(b, t))), + (Val::Vw(a), Val::Vw(b)) => Ok(Val::Vw(a.interpolate_stable(b, t))), + (Val::Vh(a), Val::Vh(b)) => Ok(Val::Vh(a.interpolate_stable(b, t))), + (Val::VMin(a), Val::VMin(b)) => Ok(Val::VMin(a.interpolate_stable(b, t))), + (Val::VMax(a), Val::VMax(b)) => Ok(Val::VMax(a.interpolate_stable(b, t))), + (Val::Auto, Val::Auto) => Ok(Val::Auto), + _ => Err(InterpolationError::MismatchedUnits), + } + } +} + /// All the types that should be able to be used in the [`Val`] enum should implement this trait. /// /// Instead of just implementing `Into` a custom trait is added. diff --git a/release-content/release-notes/fallible_interpolation.md b/release-content/release-notes/fallible_interpolation.md new file mode 100644 index 0000000000000..ed55e47b52aab --- /dev/null +++ b/release-content/release-notes/fallible_interpolation.md @@ -0,0 +1,26 @@ +--- +title: Fallible Interpolation +authors: ["@viridia"] +pull_requests: [] +--- + +## Fallible Interpolation + +The `StableInterpolate` trait is great, but sadly there's one important type that it doesn't work +with: The `Val` type from `bevy_ui`. The reason is that `Val` is an enum, representing different +length units such as pixels and percentages, and it's not generally possible or even meaningful to +try and interpolate between different units. + +However, the use cases for wanting to animate `Val` don't require mixing units: often we just want +to slide or stretch the length of a widget such as a toggle switch. We can do this so long as we +check at runtime that both interpolation control points are in the same units. + +The new `TryStableInterpolate` trait introduces the idea of interpolation that can fail, by returning +a `Result`. Note that "failure" in this case is not necessarily bad: it just means that the +animation player will need to modify the parameter in some other way, such as "snapping" or +"jumping" to the new keyframe without smoothly interpolating. This lets us create complex animations +that incorporate both kinds of parameters: ones that interpolate, and ones that don't. + +There's a blanket implementation of `TryStableInterpolate` for all types that impl +`StableInterpolate`, and these can never fail. There are additional impls for `Color` and `Val` +which can fail if the control points are not in the same units / color space. From d5d866cdfd8dcf74d875d8dadff6a3b2f2d8cdc7 Mon Sep 17 00:00:00 2001 From: Talin Date: Wed, 22 Oct 2025 20:39:04 -0700 Subject: [PATCH 02/10] Add PR number. --- release-content/release-notes/fallible_interpolation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release-content/release-notes/fallible_interpolation.md b/release-content/release-notes/fallible_interpolation.md index ed55e47b52aab..4d7674c5ec54b 100644 --- a/release-content/release-notes/fallible_interpolation.md +++ b/release-content/release-notes/fallible_interpolation.md @@ -1,7 +1,7 @@ --- title: Fallible Interpolation authors: ["@viridia"] -pull_requests: [] +pull_requests: [21633] --- ## Fallible Interpolation From 232e58244737c3b7117c2eae881a63c64f24f2c8 Mon Sep 17 00:00:00 2001 From: Talin Date: Sat, 25 Oct 2025 21:40:00 -0700 Subject: [PATCH 03/10] Remove impl TryStableInterpolate for bool. Simplify errors. --- crates/bevy_math/src/common_traits.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index dc7288399593a..415d9ebac6fc3 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -543,8 +543,6 @@ all_tuples_enumerated!( pub enum InterpolationError { /// The values to be interpolated are not in the same units. MismatchedUnits, - /// Data type cannot be interpolated because it is not contiguous - NonContiguous, } /// A trait that indicates that a value _may_ be interpolable via [`StableInterpolate`]. An @@ -592,14 +590,6 @@ impl TryStableInterpolate for T { } } -/// Boolean values can never be interpolated, but they can be animatable parameters (for things -/// like enabling and disabling lighting). -impl TryStableInterpolate for bool { - fn try_interpolate_stable(&self, _other: &Self, _t: f32) -> Result { - Err(InterpolationError::NonContiguous) - } -} - /// A type that has tangents. pub trait HasTangent { /// The tangent type. From 6922c602829d0538fe676d0507ada3196cd7f6ca Mon Sep 17 00:00:00 2001 From: Talin Date: Tue, 28 Oct 2025 02:05:44 -0700 Subject: [PATCH 04/10] Review feedback. --- crates/bevy_math/src/common_traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index 415d9ebac6fc3..cc961ff56386c 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -572,7 +572,7 @@ pub enum InterpolationError { /// Note that [`Color`] has its own, non-fallible mixing methods, but those entail /// automatically converting between different color spaces, and is both expensive and complex. /// [`TryStableInterpolate`] is more conservative, and doesn't automatically convert between -/// color spaces. This produces a color interpolation that is has more predictable performance. +/// color spaces. This produces a color interpolation that has more predictable performance. /// /// [`Val::Px`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html /// [`Val::Percent`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html From 53332361131e1249622c27c950531fe5e0a93698 Mon Sep 17 00:00:00 2001 From: Talin Date: Wed, 29 Oct 2025 03:07:39 -0700 Subject: [PATCH 05/10] Made TryStableInterpolate::Error an associated type. --- crates/bevy_color/src/color.rs | 8 +++++--- crates/bevy_math/src/common_traits.rs | 16 +++++++++------- crates/bevy_ui/src/geometry.rs | 8 +++++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/crates/bevy_color/src/color.rs b/crates/bevy_color/src/color.rs index 5c91ecf0e5f77..b28f2ca05e3d7 100644 --- a/crates/bevy_color/src/color.rs +++ b/crates/bevy_color/src/color.rs @@ -2,7 +2,7 @@ use crate::{ color_difference::EuclideanDistance, Alpha, Hsla, Hsva, Hue, Hwba, Laba, Lcha, LinearRgba, Luminance, Mix, Oklaba, Oklcha, Saturation, Srgba, StandardColor, Xyza, }; -use bevy_math::{InterpolationError, TryStableInterpolate}; +use bevy_math::{MismatchedUnitsError, TryStableInterpolate}; #[cfg(feature = "bevy_reflect")] use bevy_reflect::prelude::*; use derive_more::derive::From; @@ -892,7 +892,9 @@ impl EuclideanDistance for Color { } impl TryStableInterpolate for Color { - fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { + type Error = MismatchedUnitsError; + + fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { match (self, other) { (Color::Srgba(a), Color::Srgba(b)) => Ok(Color::Srgba(a.mix(b, t))), (Color::LinearRgba(a), Color::LinearRgba(b)) => Ok(Color::LinearRgba(a.mix(b, t))), @@ -904,7 +906,7 @@ impl TryStableInterpolate for Color { (Color::Oklaba(a), Color::Oklaba(b)) => Ok(Color::Oklaba(a.mix(b, t))), (Color::Oklcha(a), Color::Oklcha(b)) => Ok(Color::Oklcha(a.mix(b, t))), (Color::Xyza(a), Color::Xyza(b)) => Ok(Color::Xyza(a.mix(b, t))), - _ => Err(InterpolationError::MismatchedUnits), + _ => Err(MismatchedUnitsError), } } } diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index cc961ff56386c..68d9c9a8748b2 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -2,6 +2,7 @@ use crate::{ops, DVec2, DVec3, DVec4, Dir2, Dir3, Dir3A, Quat, Rot2, Vec2, Vec3, Vec3A, Vec4}; use core::{ + convert::Infallible, fmt::Debug, ops::{Add, Div, Mul, Neg, Sub}, }; @@ -538,12 +539,9 @@ all_tuples_enumerated!( T ); -/// Why the interpolation failed. +/// Error produced when the values to be interpolated are not in the same units. #[derive(Clone, Debug)] -pub enum InterpolationError { - /// The values to be interpolated are not in the same units. - MismatchedUnits, -} +pub struct MismatchedUnitsError; /// A trait that indicates that a value _may_ be interpolable via [`StableInterpolate`]. An /// interpolation may fail if the values have different units - for example, attempting to @@ -579,13 +577,17 @@ pub enum InterpolationError { /// [`Val`]: https://docs.rs/bevy/latest/bevy/ui/struct.enum.html /// [`Color`]: https://docs.rs/bevy/latest/bevy/color/enum.Color.html pub trait TryStableInterpolate: Clone { + /// Error produced when the value cannot be interpolated. + type Error; + /// Attempt to interpolate the value. This may fail if the two interpolation values have /// different units, or if the type is not interpolable. - fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result; + fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result; } impl TryStableInterpolate for T { - fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { + type Error = Infallible; + fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { Ok(self.interpolate_stable(other, t)) } } diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 3f37c87da0c90..70ff8f23ac4d2 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -1,4 +1,4 @@ -use bevy_math::{InterpolationError, StableInterpolate as _, TryStableInterpolate, Vec2}; +use bevy_math::{MismatchedUnitsError, StableInterpolate as _, TryStableInterpolate, Vec2}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_utils::default; use core::ops::{Div, DivAssign, Mul, MulAssign, Neg}; @@ -419,6 +419,8 @@ impl Val { } impl TryStableInterpolate for Val { + type Error = MismatchedUnitsError; + /// # Example /// /// ``` @@ -426,7 +428,7 @@ impl TryStableInterpolate for Val { /// # use bevy_math::TryStableInterpolate; /// assert!(matches!(Val::Px(0.0).try_interpolate_stable(&Val::Px(10.0), 0.5), Ok(Val::Px(5.0)))); /// ``` - fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { + fn try_interpolate_stable(&self, other: &Self, t: f32) -> Result { match (self, other) { (Val::Px(a), Val::Px(b)) => Ok(Val::Px(a.interpolate_stable(b, t))), (Val::Percent(a), Val::Percent(b)) => Ok(Val::Percent(a.interpolate_stable(b, t))), @@ -435,7 +437,7 @@ impl TryStableInterpolate for Val { (Val::VMin(a), Val::VMin(b)) => Ok(Val::VMin(a.interpolate_stable(b, t))), (Val::VMax(a), Val::VMax(b)) => Ok(Val::VMax(a.interpolate_stable(b, t))), (Val::Auto, Val::Auto) => Ok(Val::Auto), - _ => Err(InterpolationError::MismatchedUnits), + _ => Err(MismatchedUnitsError), } } } From 72bc0c7de9af17a558fdb9cea8f1bc1e17437f57 Mon Sep 17 00:00:00 2001 From: Talin Date: Wed, 29 Oct 2025 04:12:26 -0700 Subject: [PATCH 06/10] Added derives for error, --- crates/bevy_math/src/common_traits.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index 68d9c9a8748b2..1d6199b1a775a 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -6,6 +6,8 @@ use core::{ fmt::Debug, ops::{Add, Div, Mul, Neg, Sub}, }; +use derive_more::Display; +use thiserror::Error; use variadics_please::all_tuples_enumerated; /// A type that supports the mathematical operations of a real vector space, irrespective of dimension. @@ -540,7 +542,7 @@ all_tuples_enumerated!( ); /// Error produced when the values to be interpolated are not in the same units. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Error, Display)] pub struct MismatchedUnitsError; /// A trait that indicates that a value _may_ be interpolable via [`StableInterpolate`]. An @@ -553,7 +555,7 @@ pub struct MismatchedUnitsError; /// concept can be extended to other types as well. /// /// Fallible interpolation can be used for animated transitions, which can be set up to fail -/// gracefully if there's a mismatch of units. For example, the a transition could smoothly +/// gracefully if the the values cannot be interpolated. For example, the a transition could smoothly /// go from `Val::Px(10)` to `Val::Px(20)`, but if the user attempts to go from `Val::Px(10)` to /// `Val::Percent(10)`, the animation player can detect the failure and simply snap to the new /// value without interpolating. From e167cbe4f26f9dc58165580f09a7367a632c9230 Mon Sep 17 00:00:00 2001 From: Talin Date: Wed, 29 Oct 2025 06:12:09 -0700 Subject: [PATCH 07/10] Update crates/bevy_math/src/common_traits.rs Co-authored-by: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> --- crates/bevy_math/src/common_traits.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index 1d6199b1a775a..39bb7916e8743 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -542,7 +542,8 @@ all_tuples_enumerated!( ); /// Error produced when the values to be interpolated are not in the same units. -#[derive(Clone, Debug, Error, Display)] +#[derive(Clone, Debug, Error)] +#[error("cannot interpolate between two values of different units")] pub struct MismatchedUnitsError; /// A trait that indicates that a value _may_ be interpolable via [`StableInterpolate`]. An From d8987c3432c51c6df7188f0dd01326a8d4c06291 Mon Sep 17 00:00:00 2001 From: Talin Date: Wed, 29 Oct 2025 06:14:35 -0700 Subject: [PATCH 08/10] Update crates/bevy_math/src/common_traits.rs Co-authored-by: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> --- crates/bevy_math/src/common_traits.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index 39bb7916e8743..0f1835e5677c4 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -6,7 +6,6 @@ use core::{ fmt::Debug, ops::{Add, Div, Mul, Neg, Sub}, }; -use derive_more::Display; use thiserror::Error; use variadics_please::all_tuples_enumerated; From 79d78745a399a3e3fcf313031e297e751a5fefb4 Mon Sep 17 00:00:00 2001 From: Talin Date: Wed, 29 Oct 2025 10:32:55 -0700 Subject: [PATCH 09/10] Update crates/bevy_math/src/common_traits.rs Co-authored-by: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> --- crates/bevy_math/src/common_traits.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index 0f1835e5677c4..e78926575a3b0 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -574,9 +574,9 @@ pub struct MismatchedUnitsError; /// [`TryStableInterpolate`] is more conservative, and doesn't automatically convert between /// color spaces. This produces a color interpolation that has more predictable performance. /// -/// [`Val::Px`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html -/// [`Val::Percent`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html -/// [`Val`]: https://docs.rs/bevy/latest/bevy/ui/struct.enum.html +/// [`Val::Px`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html#variant.Px +/// [`Val::Percent`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html#variant.Percent +/// [`Val`]: https://docs.rs/bevy/latest/bevy/ui/enum.Val.html /// [`Color`]: https://docs.rs/bevy/latest/bevy/color/enum.Color.html pub trait TryStableInterpolate: Clone { /// Error produced when the value cannot be interpolated. From 5375fb0d26dada77197b5fb9eb57aa3bcb7cc59c Mon Sep 17 00:00:00 2001 From: Talin Date: Wed, 29 Oct 2025 13:43:42 -0700 Subject: [PATCH 10/10] Update crates/bevy_math/src/common_traits.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François Mockers --- crates/bevy_math/src/common_traits.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/bevy_math/src/common_traits.rs b/crates/bevy_math/src/common_traits.rs index e78926575a3b0..d02e71b4861d0 100644 --- a/crates/bevy_math/src/common_traits.rs +++ b/crates/bevy_math/src/common_traits.rs @@ -550,10 +550,6 @@ pub struct MismatchedUnitsError; /// interpolate between [`Val::Px`] and [`Val::Percent`] will fail, /// even though they are the same Rust type. /// -/// The motivating case for this trait is animating UI entities with [`Val`] -/// properties, which, because they are enums, cannot be interpolated in the normal way. This same -/// concept can be extended to other types as well. -/// /// Fallible interpolation can be used for animated transitions, which can be set up to fail /// gracefully if the the values cannot be interpolated. For example, the a transition could smoothly /// go from `Val::Px(10)` to `Val::Px(20)`, but if the user attempts to go from `Val::Px(10)` to