1#![allow(unused_braces)]
5#![allow(unused_imports)]
6#![allow(unused_parens)]
7#![allow(clippy::clone_on_copy)]
8#![allow(clippy::cloned_instead_of_copied)]
9#![allow(clippy::map_flatten)]
10#![allow(clippy::needless_question_mark)]
11#![allow(clippy::new_without_default)]
12#![allow(clippy::redundant_closure)]
13#![allow(clippy::too_many_arguments)]
14#![allow(clippy::too_many_lines)]
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, ComponentType};
20use ::re_types_core::{DeserializationError, DeserializationResult};
21
22#[derive(Clone, Debug, PartialEq, Default)]
53pub struct Arrows2D {
54 pub vectors: Option<SerializedComponentBatch>,
56
57 pub origins: Option<SerializedComponentBatch>,
61
62 pub radii: Option<SerializedComponentBatch>,
67
68 pub colors: Option<SerializedComponentBatch>,
70
71 pub labels: Option<SerializedComponentBatch>,
76
77 pub show_labels: Option<SerializedComponentBatch>,
82
83 pub draw_order: Option<SerializedComponentBatch>,
87
88 pub class_ids: Option<SerializedComponentBatch>,
92}
93
94impl Arrows2D {
95 #[inline]
99 pub fn descriptor_vectors() -> ComponentDescriptor {
100 ComponentDescriptor {
101 archetype: Some("rerun.archetypes.Arrows2D".into()),
102 component: "Arrows2D:vectors".into(),
103 component_type: Some("rerun.components.Vector2D".into()),
104 }
105 }
106
107 #[inline]
111 pub fn descriptor_origins() -> ComponentDescriptor {
112 ComponentDescriptor {
113 archetype: Some("rerun.archetypes.Arrows2D".into()),
114 component: "Arrows2D:origins".into(),
115 component_type: Some("rerun.components.Position2D".into()),
116 }
117 }
118
119 #[inline]
123 pub fn descriptor_radii() -> ComponentDescriptor {
124 ComponentDescriptor {
125 archetype: Some("rerun.archetypes.Arrows2D".into()),
126 component: "Arrows2D:radii".into(),
127 component_type: Some("rerun.components.Radius".into()),
128 }
129 }
130
131 #[inline]
135 pub fn descriptor_colors() -> ComponentDescriptor {
136 ComponentDescriptor {
137 archetype: Some("rerun.archetypes.Arrows2D".into()),
138 component: "Arrows2D:colors".into(),
139 component_type: Some("rerun.components.Color".into()),
140 }
141 }
142
143 #[inline]
147 pub fn descriptor_labels() -> ComponentDescriptor {
148 ComponentDescriptor {
149 archetype: Some("rerun.archetypes.Arrows2D".into()),
150 component: "Arrows2D:labels".into(),
151 component_type: Some("rerun.components.Text".into()),
152 }
153 }
154
155 #[inline]
159 pub fn descriptor_show_labels() -> ComponentDescriptor {
160 ComponentDescriptor {
161 archetype: Some("rerun.archetypes.Arrows2D".into()),
162 component: "Arrows2D:show_labels".into(),
163 component_type: Some("rerun.components.ShowLabels".into()),
164 }
165 }
166
167 #[inline]
171 pub fn descriptor_draw_order() -> ComponentDescriptor {
172 ComponentDescriptor {
173 archetype: Some("rerun.archetypes.Arrows2D".into()),
174 component: "Arrows2D:draw_order".into(),
175 component_type: Some("rerun.components.DrawOrder".into()),
176 }
177 }
178
179 #[inline]
183 pub fn descriptor_class_ids() -> ComponentDescriptor {
184 ComponentDescriptor {
185 archetype: Some("rerun.archetypes.Arrows2D".into()),
186 component: "Arrows2D:class_ids".into(),
187 component_type: Some("rerun.components.ClassId".into()),
188 }
189 }
190}
191
192static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
193 once_cell::sync::Lazy::new(|| [Arrows2D::descriptor_vectors()]);
194
195static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 1usize]> =
196 once_cell::sync::Lazy::new(|| [Arrows2D::descriptor_origins()]);
197
198static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 6usize]> =
199 once_cell::sync::Lazy::new(|| {
200 [
201 Arrows2D::descriptor_radii(),
202 Arrows2D::descriptor_colors(),
203 Arrows2D::descriptor_labels(),
204 Arrows2D::descriptor_show_labels(),
205 Arrows2D::descriptor_draw_order(),
206 Arrows2D::descriptor_class_ids(),
207 ]
208 });
209
210static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 8usize]> =
211 once_cell::sync::Lazy::new(|| {
212 [
213 Arrows2D::descriptor_vectors(),
214 Arrows2D::descriptor_origins(),
215 Arrows2D::descriptor_radii(),
216 Arrows2D::descriptor_colors(),
217 Arrows2D::descriptor_labels(),
218 Arrows2D::descriptor_show_labels(),
219 Arrows2D::descriptor_draw_order(),
220 Arrows2D::descriptor_class_ids(),
221 ]
222 });
223
224impl Arrows2D {
225 pub const NUM_COMPONENTS: usize = 8usize;
227}
228
229impl ::re_types_core::Archetype for Arrows2D {
230 #[inline]
231 fn name() -> ::re_types_core::ArchetypeName {
232 "rerun.archetypes.Arrows2D".into()
233 }
234
235 #[inline]
236 fn display_name() -> &'static str {
237 "Arrows 2D"
238 }
239
240 #[inline]
241 fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
242 REQUIRED_COMPONENTS.as_slice().into()
243 }
244
245 #[inline]
246 fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
247 RECOMMENDED_COMPONENTS.as_slice().into()
248 }
249
250 #[inline]
251 fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
252 OPTIONAL_COMPONENTS.as_slice().into()
253 }
254
255 #[inline]
256 fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
257 ALL_COMPONENTS.as_slice().into()
258 }
259
260 #[inline]
261 fn from_arrow_components(
262 arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
263 ) -> DeserializationResult<Self> {
264 re_tracing::profile_function!();
265 use ::re_types_core::{Loggable as _, ResultExt as _};
266 let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
267 let vectors = arrays_by_descr
268 .get(&Self::descriptor_vectors())
269 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_vectors()));
270 let origins = arrays_by_descr
271 .get(&Self::descriptor_origins())
272 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_origins()));
273 let radii = arrays_by_descr
274 .get(&Self::descriptor_radii())
275 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_radii()));
276 let colors = arrays_by_descr
277 .get(&Self::descriptor_colors())
278 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_colors()));
279 let labels = arrays_by_descr
280 .get(&Self::descriptor_labels())
281 .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_labels()));
282 let show_labels = arrays_by_descr
283 .get(&Self::descriptor_show_labels())
284 .map(|array| {
285 SerializedComponentBatch::new(array.clone(), Self::descriptor_show_labels())
286 });
287 let draw_order = arrays_by_descr
288 .get(&Self::descriptor_draw_order())
289 .map(|array| {
290 SerializedComponentBatch::new(array.clone(), Self::descriptor_draw_order())
291 });
292 let class_ids = arrays_by_descr
293 .get(&Self::descriptor_class_ids())
294 .map(|array| {
295 SerializedComponentBatch::new(array.clone(), Self::descriptor_class_ids())
296 });
297 Ok(Self {
298 vectors,
299 origins,
300 radii,
301 colors,
302 labels,
303 show_labels,
304 draw_order,
305 class_ids,
306 })
307 }
308}
309
310impl ::re_types_core::AsComponents for Arrows2D {
311 #[inline]
312 fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
313 use ::re_types_core::Archetype as _;
314 [
315 self.vectors.clone(),
316 self.origins.clone(),
317 self.radii.clone(),
318 self.colors.clone(),
319 self.labels.clone(),
320 self.show_labels.clone(),
321 self.draw_order.clone(),
322 self.class_ids.clone(),
323 ]
324 .into_iter()
325 .flatten()
326 .collect()
327 }
328}
329
330impl ::re_types_core::ArchetypeReflectionMarker for Arrows2D {}
331
332impl Arrows2D {
333 #[inline]
335 pub(crate) fn new(
336 vectors: impl IntoIterator<Item = impl Into<crate::components::Vector2D>>,
337 ) -> Self {
338 Self {
339 vectors: try_serialize_field(Self::descriptor_vectors(), vectors),
340 origins: None,
341 radii: None,
342 colors: None,
343 labels: None,
344 show_labels: None,
345 draw_order: None,
346 class_ids: None,
347 }
348 }
349
350 #[inline]
352 pub fn update_fields() -> Self {
353 Self::default()
354 }
355
356 #[inline]
358 pub fn clear_fields() -> Self {
359 use ::re_types_core::Loggable as _;
360 Self {
361 vectors: Some(SerializedComponentBatch::new(
362 crate::components::Vector2D::arrow_empty(),
363 Self::descriptor_vectors(),
364 )),
365 origins: Some(SerializedComponentBatch::new(
366 crate::components::Position2D::arrow_empty(),
367 Self::descriptor_origins(),
368 )),
369 radii: Some(SerializedComponentBatch::new(
370 crate::components::Radius::arrow_empty(),
371 Self::descriptor_radii(),
372 )),
373 colors: Some(SerializedComponentBatch::new(
374 crate::components::Color::arrow_empty(),
375 Self::descriptor_colors(),
376 )),
377 labels: Some(SerializedComponentBatch::new(
378 crate::components::Text::arrow_empty(),
379 Self::descriptor_labels(),
380 )),
381 show_labels: Some(SerializedComponentBatch::new(
382 crate::components::ShowLabels::arrow_empty(),
383 Self::descriptor_show_labels(),
384 )),
385 draw_order: Some(SerializedComponentBatch::new(
386 crate::components::DrawOrder::arrow_empty(),
387 Self::descriptor_draw_order(),
388 )),
389 class_ids: Some(SerializedComponentBatch::new(
390 crate::components::ClassId::arrow_empty(),
391 Self::descriptor_class_ids(),
392 )),
393 }
394 }
395
396 #[inline]
407 pub fn columns<I>(
408 self,
409 _lengths: I,
410 ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
411 where
412 I: IntoIterator<Item = usize> + Clone,
413 {
414 let columns = [
415 self.vectors
416 .map(|vectors| vectors.partitioned(_lengths.clone()))
417 .transpose()?,
418 self.origins
419 .map(|origins| origins.partitioned(_lengths.clone()))
420 .transpose()?,
421 self.radii
422 .map(|radii| radii.partitioned(_lengths.clone()))
423 .transpose()?,
424 self.colors
425 .map(|colors| colors.partitioned(_lengths.clone()))
426 .transpose()?,
427 self.labels
428 .map(|labels| labels.partitioned(_lengths.clone()))
429 .transpose()?,
430 self.show_labels
431 .map(|show_labels| show_labels.partitioned(_lengths.clone()))
432 .transpose()?,
433 self.draw_order
434 .map(|draw_order| draw_order.partitioned(_lengths.clone()))
435 .transpose()?,
436 self.class_ids
437 .map(|class_ids| class_ids.partitioned(_lengths.clone()))
438 .transpose()?,
439 ];
440 Ok(columns.into_iter().flatten())
441 }
442
443 #[inline]
448 pub fn columns_of_unit_batches(
449 self,
450 ) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>> {
451 let len_vectors = self.vectors.as_ref().map(|b| b.array.len());
452 let len_origins = self.origins.as_ref().map(|b| b.array.len());
453 let len_radii = self.radii.as_ref().map(|b| b.array.len());
454 let len_colors = self.colors.as_ref().map(|b| b.array.len());
455 let len_labels = self.labels.as_ref().map(|b| b.array.len());
456 let len_show_labels = self.show_labels.as_ref().map(|b| b.array.len());
457 let len_draw_order = self.draw_order.as_ref().map(|b| b.array.len());
458 let len_class_ids = self.class_ids.as_ref().map(|b| b.array.len());
459 let len = None
460 .or(len_vectors)
461 .or(len_origins)
462 .or(len_radii)
463 .or(len_colors)
464 .or(len_labels)
465 .or(len_show_labels)
466 .or(len_draw_order)
467 .or(len_class_ids)
468 .unwrap_or(0);
469 self.columns(std::iter::repeat(1).take(len))
470 }
471
472 #[inline]
474 pub fn with_vectors(
475 mut self,
476 vectors: impl IntoIterator<Item = impl Into<crate::components::Vector2D>>,
477 ) -> Self {
478 self.vectors = try_serialize_field(Self::descriptor_vectors(), vectors);
479 self
480 }
481
482 #[inline]
486 pub fn with_origins(
487 mut self,
488 origins: impl IntoIterator<Item = impl Into<crate::components::Position2D>>,
489 ) -> Self {
490 self.origins = try_serialize_field(Self::descriptor_origins(), origins);
491 self
492 }
493
494 #[inline]
499 pub fn with_radii(
500 mut self,
501 radii: impl IntoIterator<Item = impl Into<crate::components::Radius>>,
502 ) -> Self {
503 self.radii = try_serialize_field(Self::descriptor_radii(), radii);
504 self
505 }
506
507 #[inline]
509 pub fn with_colors(
510 mut self,
511 colors: impl IntoIterator<Item = impl Into<crate::components::Color>>,
512 ) -> Self {
513 self.colors = try_serialize_field(Self::descriptor_colors(), colors);
514 self
515 }
516
517 #[inline]
522 pub fn with_labels(
523 mut self,
524 labels: impl IntoIterator<Item = impl Into<crate::components::Text>>,
525 ) -> Self {
526 self.labels = try_serialize_field(Self::descriptor_labels(), labels);
527 self
528 }
529
530 #[inline]
535 pub fn with_show_labels(
536 mut self,
537 show_labels: impl Into<crate::components::ShowLabels>,
538 ) -> Self {
539 self.show_labels = try_serialize_field(Self::descriptor_show_labels(), [show_labels]);
540 self
541 }
542
543 #[inline]
548 pub fn with_many_show_labels(
549 mut self,
550 show_labels: impl IntoIterator<Item = impl Into<crate::components::ShowLabels>>,
551 ) -> Self {
552 self.show_labels = try_serialize_field(Self::descriptor_show_labels(), show_labels);
553 self
554 }
555
556 #[inline]
560 pub fn with_draw_order(mut self, draw_order: impl Into<crate::components::DrawOrder>) -> Self {
561 self.draw_order = try_serialize_field(Self::descriptor_draw_order(), [draw_order]);
562 self
563 }
564
565 #[inline]
570 pub fn with_many_draw_order(
571 mut self,
572 draw_order: impl IntoIterator<Item = impl Into<crate::components::DrawOrder>>,
573 ) -> Self {
574 self.draw_order = try_serialize_field(Self::descriptor_draw_order(), draw_order);
575 self
576 }
577
578 #[inline]
582 pub fn with_class_ids(
583 mut self,
584 class_ids: impl IntoIterator<Item = impl Into<crate::components::ClassId>>,
585 ) -> Self {
586 self.class_ids = try_serialize_field(Self::descriptor_class_ids(), class_ids);
587 self
588 }
589}
590
591impl ::re_byte_size::SizeBytes for Arrows2D {
592 #[inline]
593 fn heap_size_bytes(&self) -> u64 {
594 self.vectors.heap_size_bytes()
595 + self.origins.heap_size_bytes()
596 + self.radii.heap_size_bytes()
597 + self.colors.heap_size_bytes()
598 + self.labels.heap_size_bytes()
599 + self.show_labels.heap_size_bytes()
600 + self.draw_order.heap_size_bytes()
601 + self.class_ids.heap_size_bytes()
602 }
603}