re_types/blueprint/archetypes/
force_link.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/blueprint/archetypes/force_link.fbs".
3
4#![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/// **Archetype**: Aims to achieve a target distance between two nodes that are connected by an edge.
23///
24/// ⚠️ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
25#[derive(Clone, Debug, Default)]
26pub struct ForceLink {
27    /// Whether the link force is enabled.
28    ///
29    /// The link force aims to achieve a target distance between two nodes that are connected by one ore more edges.
30    pub enabled: Option<SerializedComponentBatch>,
31
32    /// The target distance between two nodes.
33    pub distance: Option<SerializedComponentBatch>,
34
35    /// Specifies how often this force should be applied per iteration.
36    ///
37    /// Increasing this parameter can lead to better results at the cost of longer computation time.
38    pub iterations: Option<SerializedComponentBatch>,
39}
40
41impl ForceLink {
42    /// Returns the [`ComponentDescriptor`] for [`Self::enabled`].
43    ///
44    /// The corresponding component is [`crate::blueprint::components::Enabled`].
45    #[inline]
46    pub fn descriptor_enabled() -> ComponentDescriptor {
47        ComponentDescriptor {
48            archetype: Some("rerun.blueprint.archetypes.ForceLink".into()),
49            component: "ForceLink:enabled".into(),
50            component_type: Some("rerun.blueprint.components.Enabled".into()),
51        }
52    }
53
54    /// Returns the [`ComponentDescriptor`] for [`Self::distance`].
55    ///
56    /// The corresponding component is [`crate::blueprint::components::ForceDistance`].
57    #[inline]
58    pub fn descriptor_distance() -> ComponentDescriptor {
59        ComponentDescriptor {
60            archetype: Some("rerun.blueprint.archetypes.ForceLink".into()),
61            component: "ForceLink:distance".into(),
62            component_type: Some("rerun.blueprint.components.ForceDistance".into()),
63        }
64    }
65
66    /// Returns the [`ComponentDescriptor`] for [`Self::iterations`].
67    ///
68    /// The corresponding component is [`crate::blueprint::components::ForceIterations`].
69    #[inline]
70    pub fn descriptor_iterations() -> ComponentDescriptor {
71        ComponentDescriptor {
72            archetype: Some("rerun.blueprint.archetypes.ForceLink".into()),
73            component: "ForceLink:iterations".into(),
74            component_type: Some("rerun.blueprint.components.ForceIterations".into()),
75        }
76    }
77}
78
79static REQUIRED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
80    once_cell::sync::Lazy::new(|| []);
81
82static RECOMMENDED_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 0usize]> =
83    once_cell::sync::Lazy::new(|| []);
84
85static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 3usize]> =
86    once_cell::sync::Lazy::new(|| {
87        [
88            ForceLink::descriptor_enabled(),
89            ForceLink::descriptor_distance(),
90            ForceLink::descriptor_iterations(),
91        ]
92    });
93
94static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentDescriptor; 3usize]> =
95    once_cell::sync::Lazy::new(|| {
96        [
97            ForceLink::descriptor_enabled(),
98            ForceLink::descriptor_distance(),
99            ForceLink::descriptor_iterations(),
100        ]
101    });
102
103impl ForceLink {
104    /// The total number of components in the archetype: 0 required, 0 recommended, 3 optional
105    pub const NUM_COMPONENTS: usize = 3usize;
106}
107
108impl ::re_types_core::Archetype for ForceLink {
109    #[inline]
110    fn name() -> ::re_types_core::ArchetypeName {
111        "rerun.blueprint.archetypes.ForceLink".into()
112    }
113
114    #[inline]
115    fn display_name() -> &'static str {
116        "Force link"
117    }
118
119    #[inline]
120    fn required_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
121        REQUIRED_COMPONENTS.as_slice().into()
122    }
123
124    #[inline]
125    fn recommended_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
126        RECOMMENDED_COMPONENTS.as_slice().into()
127    }
128
129    #[inline]
130    fn optional_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
131        OPTIONAL_COMPONENTS.as_slice().into()
132    }
133
134    #[inline]
135    fn all_components() -> ::std::borrow::Cow<'static, [ComponentDescriptor]> {
136        ALL_COMPONENTS.as_slice().into()
137    }
138
139    #[inline]
140    fn from_arrow_components(
141        arrow_data: impl IntoIterator<Item = (ComponentDescriptor, arrow::array::ArrayRef)>,
142    ) -> DeserializationResult<Self> {
143        re_tracing::profile_function!();
144        use ::re_types_core::{Loggable as _, ResultExt as _};
145        let arrays_by_descr: ::nohash_hasher::IntMap<_, _> = arrow_data.into_iter().collect();
146        let enabled = arrays_by_descr
147            .get(&Self::descriptor_enabled())
148            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_enabled()));
149        let distance = arrays_by_descr
150            .get(&Self::descriptor_distance())
151            .map(|array| SerializedComponentBatch::new(array.clone(), Self::descriptor_distance()));
152        let iterations = arrays_by_descr
153            .get(&Self::descriptor_iterations())
154            .map(|array| {
155                SerializedComponentBatch::new(array.clone(), Self::descriptor_iterations())
156            });
157        Ok(Self {
158            enabled,
159            distance,
160            iterations,
161        })
162    }
163}
164
165impl ::re_types_core::AsComponents for ForceLink {
166    #[inline]
167    fn as_serialized_batches(&self) -> Vec<SerializedComponentBatch> {
168        use ::re_types_core::Archetype as _;
169        [
170            self.enabled.clone(),
171            self.distance.clone(),
172            self.iterations.clone(),
173        ]
174        .into_iter()
175        .flatten()
176        .collect()
177    }
178}
179
180impl ::re_types_core::ArchetypeReflectionMarker for ForceLink {}
181
182impl ForceLink {
183    /// Create a new `ForceLink`.
184    #[inline]
185    pub fn new() -> Self {
186        Self {
187            enabled: None,
188            distance: None,
189            iterations: None,
190        }
191    }
192
193    /// Update only some specific fields of a `ForceLink`.
194    #[inline]
195    pub fn update_fields() -> Self {
196        Self::default()
197    }
198
199    /// Clear all the fields of a `ForceLink`.
200    #[inline]
201    pub fn clear_fields() -> Self {
202        use ::re_types_core::Loggable as _;
203        Self {
204            enabled: Some(SerializedComponentBatch::new(
205                crate::blueprint::components::Enabled::arrow_empty(),
206                Self::descriptor_enabled(),
207            )),
208            distance: Some(SerializedComponentBatch::new(
209                crate::blueprint::components::ForceDistance::arrow_empty(),
210                Self::descriptor_distance(),
211            )),
212            iterations: Some(SerializedComponentBatch::new(
213                crate::blueprint::components::ForceIterations::arrow_empty(),
214                Self::descriptor_iterations(),
215            )),
216        }
217    }
218
219    /// Whether the link force is enabled.
220    ///
221    /// The link force aims to achieve a target distance between two nodes that are connected by one ore more edges.
222    #[inline]
223    pub fn with_enabled(
224        mut self,
225        enabled: impl Into<crate::blueprint::components::Enabled>,
226    ) -> Self {
227        self.enabled = try_serialize_field(Self::descriptor_enabled(), [enabled]);
228        self
229    }
230
231    /// The target distance between two nodes.
232    #[inline]
233    pub fn with_distance(
234        mut self,
235        distance: impl Into<crate::blueprint::components::ForceDistance>,
236    ) -> Self {
237        self.distance = try_serialize_field(Self::descriptor_distance(), [distance]);
238        self
239    }
240
241    /// Specifies how often this force should be applied per iteration.
242    ///
243    /// Increasing this parameter can lead to better results at the cost of longer computation time.
244    #[inline]
245    pub fn with_iterations(
246        mut self,
247        iterations: impl Into<crate::blueprint::components::ForceIterations>,
248    ) -> Self {
249        self.iterations = try_serialize_field(Self::descriptor_iterations(), [iterations]);
250        self
251    }
252}
253
254impl ::re_byte_size::SizeBytes for ForceLink {
255    #[inline]
256    fn heap_size_bytes(&self) -> u64 {
257        self.enabled.heap_size_bytes()
258            + self.distance.heap_size_bytes()
259            + self.iterations.heap_size_bytes()
260    }
261}