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

Codegen/IDL 8: handwritten Rust tests and extensions for Points2D #2432

Merged
merged 70 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
5287969
more build tools
teh-cmc Jun 11, 2023
882f61a
self-review
teh-cmc Jun 11, 2023
86da1f8
addressing PR comments
teh-cmc Jun 13, 2023
e6c3c7d
introduce re_types_builder
teh-cmc Jun 11, 2023
64cf2b3
generate reflection code
teh-cmc Jun 11, 2023
b28d4b1
unindent 0.1 everywhere
teh-cmc Jun 11, 2023
e33765f
self-review
teh-cmc Jun 11, 2023
005b08b
adhering to py38+ style guide
teh-cmc Jun 12, 2023
181d27c
vscode flatbuffer things. Fix comment typo
Wumpf Jun 12, 2023
8f462e8
turn the inner from_similar into _from_similar to appease linters
teh-cmc Jun 13, 2023
2ec5b58
generate __all__ everywhere to make python tools behave
teh-cmc Jun 13, 2023
69c33b4
make sure __all__ manifests are lexically sorted
teh-cmc Jun 13, 2023
e2c5c15
adressing PR comments
teh-cmc Jun 14, 2023
c345043
introduce re_types
teh-cmc Jun 11, 2023
9de1899
self-review
teh-cmc Jun 11, 2023
075c79f
python shall output to rerun_py/rerun_sdk/rerun2
teh-cmc Jun 12, 2023
78ad63a
addressing PR comments
teh-cmc Jun 14, 2023
d601fa3
Rerun attributes' definitions
teh-cmc Jun 11, 2023
efcccc5
Rerun datatypes' definitions
teh-cmc Jun 11, 2023
6787d17
Rerun components' definitions
teh-cmc Jun 11, 2023
c4fbbc0
Rerun archetypes' definitions
teh-cmc Jun 11, 2023
717e8bb
fixing typo in re_types_builder doc
teh-cmc Jun 11, 2023
f4b8355
self-review
teh-cmc Jun 11, 2023
4d84e2b
fix DrawOrder missing PartialEq & PartialOrd
teh-cmc Jun 12, 2023
e0fe71a
addressing PR comments
teh-cmc Jun 14, 2023
2b53494
fixing typo in re_types_builder doc
teh-cmc Jun 11, 2023
20130a6
autogenerated python code
teh-cmc Jun 11, 2023
8f4b3de
freshly autogenerated python code for new py38+ style guide
teh-cmc Jun 12, 2023
5d1c617
python shall go into rerun_py/rerun_sdk/rerun2
teh-cmc Jun 12, 2023
5f1c36a
setting up pyproject and runtime redirections apropriately
teh-cmc Jun 12, 2023
3f4495d
regen after rebase
teh-cmc Jun 13, 2023
1b65e28
regen post rebase
teh-cmc Jun 13, 2023
92facef
addressing PR comments
teh-cmc Jun 14, 2023
725f88d
force regen this so the PR train makes sense
teh-cmc Jun 14, 2023
414e495
fixed wrong indent in python codegen
teh-cmc Jun 14, 2023
8af0471
left a dbg didnt i
teh-cmc Jun 14, 2023
42b607d
autogenerated rust code
teh-cmc Jun 12, 2023
b64aaa8
{Datatype,Component,Archetype}Name
teh-cmc Jun 14, 2023
650ee38
regen post rebase
teh-cmc Jun 14, 2023
0643dfe
regen hash post rebase
teh-cmc Jun 14, 2023
f61f8b3
fixing typo in re_types_builder doc
teh-cmc Jun 11, 2023
abf9817
autogenerated rust code
teh-cmc Jun 12, 2023
48c8323
regen post rebase
teh-cmc Jun 13, 2023
78a3186
add datatypes.Vec2D extensions
teh-cmc Jun 13, 2023
cf52260
tests and extensions for components.Point2D
teh-cmc Jun 13, 2023
5c12cc9
tests and extensions for components.Radius
teh-cmc Jun 13, 2023
aa40558
tests and extensions for components.Label
teh-cmc Jun 13, 2023
3db48dd
tests and extensions for components.DrawOrder
teh-cmc Jun 13, 2023
d658808
tests and extensions for components.ClassId
teh-cmc Jun 13, 2023
86b0c7b
tests and extensions for components.KeypointId
teh-cmc Jun 13, 2023
61a44e5
tests and extensions for components.InstanceKey
teh-cmc Jun 13, 2023
51af0ff
switch to a zip-longest rather than a product so python doesnt die on us
teh-cmc Jun 13, 2023
9110434
tests and extensions for components.Color
teh-cmc Jun 13, 2023
2834069
back to prod imports
teh-cmc Jun 13, 2023
bdb15f7
fmt
teh-cmc Jun 13, 2023
f304081
ignore weird inheritance lint -- whatever
teh-cmc Jun 13, 2023
5ecd957
types are types, but type aliases are Types with a T
teh-cmc Jun 13, 2023
c9da4da
regen post rebase
teh-cmc Jun 14, 2023
b50c99f
addressing PR comments
teh-cmc Jun 14, 2023
8c27868
regen hash post rebase
teh-cmc Jun 14, 2023
85a4d70
fighting mypy, round #2345235923523099834
teh-cmc Jun 14, 2023
17c4d54
oh for the love of god do whatever you want but stop complaining ffs
teh-cmc Jun 14, 2023
3b36f28
fighting mypy, round #2345235923523099835
teh-cmc Jun 14, 2023
fe897ed
make sure black and ruff use the right config no matter what
teh-cmc Jun 14, 2023
a37e78a
fighting mypy, round #2345235923523099836
teh-cmc Jun 14, 2023
c3593f7
fighting mypy, round #2345235923523099837
teh-cmc Jun 14, 2023
2edaffb
add rust extensions
teh-cmc Jun 14, 2023
e288dd9
add rust tests
teh-cmc Jun 14, 2023
12ceb39
once is enough
teh-cmc Jun 14, 2023
3eeb9fa
broke git
teh-cmc Jun 14, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/re_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ macaw = { workspace = true, optional = true }
# External
glam.workspace = true
itertools.workspace = true
similar-asserts = "1.4.2"


