spatial_hasher/
rotation_axis.rs

1//! The `rotation_axis` module provides the `RotationAxis` struct, representing an axis of rotation in 3D space.
2
3use serde::{Deserialize, Serialize};
4use std::hash::{Hash, Hasher};
5/// Represents an axis of rotation in 3D space.
6///
7/// # Fields
8///
9/// - `x`: The x-component of the rotation axis.
10/// - `y`: The y-component of the rotation axis.
11/// - `z`: The z-component of the rotation axis.
12///
13/// # Examples
14///
15/// ```
16/// use spatial_hasher::RotationAxis;
17///
18/// let axis = RotationAxis { x: 0.0, y: 1.0, z: 0.0 };
19/// ```
20#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
21pub struct RotationAxis {
22    /// The x-component of the rotation axis.
23    pub x: f64,
24    /// The y-component of the rotation axis.
25    pub y: f64,
26    /// The z-component of the rotation axis.
27    pub z: f64,
28}
29
30impl Hash for RotationAxis {
31    /// Hashes the `RotationAxis` by writing the bit representations of its components into the provided hasher.
32    ///
33    /// This method uses the `to_bits()` function to obtain the raw memory representation of the floating-point numbers, ensuring consistent hashing.
34    ///
35    /// # Arguments
36    ///
37    /// * `state` - A mutable reference to a type implementing the `Hasher` trait.
38    fn hash<H: Hasher>(&self, state: &mut H) {
39        state.write_u64(self.x.to_bits());
40        state.write_u64(self.y.to_bits());
41        state.write_u64(self.z.to_bits());
42    }
43}