pub trait Point: Sized + PartialEq {
// Required methods
fn distance(&self, other: &Self) -> f64;
fn move_towards(&self, other: &Self, d: f64) -> Self;
// Provided method
fn midpoint(a: &Self, b: &Self) -> 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 f64
s. 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)
.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§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]
.
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]
.