[build-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct DrawOrder (
"attr.arrow.transparent",
"attr.python.aliases": "float",
"attr.python.array_aliases": "npt.NDArray[np.float32]",
"attr.rust.derive": "Debug, Clone, Copy, PartialEq, PartialOrd",
"attr.rust.derive": "Debug, Clone, Copy",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct",
order: 100
Expand Down
7 changes: 7 additions & 0 deletions crates/re_types/src/components/class_id_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use super::ClassId;

impl From<u16> for ClassId {
fn from(value: u16) -> Self {
Self(value)
}
}
50 changes: 50 additions & 0 deletions crates/re_types/src/components/color_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use super::Color;

impl Color {
#[inline]
pub fn from_rgb(r: u8, g: u8, b: u8) -> Self {
Self::from([r, g, b, 255])
}

#[inline]
pub fn from_unmultiplied_rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
Self::from([r, g, b, a])
}

#[inline]
pub fn to_array(&self) -> [u8; 4] {
[
(self.0 >> 24) as u8,
(self.0 >> 16) as u8,
(self.0 >> 8) as u8,
self.0 as u8,
]
}
}

impl From<u32> for Color {
#[inline]
fn from(c: u32) -> Self {
Self(c)
}
}

impl From<[u8; 4]> for Color {
#[inline]
fn from(bytes: [u8; 4]) -> Self {
Self(
(bytes[0] as u32) << 24
| (bytes[1] as u32) << 16
| (bytes[2] as u32) << 8
| (bytes[3] as u32),
)
}
}

#[cfg(feature = "ecolor")]
impl From<Color> for ecolor::Color32 {
fn from(color: Color) -> Self {
let [r, g, b, a] = color.to_array();
Self::from_rgba_premultiplied(r, g, b, a)
}
}
2 changes: 1 addition & 1 deletion crates/re_types/src/components/draw_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// Within an entity draw order is governed by the order of the components.
///
/// Draw order for entities with the same draw order is generally undefined.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct DrawOrder(pub f32);

Expand Down
60 changes: 60 additions & 0 deletions crates/re_types/src/components/draw_order_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use super::DrawOrder;

// TODO(cmc): come up with some DSL in our flatbuffers definitions so that we can declare these
// constants directly in there.
impl DrawOrder {
/// Draw order used for images if no draw order was specified.
pub const DEFAULT_IMAGE: DrawOrder = DrawOrder(-10.0);

/// Draw order used for 2D boxes if no draw order was specified.
pub const DEFAULT_BOX2D: DrawOrder = DrawOrder(10.0);

/// Draw order used for 2D lines if no draw order was specified.
pub const DEFAULT_LINES2D: DrawOrder = DrawOrder(20.0);

/// Draw order used for 2D points if no draw order was specified.
pub const DEFAULT_POINTS2D: DrawOrder = DrawOrder(30.0);
}

impl std::cmp::PartialEq for DrawOrder {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.0.is_nan() && other.0.is_nan() || self.0 == other.0
}
}

