Skip to content

Commit

Permalink
Codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Jul 4, 2023
1 parent 9c2bab1 commit 22bd5a8
Show file tree
Hide file tree
Showing 27 changed files with 1,206 additions and 2,765 deletions.
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
5cac23400a6084eaaa53fba54885d12daefa92fdbdb057c8221ec343dcdd9586
cfb190847b7ffeee14ee498f1f513044c7bdf2ffe8459ac14b39d82fa5c503a0
172 changes: 3 additions & 169 deletions crates/re_types/src/archetypes/fuzzy.rs

Large diffs are not rendered by default.

1,073 changes: 0 additions & 1,073 deletions crates/re_types/src/components/fuzzy.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion crates/re_types/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub use self::color::Color;
pub use self::draw_order::DrawOrder;
pub use self::fuzzy::{
AffixFuzzer1, AffixFuzzer2, AffixFuzzer3, AffixFuzzer4, AffixFuzzer5, AffixFuzzer6,
AffixFuzzer7,
};
pub use self::instance_key::InstanceKey;
pub use self::keypoint_id::KeypointId;
Expand Down
135 changes: 46 additions & 89 deletions crates/re_types/src/components/point2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#[doc = "A point in 2D space."]
#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd)]
pub struct Point2D {
pub x: f32,
pub y: f32,
pub xy: crate::datatypes::Point2D,
}

