Delete redundant implementations of min and max for geom types. They get it for free by implementing Ord.

This commit is contained in:
Dustin Carlino 2021-02-12 15:22:27 -08:00
parent 8d0718d37d
commit 9b966205c9
4 changed files with 9 additions and 70 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {