1use std::ops::{
2 Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
3};
4
5use crate::{tween::Tweenable, Value};
6
7#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[cfg_attr(feature = "serde", serde(transparent))]
10pub struct Mix(pub f32);
21
22impl Mix {
23 pub const DRY: Self = Self(0.0);
25 pub const WET: Self = Self(1.0);
27}
28
29impl Tweenable for Mix {
30 fn interpolate(a: Self, b: Self, amount: f64) -> Self {
31 Self(Tweenable::interpolate(a.0, b.0, amount))
32 }
33}
34
35impl From<f32> for Mix {
36 fn from(value: f32) -> Self {
37 Self(value)
38 }
39}
40
41impl From<f32> for Value<Mix> {
42 fn from(value: f32) -> Self {
43 Self::Fixed(Mix(value))
44 }
45}
46
47impl From<Mix> for Value<Mix> {
48 fn from(value: Mix) -> Self {
49 Self::Fixed(value)
50 }
51}
52
53impl Add<Mix> for Mix {
54 type Output = Mix;
55
56 fn add(self, rhs: Mix) -> Self::Output {
57 Self(self.0 + rhs.0)
58 }
59}
60
61impl AddAssign<Mix> for Mix {
62 fn add_assign(&mut self, rhs: Mix) {
63 self.0 += rhs.0;
64 }
65}
66
67impl Sub<Mix> for Mix {
68 type Output = Mix;
69
70 fn sub(self, rhs: Mix) -> Self::Output {
71 Self(self.0 - rhs.0)
72 }
73}
74
75impl SubAssign<Mix> for Mix {
76 fn sub_assign(&mut self, rhs: Mix) {
77 self.0 -= rhs.0;
78 }
79}
80
81impl Mul<f32> for Mix {
82 type Output = Mix;
83
84 fn mul(self, rhs: f32) -> Self::Output {
85 Self(self.0 * rhs)
86 }
87}
88
89impl MulAssign<f32> for Mix {
90 fn mul_assign(&mut self, rhs: f32) {
91 self.0 *= rhs;
92 }
93}
94
95impl Div<f32> for Mix {
96 type Output = Mix;
97
98 fn div(self, rhs: f32) -> Self::Output {
99 Self(self.0 / rhs)
100 }
101}
102
103impl DivAssign<f32> for Mix {
104 fn div_assign(&mut self, rhs: f32) {
105 self.0 /= rhs;
106 }
107}
108
109impl Neg for Mix {
110 type Output = Mix;
111
112 fn neg(self) -> Self::Output {
113 Self(-self.0)
114 }
115}
116
117impl Rem<f32> for Mix {
118 type Output = Mix;
119
120 fn rem(self, rhs: f32) -> Self::Output {
121 Self(self.0 % rhs)
122 }
123}
124
125impl RemAssign<f32> for Mix {
126 fn rem_assign(&mut self, rhs: f32) {
127 self.0 %= rhs;
128 }
129}