Skip to main content

spatialrust_math/
pose.rs

1use crate::{Isometry3, Mat3, Real};
2
3/// 3x3 symmetric covariance matrix.
4#[derive(Clone, Copy, Debug, PartialEq)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct Cov3<T: Real> {
7    /// Symmetric covariance stored in row-major form.
8    pub matrix: Mat3<T>,
9}
10
11/// Pose with optional translation covariance.
12#[derive(Clone, Copy, Debug, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct Pose3<T: Real> {
15    /// Rigid pose.
16    pub isometry: Isometry3<T>,
17    /// Optional translation covariance.
18    pub translation_covariance: Option<Cov3<T>>,
19}
20
21impl<T: Real> Cov3<T> {
22    /// Creates a covariance matrix from a symmetric 3x3 matrix.
23    #[must_use]
24    pub const fn new(matrix: Mat3<T>) -> Self {
25        Self { matrix }
26    }
27}
28
29impl<T: Real> Pose3<T> {
30    /// Creates a pose without covariance.
31    #[must_use]
32    pub const fn new(isometry: Isometry3<T>) -> Self {
33        Self { isometry, translation_covariance: None }
34    }
35
36    /// Creates a pose with translation covariance.
37    #[must_use]
38    pub const fn with_covariance(isometry: Isometry3<T>, covariance: Cov3<T>) -> Self {
39        Self { isometry, translation_covariance: Some(covariance) }
40    }
41}