Skip to main content

Position

Struct Position 

Source
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>

Source

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., ObserverSite for Topocentric)
  • x, y, z: Component values (converted to Quantity<U>)
Source

pub fn from_vec3(center_params: C::Params, vec3: Vector3<Quantity<U>>) -> Self

Creates a position from a nalgebra Vector3 with explicit center parameters.

Source

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.

Source

pub fn center_params(&self) -> &C::Params

Returns a reference to the center parameters.

Source§

impl<C, F, U> Position<C, F, U>
where C: ReferenceCenter<Params = ()>, F: ReferenceFrame, U: LengthUnit,

Source

pub const CENTER: Self

The origin of this coordinate system (all coordinates zero).

Source

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);
Source

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>

Source

pub fn x(&self) -> Quantity<U>

Returns the x-component.

Source

pub fn y(&self) -> Quantity<U>

Returns the y-component.

Source

pub fn z(&self) -> Quantity<U>

Returns the z-component.

Source

pub fn as_vec3(&self) -> &Vector3<Quantity<U>>

Returns the underlying nalgebra Vector3.

Source

pub fn to_unit<U2: LengthUnit>(&self) -> Position<C, F, U2>
where C::Params: Clone,

Converts this position to another length unit.

The center and frame are preserved while each Cartesian component is converted independently via qtty::Quantity::to.

Source§

impl<C: ReferenceCenter, F: ReferenceFrame, U: LengthUnit> Position<C, F, U>

Source

pub fn distance(&self) -> Quantity<U>

Computes the distance from the reference center.

Source

pub fn distance_to(&self, other: &Self) -> Quantity<U>
where C::Params: PartialEq,

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.

Source

pub fn try_distance_to( &self, other: &Self, ) -> Result<Quantity<U>, CenterParamsMismatchError>
where C::Params: PartialEq,

Checked version of distance_to that returns Err instead of panicking when center parameters don’t match.

For centers with Params = (), this always succeeds.

Source

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.

Source

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.

Source

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).

Source

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>

Source

pub fn checked_sub( &self, other: &Self, ) -> Result<Displacement<F, U>, CenterParamsMismatchError>
where C::Params: PartialEq,

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, F, U> Add<Vector<F, U>> for Position<C, F, U>

Source§

fn add(self, displacement: Displacement<F, U>) -> Self::Output

Translates the position by a displacement vector.

Source§

type Output = Position<C, F, U>

The resulting type after applying the + operator.
Source§

impl<C: Clone + ReferenceCenter, F: Clone + ReferenceFrame, U: Clone + LengthUnit> Clone for Position<C, F, U>
where C::Params: Clone,

Source§

fn clone(&self) -> Position<C, F, U>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + ReferenceCenter, F: Debug + ReferenceFrame, U: Debug + LengthUnit> Debug for Position<C, F, U>
where C::Params: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C, F, U> Display for Position<C, F, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C, F, U> Sub<&Position<C, F, U>> for &Position<C, F, U>

Source§

fn sub(self, other: &Position<C, F, U>) -> Self::Output

Computes the displacement vector from other to self.

§Panics

Panics if the positions have different center parameters.

Source§

type Output = Vector<F, U>

The resulting type after applying the - operator.
Source§

impl<C, F, U> Sub<Vector<F, U>> for Position<C, F, U>

Source§

fn sub(self, displacement: Displacement<F, U>) -> Self::Output

Translates the position backwards by a displacement vector.

Source§

type Output = Position<C, F, U>

The resulting type after applying the - operator.
Source§

impl<C, F, U> Sub for Position<C, F, U>

Source§

fn sub(self, other: Self) -> Self::Output

Computes the displacement vector from other to self.

§Panics

Panics if the positions have different center parameters. For a non-panicking alternative, use Position::checked_sub.

Source§

type Output = Vector<F, U>

The resulting type after applying the - operator.
Source§

impl<C: Copy + ReferenceCenter, F: Copy + ReferenceFrame, U: Copy + LengthUnit> Copy for Position<C, F, U>
where C::Params: Copy,

Auto Trait Implementations§

§

impl<C, F, U> Freeze for Position<C, F, U>
where <C as ReferenceCenter>::Params: Freeze,

§

impl<C, F, U> RefUnwindSafe for Position<C, F, U>

§

impl<C, F, U> Send for Position<C, F, U>
where <C as ReferenceCenter>::Params: Send, F: Send, U: Send,

§

impl<C, F, U> Sync for Position<C, F, U>
where <C as ReferenceCenter>::Params: Sync, F: Sync, U: Sync,

§

impl<C, F, U> Unpin for Position<C, F, U>
where <C as ReferenceCenter>::Params: Unpin, F: Unpin, U: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.