Skip to content

Commit bea5012

Browse files
committed
Add Rot3 for representing 3D rotations
1 parent ce64dab commit bea5012

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lighthouse-protocol/src/utils/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod color;
22
mod direction;
33
mod rect;
44
mod rem_euclid;
5+
mod rot3;
56
mod rotation;
67
mod sqrt;
78
mod unity;
@@ -13,6 +14,7 @@ pub use color::*;
1314
pub use direction::*;
1415
pub use rect::*;
1516
pub use rem_euclid::*;
17+
pub use rot3::*;
1618
pub use rotation::*;
1719
pub use sqrt::*;
1820
pub use unity::*;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use super::Zero;
4+
5+
/// A 3D rotation.
6+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
7+
pub struct Rot3<T> {
8+
pub alpha: T,
9+
pub beta: T,
10+
pub gamma: T,
11+
}
12+
13+
impl<T> Rot3<T> {
14+
/// Creates a mew position.
15+
pub const fn new(alpha: T, beta: T, gamma: T) -> Self {
16+
Self { alpha, beta, gamma }
17+
}
18+
19+
/// Maps a function over the vector.
20+
pub fn map<U>(self, mut f: impl FnMut(T) -> U) -> Rot3<U> {
21+
Rot3 {
22+
alpha: f(self.alpha),
23+
beta: f(self.beta),
24+
gamma: f(self.gamma),
25+
}
26+
}
27+
}
28+
29+
impl<T> Zero for Rot3<T> where T: Zero {
30+
/// The origin.
31+
const ZERO: Self = Self::new(T::ZERO, T::ZERO, T::ZERO);
32+
}

0 commit comments

Comments
 (0)