use crate::prelude::*;
use std::fmt::Debug;
pub trait Approx: HasXY {
fn is_ulps_eq(
self,
other: Self,
epsilon: <Self::Scalar as approx::AbsDiffEq>::Epsilon,
max_ulps: u32,
) -> bool;
fn is_abs_diff_eq(
self,
other: Self,
epsilon: <Self::Scalar as approx::AbsDiffEq>::Epsilon,
) -> bool;
}
pub trait HasXY: Sync + Send + Copy + Debug + Sized {
type Scalar: GenericScalar;
fn new_2d(x: Self::Scalar, y: Self::Scalar) -> Self;
fn x(self) -> Self::Scalar;
fn x_mut(&mut self) -> &mut Self::Scalar;
fn set_x(&mut self, val: Self::Scalar);
fn y(self) -> Self::Scalar;
fn y_mut(&mut self) -> &mut Self::Scalar;
fn set_y(&mut self, val: Self::Scalar);
}
pub trait GenericVector2:
HasXY
+ Copy
+ Approx
+ PartialEq
+ std::ops::Index<usize, Output = Self::Scalar>
+ std::ops::IndexMut<usize, Output = Self::Scalar>
+ std::ops::AddAssign
+ std::ops::SubAssign
+ std::ops::Neg<Output = Self>
+ std::ops::Add<Self, Output = Self>
+ std::ops::Sub<Self, Output = Self>
+ std::ops::Mul<Self::Scalar, Output = Self>
+ std::ops::Div<Self::Scalar, Output = Self>
+ Into<[Self::Scalar; 2]>
+ From<[Self::Scalar; 2]>
{
const ZERO: Self;
const ONE: Self;
type Vector3: GenericVector3<Scalar = Self::Scalar, Vector2 = Self>;
type Affine: Affine2D<Vector2 = Self>;
type Aabb: Aabb2<Vector = Self> + Into<Vec<Self>>;
fn new(x: Self::Scalar, y: Self::Scalar) -> Self;
fn splat(value: Self::Scalar) -> Self;
fn to_3d(self, z: Self::Scalar) -> Self::Vector3;
fn magnitude(self) -> Self::Scalar;
fn magnitude_sq(self) -> Self::Scalar;
fn dot(self, other: Self) -> Self::Scalar;
fn perp_dot(self, rhs: Self) -> Self::Scalar;
fn distance(self, rhs: Self) -> Self::Scalar;
fn distance_sq(self, rhs: Self) -> Self::Scalar;
fn normalize(self) -> Self;
fn try_normalize(self, epsilon: Self::Scalar) -> Option<Self>;
fn min(self, rhs: Self) -> Self;
fn max(self, rhs: Self) -> Self;
fn clamp(self, min: Self, max: Self) -> Self;
fn is_finite(self) -> bool;
}