1use crate::trig::{Cos, Sin};
17use core::ops::{Mul, MulAssign};
18use core::primitive::f32;
19use derive_more::{Add, AddAssign, From, Into, Neg, Sub};
20
21macro_rules! impl_trig_ops {
22 ($tr: ty, $nt: ty) => {
23 impl Mul<$nt> for $tr {
24 fn mul(self, rhs: $nt) -> $nt {
25 rhs * self
26 }
27 type Output = $nt;
28 }
29
30 impl Mul<$tr> for $nt {
31 fn mul(self, other: $tr) -> $nt {
32 self * f32::from(other)
33 }
34 type Output = $nt;
35 }
36
37 impl MulAssign<$tr> for $nt {
38 fn mul_assign(&mut self, other: $tr) {
39 self.0 *= f32::from(other);
40 }
41 }
42 };
43}
44
45macro_rules! impl_number {
46 ($t:ty) => {
47 impl Mul<f32> for $t {
48 fn mul(self, other: f32) -> $t {
49 (self.0 * other).into()
50 }
51 type Output = $t;
52 }
53
54 impl Mul<$t> for f32 {
55 fn mul(self, other: $t) -> $t {
56 (self * other.0).into()
57 }
58 type Output = $t;
59 }
60
61 impl_trig_ops!(Sin, $t);
62 impl_trig_ops!(Cos, $t);
63 };
64}
65
66#[derive(Neg, AddAssign, Add, Sub, Debug, Copy, Clone, PartialEq, From, Into)]
68pub struct Voltage(f32);
69
70#[derive(Neg, AddAssign, Add, Sub, Debug, Copy, Clone, PartialEq, From, Into)]
72pub struct Current(f32);
73
74#[derive(Neg, AddAssign, Add, Sub, Debug, Copy, Clone, PartialEq, From, Into)]
76pub struct Power(f32);
77
78#[derive(Neg, AddAssign, Add, Sub, Debug, Copy, Clone, PartialEq, From, Into)]
80pub struct Impedance(f32);
81
82impl_number!(Voltage);
84impl_number!(Current);
85impl_number!(Power);
86impl_number!(Impedance);
87
88impl Mul<Current> for Voltage {
90 fn mul(self, rhs: Current) -> Power {
91 Power(self.0 * rhs.0)
92 }
93 type Output = Power;
94}
95
96impl Mul<Voltage> for Current {
97 fn mul(self, rhs: Voltage) -> Power {
98 Power(self.0 * rhs.0)
99 }
100 type Output = Power;
101}
102
103impl Mul<Current> for Impedance {
104 fn mul(self, rhs: Current) -> Voltage {
105 Voltage(self.0 * rhs.0)
106 }
107 type Output = Voltage;
108}
109
110impl Mul<Impedance> for Current {
111 fn mul(self, rhs: Impedance) -> Voltage {
112 Voltage(self.0 * rhs.0)
113 }
114 type Output = Voltage;
115}