Skip to content

Commit

Permalink
helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Apr 12, 2023
1 parent 42bbb1e commit 137a937
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 46 deletions.
6 changes: 6 additions & 0 deletions crates/re_log_types/src/component_types/instance_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ impl InstanceKey {
/// for example all points in a point cloud entity.
pub const SPLAT: Self = Self(u64::MAX);

#[allow(clippy::should_implement_trait)]
#[inline]
pub fn from_iter(it: impl IntoIterator<Item = impl Into<Self>>) -> Vec<Self> {
it.into_iter().map(Into::into).collect::<Vec<_>>()
}

/// Are we referring to all instances of the entity (e.g. all points in a point cloud entity)?
///
/// The opposite of [`Self::is_specific`].
Expand Down
8 changes: 1 addition & 7 deletions crates/re_query/src/entity_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,7 @@ fn lookup_value() {
use re_log_types::component_types::{InstanceKey, Point2D, Rect2D};
use re_log_types::external::arrow2_convert::serialize::arrow_serialize_to_mutable_array;

let instance_keys = [
InstanceKey(0), //
InstanceKey(1),
InstanceKey(2),
InstanceKey(3),
InstanceKey(4),
];
let instance_keys = InstanceKey::from_iter(0..5);

let points = [
Point2D { x: 1.0, y: 2.0 }, //
Expand Down
6 changes: 1 addition & 5 deletions crates/re_query/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
//! # use re_query::EntityView;
//! # use re_log_types::component_types::{ColorRGBA, InstanceKey, Point2D};
//!
//! let instances = [
//! InstanceKey(0),
//! InstanceKey(1),
//! InstanceKey(2),
//! ];
//! let instances = InstanceKey::from_iter(0..3);
//!
//! let points = [
//! Point2D { x: 1.0, y: 2.0 },
Expand Down
40 changes: 6 additions & 34 deletions crates/re_query/tests/visit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use re_query::{ComponentWithInstances, EntityView};

#[test]
fn basic_single_iter() {
let instance_keys = [
InstanceKey(0), //
InstanceKey(1),
];
let instance_keys = InstanceKey::from_iter(0..2);
let points = [
Point2D { x: 1.0, y: 2.0 }, //
Point2D { x: 3.0, y: 4.0 },
Expand All @@ -28,11 +25,7 @@ fn basic_single_iter() {

#[test]
fn implicit_joined_iter() {
let instance_keys = [
InstanceKey(0), //
InstanceKey(1),
InstanceKey(2),
];
let instance_keys = InstanceKey::from_iter(0..3);

let points = [
Point2D { x: 1.0, y: 2.0 }, //
Expand Down Expand Up @@ -69,11 +62,7 @@ fn implicit_joined_iter() {

#[test]
fn implicit_primary_joined_iter() {
let point_ids = [
InstanceKey(0), //
InstanceKey(1),
InstanceKey(2),
];
let point_ids = InstanceKey::from_iter(0..3);

let points = [
Point2D { x: 1.0, y: 2.0 }, //
Expand Down Expand Up @@ -126,13 +115,7 @@ fn implicit_component_joined_iter() {
Point2D { x: 5.0, y: 6.0 },
];

let color_ids = [
InstanceKey(0), //
InstanceKey(1),
InstanceKey(2),
InstanceKey(3),
InstanceKey(4),
];
let color_ids = InstanceKey::from_iter(0..5);

let colors = [
ColorRGBA(0), //
Expand Down Expand Up @@ -219,12 +202,7 @@ fn complex_joined_iter() {

#[test]
fn single_visit() {
let instance_keys = [
InstanceKey(0), //
InstanceKey(1),
InstanceKey(2),
InstanceKey(3),
];
let instance_keys = InstanceKey::from_iter(0..4);
let points = [
Point2D { x: 1.0, y: 2.0 },
Point2D { x: 3.0, y: 4.0 },
Expand Down Expand Up @@ -259,13 +237,7 @@ fn joint_visit() {
Point2D { x: 9.0, y: 10.0 },
];

let point_ids = [
InstanceKey(0), //
InstanceKey(1),
InstanceKey(2),
InstanceKey(3),
InstanceKey(4),
];
let point_ids = InstanceKey::from_iter(0..5);

let colors = vec![
ColorRGBA(0xff000000), //
Expand Down

0 comments on commit 137a937

Please sign in to comment.