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
// Copyright (C) 2025 Christian Mauduit <ufoot@ufoot.org>
use crate*;
use crate*;
/// Trait for converting between 2D coordinates and linear indices.
///
/// This trait provides bidirectional conversion between 2D `(x, y)` coordinates
/// and 1D linear indices, which is essential for mapping between grid positions
/// and array/vector storage.
///
/// # Coordinate System
///
/// - `x` increases from left to right (column index)
/// - `y` increases from top to bottom (row index)
/// - Linear indices typically follow row-major order: `index = y * width + x`
///
/// # Example
///
/// ```
/// use shortestpath::mesh_2d::{Index2D, Full2D};
///
/// let mesh = Full2D::new(5, 4);
///
/// // Convert (x, y) to linear index
/// let index = mesh.xy_to_index(2, 1).unwrap();
/// assert_eq!(index, 7); // 1 * 5 + 2 = 7
///
/// // Convert back to coordinates
/// let (x, y) = mesh.index_to_xy(7).unwrap();
/// assert_eq!((x, y), (2, 1));
/// ```