Skip to content

Commit

Permalink
Fixing ValArithmeticError typo and unused variant (#17597)
Browse files Browse the repository at this point in the history
# Objective

- `ValArithmeticError` contains a typo, and one of it's variants is not
used

## Solution

- Rename `NonEvaluateable::NonEvaluateable ` variant to
`NonEvaluateable::NonEvaluable`.
- Remove variant `ValArithmeticError:: NonIdenticalVariants`.

## Testing

- `cargo run -p ci`

---

## Migration Guide


- `ValArithmeticError::NonEvaluateable` has been renamed to
`NonEvaluateable::NonEvaluable`
- `ValArithmeticError::NonIdenticalVariants ` has been removed
  • Loading branch information
eckz authored Feb 2, 2025
1 parent a893c5d commit 416100a
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions crates/bevy_ui/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,13 @@ impl Neg for Val {

#[derive(Debug, Eq, PartialEq, Clone, Copy, Error)]
pub enum ValArithmeticError {
#[error("the variants of the Vals don't match")]
NonIdenticalVariants,
#[error("the given variant of Val is not evaluateable (non-numeric)")]
NonEvaluateable,
#[error("the given variant of Val is not evaluable (non-numeric)")]
NonEvaluable,
}

impl Val {
/// Resolves a [`Val`] to its value in logical pixels and returns this as an [`f32`].
/// Returns a [`ValArithmeticError::NonEvaluateable`] if the [`Val`] is impossible to resolve into a concrete value.
/// Returns a [`ValArithmeticError::NonEvaluable`] if the [`Val`] is impossible to resolve into a concrete value.
///
/// **Note:** If a [`Val::Px`] is resolved, its inner value is returned unchanged.
pub fn resolve(self, parent_size: f32, viewport_size: Vec2) -> Result<f32, ValArithmeticError> {
Expand All @@ -269,7 +267,7 @@ impl Val {
Val::Vh(value) => Ok(viewport_size.y * value / 100.0),
Val::VMin(value) => Ok(viewport_size.min_element() * value / 100.0),
Val::VMax(value) => Ok(viewport_size.max_element() * value / 100.0),
Val::Auto => Err(ValArithmeticError::NonEvaluateable),
Val::Auto => Err(ValArithmeticError::NonEvaluable),
}
}
}
Expand Down Expand Up @@ -743,23 +741,19 @@ mod tests {
}

#[test]
fn val_auto_is_non_resolveable() {
fn val_auto_is_non_evaluable() {
let size = 250.;
let viewport_size = vec2(1000., 500.);
let resolve_auto = Val::Auto.resolve(size, viewport_size);

assert_eq!(resolve_auto, Err(ValArithmeticError::NonEvaluateable));
assert_eq!(resolve_auto, Err(ValArithmeticError::NonEvaluable));
}

#[test]
fn val_arithmetic_error_messages() {
assert_eq!(
format!("{}", ValArithmeticError::NonIdenticalVariants),
"the variants of the Vals don't match"
);
assert_eq!(
format!("{}", ValArithmeticError::NonEvaluateable),
"the given variant of Val is not evaluateable (non-numeric)"
format!("{}", ValArithmeticError::NonEvaluable),
"the given variant of Val is not evaluable (non-numeric)"
);
}

Expand Down

0 comments on commit 416100a

Please sign in to comment.