si_vectors/cartesian/
mod.rs1
2use crate::{SiUnit,Vector};
3use core::ops::Add;
4#[derive(Debug)]
5pub struct Cartesian{
7 pub x:f64,
9 pub y:f64,
11 pub num: Vec<SiUnit>,
13 pub den: Vec<SiUnit>
15}
16impl From<Vector> for Cartesian{
30 fn from(other: Vector) -> Self {
31 Self{x:other.value.magnitude*other.theta.cos(),
32 y:other.value.magnitude*other.theta.sin(),
33 num:other.value.si_units_num,
34 den:other.value.si_units_den}
35 }
36}
37
38
39impl Add<Cartesian> for Cartesian {
44 type Output = Cartesian;
45 fn add(self, rhs: Cartesian) -> Self::Output {
46 if self.num.len() == rhs.num.len(){
47 for i in 0..self.num.len(){
48 if !(self.num[i] == rhs.num[i]){
49 println!("Paniccc");
50 panic!("Units not identical");
51 }
52 }
53 }else {
54 panic!("Units not identical");
55 }
56 if self.den.len() == rhs.den.len() {
57 for i in 0..self.den.len(){
58 if !(self.den[i] == rhs.den[i]){
59 panic!("Units not identical");
60 }
61 }
62 }
63 Self{x: self.x + rhs.x,y: self.y + rhs.y,..self}
64 }
65}
66impl Clone for Cartesian{
67 fn clone(&self) -> Self {
68 Self{x: self.x,y:self.y,num:self.num.clone(),den:self.den.clone()}
69 }
70}