Skip to content

Commit

Permalink
Handle proper half-size splatting semantics in from_mins_and_sizes (#…
Browse files Browse the repository at this point in the history
…7291)

- Resolves: #7289
  • Loading branch information
jleibs authored Aug 28, 2024
1 parent e13b389 commit 88b19f9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
32 changes: 23 additions & 9 deletions crates/store/re_types/src/archetypes/boxes2d_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,28 @@ impl Boxes2D {
sizes: impl IntoIterator<Item = impl Into<Vec2D>>,
) -> Self {
let boxes = Self::from_sizes(sizes);
let centers: Vec<_> = mins
.into_iter()
.zip(boxes.half_sizes.iter())
.map(|(min, half_size)| {
let min = min.into();
Position2D::new(min.x() + half_size.x(), min.y() + half_size.y())
})
.collect();
boxes.with_centers(centers)

// The box semantics are such that the last half-size is used for all remaining boxes.
if let Some(last_half_size) = boxes.half_sizes.last() {
let centers: Vec<_> = mins
.into_iter()
.zip(
boxes
.half_sizes
.iter()
.chain(std::iter::repeat(last_half_size)),
)
.map(|(min, half_size)| {
let min = min.into();
Position2D::new(min.x() + half_size.x(), min.y() + half_size.y())
})
.collect();
boxes.with_centers(centers)
} else {
if mins.into_iter().next().is_some() {
re_log::warn_once!("Must provide at least one size to create boxes.");
}
boxes.with_centers(std::iter::empty::<crate::components::Position2D>())
}
}
}
38 changes: 26 additions & 12 deletions crates/store/re_types/src/archetypes/boxes3d_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,32 @@ impl Boxes3D {
sizes: impl IntoIterator<Item = impl Into<Vec3D>>,
) -> Self {
let boxes = Self::from_sizes(sizes);
let centers: Vec<_> = mins
.into_iter()
.zip(boxes.half_sizes.iter())
.map(|(min, half_size)| {
let min = min.into();
PoseTranslation3D::new(
min.x() + half_size.x(),
min.y() + half_size.y(),
min.z() + half_size.z(),

// The box semantics are such that the last half-size is used for all remaining boxes.
if let Some(last_half_size) = boxes.half_sizes.last() {
let centers: Vec<_> = mins
.into_iter()
.zip(
boxes
.half_sizes
.iter()
.chain(std::iter::repeat(last_half_size)),
)
})
.collect();
boxes.with_centers(centers)
.map(|(min, half_size)| {
let min = min.into();
PoseTranslation3D::new(
min.x() + half_size.x(),
min.y() + half_size.y(),
min.z() + half_size.z(),
)
})
.collect();
boxes.with_centers(centers)
} else {
if mins.into_iter().next().is_some() {
re_log::warn_once!("Must provide at least one size to create boxes.");
}
boxes.with_centers(std::iter::empty::<crate::components::PoseTranslation3D>())
}
}
}

0 comments on commit 88b19f9

Please sign in to comment.