impl<'a> From<Point2D> for ::std::borrow::Cow<'a, Point2D> {
Expand All @@ -39,20 +38,25 @@ impl crate::Component for Point2D {
#[inline]
fn to_arrow_datatype() -> arrow2::datatypes::DataType {
use ::arrow2::datatypes::*;
DataType::Struct(vec![
Field {
name: "x".to_owned(),
data_type: DataType::Float32,
is_nullable: false,
metadata: [].into(),
},
Field {
name: "y".to_owned(),
data_type: DataType::Float32,
is_nullable: false,
metadata: [].into(),
},
])
DataType::Struct(vec![Field {
name: "xy".to_owned(),
data_type: DataType::Struct(vec![
Field {
name: "x".to_owned(),
data_type: DataType::Float32,
is_nullable: false,
metadata: [].into(),
},
Field {
name: "y".to_owned(),
data_type: DataType::Float32,
is_nullable: false,
metadata: [].into(),
},
]),
is_nullable: false,
metadata: [].into(),
}])
}

#[allow(unused_imports, clippy::wildcard_imports)]
Expand Down Expand Up @@ -89,58 +93,27 @@ impl crate::Component for Point2D {
})
.to_logical_type()
.clone(),
vec![
{
let (somes, x): (Vec<_>, Vec<_>) = data
.iter()
.map(|datum| {
let datum = datum.as_ref().map(|datum| {
let Self { x, .. } = &**datum;
x.clone()
});
(datum.is_some(), datum)
})
.unzip();
let x_bitmap: Option<::arrow2::bitmap::Bitmap> = {
let any_nones = somes.iter().any(|some| !*some);
any_nones.then(|| somes.into())
};
PrimitiveArray::new(
{
_ = extension_wrapper;
DataType::Float32.to_logical_type().clone()
},
x.into_iter().map(|v| v.unwrap_or_default()).collect(),
x_bitmap,
)
.boxed()
},
vec![{
let (somes, xy): (Vec<_>, Vec<_>) = data
.iter()
.map(|datum| {
let datum = datum.as_ref().map(|datum| {
let Self { xy, .. } = &**datum;
xy.clone()
});
(datum.is_some(), datum)
})
.unzip();
let xy_bitmap: Option<::arrow2::bitmap::Bitmap> = {
let any_nones = somes.iter().any(|some| !*some);
any_nones.then(|| somes.into())
};
{
let (somes, y): (Vec<_>, Vec<_>) = data
.iter()
.map(|datum| {
let datum = datum.as_ref().map(|datum| {
let Self { y, .. } = &**datum;
y.clone()
});
(datum.is_some(), datum)
})
.unzip();
let y_bitmap: Option<::arrow2::bitmap::Bitmap> = {
let any_nones = somes.iter().any(|some| !*some);
any_nones.then(|| somes.into())
};
PrimitiveArray::new(
{
_ = extension_wrapper;
DataType::Float32.to_logical_type().clone()
},
y.into_iter().map(|v| v.unwrap_or_default()).collect(),
y_bitmap,
)
.boxed()
},
],
_ = xy_bitmap;
_ = extension_wrapper;
crate::datatypes::Point2D::try_to_arrow_opt(xy, None::<&str>)?
}
}],
bitmap,
)
.boxed()
Expand Down Expand Up @@ -172,34 +145,18 @@ impl crate::Component for Point2D {
.map(|field| field.name.as_str())
.zip(data_arrays)
.collect();
let x = {
let data = &**arrays_by_name["x"];
let xy = {
let data = &**arrays_by_name["xy"];

data.as_any()
.downcast_ref::<Float32Array>()
.unwrap()
.into_iter()
.map(|v| v.copied())
crate::datatypes::Point2D::try_from_arrow_opt(data)?.into_iter()
};
let y = {
let data = &**arrays_by_name["y"];

data.as_any()
.downcast_ref::<Float32Array>()
.unwrap()
.into_iter()
.map(|v| v.copied())
};
::itertools::izip!(x, y)
::itertools::izip!(xy)
.enumerate()
.map(|(i, (x, y))| {
.map(|(i, (xy))| {
is_valid(i)
.then(|| {
Ok(Self {
x: x.ok_or_else(|| crate::DeserializationError::MissingData {
datatype: data.data_type().clone(),
})?,
y: y.ok_or_else(|| crate::DeserializationError::MissingData {
xy: xy.ok_or_else(|| crate::DeserializationError::MissingData {
datatype: data.data_type().clone(),
})?,
})
Expand Down
84 changes: 19 additions & 65 deletions crates/re_types/src/components/point2d_ext.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
use super::Point2D;

// ---

impl Point2D {
pub const ZERO: Self = Self::new(0.0, 0.0);
pub const ONE: Self = Self::new(1.0, 1.0);

#[inline]
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
Self {
xy: crate::datatypes::Point2D::new(x, y),
}
}

#[inline]
pub fn x(&self) -> f32 {
self.xy.x
}

#[inline]
pub fn y(&self) -> f32 {
self.xy.y
}
}

impl From<(f32, f32)> for Point2D {
#[inline]
fn from((x, y): (f32, f32)) -> Self {
Self { x, y }
Self::new(x, y)
}
}

impl From<[f32; 2]> for Point2D {
#[inline]
fn from([x, y]: [f32; 2]) -> Self {
Self { x, y }
Self::new(x, y)
}
}

Expand All @@ -36,74 +50,14 @@ impl From<glam::Vec2> for Point2D {
impl From<Point2D> for glam::Vec2 {
#[inline]
fn from(pt: Point2D) -> Self {
Self::new(pt.x, pt.y)
Self::new(pt.x(), pt.y())
}
}

#[cfg(feature = "glam")]
impl From<Point2D> for glam::Vec3 {
#[inline]
fn from(pt: Point2D) -> Self {
Self::new(pt.x, pt.y, 0.0)
Self::new(pt.x(), pt.y(), 0.0)
}
}

// ---

// TODO(cmc): use the following definition instead once we've finalized the switch to HOPE.

// impl Point2D {
// pub const ZERO: Self = Self::new(0.0, 0.0);
// pub const ONE: Self = Self::new(1.0, 1.0);

// #[inline]
// pub const fn new(x: f32, y: f32) -> Self {
// Self(crate::datatypes::Vec2D::new(x, y))
// }
// }

// impl std::ops::Deref for Point2D {
// type Target = crate::datatypes::Vec2D;

// fn deref(&self) -> &Self::Target {
// &self.0
// }
// }

// impl From<(f32, f32)> for Point2D {
// #[inline]
// fn from(xy: (f32, f32)) -> Self {
// Self(xy.into())
// }
// }

// impl From<[f32; 2]> for Point2D {
// #[inline]
// fn from(p: [f32; 2]) -> Self {
// Self(p.into())
// }
// }

// #[cfg(feature = "glam")]
// impl From<glam::Vec2> for Point2D {
// #[inline]
// fn from(pt: glam::Vec2) -> Self {
// Self::new(pt.x, pt.y)
// }
// }

// #[cfg(feature = "glam")]
// impl From<Point2D> for glam::Vec2 {
// #[inline]
// fn from(pt: Point2D) -> Self {
// Self::new(pt.x(), pt.y())
// }
// }

// #[cfg(feature = "glam")]
// impl From<Point2D> for glam::Vec3 {
// #[inline]
// fn from(pt: Point2D) -> Self {
// Self::new(pt.x(), pt.y(), 0.0)
// }
// }
3 changes: 3 additions & 0 deletions crates/re_types/src/datatypes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT.

mod fuzzy;
mod point2d;
mod point2d_ext;
mod vec2d;
mod vec2d_ext;

pub use self::fuzzy::{AffixFuzzer1, AffixFuzzer2};
pub use self::point2d::Point2D;
pub use self::vec2d::Vec2D;
Loading

0 comments on commit 22bd5a8

Please sign in to comment.