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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Cell orientation computation.
//!
//! Each A5 cell has a deterministic orientation derived from its position on the
//! planet surface. The A5 system is based on a dodecahedron with 12 origin faces,
//! each with a known quaternion rotation. This module computes orientations for
//! cells at any resolution.
//!
//! Two conventions are available:
//!
//! - [`cell_vertex_orientation`] — **the canonical convention used by
//! `propagate_geo_transforms`.** The cell centre is the local origin, +Y is
//! radial-up, and -Z (Bevy "forward") points from the cell centre to the
//! cell's first boundary vertex. This makes the local frame line up with the
//! pentagon's geometry: a unit vector in -Z lands on the cell's first
//! vertex direction.
//! - [`cell_orientation`] — the geographic convention. -Z points toward
//! geographic north (higher latitude). Useful when you want every cell to
//! share a global compass alignment.
use ;
use cratecoord;
/// Compute the **geographic** orientation quaternion for a cell.
///
/// The returned quaternion transforms from a local frame where:
/// - +Y is "up" (radial, away from planet center)
/// - -Z is "forward" (toward geographic north, projected onto the tangent plane)
/// - +X is "right" (toward geographic east)
///
/// This matches Bevy's default camera/entity orientation conventions.
///
/// Note: [`propagate_geo_transforms`](crate::systems::propagate_geo_transforms)
/// uses [`cell_vertex_orientation`] instead. Use this function if you want a
/// consistent geographic frame independent of which cell you're in.
///
/// Returns `None` if the cell index is invalid.
/// Compute an orientation quaternion for a specific longitude/latitude on the planet.
///
/// See [`cell_orientation`] for the coordinate frame convention.
/// Compute the **vertex-aligned** orientation quaternion for a cell.
///
/// The returned quaternion transforms from a local frame where:
/// - the cell centre is the local origin (0, 0, 0)
/// - +Y is radial-up (away from planet centre)
/// - -Z (Bevy "forward") points from the cell centre to the cell's first
/// boundary vertex, projected onto the tangent plane
/// - +X is "right" (cross of forward and up)
///
/// This is the canonical convention used by
/// [`propagate_geo_transforms`](crate::systems::propagate_geo_transforms): the
/// local frame is anchored to the cell's pentagonal geometry. A child entity
/// at `Transform::from_xyz(0.0, 0.0, -boundary_distance)` sits exactly on the
/// cell's first boundary vertex.
///
/// Note that adjacent cells have different vertex-aligned frames, so a Vec3
/// in one cell's frame doesn't correspond to the same direction in a
/// neighbour's frame — that's the price of the cell-local convention.
///
/// Returns `None` if the cell index is invalid.