affn/lib.rs
1//! # affn - Affine Geometry Primitives
2//!
3//! This crate provides strongly-typed coordinate systems with compile-time safety for
4//! scientific computing applications. It defines the mathematical foundation for
5//! working with positions, directions, and displacements in various reference frames.
6//!
7//! ## Domain-Agnostic Design
8//!
9//! `affn` is a **pure geometry kernel** that contains no domain-specific vocabulary.
10//! Concrete frame and center types (e.g., astronomical frames, robotic frames)
11//! should be defined in downstream crates that depend on `affn`.
12//!
13//! ## Core Concepts
14//!
15//! ### Reference Centers
16//!
17//! A [`ReferenceCenter`](centers::ReferenceCenter) defines the origin point of a coordinate system.
18//! Some centers require runtime parameters (stored in `ReferenceCenter::Params`).
19//!
20//! ### Reference Frames
21//!
22//! A [`ReferenceFrame`](frames::ReferenceFrame) defines the orientation of coordinate axes.
23//!
24//! ### Coordinate Types
25//!
26//! - **Position**: An affine point in space (center + frame + distance)
27//! - **Direction**: A unit vector representing orientation (frame only)
28//! - **Displacement/Velocity**: Free vectors (frame + magnitude)
29//!
30//! ## Creating Custom Frames and Centers
31//!
32//! Use derive macros for convenient definitions:
33//!
34//! ```rust
35//! use affn::prelude::*;
36//!
37//! #[derive(Debug, Copy, Clone, ReferenceFrame)]
38//! struct MyFrame;
39//!
40//! #[derive(Debug, Copy, Clone, ReferenceCenter)]
41//! struct MyCenter;
42//!
43//! assert_eq!(MyFrame::frame_name(), "MyFrame");
44//! assert_eq!(MyCenter::center_name(), "MyCenter");
45//! ```
46//!
47//! ## Algebraic Rules
48//!
49//! The type system enforces mathematical correctness:
50//!
51//! | Operation | Result | Meaning |
52//! |-----------|--------|---------|
53//! | `Position - Position` | `Displacement` | Displacement between points |
54//! | `Position + Displacement` | `Position` | Translate point |
55//! | `Displacement + Displacement` | `Displacement` | Add displacements |
56//! | `Direction * Length` | `Displacement` | Scale direction |
57//! | `normalize(Displacement)` | `Direction` | Extract orientation |
58//!
59//! ## Example
60//!
61//! ```rust
62//! use affn::cartesian::{Position, Displacement};
63//! use affn::frames::ReferenceFrame;
64//! use affn::centers::ReferenceCenter;
65//! use qtty::*;
66//!
67//! // Define domain-specific types
68//! #[derive(Debug, Copy, Clone)]
69//! struct WorldFrame;
70//! impl ReferenceFrame for WorldFrame {
71//! fn frame_name() -> &'static str { "WorldFrame" }
72//! }
73//!
74//! #[derive(Debug, Copy, Clone)]
75//! struct WorldOrigin;
76//! impl ReferenceCenter for WorldOrigin {
77//! type Params = ();
78//! fn center_name() -> &'static str { "WorldOrigin" }
79//! }
80//!
81//! let a = Position::<WorldOrigin, WorldFrame, Kilometer>::new(100.0, 200.0, 300.0);
82//! let b = Position::<WorldOrigin, WorldFrame, Kilometer>::new(150.0, 250.0, 350.0);
83//!
84//! // Positions subtract to give displacements
85//! let displacement: Displacement<WorldFrame, Kilometer> = b - a;
86//! ```
87
88// Allow the crate to refer to itself as `::affn::` for derive macro compatibility
89extern crate self as affn;
90
91// Coordinate type implementations
92pub mod cartesian;
93pub mod spherical;
94
95// Core traits and marker types
96pub mod centers;
97pub mod frames;
98
99// Ellipsoid definitions and frame-ellipsoid association
100pub mod ellipsoid;
101
102// Ellipsoidal coordinate system (lon, lat, height-above-ellipsoid)
103pub mod ellipsoidal;
104
105// Affine operators (rotation, translation, isometry)
106pub mod ops;
107
108// Shared serde utilities
109#[cfg(feature = "serde")]
110pub(crate) mod serde_utils;
111
112// Re-export derive macros from affn-derive
113// Named with Derive prefix to avoid conflicts with trait names
114pub use affn_derive::{
115 ReferenceCenter as DeriveReferenceCenter, ReferenceFrame as DeriveReferenceFrame,
116};
117
118// Re-export traits at crate level with their original names
119// This is the standard pattern: traits and derives co-exist with same names
120pub use centers::{AffineCenter, NoCenter, ReferenceCenter};
121pub use frames::ReferenceFrame;
122
123// Re-export operators at crate level
124pub use ops::{Isometry3, Rotation3, Translation3};
125
126// Re-export concrete Position/Direction types for standalone usage
127pub use cartesian::{
128 CenterParamsMismatchError, Direction as CartesianDirection, Displacement, Position, Vector,
129 Velocity,
130};
131pub use spherical::{Direction as SphericalDirection, Position as SphericalPosition};
132
133// Re-export ellipsoidal Position for standalone usage
134pub use ellipsoidal::Position as EllipsoidalPosition;
135
136/// Prelude module for convenient imports.
137///
138/// Import everything you need with:
139/// ```rust
140/// use affn::prelude::*;
141/// ```
142pub mod prelude {
143 // Derive macros - aliased to standard names in prelude
144 pub use crate::{
145 DeriveReferenceCenter as ReferenceCenter, DeriveReferenceFrame as ReferenceFrame,
146 };
147
148 // Traits - keep full names to avoid conflicts with derives
149 pub use crate::centers::{AffineCenter, NoCenter, ReferenceCenter as ReferenceCenterTrait};
150 pub use crate::frames::ReferenceFrame as ReferenceFrameTrait;
151
152 // Core coordinate types
153 pub use crate::cartesian::{
154 Direction as CartesianDirection, Displacement, Position, Vector, Velocity,
155 };
156 pub use crate::spherical::{Direction as SphericalDirection, Position as SphericalPosition};
157
158 // Operators
159 pub use crate::ops::{Isometry3, Rotation3, Translation3};
160
161 // Ellipsoidal coordinate type (always available)
162 pub use crate::ellipsoidal::Position as EllipsoidalPosition;
163
164 // Ellipsoid traits and predefined ellipsoids (always available)
165 pub use crate::ellipsoid::{Ellipsoid, Grs80, HasEllipsoid, Wgs84};
166
167 // Feature-gated astronomical frames
168 #[cfg(feature = "astro")]
169 pub use crate::frames::{
170 EclipticMeanJ2000, EclipticMeanOfDate, EclipticOfDate, EclipticTrueOfDate,
171 EquatorialMeanJ2000, EquatorialMeanOfDate, EquatorialTrueOfDate, Galactic, Horizontal,
172 ECEF, ICRF, ICRS, ITRF,
173 };
174}