use crate::constants::AU;
use nalgebra::Vector3;
use std::ops::{Add, Div, Sub};
#[derive(Debug, PartialEq, Clone)]
pub struct InterpResult {
pub position: Vector3<f64>,
pub velocity: Option<Vector3<f64>>,
pub acceleration: Option<Vector3<f64>>,
}
impl InterpResult {
#[must_use = "`.to_au()` returns a new InterpResult; assign or use it"]
pub fn to_au(&self) -> Self {
self / AU
}
}
impl Add for InterpResult {
type Output = Self;
fn add(self, other: Self) -> Self::Output {
InterpResult {
position: self.position + other.position,
velocity: match (self.velocity, other.velocity) {
(Some(v1), Some(v2)) => Some(v1 + v2),
_ => None,
},
acceleration: match (self.acceleration, other.acceleration) {
(Some(a1), Some(a2)) => Some(a1 + a2),
_ => None,
},
}
}
}
impl Add for &InterpResult {
type Output = InterpResult;
fn add(self, other: Self) -> Self::Output {
InterpResult {
position: self.position + other.position,
velocity: match (self.velocity, other.velocity) {
(Some(v1), Some(v2)) => Some(v1 + v2),
_ => None,
},
acceleration: match (self.acceleration, other.acceleration) {
(Some(a1), Some(a2)) => Some(a1 + a2),
_ => None,
},
}
}
}
impl Sub for InterpResult {
type Output = Self;
fn sub(self, other: Self) -> Self::Output {
InterpResult {
position: self.position - other.position,
velocity: match (self.velocity, other.velocity) {
(Some(v1), Some(v2)) => Some(v1 - v2),
_ => None,
},
acceleration: match (self.acceleration, other.acceleration) {
(Some(a1), Some(a2)) => Some(a1 - a2),
_ => None,
},
}
}
}
impl Sub for &InterpResult {
type Output = InterpResult;
fn sub(self, other: Self) -> Self::Output {
InterpResult {
position: self.position - other.position,
velocity: match (self.velocity, other.velocity) {
(Some(v1), Some(v2)) => Some(v1 - v2),
_ => None,
},
acceleration: match (self.acceleration, other.acceleration) {
(Some(a1), Some(a2)) => Some(a1 - a2),
_ => None,
},
}
}
}
impl Div<f64> for InterpResult {
type Output = Self;
fn div(self, rhs: f64) -> Self::Output {
InterpResult {
position: self.position / rhs,
velocity: self.velocity.map(|v| v / rhs),
acceleration: self.acceleration.map(|a| a / rhs),
}
}
}
impl Div<f64> for &InterpResult {
type Output = InterpResult;
fn div(self, rhs: f64) -> Self::Output {
InterpResult {
position: self.position / rhs,
velocity: self.velocity.map(|v| v / rhs),
acceleration: self.acceleration.map(|a| a / rhs),
}
}
}