pub trait SpatialMathWithPolicy: CoreMathWithPolicy {
// Required methods
fn hypot_p<P: Policy>(self, other: Self) -> Self;
fn hypot_n_p<P: Policy, const N: usize>(values: [Self; N]) -> Self;
fn inv_hypot_n_p<P: Policy, const N: usize>(values: [Self; N]) -> Self;
fn l1_norm_p<P: Policy>(self) -> Self;
fn l2_norm_p<P: Policy>(self) -> Self;
fn l2_norm_squared_p<P: Policy>(self) -> Self;
}Expand description
Spatial Math functions for floating-point vectors with customizable policies. Spatial mathematical functions like norms and distances.
These functions are primarily useful in dimensions higher than one.
This trait provides a set of spatial mathematical operations that can be performed on floating-point vector types. Each function has a variant that accepts a policy parameter, allowing for fine-tuned control over precision and performance.
For convenience, a default implementation is also provided in the SpatialMath trait,
which uses the DefaultPolicy. All floating-point vector types that implement
the necessary internal math operations will automatically implement this trait, and
the SpatialMath trait as well for all types that implement this one.
Required Methods§
Sourcefn hypot_p<P: Policy>(self, other: Self) -> Self
fn hypot_p<P: Policy>(self, other: Self) -> Self
Computes the Euclidean norm (hypotenuse) of self and other, i.e., sqrt(self^2 + other^2).
This is not higher performance than the naive implementation, but is more resistant to overflow and underflow. If using the worst precision policy, it becomes equivalent to the naive implementation.
Check out hypot_n for a more general version that computes the hypotenuse of N values.
Sourcefn hypot_n_p<P: Policy, const N: usize>(values: [Self; N]) -> Self
fn hypot_n_p<P: Policy, const N: usize>(values: [Self; N]) -> Self
Computes the Euclidean norm (hypotenuse) of N values, i.e., $\sqrt{x_1^2 + x_2^2 + \dots + x_N^2}$.
This is typically higher performance than naively computing the sum of squares and then taking the square root, especially for larger N, and is more resistant to overflow and underflow when using average or higher precision policies.
Sourcefn inv_hypot_n_p<P: Policy, const N: usize>(values: [Self; N]) -> Self
fn inv_hypot_n_p<P: Policy, const N: usize>(values: [Self; N]) -> Self
Computes the inverse Euclidean norm (inverse hypotenuse) of N values, i.e., $1/\sqrt{x_1^2 + x_2^2 + \dots + x_N^2}$.
This is typically higher performance than naively computing the sum of squares, taking the square root, and then inverting, especially for larger N, and is more resistant to overflow and underflow when using average or higher precision policies.
At lower precision policies, we can take advantage of fast approximate inverse square root implementations for better performance.
Sourcefn l1_norm_p<P: Policy>(self) -> Self
fn l1_norm_p<P: Policy>(self) -> Self
L1 Norm, or the “Manhattan” distance from the origin.
For 1D vectors, this is equivalent to the absolute value.
Sourcefn l2_norm_p<P: Policy>(self) -> Self
fn l2_norm_p<P: Policy>(self) -> Self
L2 Norm, or the “Euclidean” distance from the origin.
For 1D vectors, this is equivalent to the absolute value.
Sourcefn l2_norm_squared_p<P: Policy>(self) -> Self
fn l2_norm_squared_p<P: Policy>(self) -> Self
Squared L2 Norm, or the squared “Euclidean” distance from the origin.
For 1D vectors, this is equivalent to squaring the value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".