matrix/
scalar.rs

1use std::{fmt::Debug, iter::Sum};
2
3pub trait Scalar:
4    Debug
5    + Copy
6    + Default
7    + std::cmp::PartialOrd
8    + std::ops::Neg<Output = Self>
9    + std::ops::Add<Output = Self>
10    + std::ops::Sub<Output = Self>
11    + std::ops::Mul<Output = Self>
12    + std::ops::Div<Output = Self>
13    + std::ops::AddAssign
14    + std::ops::SubAssign
15    + std::ops::MulAssign
16    + std::ops::DivAssign
17    + std::iter::Sum
18    + MulAdd<Self, Self>
19    + Lerp
20{
21    type AbsOutput: Sum<Self::AbsOutput>
22        + Debug
23        + Copy
24        + Default
25        + std::cmp::PartialOrd
26        + std::ops::AddAssign
27        + MulAdd<Self::AbsOutput, Self::AbsOutput>
28        + Sqrt
29        + std::ops::Mul<Output = Self::AbsOutput>;
30    type TanOutput;
31    type CosOutput;
32    type SinOutput;
33
34    fn abs(&self) -> Self::AbsOutput;
35    fn one() -> Self;
36    fn inv(self) -> Self;
37    fn tan(self) -> Self::TanOutput;
38    fn sin(self) -> Self::SinOutput;
39    fn cos(self) -> Self::CosOutput;
40    fn is_non_zero(&self) -> bool;
41}
42
43pub trait MulAdd<U, V> {
44    fn mul_add(self, a: &U, b: &V) -> Self;
45}
46
47pub trait Sqrt {
48    fn sqrt(self) -> Self;
49}
50
51pub trait Lerp {
52    fn lerp(u: Self, v: Self, t: f32) -> Self;
53}
54
55pub fn lerp<V: Lerp>(u: V, v: V, t: f32) -> V {
56    V::lerp(u, v, t)
57}