1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2025 Christian Mauduit <ufoot@ufoot.org>
use crate*;
use crate*;
/// Trait for converting between 3D coordinates and linear indices.
///
/// This trait provides bidirectional conversion between 3D `(x, y, z)` coordinates
/// and 1D linear indices, essential for mapping between volumetric positions
/// and array/vector storage.
///
/// # Coordinate System
///
/// - `x` increases from left to right (column index)
/// - `y` increases from top to bottom (row index)
/// - `z` increases from front to back (depth/layer index)
/// - Linear indices typically follow layer-major order: `index = z * (width * height) + y * width + x`
///
/// # Example
///
/// ```
/// use shortestpath::mesh_3d::{Index3D, Full3D};
///
/// let mesh = Full3D::new(5, 4, 3);
///
/// // Convert (x, y, z) to linear index
/// let index = mesh.xyz_to_index(2, 1, 1).unwrap();
/// assert_eq!(index, 27); // 1 * (5 * 4) + 1 * 5 + 2 = 27
///
/// // Convert back to coordinates
/// let (x, y, z) = mesh.index_to_xyz(27).unwrap();
/// assert_eq!((x, y, z), (2, 1, 1));
/// ```