Skip to main content

Angle

Struct Angle 

Source
pub struct Angle { /* private fields */ }
Expand description

An angular measurement stored as radians.

Angle is the primary type for representing angles throughout this library. It stores the angle as a 64-bit float in radians and provides conversions to/from other angular units commonly used in astronomy.

§Internal Representation

Angles are stored as radians (f64). This choice optimizes for:

  • Direct use with trigonometric functions
  • Precision in intermediate calculations
  • Consistency with mathematical conventions

§Derives

  • Copy, Clone: Angles are small (8 bytes) and cheap to copy
  • Debug: Shows internal radian value
  • PartialEq, PartialOrd: Compare angles directly (compares radian values)

Note: Eq and Ord are not implemented because f64 can be NaN.

Implementations§

Source§

impl Angle

Source

pub const ZERO: Self

Zero angle (0 radians).

Source

pub const PI: Self

Pi radians (180 degrees). Useful for half-circle operations.

Source

pub const HALF_PI: Self

Pi/2 radians (90 degrees). Useful for right angles and pole declinations.

Source

pub const fn from_radians(rad: f64) -> Self

Creates an angle from radians.

This is the only const constructor because radians are the internal representation.

§Example
use celestial_core::Angle;
use std::f64::consts::FRAC_PI_4;

let angle = Angle::from_radians(FRAC_PI_4);
assert!((angle.degrees() - 45.0).abs() < 1e-10);
Source

pub fn from_degrees(deg: f64) -> Self

Creates an angle from degrees.

§Example
use celestial_core::Angle;

let angle = Angle::from_degrees(180.0);
assert!((angle.radians() - celestial_core::constants::PI).abs() < 1e-10);
Source

pub fn from_hours(h: f64) -> Self

Creates an angle from hours.

In astronomy, right ascension is measured in hours where 24h = 360 degrees. Each hour equals 15 degrees.

§Example
use celestial_core::Angle;

let ra = Angle::from_hours(6.0);  // 6h = 90 degrees
assert!((ra.degrees() - 90.0).abs() < 1e-10);

let ra_24h = Angle::from_hours(24.0);  // Full circle
assert!((ra_24h.degrees() - 360.0).abs() < 1e-10);
Source

pub fn from_arcseconds(arcsec: f64) -> Self

Creates an angle from arcseconds.

One arcsecond = 1/3600 of a degree. Commonly used for:

  • Parallax measurements
  • Proper motion
  • Small angular separations
§Example
use celestial_core::Angle;

let angle = Angle::from_arcseconds(3600.0);  // 1 degree
assert!((angle.degrees() - 1.0).abs() < 1e-10);

// Proxima Centauri's parallax is about 0.77 arcseconds
let parallax = Angle::from_arcseconds(0.77);
Source

pub fn from_arcminutes(arcmin: f64) -> Self

Creates an angle from arcminutes.

One arcminute = 1/60 of a degree. Commonly used for:

  • Field of view specifications
  • Object sizes (e.g., the Moon is about 31 arcminutes)
§Example
use celestial_core::Angle;

let angle = Angle::from_arcminutes(60.0);  // 1 degree
assert!((angle.degrees() - 1.0).abs() < 1e-10);

// Full Moon's apparent diameter
let moon_diameter = Angle::from_arcminutes(31.0);
Source

pub fn radians(self) -> f64

Returns the angle in radians.

This is the internal representation, so no conversion occurs.

Source

pub fn degrees(self) -> f64

Returns the angle in degrees.

Source

pub fn hours(self) -> f64

Returns the angle in hours.

Useful for right ascension where 24h = 360 degrees.

Source

pub fn arcseconds(self) -> f64

Returns the angle in arcseconds.

Source

pub fn arcminutes(self) -> f64

Returns the angle in arcminutes.

Source

pub fn sin(self) -> f64

Returns the sine of the angle.

Source

pub fn cos(self) -> f64

Returns the cosine of the angle.

Source

pub fn sin_cos(self) -> (f64, f64)

Returns both sine and cosine of the angle.

Convenience method when you need both values.

§Returns

A tuple (sin, cos).

§Example
use celestial_core::Angle;

let angle = Angle::from_degrees(30.0);
let (sin, cos) = angle.sin_cos();
assert!((sin - 0.5).abs() < 1e-10);
assert!((cos - 0.866025).abs() < 1e-5);
Source

pub fn tan(self) -> f64

Returns the tangent of the angle.

Source

