Struct Period

Source
pub struct Period(/* private fields */);
Expand description

Angles and Time are the most prominent use for this type

Additional Methods:

Implementations§

Source§

impl Period

Source

pub const fn radians(self) -> f64

Returns the angle as radians.

This is the only function that should directly access the fields of the type.

use pracstro::time::Period;
Period::from_degrees(180.0).radians(); // Pi
Source

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

Constructs a angle from radians, reducing it to the range of [0, 2*PI].

This is the one of the two only functions that directly access Period. Reduction to the desired range is done with Least Positive Residue instead of the remainder operator.

use pracstro::time::Period;
Period::from_radians(std::f64::consts::PI).degrees(); // 180.0
Source

pub const fn to_latitude(self) -> Self

Converts angles internally so that formatting them as latitudes makes sense

This should be used directly in conjunction with a formatting function. The main use case for this is in coordinate handling where angles of latitude can be negative. This is the only other function that should be able to directly access Period than Period::from_radians().

use pracstro::time::Period;
Period::from_degrees(-25.0).degrees(); // 335.0
Period::from_degrees(-25.0).to_latitude().degrees(); // -25.0
Examples found in repository?
examples/speed.rs (line 23)
19    fn ephem() {
20        let now = time::Date::now();
21        for p in sol::PLANETS {
22            let (ra, de) = p.location(now).equatorial();
23            (ra.clock(), de.to_latitude().degminsec());
24        }
25    }
More examples
Hide additional examples
examples/ephem.rs (line 7)
3fn main() {
4    let now = time::Date::now();
5    for p in sol::PLANETS {
6        let (ra, de) = p.location(now).equatorial();
7        let ((rah, ram, _), (ded, dem, _)) = (ra.clock(), de.to_latitude().degminsec());
8        println!(
9            "{:<10} {:>2}h{:02} RA {:>3}°{:02}' De {:.2} AU",
10            p.name,
11            rah,
12            ram,
13            ded,
14            dem,
15            p.distance(now)
16        );
17    }
18}
Source

pub const fn degrees(self) -> f64

Returns the angle as fractional degrees.

A wrapper around f64::to_degrees()

use pracstro::time::Period;
Period::from_degrees(-25.0).degrees(); // 335.0
Source

pub const fn from_degrees(x: f64) -> Self

Constructs an angle from fractional degrees.

A wrapper around f64::to_radians()

use pracstro::time::Period;
Period::from_degrees(-25.0).degrees(); // 335.0
Source

pub const fn turns(self) -> f64

Returns the angle in the range between 0 and 1 (i.e. turns)

Used in the calculation for the illuminated fraction of planets

Source

pub const fn from_turns(x: f64) -> Self

Constructs an angle from a value between 0 and 1

Used in the calculation for the illuminated fraction of planets

Source

pub const fn decimal(self) -> f64

Returns the angle in fractional number of hours

A wrapper around Period::degrees() and one division by 15. Since one hour is 15 degrees of rotation

use pracstro::time::Period;
Period::from_degrees(120.0).decimal(); // 8.0
Source

pub const fn from_decimal(x: f64) -> Self

Constructs an angle from a fractional number of hours

A wrapper around Period::from_degrees() and one multiplication by 15. Since one hour is 15 degrees of rotation

use pracstro::time::Period;
Period::from_decimal(8.0).degrees(); // 120.00
Source

pub fn clock(self) -> (u8, u8, f64)

Returns (Hour, Minute, Second) of a time/angle

Used in hour-angle displays for some coordinate systems, and in times.

use pracstro::time::Period;
Period::from_decimal(8.0).clock(); // (8, 0, 0.0)
Examples found in repository?
examples/speed.rs (line 23)
19    fn ephem() {
20        let now = time::Date::now();
21        for p in sol::PLANETS {
22            let (ra, de) = p.location(now).equatorial();
23            (ra.clock(), de.to_latitude().degminsec());
24        }
25    }
More examples
Hide additional examples
examples/ephem.rs (line 7)
3fn main() {
4    let now = time::Date::now();
5    for p in sol::PLANETS {
6        let (ra, de) = p.location(now).equatorial();
7        let ((rah, ram, _), (ded, dem, _)) = (ra.clock(), de.to_latitude().degminsec());
8        println!(
9            "{:<10} {:>2}h{:02} RA {:>3}°{:02}' De {:.2} AU",
10            p.name,
11            rah,
12            ram,
13            ded,
14            dem,
15            p.distance(now)
16        );
17    }
18}
Source

