From a79b20bda9a4b695f00332394dedcc5f38c436d0 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Tue, 4 Jul 2023 15:53:47 +0200 Subject: [PATCH] add roundtrip test for points2d archetype (rs) --- Cargo.lock | 9 +++++ Cargo.toml | 1 + tests/rust/roundtrips/points2d/Cargo.toml | 13 ++++++ tests/rust/roundtrips/points2d/src/main.rs | 47 ++++++++++++++++++++++ tests/rust/test_api/Cargo.toml | 8 ++-- 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 tests/rust/roundtrips/points2d/Cargo.toml create mode 100644 tests/rust/roundtrips/points2d/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index b739931e9d4a..cc6333e26922 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4927,6 +4927,15 @@ dependencies = [ "serde", ] +[[package]] +name = "roundtrip_points2d" +version = "0.8.0-alpha.0" +dependencies = [ + "anyhow", + "clap", + "rerun", +] + [[package]] name = "run_wasm" version = "0.8.0-alpha.0" diff --git a/Cargo.toml b/Cargo.toml index f05459feb8d7..1c8a744852f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ "rerun_py", "run_wasm", "tests/rust/test_*", + "tests/rust/roundtrips/points2d", ] [workspace.package] diff --git a/tests/rust/roundtrips/points2d/Cargo.toml b/tests/rust/roundtrips/points2d/Cargo.toml new file mode 100644 index 000000000000..b30f9b2b3c69 --- /dev/null +++ b/tests/rust/roundtrips/points2d/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "roundtrip_points2d" +edition.workspace = true +license.workspace = true +publish = false +rust-version.workspace = true +version.workspace = true + +[dependencies] +rerun = { path = "../../../../crates/rerun", features = ["native_viewer"] } + +anyhow = "1.0" +clap = { version = "4.0", features = ["derive"] } diff --git a/tests/rust/roundtrips/points2d/src/main.rs b/tests/rust/roundtrips/points2d/src/main.rs new file mode 100644 index 000000000000..cf86a5208de7 --- /dev/null +++ b/tests/rust/roundtrips/points2d/src/main.rs @@ -0,0 +1,47 @@ +use rerun::{ + components::Rect2D, experimental::archetypes::Points2D, external::re_log, MsgSender, + RecordingStream, +}; + +#[derive(Debug, clap::Parser)] +#[clap(author, version, about)] +struct Args { + #[command(flatten)] + rerun: rerun::clap::RerunArgs, +} + +fn run(rec_stream: &RecordingStream, _args: &Args) -> anyhow::Result<()> { + MsgSender::from_archetype( + "points2d", + &Points2D::new([(1.0, 2.0), (3.0, 4.0)]) + .with_radii([0.42, 0.43]) + .with_colors([0xAA0000CC, 0x00BB00DD]) + .with_labels(["hello", "friend"]) + .with_draw_order(300.0) + .with_class_ids([126, 127]) + .with_keypoint_ids([2, 3]) + .with_instance_keys([66, 666]), + )? + .send(rec_stream)?; + + // Hack to establish 2d view bounds + MsgSender::new("rect") + .with_component(&[Rect2D::from_xywh(0.0, 0.0, 4.0, 6.0)])? + .send(rec_stream)?; + + Ok(()) +} + +fn main() -> anyhow::Result<()> { + re_log::setup_native_logging(); + + use clap::Parser as _; + let args = Args::parse(); + + let default_enabled = true; + args.rerun + .clone() + .run("roundtrip_points2d", default_enabled, move |rec_stream| { + run(&rec_stream, &args).unwrap(); + }) +} diff --git a/tests/rust/test_api/Cargo.toml b/tests/rust/test_api/Cargo.toml index c0a36e6f95af..0442b77beca1 100644 --- a/tests/rust/test_api/Cargo.toml +++ b/tests/rust/test_api/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "test_api" -version = "0.8.0-alpha.0" -edition = "2021" -rust-version = "1.69" -license = "MIT OR Apache-2.0" +edition.workspace = true +license.workspace = true publish = false +rust-version.workspace = true +version.workspace = true [dependencies] rerun = { path = "../../../crates/rerun", features = [