pub struct Position<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> { /* private fields */ }Expand description
An affine point in 3D Cartesian coordinates.
Positions represent locations in space relative to a reference center (origin). Unlike vectors, positions do not form a vector space.
§Type Parameters
C: The reference center (e.g.,Heliocentric,Geocentric,Topocentric)F: The reference frame (e.g.,ICRS,EclipticMeanJ2000,Equatorial)U: The length unit (e.g.,AstronomicalUnit,Kilometer)
§Center Parameters
Some centers (like Topocentric) require runtime parameters stored in C::Params.
For most centers, Params = () (zero overhead).
Implementations§
Source§impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>
impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>
Sourcepub fn new_with_params<T: Into<Quantity<U>>>(
center_params: C::Params,
x: T,
y: T,
z: T,
) -> Self
pub fn new_with_params<T: Into<Quantity<U>>>( center_params: C::Params, x: T, y: T, z: T, ) -> Self
Creates a new position with explicit center parameters.
§Arguments
center_params: Runtime parameters for the center (e.g.,ObserverSitefor Topocentric)x,y,z: Component values (converted toQuantity<U>)
Sourcepub fn from_vec3(center_params: C::Params, vec3: Vector3<Quantity<U>>) -> Self
pub fn from_vec3(center_params: C::Params, vec3: Vector3<Quantity<U>>) -> Self
Creates a position from a nalgebra Vector3 with explicit center parameters.
Sourcepub const fn new_const(
center_params: C::Params,
x: Quantity<U>,
y: Quantity<U>,
z: Quantity<U>,
) -> Self
pub const fn new_const( center_params: C::Params, x: Quantity<U>, y: Quantity<U>, z: Quantity<U>, ) -> Self
Const constructor for use in const contexts.
Sourcepub fn center_params(&self) -> &C::Params
pub fn center_params(&self) -> &C::Params
Returns a reference to the center parameters.
Source§impl<C, F, U> Position<C, F, U>
impl<C, F, U> Position<C, F, U>
Sourcepub fn new<T: Into<Quantity<U>>>(x: T, y: T, z: T) -> Self
pub fn new<T: Into<Quantity<U>>>(x: T, y: T, z: T) -> Self
Creates a new position for centers with Params = ().
This is a convenience constructor that doesn’t require passing () explicitly.
§Example
use affn::cartesian::Position;
use affn::frames::ReferenceFrame;
use affn::centers::ReferenceCenter;
use qtty::*;
#[derive(Debug, Copy, Clone)]
struct WorldFrame;
impl ReferenceFrame for WorldFrame {
fn frame_name() -> &'static str { "WorldFrame" }
}
#[derive(Debug, Copy, Clone)]
struct WorldOrigin;
impl ReferenceCenter for WorldOrigin {
type Params = ();
fn center_name() -> &'static str { "WorldOrigin" }
}
let pos = Position::<WorldOrigin, WorldFrame, Meter>::new(1.0, 0.0, 0.0);Sourcepub fn from_vec3_origin(vec3: Vector3<Quantity<U>>) -> Self
pub fn from_vec3_origin(vec3: Vector3<Quantity<U>>) -> Self
Creates a position from a nalgebra Vector3 for centers with Params = ().
Source§impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>
impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>
Source§impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>
impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>
Sourcepub fn distance_to(&self, other: &Self) -> Quantity<U>
pub fn distance_to(&self, other: &Self) -> Quantity<U>
Computes the distance to another position in the same center and frame.
§Panics
Panics if the positions have different center parameters.
For a non-panicking alternative, use try_distance_to.
§Note on Parameterized Centers
For centers with Params = () (e.g., Geocentric, Heliocentric), this check
is a compile-time guarantee and has zero runtime cost. For parameterized centers
(e.g., Topocentric with ObserverSite), the check is performed at runtime.
Sourcepub fn try_distance_to(
&self,
other: &Self,
) -> Result<Quantity<U>, CenterParamsMismatchError>
pub fn try_distance_to( &self, other: &Self, ) -> Result<Quantity<U>, CenterParamsMismatchError>
Checked version of distance_to that returns Err
instead of panicking when center parameters don’t match.
For centers with Params = (), this always succeeds.
Sourcepub fn direction(&self) -> Option<Direction<F>>
pub fn direction(&self) -> Option<Direction<F>>
Returns the direction (unit vector) from the center to this position.
Note: Directions are frame-only types (no center). This extracts the normalized direction of the position vector.
Returns None if the position is at the origin.
Sourcepub fn direction_unchecked(&self) -> Direction<F>
pub fn direction_unchecked(&self) -> Direction<F>
Returns the direction, assuming non-zero distance from origin.
§Panics
May produce NaN if the position is at the origin.
Sourcepub fn to_spherical(&self) -> Position<C, F, U>
pub fn to_spherical(&self) -> Position<C, F, U>
Converts this Cartesian position to spherical coordinates.
Returns a spherical position with the same center and frame, with (polar, azimuth, distance) computed from (x, y, z).
Sourcepub fn from_spherical(sph: &Position<C, F, U>) -> Self
pub fn from_spherical(sph: &Position<C, F, U>) -> Self
Constructs a Cartesian position from spherical coordinates.
This is equivalent to spherical_pos.to_cartesian().
Source§impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>
impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>
Sourcepub fn checked_sub(
&self,
other: &Self,
) -> Result<Displacement<F, U>, CenterParamsMismatchError>
pub fn checked_sub( &self, other: &Self, ) -> Result<Displacement<F, U>, CenterParamsMismatchError>
Checked subtraction that returns Err instead of panicking when
center parameters don’t match.
This is the safe alternative to the Sub operator (pos_a - pos_b).
For centers with Params = (), this always succeeds.
Trait Implementations§
Source§impl<C: Clone + ReferenceCenter, F: Clone + ReferenceFrame, U: Clone + LengthUnit> Clone for Position<C, F, U>
impl<C: Clone + ReferenceCenter, F: Clone + ReferenceFrame, U: Clone + LengthUnit> Clone for Position<C, F, U>
Source§impl<C: Debug + ReferenceCenter, F: Debug + ReferenceFrame, U: Debug + LengthUnit> Debug for Position<C, F, U>
impl<C: Debug + ReferenceCenter, F: Debug + ReferenceFrame, U: Debug + LengthUnit> Debug for Position<C, F, U>
Source§impl<C, F, U> Sub for Position<C, F, U>
impl<C, F, U> Sub for Position<C, F, U>
impl<C: Copy + ReferenceCenter, F: Copy + ReferenceFrame, U: Copy + LengthUnit> Copy for Position<C, F, U>
Auto Trait Implementations§
impl<C, F, U> Freeze for Position<C, F, U>
impl<C, F, U> RefUnwindSafe for Position<C, F, U>
impl<C, F, U> Send for Position<C, F, U>
impl<C, F, U> Sync for Position<C, F, U>
impl<C, F, U> Unpin for Position<C, F, U>
impl<C, F, U> UnsafeUnpin for Position<C, F, U>
impl<C, F, U> UnwindSafe for Position<C, F, U>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.