Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type NearestTransforms<'a, T> = (Option<(&'a T, &'a Isometry)>, Option<(&'a T, &
/// than `max_age` relative to the latest inserted timestamp are removed
/// automatically on insert. A buffer created with [`Buffer::dynamic`] never
/// expires entries; use [`Buffer::remove_before`] for manual cleanup.
#[derive(Clone)]
pub(crate) struct Buffer<T = Timestamp>
where
T: TimePoint,
Expand Down Expand Up @@ -118,6 +119,7 @@ where
/// a time series of dynamic samples. Keeping the kind structural — instead
/// of a flag re-derived from the stored data — makes it impossible for a
/// buffer to change kind when it is emptied and refilled.
#[derive(Clone)]
enum Kind<T>
where
T: TimePoint,
Expand Down
18 changes: 17 additions & 1 deletion src/core/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<'a> Mul for Hop<'a> {
/// `Registry<T>` is `Send` and `Sync` when `T` is. An external `RwLock` permits
/// concurrent readers; writers need exclusive access, and readers may wait for
/// writers. Keep dependent queries under one guard.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Registry<T = Timestamp>
where
T: TimePoint,
Expand Down Expand Up @@ -159,6 +159,22 @@ where
Self::process_add_transform(t, &mut self.data, self.max_age)
}

/// Inserts a batch atomically. An invalid transform leaves the registry unchanged.
///
/// # Errors
/// Returns the first error from [`Registry::add_transform`].
pub fn add_transforms(
&mut self,
transforms: impl IntoIterator<Item = Transform<T>>,
) -> Result<(), RegistryError<T>> {
let mut next = self.clone();
for transform in transforms {
next.add_transform(transform)?;
}
*self = next;
Ok(())
}

/// Maps `source`-frame coordinates into `target` at `timestamp`.
///
/// The argument order matches tf2's `lookupTransform(target, source, time)`.
Expand Down
50 changes: 50 additions & 0 deletions src/core/registry/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3732,4 +3732,54 @@ mod registry_tests {
"expected the moved frame to still be static, got {result:?}"
);
}
#[test]
fn a_failed_batch_does_not_leave_edges_or_evictions_behind() {
let mut registry = Registry::with_max_age(Duration::from_nanos(10));
let sample = |parent, child, ns, x| {
Transform::new(
parent,
child,
Vector3::new(x, 0.0, 0.0),
Quaternion::identity(),
Stamp::At(Timestamp::from_nanos(ns)),
)
.unwrap()
};
registry
.add_transform(sample("map", "base", 1, 1.0))
.unwrap();
let result = registry.add_transforms([
sample("map", "base", 100, 2.0),
sample("base", "camera", 100, 3.0),
sample("camera", "map", 100, 4.0),
]);
assert!(matches!(result, Err(RegistryError::CycleDetected)));
assert_eq!(
registry
.get_transform("map", "base", Timestamp::from_nanos(1))
.unwrap()
.translation()
.x,
1.0
);
assert!(
registry
.get_transform("base", "camera", Timestamp::from_nanos(100))
.is_err()
);
registry
.add_transforms([
sample("map", "base", 2, 2.0),
sample("base", "camera", 2, 3.0),
])
.unwrap();
assert_eq!(
registry
.get_transform("map", "camera", Timestamp::from_nanos(2))
.unwrap()
.translation()
.x,
5.0
);
}
}