Skip to main content

lib_jsl_geometry/
coordinate_systems.rs

1//! Coordinate-system enums, markers, and conversion traits.
2
3use crate::common::CoordinatePrimitive;
4
5/// Supported coordinate systems for 2D primitives.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub enum CoordinateSystem2D {
9    /// Standard x/y Cartesian coordinates.
10    Cartesian,
11    /// Radius/angle polar coordinates.
12    Polar,
13}
14
15/// Supported coordinate systems for 3D primitives.
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18pub enum CoordinateSystem3D {
19    /// Standard x/y/z Cartesian coordinates.
20    Cartesian,
21    /// Radius/inclination/azimuth spherical coordinates.
22    Spherical,
23    /// Radius/angle/height cylindrical coordinates.
24    Cylindrical,
25}
26
27/// Marker trait for 2D coordinate-system tags.
28pub trait IsCoordinateSystem2D {}
29
30/// Marker trait for 2D Cartesian coordinate systems.
31pub trait IsCartesian2D: IsCoordinateSystem2D {}
32
33/// Marker trait for 2D polar coordinate systems.
34pub trait IsPolar: IsCoordinateSystem2D {}
35
36/// Marker trait for 3D coordinate-system tags.
37pub trait IsCoordinateSystem3D {}
38
39/// Marker trait for 3D Cartesian coordinate systems.
40pub trait IsCartesian3D: IsCoordinateSystem3D {}
41
42/// Marker trait for 3D spherical coordinate systems.
43pub trait IsSpherical: IsCoordinateSystem3D {}
44
45/// Marker trait for 3D cylindrical coordinate systems.
46pub trait IsCylindrical: IsCoordinateSystem3D {}
47
48/// Converts a value into a Cartesian representation.
49pub trait ToCartesian {
50    /// Cartesian result type.
51    type Cartesian: CoordinatePrimitive;
52
53    /// Returns the Cartesian representation of `self`.
54    fn to_cartesian(&self) -> Self::Cartesian;
55}
56
57/// Converts a value into a polar representation.
58pub trait ToPolar {
59    /// Polar result type.
60    type Polar: CoordinatePrimitive;
61
62    /// Returns the polar representation of `self`.
63    fn to_polar(&self) -> Self::Polar;
64}
65
66/// Converts a value into a spherical representation.
67pub trait ToSpherical {
68    /// Spherical result type.
69    type Spherical: CoordinatePrimitive;
70
71    /// Returns the spherical representation of `self`.
72    fn to_spherical(&self) -> Self::Spherical;
73}
74
75/// Converts a value into a cylindrical representation.
76pub trait ToCylindrical {
77    /// Cylindrical result type.
78    type Cylindrical: CoordinatePrimitive;
79
80    /// Returns the cylindrical representation of `self`.
81    fn to_cylindrical(&self) -> Self::Cylindrical;
82}