pub fn abs(self) -> Self

Returns the absolute value of the angle.

§Example
use celestial_core::Angle;

let negative = Angle::from_degrees(-45.0);
let absolute = negative.abs();
assert!((absolute.degrees() - 45.0).abs() < 1e-10);
Source

pub fn wrapped(self) -> Self

Wraps the angle to the range [-pi, +pi) (i.e., [-180, +180) degrees).

Use this for longitude-like quantities or angular differences where you want the shortest arc representation.

§Example
use celestial_core::Angle;

let angle = Angle::from_degrees(270.0);
let wrapped = angle.wrapped();
assert!((wrapped.degrees() - (-90.0)).abs() < 1e-10);

let angle2 = Angle::from_degrees(-270.0);
let wrapped2 = angle2.wrapped();
assert!((wrapped2.degrees() - 90.0).abs() < 1e-10);
Source

pub fn normalized(self) -> Self

Normalizes the angle to the range [0, 2*pi) (i.e., [0, 360) degrees).

Use this for right ascension or any angle that should be non-negative.

§Example
use celestial_core::Angle;

let angle = Angle::from_degrees(-90.0);
let normalized = angle.normalized();
assert!((normalized.degrees() - 270.0).abs() < 1e-10);

let angle2 = Angle::from_degrees(450.0);
let normalized2 = angle2.normalized();
assert!((normalized2.degrees() - 90.0).abs() < 1e-10);
Source

pub fn validate_longitude(self, normalize: bool) -> Result<Self, AstroError>

Validates the angle as a longitude.

If normalize is true, wraps to [0, 2*pi) and returns Ok. If normalize is false, requires the angle to be in [-pi, +pi] or returns Err.

§Errors

Returns AstroError if:

  • The angle is not finite (NaN or infinity)
  • normalize is false and the angle is outside [-180, +180] degrees
Source

pub fn validate_latitude(self) -> Result<Self, AstroError>

Validates the angle as a geographic latitude.

Latitude must be in [-90, +90] degrees ([-pi/2, +pi/2] radians).

§Errors

Returns AstroError if:

  • The angle is not finite (NaN or infinity)
  • The angle is outside [-90, +90] degrees
Source

pub fn validate_declination(self, beyond_pole: bool) -> Result<Self, AstroError>

Validates the angle as a declination.

  • beyond_pole = false: standard range [-90°, +90°]
  • beyond_pole = true: extended range [-180°, +180°] for GEM pier-flipped observations
§Errors

Returns AstroError if:

  • The angle is not finite (NaN or infinity)
  • The angle is outside the valid range
Source

pub fn validate_right_ascension(self) -> Result<Self, AstroError>

Validates the angle as a right ascension, normalizing to [0, 360) degrees.

Unlike declination, right ascension is cyclic. This method accepts any finite angle and normalizes it to [0, 2*pi).

§Errors

Returns AstroError if the angle is not finite (NaN or infinity).

Trait Implementations§

Source§

impl Add for Angle

Angle + Angle → Angle

Source§

type Output = Angle

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl Clone for Angle

Source§

fn clone(&self) -> Angle

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 Debug for Angle

Source§

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

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

impl Display for Angle

Source§

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

Formats the angle as decimal degrees with 6 decimal places.

This provides a simple, unambiguous representation suitable for debugging and data export. For astronomical notation, use DmsFmt or HmsFmt.

Source§

impl Div<f64> for Angle

Angle / scalar → Angle

Source§

type Output = Angle

The resulting type after applying the / operator.
Source§

fn div(self, k: f64) -> Self

Performs the / operation. Read more
Source§

impl Mul<f64> for Angle

Angle * scalar → Angle

Source§

type Output = Angle

The resulting type after applying the * operator.
Source§

fn mul(self, k: f64) -> Self

Performs the * operation. Read more
Source§

impl Neg for Angle

-Angle → Angle

Source§

type Output = Angle

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Angle

Source§

fn eq(&self, other: &Angle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Angle

Source§

fn partial_cmp(&self, other: &Angle) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Angle

Angle - Angle → Angle

Source§

type Output = Angle

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl Copy for Angle

Source§

impl StructuralPartialEq for Angle

Auto Trait Implementations§

§

impl Freeze for Angle

§

impl RefUnwindSafe for Angle

§

impl Send for Angle

§

impl Sync for Angle

§

impl Unpin for Angle

§

impl UnsafeUnpin for Angle

§

impl UnwindSafe for Angle

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