pub trait Point: Sized + PartialEq {
// Required methods
fn distance(&self, other: &Self) -> f64;
fn move_towards(&self, other: &Self, d: f64) -> Self;
}Expand description
A Point is something that exists in some sort of metric space, and
can thus calculate its distance to another Point, and can be moved
a certain distance towards another Point.
Required Methods§
sourcefn distance(&self, other: &Self) -> f64
fn distance(&self, other: &Self) -> f64
Distances should be positive, finite f64s. It is undefined behavior to
return a negative, infinite, or NaN result.
Distance should satisfy the triangle inequality. That is, a.distance(c)
must be less or equal to than a.distance(b) + b.distance(c).
sourcefn move_towards(&self, other: &Self, d: f64) -> Self
fn move_towards(&self, other: &Self, d: f64) -> Self
If d is 0, a point equal to the self should be returned. If d is equal
to self.distance(other), a point equal to other should be returned.
Intermediate distances should be linearly interpolated between the two points,
so if d is equal to self.distance(other) / 2.0, the midpoint should be
returned.
It is undefined behavior to use a distance that is negative, NaN, or greater
than self.distance(other).
Implementations on Foreign Types§
source§impl<const D: usize> Point for [f64; D]
impl<const D: usize> Point for [f64; D]
Implement Point in the normal D dimensional Euclidean way for all arrays of floats. For example, a 2D point
would be a [f64; 2].