transforms::core::registry::sync_impl

Struct Registry

Source
pub struct Registry {
    pub data: HashMap<String, Buffer>,
    /* private fields */
}
Expand description

A registry for managing transforms between different frames. It can traverse the parent-child tree and calculate the final transform. It will interpolate between two entries if a time is requested that lies in between.

The Registry struct provides methods to add and retrieve transforms between frames, supporting both synchronous and asynchronous operations depending on the feature flags.

§Examples

use std::time::Duration;
use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
    Registry,
};

// Create a new registry with a max_age duration
let mut registry = Registry::new(Duration::from_secs(60));
let t1 = Timestamp::now();
let t2 = t1.clone();

// Define a transform from frame "a" to frame "b"
let t_a_b_1 = Transform {
    translation: Vector3 {
        x: 1.0,
        y: 0.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: t1,
    parent: "a".into(),
    child: "b".into(),
};

// For validation
let t_a_b_2 = t_a_b_1.clone();

// Add the transform to the registry
let result = registry.add_transform(t_a_b_1);
assert!(result.is_ok());

// Retrieve the transform from "a" to "b"
let result = registry.get_transform("a", "b", t2);
assert!(result.is_ok());
assert_eq!(result.unwrap(), t_a_b_2);

Fields§

§data: HashMap<String, Buffer>

Implementations§

Source§

impl Registry

Source

pub fn new(max_age: Duration) -> Self

Creates a new Registry with the specified max_age duration.

§Arguments
  • max_age - The duration for which transforms are considered valid.
§Returns

A new instance of Registry.

§Examples
use std::time::Duration;
use transforms::Registry;

let mut registry = Registry::new(Duration::from_secs(60));
Source

pub fn add_transform(&mut self, t: Transform) -> Result<(), BufferError>

Adds a transform to the registry.

§Arguments
  • t - The transform to add.
§Errors

Returns a BufferError if the transform cannot be added.

§Examples
use std::time::Duration;
use transforms::{geometry::Transform, Registry};

let mut registry = Registry::new(Duration::from_secs(60));
let transform = Transform::identity();

let result = registry.add_transform(transform);
assert!(result.is_ok());
Source

pub fn get_transform( &mut self, from: &str, to: &str, timestamp: Timestamp, ) -> Result<Transform, TransformError>

Retrieves a transform from the registry.

§Arguments
  • from - The source frame.
  • to - The destination frame.
  • timestamp - The timestamp for which the transform is requested.
§Errors

Returns a TransformError if the transform cannot be found.

§Examples
use std::time::Duration;
use transforms::{
    geometry::{Quaternion, Transform, Vector3},
    time::Timestamp,
    Registry,
};

let mut registry = Registry::new(Duration::from_secs(60));
let t1 = Timestamp::zero();
let t2 = t1.clone();

// Define a transform from frame "a" to frame "b"
let t_a_b_1 = Transform {
    translation: Vector3 {
        x: 1.0,
        y: 0.0,
        z: 0.0,
    },
    rotation: Quaternion {
        w: 1.0,
        x: 0.0,
        y: 0.0,
        z: 0.0,
    },
    timestamp: t1,
    parent: "a".into(),
    child: "b".into(),
};
// For validation
let t_a_b_2 = t_a_b_1.clone();

let result = registry.add_transform(t_a_b_1);
assert!(result.is_ok());

let result = registry.get_transform("a", "b", t2);
assert!(result.is_ok());
assert_eq!(result.unwrap(), t_a_b_2);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.