Rename Time::<Fixed>::overstep_percentage() and Time::<Fixed>::overstep_percentage_f64() (#10448)

# Objective
This is similar to #10439.

`Time::<Fixed>::overstep_percentage()` and
`Time::<Fixed>::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::<Fixed>::overstep_percentage()` to
`Time::<Fixed>::overstep_fraction()`
- Renamed `Time::<Fixed>::overstep_percentage_f64()` to
`Time::<Fixed>::overstep_fraction_f64()`

## Migration Guide
- `Time::<Fixed>::overstep_percentage()` has been renamed to
`Time::<Fixed>::overstep_fraction()`
- `Time::<Fixed>::overstep_percentage_f64()` has been renamed to
`Time::<Fixed>::overstep_fraction_f64()`
This commit is contained in:
mamekoro 2023-11-13 14:36:46 +00:00 committed by GitHub
parent bf4f4e42da
commit 54b7cabc7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -178,14 +178,14 @@ impl Time<Fixed> {
/// Returns the amount of overstep time accumulated toward new steps, as an /// Returns the amount of overstep time accumulated toward new steps, as an
/// [`f32`] fraction of the timestep. /// [`f32`] fraction of the timestep.
#[inline] #[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() self.context().overstep.as_secs_f32() / self.context().timestep.as_secs_f32()
} }
/// Returns the amount of overstep time accumulated toward new steps, as an /// Returns the amount of overstep time accumulated toward new steps, as an
/// [`f64`] fraction of the timestep. /// [`f64`] fraction of the timestep.
#[inline] #[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() 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.delta(), Duration::ZERO);
assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO);
assert_eq!(time.overstep(), Duration::from_secs(1)); assert_eq!(time.overstep(), Duration::from_secs(1));
assert_eq!(time.overstep_percentage(), 0.5); assert_eq!(time.overstep_fraction(), 0.5);
assert_eq!(time.overstep_percentage_f64(), 0.5); assert_eq!(time.overstep_fraction_f64(), 0.5);
assert!(!time.expend()); // false assert!(!time.expend()); // false
assert_eq!(time.delta(), Duration::ZERO); assert_eq!(time.delta(), Duration::ZERO);
assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO);
assert_eq!(time.overstep(), Duration::from_secs(1)); assert_eq!(time.overstep(), Duration::from_secs(1));
assert_eq!(time.overstep_percentage(), 0.5); assert_eq!(time.overstep_fraction(), 0.5);
assert_eq!(time.overstep_percentage_f64(), 0.5); assert_eq!(time.overstep_fraction_f64(), 0.5);
time.accumulate(Duration::from_secs(1)); time.accumulate(Duration::from_secs(1));
assert_eq!(time.delta(), Duration::ZERO); assert_eq!(time.delta(), Duration::ZERO);
assert_eq!(time.elapsed(), Duration::ZERO); assert_eq!(time.elapsed(), Duration::ZERO);
assert_eq!(time.overstep(), Duration::from_secs(2)); assert_eq!(time.overstep(), Duration::from_secs(2));
assert_eq!(time.overstep_percentage(), 1.0); assert_eq!(time.overstep_fraction(), 1.0);
assert_eq!(time.overstep_percentage_f64(), 1.0); assert_eq!(time.overstep_fraction_f64(), 1.0);
assert!(time.expend()); // true assert!(time.expend()); // true
assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.delta(), Duration::from_secs(2));
assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2));
assert_eq!(time.overstep(), Duration::ZERO); assert_eq!(time.overstep(), Duration::ZERO);
assert_eq!(time.overstep_percentage(), 0.0); assert_eq!(time.overstep_fraction(), 0.0);
assert_eq!(time.overstep_percentage_f64(), 0.0); assert_eq!(time.overstep_fraction_f64(), 0.0);
assert!(!time.expend()); // false assert!(!time.expend()); // false
assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.delta(), Duration::from_secs(2));
assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2));
assert_eq!(time.overstep(), Duration::ZERO); assert_eq!(time.overstep(), Duration::ZERO);
assert_eq!(time.overstep_percentage(), 0.0); assert_eq!(time.overstep_fraction(), 0.0);
assert_eq!(time.overstep_percentage_f64(), 0.0); assert_eq!(time.overstep_fraction_f64(), 0.0);
time.accumulate(Duration::from_secs(1)); time.accumulate(Duration::from_secs(1));
assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.delta(), Duration::from_secs(2));
assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2));
assert_eq!(time.overstep(), Duration::from_secs(1)); assert_eq!(time.overstep(), Duration::from_secs(1));
assert_eq!(time.overstep_percentage(), 0.5); assert_eq!(time.overstep_fraction(), 0.5);
assert_eq!(time.overstep_percentage_f64(), 0.5); assert_eq!(time.overstep_fraction_f64(), 0.5);
assert!(!time.expend()); // false assert!(!time.expend()); // false
assert_eq!(time.delta(), Duration::from_secs(2)); assert_eq!(time.delta(), Duration::from_secs(2));
assert_eq!(time.elapsed(), Duration::from_secs(2)); assert_eq!(time.elapsed(), Duration::from_secs(2));
assert_eq!(time.overstep(), Duration::from_secs(1)); assert_eq!(time.overstep(), Duration::from_secs(1));
assert_eq!(time.overstep_percentage(), 0.5); assert_eq!(time.overstep_fraction(), 0.5);
assert_eq!(time.overstep_percentage_f64(), 0.5); assert_eq!(time.overstep_fraction_f64(), 0.5);
} }
#[test] #[test]