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
59
60
61
62
63
64
65
//! Offset coordinate system for grid positioning.
//!
//! [`OffsetCoordinate`] describes the column and row of a tile in a grid.
//! It is used to tackle with the situation where the grid is wrapped.
//!
//! That picture below shows a unwrapped grid with offset coordinates.
//!
//! ```txt
//! Y ↑
//! |
//! | (0,height-1) (width-1,height-1)
//! | +-------------------+
//! | | |
//! | | Grid Area |
//! | | |
//! | +-------------------+
//! | (0,0) (width-1,0)
//! +--------------------------------→ X
//! Origin (bottom-left corner)
//! ```
//!
//! The coordinate ranges depend on whether the grid wraps at boundaries:
//!
//! - **Non-wrapped grid**: `x ∈ [0, width)`, `y ∈ [0, height)`
//! - **Wrapped grid**:
//! - Only Wrap x: x can be any value, y ∈ [0, height)
//! - Example (x-wrapped): `(0, 0) ≡ (width, 0) ≡ (-width, 0) ≡ (2*width, 0)` is the same cell/tile
//! - Only Wrap y: x ∈ [0, width), y can be any value
//! - Example (y-wrapped): `(0, 0) ≡ (0, height) ≡ (0, -height) ≡ (0, 2*height)` is the same cell/tile
//! - Wrap both x and y: x and y can be any value
//! - Example (both x and y wrapped): `(0, 0) ≡ (width, height) ≡ (-width, -height) ≡ (2*width, 2*height)` is the same cell/tile
//!
//! In wrapped grids multiple offset coordinates can represent the same cell,
//! when we normalize an offset coordinate, i.e. wrap its x and y coordinates to the range `([0, width), [0, height))`,
//! it can be transformed into [`Cell`] uniquely. See the documentation of [`Grid::normalize_offset`](crate::grid::Grid::normalize_offset) for details on normalization.
//!
use IVec2;
/// A coordinate in the offset coordinate system.
///
/// See the [module-level documentation](self) for details on coordinate ranges,
/// normalization, and relationships to other coordinate systems.
;