dynamics_spatial/
vector6d.rs1use std::{fmt::Display, ops::Mul};
4
5use nalgebra::{Matrix6, Vector6};
6
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub struct Vector6D(pub Vector6<f64>);
14
15impl Vector6D {
16 #[must_use]
17 pub fn new(x: f64, y: f64, z: f64, w: f64, v: f64, u: f64) -> Self {
18 Self(Vector6::new(x, y, z, w, v, u))
19 }
20
21 #[must_use]
22 pub fn from_slice(data: &[f64; 6]) -> Self {
23 Self(Vector6::from_column_slice(data))
24 }
25
26 #[must_use]
27 pub fn zeros() -> Self {
28 Self(Vector6::zeros())
29 }
30
31 #[must_use]
32 pub fn as_slice(&self) -> &[f64; 6] {
33 self.0.as_slice().try_into().unwrap()
34 }
35
36 #[must_use]
38 pub fn as_diagonal(&self) -> Matrix6<f64> {
39 Matrix6::from_diagonal(&self.0)
40 }
41}
42
43impl Mul<f64> for &Vector6D {
44 type Output = Vector6D;
45
46 fn mul(self, rhs: f64) -> Self::Output {
47 Vector6D(self.0 * rhs)
48 }
49}
50
51impl Mul<&Vector6D> for f64 {
52 type Output = Vector6D;
53
54 fn mul(self, rhs: &Vector6D) -> Self::Output {
55 Vector6D(self * rhs.0)
56 }
57}
58
59impl Display for Vector6D {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 write!(f, "Vector6D({:?})", self.0.as_slice())
62 }
63}