feo_math/multivariate/
one_unknown.rs1use std::{ ops::{Div, Mul, Sub}};
2
3use super::with_var::WithVar;
4
5#[derive(Clone, Copy)]
6pub(crate) struct Equa1<T>(pub T, pub WithVar<T>);
7
8impl<T> Equa1<T>{
9 pub fn new(non_var: T, a: WithVar<T>) -> Self {
10 Equa1(non_var, a)
11 }
12 #[allow(dead_code)]
13 pub fn set_eq(&self, other: Self) -> T
14 where T: Div<T, Output = T> + Sub<T, Output = T> + Copy {
15 (self.0 - other.0) / (other.1 - self.1).val
16 }
17 pub fn solve(&self, other: T) -> T
18 where T: Sub<T, Output = T> + Div<T, Output = T> + Copy {
19 (other - self.0) / (self.1).val
20 }
21 pub fn get_var(&self, var: char) -> Option<WithVar<T>>
22 where T: Copy {
23 if self.1.var == var {
24 return Some(self.1);
25 }
26 println!("{} {}", self.1.var, var);
27 None
28 }
29}
30
31impl<T> Mul<T> for Equa1<T>
32where T: Mul<T, Output = T> + Copy {
33 type Output = Self;
34
35 fn mul(self, rhs: T) -> Self::Output {
36 Equa1(self.0 * rhs, self.1 * rhs)
37 }
38}
39
40impl<T> Mul<WithVar<T>> for Equa1<T>
41where T: Mul<T, Output = T> + Copy {
42 type Output = Result<Self, ()>;
43
44 fn mul(self, rhs: WithVar<T>) -> Self::Output {
45 match self.get_var(rhs.var){ Some(_var) => Ok(Equa1(self.0, self.1 * rhs)),
47 None => Err(())
48 }
49 }
50}
51
52impl<T> Div<WithVar<T>> for Equa1<T>
53where T: Div<T, Output = T> + Copy {
54 type Output = Result<Self, ()>;
55
56 fn div(self, rhs: WithVar<T>) -> Self::Output {
57 match self.get_var(rhs.var){ Some(_var) => Ok(Equa1(self.0, self.1 / rhs)),
59 None => Err(())
60 }
61 }
62}
63
64impl<T> Div<T> for Equa1<T>
65where T: Div<T, Output = T> + Copy {
66 type Output = Self;
67
68 fn div(self, rhs: T) -> Self::Output {
69 Equa1(self.0/rhs, self.1 / rhs)
70 }
71}