re_types/components/
transform_relation.rs1#![allow(unused_imports)]
5#![allow(unused_parens)]
6#![allow(clippy::clone_on_copy)]
7#![allow(clippy::cloned_instead_of_copied)]
8#![allow(clippy::map_flatten)]
9#![allow(clippy::needless_question_mark)]
10#![allow(clippy::new_without_default)]
11#![allow(clippy::redundant_closure)]
12#![allow(clippy::too_many_arguments)]
13#![allow(clippy::too_many_lines)]
14#![allow(non_camel_case_types)]
15
16use ::re_types_core::try_serialize_field;
17use ::re_types_core::SerializationResult;
18use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
19use ::re_types_core::{ComponentDescriptor, ComponentName};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Default)]
24#[repr(u8)]
25pub enum TransformRelation {
26 #[default]
32 ParentFromChild = 1,
33
34 ChildFromParent = 2,
40}
41
42impl ::re_types_core::Component for TransformRelation {
43 #[inline]
44 fn descriptor() -> ComponentDescriptor {
45 ComponentDescriptor::new("rerun.components.TransformRelation")
46 }
47}
48
49::re_types_core::macros::impl_into_cow!(TransformRelation);
50
51impl ::re_types_core::Loggable for TransformRelation {
52 #[inline]
53 fn arrow_datatype() -> arrow::datatypes::DataType {
54 #![allow(clippy::wildcard_imports)]
55 use arrow::datatypes::*;
56 DataType::UInt8
57 }
58
59 fn to_arrow_opt<'a>(
60 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
61 ) -> SerializationResult<arrow::array::ArrayRef>
62 where
63 Self: Clone + 'a,
64 {
65 #![allow(clippy::wildcard_imports)]
66 #![allow(clippy::manual_is_variant_and)]
67 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
68 use arrow::{array::*, buffer::*, datatypes::*};
69 Ok({
70 let (somes, data0): (Vec<_>, Vec<_>) = data
71 .into_iter()
72 .map(|datum| {
73 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
74 let datum = datum.map(|datum| *datum as u8);
75 (datum.is_some(), datum)
76 })
77 .unzip();
78 let data0_validity: Option<arrow::buffer::NullBuffer> = {
79 let any_nones = somes.iter().any(|some| !*some);
80 any_nones.then(|| somes.into())
81 };
82 as_array_ref(PrimitiveArray::<UInt8Type>::new(
83 ScalarBuffer::from(
84 data0
85 .into_iter()
86 .map(|v| v.unwrap_or_default())
87 .collect::<Vec<_>>(),
88 ),
89 data0_validity,
90 ))
91 })
92 }
93
94 fn from_arrow_opt(
95 arrow_data: &dyn arrow::array::Array,
96 ) -> DeserializationResult<Vec<Option<Self>>>
97 where
98 Self: Sized,
99 {
100 #![allow(clippy::wildcard_imports)]
101 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
102 use arrow::{array::*, buffer::*, datatypes::*};
103 Ok(arrow_data
104 .as_any()
105 .downcast_ref::<UInt8Array>()
106 .ok_or_else(|| {
107 let expected = Self::arrow_datatype();
108 let actual = arrow_data.data_type().clone();
109 DeserializationError::datatype_mismatch(expected, actual)
110 })
111 .with_context("rerun.components.TransformRelation#enum")?
112 .into_iter()
113 .map(|typ| match typ {
114 Some(1) => Ok(Some(Self::ParentFromChild)),
115 Some(2) => Ok(Some(Self::ChildFromParent)),
116 None => Ok(None),
117 Some(invalid) => Err(DeserializationError::missing_union_arm(
118 Self::arrow_datatype(),
119 "<invalid>",
120 invalid as _,
121 )),
122 })
123 .collect::<DeserializationResult<Vec<Option<_>>>>()
124 .with_context("rerun.components.TransformRelation")?)
125 }
126}
127
128impl std::fmt::Display for TransformRelation {
129 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
130 match self {
131 Self::ParentFromChild => write!(f, "ParentFromChild"),
132 Self::ChildFromParent => write!(f, "ChildFromParent"),
133 }
134 }
135}
136
137impl ::re_types_core::reflection::Enum for TransformRelation {
138 #[inline]
139 fn variants() -> &'static [Self] {
140 &[Self::ParentFromChild, Self::ChildFromParent]
141 }
142
143 #[inline]
144 fn docstring_md(self) -> &'static str {
145 match self {
146 Self::ParentFromChild => {
147 "The transform describes how to transform into the parent entity's space.\n\nE.g. a translation of (0, 1, 0) with this [`components.TransformRelation`](https://rerun.io/docs/reference/types/components/transform_relation) logged at `parent/child` means\nthat from the point of view of `parent`, `parent/child` is translated 1 unit along `parent`'s Y axis.\nFrom perspective of `parent/child`, the `parent` entity is translated -1 unit along `parent/child`'s Y axis."
148 }
149 Self::ChildFromParent => {
150 "The transform describes how to transform into the child entity's space.\n\nE.g. a translation of (0, 1, 0) with this [`components.TransformRelation`](https://rerun.io/docs/reference/types/components/transform_relation) logged at `parent/child` means\nthat from the point of view of `parent`, `parent/child` is translated -1 unit along `parent`'s Y axis.\nFrom perspective of `parent/child`, the `parent` entity is translated 1 unit along `parent/child`'s Y axis."
151 }
152 }
153 }
154}
155
156impl ::re_byte_size::SizeBytes for TransformRelation {
157 #[inline]
158 fn heap_size_bytes(&self) -> u64 {
159 0
160 }
161
162 #[inline]
163 fn is_pod() -> bool {
164 true
165 }
166}