honeycomb_core/cmap/dim3/
utils.rs

1//! [`CMap3`] utilities implementations
2//!
3//! This module contains utility code for the [`CMap3`] structure.
4
5use crate::cmap::{CMap3, DartIdType};
6use crate::geometry::CoordsFloat;
7use crate::stm::atomically;
8
9use super::CMAP3_BETA;
10
11/// **Utilities**
12impl<T: CoordsFloat> CMap3<T> {
13    /// Set the value of the specified beta function of a dart.
14    ///
15    /// # Arguments
16    ///
17    /// - `const I: u8` -- Beta function to edit.
18    /// - `dart_id: DartIdType` -- ID of the dart of interest.
19    /// - `val: DartIdType` -- New value of *β<sub>`I`</sub>(`dart_id`)*.
20    pub fn set_beta<const I: u8>(&self, dart_id: DartIdType, val: DartIdType) {
21        atomically(|trans| self.betas[(I, dart_id)].write(trans, val));
22    }
23
24    /// Set the values of the beta functions of a dart.
25    ///
26    /// # Arguments
27    ///
28    /// - `dart_id: DartIdType` -- ID of the dart of interest.
29    /// - `betas: [DartIdType; 4]` -- New values of
30    ///   *[β<sub>0</sub>(dart), β<sub>1</sub>(dart), β<sub>2</sub>(dart), β<sub>3</sub>(dart)]*
31    ///
32    pub fn set_betas(&self, dart_id: DartIdType, [b0, b1, b2, b3]: [DartIdType; CMAP3_BETA]) {
33        // store separately to use non-mutable methods
34        atomically(|trans| {
35            self.betas[(0, dart_id)].write(trans, b0)?;
36            self.betas[(1, dart_id)].write(trans, b1)?;
37            self.betas[(2, dart_id)].write(trans, b2)?;
38            self.betas[(3, dart_id)].write(trans, b3)?;
39            Ok(())
40        });
41    }
42}