pub fn from_clock(h: u8, m: u8, s: f64) -> Self

Constructs an angle out of an hour, minute, and second

Used in hour-angle displays for some coordinate systems, and in times.

use pracstro::time::Period;
Period::from_clock(8, 0, 0.0).decimal(); // 8.0
Source

pub fn degminsec(self) -> (i16, u8, f64)

Converts an angle to a degree with arcminutes and arcseconds

Examples found in repository?
examples/speed.rs (line 23)
19    fn ephem() {
20        let now = time::Date::now();
21        for p in sol::PLANETS {
22            let (ra, de) = p.location(now).equatorial();
23            (ra.clock(), de.to_latitude().degminsec());
24        }
25    }
More examples
Hide additional examples
examples/ephem.rs (line 7)
3fn main() {
4    let now = time::Date::now();
5    for p in sol::PLANETS {
6        let (ra, de) = p.location(now).equatorial();
7        let ((rah, ram, _), (ded, dem, _)) = (ra.clock(), de.to_latitude().degminsec());
8        println!(
9            "{:<10} {:>2}h{:02} RA {:>3}°{:02}' De {:.2} AU",
10            p.name,
11            rah,
12            ram,
13            ded,
14            dem,
15            p.distance(now)
16        );
17    }
18}
Source

pub fn from_degminsec(d: i16, m: u8, s: f64) -> Self

Identical to from_clock in math

Source

pub fn gst(self, date: Date) -> Self

Handles the discontinuity created by the orbit of the earth as compared to its rotation.

Algorithm from Practical Astronomy with Your Calculator, although similar algorithms exist in other sources

Source

pub fn ungst(self, date: Date) -> Self

Handles the discontinuity created by the orbit of the earth as compared to its rotation.

Algorithm from Practical Astronomy with Your Calculator, although similar algorithms exist in other sources

Source

pub fn hourangle_rightas(self, date: Date, time: Period, longi: Period) -> Self

Gets the hour angle from the angle as if it were a right ascension, and vice versa.

Used in horizontal coordinates.

Source

pub fn sin(self) -> f64

Sine of Period

Source

pub fn cos(self) -> f64

Cosine of Period

Source

pub fn tan(self) -> f64

Tangent of Period

Source

pub fn asin(x: f64) -> Self

Period from Arcsine

Source

pub fn acos(x: f64) -> Self

Period from Arccosine

Source

pub fn atan2(x: f64, y: f64) -> Self

Period from 2-argument Arctangent

Source

pub fn inverse(self) -> Self

Reverses the angle

Trait Implementations§

Source§

impl Add for Period

Source§

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

Addition, For timezones and LST

Source§

type Output = Period

The resulting type after applying the + operator.
Source§

impl Clone for Period

Source§

fn clone(&self) -> Period

Returns a copy 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 Period

Used in testing

Source§

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

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

impl Default for Period

Source§

fn default() -> Period

Returns the “default value” for a type. Read more
Source§

impl Div<f64> for Period

Source§

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

Multiplication

Source§

type Output = Period

The resulting type after applying the / operator.
Source§

impl Mul<f64> for Period

Source§

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

Multiplication

Source§

type Output = Period

The resulting type after applying the * operator.
Source§

impl PartialEq for Period

Does not check if arcseconds are equal

Source§

fn eq(&self, other: &Self) -> 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 Period

Source§

fn partial_cmp(&self, other: &Period) -> 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 Period

Source§

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

Subtraction, For timezones and LST

Source§

type Output = Period

The resulting type after applying the - operator.
Source§

impl Copy for Period

Auto Trait Implementations§

§

impl Freeze for Period

§

impl RefUnwindSafe for Period

§

impl Send for Period

§

impl Sync for Period

§

impl Unpin for Period

§

impl UnwindSafe for Period

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