1use nalgebra::{RealField, convert};
2use simba::scalar::SubsetOf;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct Scale<N: Copy + RealField> {
9 den: N,
11}
12
13impl<N: Copy + RealField> Default for Scale<N> {
14 fn default() -> Self {
15 Self {
16 den: convert(120.0),
17 }
18 }
19}
20
21impl<N: Copy + RealField> Scale<N> {
22 #[must_use]
24 pub fn compute(&self, num: N) -> N {
25 N::one() - num / self.den
26 }
27 #[must_use]
29 pub const fn denominator(&self) -> N {
30 self.den
31 }
32 pub const fn set_denominator(&mut self, den: N) {
34 self.den = den;
35 }
36 #[must_use]
38 pub fn cast<M: Copy + RealField>(self) -> Scale<M>
39 where
40 N: SubsetOf<M>,
41 {
42 Scale {
43 den: self.den.to_superset(),
44 }
45 }
46}