mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
Delete redundant implementations of min and max for geom types. They get it for free by implementing Ord.
This commit is contained in:
parent
8d0718d37d
commit
9b966205c9
@ -92,24 +92,6 @@ impl Distance {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the largest of the two inputs.
|
||||
pub fn max(self, other: Distance) -> Distance {
|
||||
if self >= other {
|
||||
self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the smallest of the two inputs.
|
||||
pub fn min(self, other: Distance) -> Distance {
|
||||
if self <= other {
|
||||
self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Distance {
|
||||
|
@ -222,24 +222,6 @@ impl Duration {
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
/// Returns the largest of the two inputs.
|
||||
pub fn max(self, other: Duration) -> Duration {
|
||||
if self >= other {
|
||||
self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the smallest of the two inputs.
|
||||
pub fn min(self, other: Duration) -> Duration {
|
||||
if self <= other {
|
||||
self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Duration {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::ops;
|
||||
use std::{cmp, ops};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -8,6 +8,14 @@ use crate::{trim_f64, Distance, Duration, UnitFmt};
|
||||
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
pub struct Speed(f64);
|
||||
|
||||
// By construction, Speed is a finite f64 with trimmed precision.
|
||||
impl Eq for Speed {}
|
||||
impl Ord for Speed {
|
||||
fn cmp(&self, other: &Speed) -> cmp::Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Speed {
|
||||
pub const ZERO: Speed = Speed::const_meters_per_second(0.0);
|
||||
|
||||
@ -40,22 +48,6 @@ impl Speed {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn max(self, other: Speed) -> Speed {
|
||||
if self >= other {
|
||||
self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
pub fn min(self, other: Speed) -> Speed {
|
||||
if self <= other {
|
||||
self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the speed according to formatting rules.
|
||||
pub fn to_string(self, fmt: &UnitFmt) -> String {
|
||||
if fmt.metric {
|
||||
|
@ -120,23 +120,6 @@ impl Time {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Why isn't this free given Ord?
|
||||
pub fn min(self, other: Time) -> Time {
|
||||
if self <= other {
|
||||
self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max(self, other: Time) -> Time {
|
||||
if self >= other {
|
||||
self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
// TODO These are a little weird, so don't operator overload yet
|
||||
pub fn percent_of(self, p: f64) -> Time {
|
||||
if p < 0.0 || p > 1.0 {
|
||||
|
Loading…
Reference in New Issue
Block a user