1#![no_std]
2#![deny(missing_docs)]
3use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
12use scalars::{Real, Zero};
13
14pub trait VectorSpace: Sized + Zero + PartialEq
17where
18 Self: Add<Output = Self>
19 + Sub<Output = Self>
20 + Mul<<Self as VectorSpace>::Scalar, Output = Self>
21 + Div<<Self as VectorSpace>::Scalar, Output = Self>
22 + Neg<Output = Self>,
23{
24 type Scalar: Real;
26}
27
28impl VectorSpace for f32 {
29 type Scalar = Self;
30}
31impl VectorSpace for f64 {
32 type Scalar = Self;
33}
34
35pub trait VectorSpaceAssign:
37 VectorSpace + AddAssign + SubAssign + MulAssign<Self::Scalar> + DivAssign<Self::Scalar>
38{
39}
40impl<T> VectorSpaceAssign for T where
41 T: VectorSpace + AddAssign + SubAssign + MulAssign<Self::Scalar> + DivAssign<Self::Scalar>
42{
43}
44
45pub trait AffineSpace: Sub<Output = Self::Diff> + Sized {
47 type Diff: VectorSpace;
49}
50
51impl<T, D> AffineSpace for T
52where
53 T: Sub<Output = D>,
54 D: VectorSpace,
55{
56 type Diff = D;
57}
58
59pub trait Transform<V> {
65 fn apply_point(&self, point: V) -> V;
67}
68
69#[inline]
71pub fn interpolate<T>(a: T, b: T, ratio: <T::Diff as VectorSpace>::Scalar) -> T
72where
73 T: Clone + AffineSpace + Add<T::Diff, Output = T>,
74{
75 a.clone() + (b - a) * ratio
76}