Orbit picker: move vector stuff to its own module and add more impls

[?]
Jun 16, 2021, 1:00 AM
PNOS6DEINQADXVZQ2KNV6LV2UTNK7IHECWYFE6MC4BCHDF6FP4IQC

Dependencies

  • [2] EWUP525B Basic vector arithmetic for the orbit picker
  • [3] K3V2JNKC Initialize sub-project for choosing lunar orbital parameters
  • [4] 4LTVYHHI Add async runtime for the orbital parameter picker

Change contents

  • file addition: vec3.rs (----------)
    [3.19]
    #[derive(Copy,Clone,Debug)]
    pub struct V3 {
    pub x: f64,
    pub y: f64,
    pub z: f64
    }
    impl std::fmt::Display for V3 {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
    }
    }
    impl std::ops::Mul<f64> for V3 {
    type Output = V3;
    fn mul(self, f: f64) -> Self::Output {
    V3 {
    x: self.x * f,
    y: self.y * f,
    z: self.z * f,
    }
    }
    }
    impl std::ops::MulAssign<f64> for V3 {
    fn mul_assign(&mut self, f: f64) {
    self.x *= f;
    self.y *= f;
    self.z *= f;
    }
    }
    impl std::ops::Add<V3> for V3 {
    type Output = V3;
    fn add(self, rhs: V3) -> V3 {
    V3 {
    x: self.x + rhs.x,
    y: self.y + rhs.y,
    z: self.z + rhs.z,
    }
    }
    }
    impl std::ops::AddAssign<V3> for V3 {
    fn add_assign(&mut self, other: Self) {
    self.x += other.x;
    self.y += other.y;
    self.z += other.z;
    }
    }
    impl std::ops::Neg for V3 {
    type Output = Self;
    fn neg(self) -> Self::Output {
    V3 {
    x: -self.x,
    y: -self.y,
    z: -self.z,
    }
    }
    }
    impl std::ops::Sub<V3> for V3 {
    type Output = Self;
    fn sub(self, other: Self) -> Self::Output {
    V3 {
    x: self.x - other.x,
    y: self.y - other.y,
    z: self.z - other.z,
    }
    }
    }
    impl std::ops::SubAssign<V3> for V3 {
    fn sub_assign(&mut self, other: Self) {
    self.x -= other.x;
    self.y -= other.y;
    self.z -= other.z;
    }
    }
    impl std::ops::Div<f64> for V3 {
    type Output = Self;
    fn div(self, f: f64) -> Self::Output {
    V3 {
    x: self.x / f,
    y: self.y / f,
    z: self.z / f,
    }
    }
    }
    impl std::ops::DivAssign<f64> for V3 {
    fn div_assign(&mut self, f: f64) {
    self.x /= f;
    self.y /= f;
    self.z /= f;
    }
    }
    impl V3 {
    pub fn magnitude(self) -> f64 {
    (self.x*self.x + self.y*self.y + self.z*self.z).sqrt()
    }
    pub fn normalize(self) -> Self {
    self / self.magnitude()
    }
    pub fn x_product(self, other: Self) -> Self {
    V3 {
    x: self.y * other.z - self.z - other.y,
    y: self.z * other.x - self.x - other.z,
    z: self.x * other.y - self.y - other.x,
    }
    }
    }
  • edit in orbitpick/src/main.rs at line 2
    [3.11][2.0:255](),[2.255][3.11:12](),[3.11][3.11:12](),[3.12][2.256:465]()
    #[derive(Debug)]
    pub struct V3 {
    pub x: f64,
    pub y: f64,
    pub z: f64
    }
    impl std::fmt::Display for V3 {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
    }
    }
    impl std::ops::Mul<f64> for V3 {
    type Output = V3;
    fn mul(self, f: f64) -> Self::Output {
    V3 {
    x: self.x * f,
    y: self.y * f,
    z: self.z * f
    }
    }
    }
  • replacement in orbitpick/src/main.rs at line 3
    [2.466][2.466:677]()
    impl std::ops::Add<V3> for V3 {
    type Output = V3;
    fn add(self, rhs: V3) -> V3 {
    V3 {
    x: self.x + rhs.x,
    y: self.y + rhs.y,
    z: self.z + rhs.z
    }
    }
    }
    [2.466]
    [2.677]
    mod vec3;
    // use vec3::V3;