deep_causality/traits/contextuable/coordinate.rs
1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6use crate::IndexError;
7
8/// Provides a generalized interface for N-dimensional coordinate access.
9///
10/// This trait is agnostic to geometry and is designed to support
11/// both standard (Cartesian) coordinates and abstract representations such as:
12/// - Curved spacetime manifolds
13/// - Quaternionic rotations
14/// - Symbolic embeddings (e.g., logical coordinates)
15///
16/// The trait provides only **index-based access** and leaves axis naming,
17/// scaling, or metric behavior to higher-level abstractions.
18///
19/// # Example
20/// ```
21/// use deep_causality::{Coordinate, IndexError};
22///
23/// struct Vec3D {
24/// x: f64,
25/// y: f64,
26/// z: f64,
27/// }
28///
29/// impl Coordinate<f64> for Vec3D {
30/// fn dimension(&self) -> usize {
31/// 3
32/// }
33///
34/// fn coordinate(&self, index: usize) -> Result<&f64, IndexError> {
35/// match index {
36/// 0 => Ok(&self.x),
37/// 1 => Ok(&self.y),
38/// 2 => Ok(&self.z),
39/// _ => Err(IndexError("Index out of bounds".to_string())),
40/// }
41/// }
42/// }
43/// ```
44pub trait Coordinate<V> {
45 /// Returns the number of dimensions defined in this coordinate system.
46 fn dimension(&self) -> usize;
47
48 /// Returns a reference to the value at a given axis index (0-based).
49 ///
50 /// # Errors
51 /// Returns `IndexError` if the index is out of bounds.
52 fn coordinate(&self, index: usize) -> Result<&V, IndexError>;
53}