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