impl std::cmp::Eq for DrawOrder {}

impl std::cmp::PartialOrd for DrawOrder {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
if other == self {
Some(std::cmp::Ordering::Equal)
} else if other.0.is_nan() || self.0 < other.0 {
Some(std::cmp::Ordering::Less)
} else {
Some(std::cmp::Ordering::Greater)
}
}
}

impl std::cmp::Ord for DrawOrder {
#[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.partial_cmp(other).unwrap()
}
}

impl From<f32> for DrawOrder {
#[inline]
fn from(value: f32) -> Self {
Self(value)
}
}

impl From<DrawOrder> for f32 {
#[inline]
fn from(value: DrawOrder) -> Self {
value.0
}
}
22 changes: 22 additions & 0 deletions crates/re_types/src/components/instance_key_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use super::InstanceKey;

// TODO(cmc): come up with some DSL in our flatbuffers definitions so that we can declare these
// constants directly in there.
impl InstanceKey {
/// Draw order used for images if no draw order was specified.
pub const SPLAT: Self = Self(u64::MAX);
}

impl From<u64> for InstanceKey {
#[inline]
fn from(value: u64) -> Self {
Self(value)
}
}

impl From<InstanceKey> for u64 {
#[inline]
fn from(value: InstanceKey) -> Self {
value.0
}
}
7 changes: 7 additions & 0 deletions crates/re_types/src/components/keypoint_id_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use super::KeypointId;

impl From<u16> for KeypointId {
fn from(value: u16) -> Self {
Self(value)
}
}
51 changes: 51 additions & 0 deletions crates/re_types/src/components/label_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use super::Label;

impl Label {
#[inline]
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}

impl From<String> for Label {
#[inline]
fn from(value: String) -> Self {
Self(value)
}
}

impl From<&str> for Label {
#[inline]
fn from(value: &str) -> Self {
Self(value.to_owned())
}
}

impl From<Label> for String {
#[inline]
fn from(value: Label) -> Self {
value.0
}
}

impl AsRef<str> for Label {
#[inline]
fn as_ref(&self) -> &str {
self.as_str()
}
}

impl std::borrow::Borrow<str> for Label {
#[inline]
fn borrow(&self) -> &str {
self.as_str()
}
}

impl std::ops::Deref for Label {
type Target = str;
#[inline]
fn deref(&self) -> &str {
self.as_str()
}
}
8 changes: 8 additions & 0 deletions crates/re_types/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT.

mod class_id;
mod class_id_ext;
mod color;
mod color_ext;
mod draw_order;
mod draw_order_ext;
mod instance_key;
mod instance_key_ext;
mod keypoint_id;
mod keypoint_id_ext;
mod label;
mod label_ext;
mod point2d;
mod point2d_ext;
mod radius;
mod radius_ext;

pub use self::class_id::ClassId;
pub use self::color::Color;
Expand Down
57 changes: 57 additions & 0 deletions crates/re_types/src/components/point2d_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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(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)
}
}
24 changes: 24 additions & 0 deletions crates/re_types/src/components/radius_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use super::Radius;

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

#[inline]
pub const fn new(r: f32) -> Self {
Self(r)
}
}

impl From<f32> for Radius {
#[inline]
fn from(r: f32) -> Self {
Self::new(r)
}
}

impl std::fmt::Display for Radius {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:.prec$}", self.0, prec = crate::DISPLAY_PRECISION,)
}
}
1 change: 1 addition & 0 deletions crates/re_types/src/datatypes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT.

mod vec2d;
mod vec2d_ext;

pub use self::vec2d::Vec2D;
Loading