re_types/components/
line_strip3d.rs

1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs
2// Based on "crates/store/re_types/definitions/rerun/components/line_strip3d.fbs".
3
4#![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
15use ::re_types_core::try_serialize_field;
16use ::re_types_core::SerializationResult;
17use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
18use ::re_types_core::{ComponentDescriptor, ComponentName};
19use ::re_types_core::{DeserializationError, DeserializationResult};
20
21/// **Component**: A line strip in 3D space.
22///
23/// A line strip is a list of points connected by line segments. It can be used to draw
24/// approximations of smooth curves.
25///
26/// The points will be connected in order, like so:
27/// ```text
28///        2------3     5
29///       /        \   /
30/// 0----1          \ /
31///                  4
32/// ```
33#[derive(Clone, Debug, Default, PartialEq)]
34pub struct LineStrip3D(pub Vec<crate::datatypes::Vec3D>);
35
36impl ::re_types_core::Component for LineStrip3D {
37    #[inline]
38    fn descriptor() -> ComponentDescriptor {
39        ComponentDescriptor::new("rerun.components.LineStrip3D")
40    }
41}
42
43::re_types_core::macros::impl_into_cow!(LineStrip3D);
44
45impl ::re_types_core::Loggable for LineStrip3D {
46    #[inline]
47    fn arrow_datatype() -> arrow::datatypes::DataType {
48        #![allow(clippy::wildcard_imports)]
49        use arrow::datatypes::*;
50        DataType::List(std::sync::Arc::new(Field::new(
51            "item",
52            <crate::datatypes::Vec3D>::arrow_datatype(),
53            false,
54        )))
55    }
56
57    fn to_arrow_opt<'a>(
58        data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
59    ) -> SerializationResult<arrow::array::ArrayRef>
60    where
61        Self: Clone + 'a,
62    {
63        #![allow(clippy::wildcard_imports)]
64        #![allow(clippy::manual_is_variant_and)]
65        use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
66        use arrow::{array::*, buffer::*, datatypes::*};
67        Ok({
68            let (somes, data0): (Vec<_>, Vec<_>) = data
69                .into_iter()
70                .map(|datum| {
71                    let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
72                    let datum = datum.map(|datum| datum.into_owned().0);
73                    (datum.is_some(), datum)
74                })
75                .unzip();
76            let data0_validity: Option<arrow::buffer::NullBuffer> = {
77                let any_nones = somes.iter().any(|some| !*some);
78                any_nones.then(|| somes.into())
79            };
80            {
81                let offsets = arrow::buffer::OffsetBuffer::<i32>::from_lengths(
82                    data0
83                        .iter()
84                        .map(|opt| opt.as_ref().map_or(0, |datum| datum.len())),
85                );
86                let data0_inner_data: Vec<_> = data0.into_iter().flatten().flatten().collect();
87                let data0_inner_validity: Option<arrow::buffer::NullBuffer> = None;
88                as_array_ref(ListArray::try_new(
89                    std::sync::Arc::new(Field::new(
90                        "item",
91                        <crate::datatypes::Vec3D>::arrow_datatype(),
92                        false,
93                    )),
94                    offsets,
95                    {
96                        let data0_inner_data_inner_data: Vec<_> = data0_inner_data
97                            .into_iter()
98                            .map(|datum| datum.0)
99                            .flatten()
100                            .collect();
101                        let data0_inner_data_inner_validity: Option<arrow::buffer::NullBuffer> =
102                            None;
103                        as_array_ref(FixedSizeListArray::new(
104                            std::sync::Arc::new(Field::new("item", DataType::Float32, false)),
105                            3,
106                            as_array_ref(PrimitiveArray::<Float32Type>::new(
107                                ScalarBuffer::from(
108                                    data0_inner_data_inner_data.into_iter().collect::<Vec<_>>(),
109                                ),
110                                data0_inner_data_inner_validity,
111                            )),
112                            data0_inner_validity,
113                        ))
114                    },
115                    data0_validity,
116                )?)
117            }
118        })
119    }
120
121    fn from_arrow_opt(
122        arrow_data: &dyn arrow::array::Array,
123    ) -> DeserializationResult<Vec<Option<Self>>>
124    where
125        Self: Sized,
126    {
127        #![allow(clippy::wildcard_imports)]
128        use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
129        use arrow::{array::*, buffer::*, datatypes::*};
130        Ok({
131            let arrow_data = arrow_data
132                .as_any()
133                .downcast_ref::<arrow::array::ListArray>()
134                .ok_or_else(|| {
135                    let expected = Self::arrow_datatype();
136                    let actual = arrow_data.data_type().clone();
137                    DeserializationError::datatype_mismatch(expected, actual)
138                })
139                .with_context("rerun.components.LineStrip3D#points")?;
140            if arrow_data.is_empty() {
141                Vec::new()
142            } else {
143                let arrow_data_inner = {
144                    let arrow_data_inner = &**arrow_data.values();
145                    {
146                        let arrow_data_inner = arrow_data_inner
147                            .as_any()
148                            .downcast_ref::<arrow::array::FixedSizeListArray>()
149                            .ok_or_else(|| {
150                                let expected = DataType::FixedSizeList(
151                                    std::sync::Arc::new(Field::new(
152                                        "item",
153                                        DataType::Float32,
154                                        false,
155                                    )),
156                                    3,
157                                );
158                                let actual = arrow_data_inner.data_type().clone();
159                                DeserializationError::datatype_mismatch(expected, actual)
160                            })
161                            .with_context("rerun.components.LineStrip3D#points")?;
162                        if arrow_data_inner.is_empty() {
163                            Vec::new()
164                        } else {
165                            let offsets = (0..)
166                                .step_by(3usize)
167                                .zip((3usize..).step_by(3usize).take(arrow_data_inner.len()));
168                            let arrow_data_inner_inner = {
169                                let arrow_data_inner_inner = &**arrow_data_inner.values();
170                                arrow_data_inner_inner
171                                    .as_any()
172                                    .downcast_ref::<Float32Array>()
173                                    .ok_or_else(|| {
174                                        let expected = DataType::Float32;
175                                        let actual = arrow_data_inner_inner.data_type().clone();
176                                        DeserializationError::datatype_mismatch(expected, actual)
177                                    })
178                                    .with_context("rerun.components.LineStrip3D#points")?
179                                    .into_iter()
180                                    .collect::<Vec<_>>()
181                            };
182                            ZipValidity::new_with_validity(offsets, arrow_data_inner.nulls())
183                                .map(|elem| {
184                                    elem.map(|(start, end): (usize, usize)| {
185                                        debug_assert!(end - start == 3usize);
186                                        if arrow_data_inner_inner.len() < end {
187                                            return Err(DeserializationError::offset_slice_oob(
188                                                (start, end),
189                                                arrow_data_inner_inner.len(),
190                                            ));
191                                        }
192
193                                        #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
194                                        let data = unsafe {
195                                            arrow_data_inner_inner.get_unchecked(start..end)
196                                        };
197                                        let data =
198                                            data.iter().cloned().map(Option::unwrap_or_default);
199
200                                        // NOTE: Unwrapping cannot fail: the length must be correct.
201                                        #[allow(clippy::unwrap_used)]
202                                        Ok(array_init::from_iter(data).unwrap())
203                                    })
204                                    .transpose()
205                                })
206                                .map(|res_or_opt| {
207                                    res_or_opt
208                                        .map(|res_or_opt| res_or_opt.map(crate::datatypes::Vec3D))
209                                })
210                                .collect::<DeserializationResult<Vec<Option<_>>>>()?
211                        }
212                        .into_iter()
213                    }
214                    .collect::<Vec<_>>()
215                };
216                let offsets = arrow_data.offsets();
217                ZipValidity::new_with_validity(offsets.windows(2), arrow_data.nulls())
218                    .map(|elem| {
219                        elem.map(|window| {
220                            let start = window[0] as usize;
221                            let end = window[1] as usize;
222                            if arrow_data_inner.len() < end {
223                                return Err(DeserializationError::offset_slice_oob(
224                                    (start, end),
225                                    arrow_data_inner.len(),
226                                ));
227                            }
228
229                            #[allow(unsafe_code, clippy::undocumented_unsafe_blocks)]
230                            let data = unsafe { arrow_data_inner.get_unchecked(start..end) };
231                            let data = data
232                                .iter()
233                                .cloned()
234                                .map(Option::unwrap_or_default)
235                                .collect();
236                            Ok(data)
237                        })
238                        .transpose()
239                    })
240                    .collect::<DeserializationResult<Vec<Option<_>>>>()?
241            }
242            .into_iter()
243        }
244        .map(|v| v.ok_or_else(DeserializationError::missing_data))
245        .map(|res| res.map(|v| Some(Self(v))))
246        .collect::<DeserializationResult<Vec<Option<_>>>>()
247        .with_context("rerun.components.LineStrip3D#points")
248        .with_context("rerun.components.LineStrip3D")?)
249    }
250}
251
252impl<I: Into<crate::datatypes::Vec3D>, T: IntoIterator<Item = I>> From<T> for LineStrip3D {
253    fn from(v: T) -> Self {
254        Self(v.into_iter().map(|v| v.into()).collect())
255    }
256}
257
258impl ::re_byte_size::SizeBytes for LineStrip3D {
259    #[inline]
260    fn heap_size_bytes(&self) -> u64 {
261        self.0.heap_size_bytes()
262    }
263
264    #[inline]
265    fn is_pod() -> bool {
266        <Vec<crate::datatypes::Vec3D>>::is_pod()
267    }
268}