From 54b7cabc7b73737298bffbfd4639f36bceb54fbf Mon Sep 17 00:00:00 2001 From: mamekoro <86554319+mamekoro@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:36:46 +0000 Subject: [PATCH] Rename `Time::::overstep_percentage()` and `Time::::overstep_percentage_f64()` (#10448) # Objective This is similar to #10439. `Time::::overstep_percentage()` and `Time::::overstep_percentage_f64()` returns values from 0.0 to 1.0, but their names use the word "percentage". These function names make it easy to misunderstand that they return values from 0.0 to 100.0. To avoid confusion, these functions should be renamed to "`overstep_fraction(_f64)`". ## Solution Rename them. --- ## Changelog ### Changed - Renamed `Time::::overstep_percentage()` to `Time::::overstep_fraction()` - Renamed `Time::::overstep_percentage_f64()` to `Time::::overstep_fraction_f64()` ## Migration Guide - `Time::::overstep_percentage()` has been renamed to `Time::::overstep_fraction()` - `Time::::overstep_percentage_f64()` has been renamed to `Time::::overstep_fraction_f64()` --- crates/bevy_time/src/fixed.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/bevy_time/src/fixed.rs b/crates/bevy_time/src/fixed.rs index 60270172aa..ced8e821ce 100644 --- a/crates/bevy_time/src/fixed.rs +++ b/crates/bevy_time/src/fixed.rs @@ -178,14 +178,14 @@ impl Time { /// Returns the amount of overstep time accumulated toward new steps, as an /// [`f32`] fraction of the timestep. #[inline] - pub fn overstep_percentage(&self) -> f32 { + pub fn overstep_fraction(&self) -> f32 { self.context().overstep.as_secs_f32() / self.context().timestep.as_secs_f32() } /// Returns the amount of overstep time accumulated toward new steps, as an /// [`f64`] fraction of the timestep. #[inline] - pub fn overstep_percentage_f64(&self) -> f64 { + pub fn overstep_fraction_f64(&self) -> f64 { self.context().overstep.as_secs_f64() / self.context().timestep.as_secs_f64() } @@ -265,56 +265,56 @@ mod test { assert_eq!(time.delta(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.overstep(), Duration::from_secs(1)); - assert_eq!(time.overstep_percentage(), 0.5); - assert_eq!(time.overstep_percentage_f64(), 0.5); + assert_eq!(time.overstep_fraction(), 0.5); + assert_eq!(time.overstep_fraction_f64(), 0.5); assert!(!time.expend()); // false assert_eq!(time.delta(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.overstep(), Duration::from_secs(1)); - assert_eq!(time.overstep_percentage(), 0.5); - assert_eq!(time.overstep_percentage_f64(), 0.5); + assert_eq!(time.overstep_fraction(), 0.5); + assert_eq!(time.overstep_fraction_f64(), 0.5); time.accumulate(Duration::from_secs(1)); assert_eq!(time.delta(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.overstep(), Duration::from_secs(2)); - assert_eq!(time.overstep_percentage(), 1.0); - assert_eq!(time.overstep_percentage_f64(), 1.0); + assert_eq!(time.overstep_fraction(), 1.0); + assert_eq!(time.overstep_fraction_f64(), 1.0); assert!(time.expend()); // true assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::ZERO); - assert_eq!(time.overstep_percentage(), 0.0); - assert_eq!(time.overstep_percentage_f64(), 0.0); + assert_eq!(time.overstep_fraction(), 0.0); + assert_eq!(time.overstep_fraction_f64(), 0.0); assert!(!time.expend()); // false assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::ZERO); - assert_eq!(time.overstep_percentage(), 0.0); - assert_eq!(time.overstep_percentage_f64(), 0.0); + assert_eq!(time.overstep_fraction(), 0.0); + assert_eq!(time.overstep_fraction_f64(), 0.0); time.accumulate(Duration::from_secs(1)); assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::from_secs(1)); - assert_eq!(time.overstep_percentage(), 0.5); - assert_eq!(time.overstep_percentage_f64(), 0.5); + assert_eq!(time.overstep_fraction(), 0.5); + assert_eq!(time.overstep_fraction_f64(), 0.5); assert!(!time.expend()); // false assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::from_secs(1)); - assert_eq!(time.overstep_percentage(), 0.5); - assert_eq!(time.overstep_percentage_f64(), 0.5); + assert_eq!(time.overstep_fraction(), 0.5); + assert_eq!(time.overstep_fraction_f64(), 0.5); } #[test]