Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle proper half-size splatting semantics in from_mins_and_sizes #7291

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
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>())
}
}
}
Loading