Skip to main content

Angle

Struct Angle 

Source
pub struct Angle<T>
where T: Float,
{ /* private fields */ }
Expand description

An angle represented by it’s sine and cosine as UnitNegRanges.

Implementations§

Source§

impl<T> Angle<T>
where T: Float,

Source

pub const fn new(sin: UnitNegRange<T>, cos: UnitNegRange<T>) -> Angle<T>

Construct an Angle from sin and cos values.

Source

pub fn from_y_x(y: T, x: T) -> Angle<T>

Construct an Angle from y and x values. Normalizes the values.

Source

pub const fn sin(self) -> UnitNegRange<T>

The sine of the Angle.

Source

pub const fn cos(self) -> UnitNegRange<T>

The cosine of the Angle.

Source

pub fn tan(self) -> Option<T>

The tangent of the Angle.

returns the tangent or None if self.cos < SQ_EPSILON

Source

pub fn csc(self) -> Option<T>

The cosecant of the Angle.

returns the cosecant or None if self.sin < SQ_EPSILON

Source

pub fn sec(self) -> Option<T>

The secant of the Angle.

returns the secant or None if self.cos < SQ_EPSILON

Source

pub fn cot(self) -> Option<T>

The cotangent of the Angle.

returns the cotangent or None if self.sin < SQ_EPSILON

Source

pub fn abs(self) -> Angle<T>

The absolute value of the angle, i.e. the angle with a positive sine.

§Examples
use angle_sc::{Angle, Degrees};

let angle_m45 = Angle::from(Degrees(-45.0));
let result_45 = angle_m45.abs();
assert_eq!(Degrees(45.0), Degrees::from(result_45));
Source

pub fn opposite(self) -> Angle<T>

The opposite angle on the circle, i.e. +/- 180 degrees.

§Examples
use angle_sc::{Angle, Degrees};

let angle_m30 = Angle::from(Degrees(-30.0));
let result = angle_m30.opposite();
assert_eq!(Degrees(150.0), Degrees::from(result));
Source

pub fn quarter_turn_cw(self) -> Angle<T>

A quarter turn clockwise around the circle, i.e. + 90°.

§Examples
use angle_sc::{Angle, Degrees};

let angle_m30 = Angle::from(Degrees(-30.0));
let result = angle_m30.quarter_turn_cw();
assert_eq!(Angle::from(Degrees(60.0)), result);
Source

pub fn quarter_turn_ccw(self) -> Angle<T>

A quarter turn counter-clockwise around the circle, i.e. - 90°.

§Examples
use angle_sc::{Angle, Degrees};

let angle_120 = Angle::from(Degrees(120.0));
let result = angle_120.quarter_turn_ccw();
assert_eq!(Angle::from(Degrees(30.0)), result);
Source

pub fn negate_cos(self) -> Angle<T>

Negate the cosine of the Angle. I.e. PI - angle.radians() for positive angles, angle.radians() + PI for negative angles

§Examples
use angle_sc::{Angle, Degrees};

let angle_45 = Angle::from(Degrees(45.0));
let result_45 = angle_45.negate_cos();
assert_eq!(Degrees(135.0), Degrees::from(result_45));
Source

pub fn double(self) -> Angle<T>

Double the Angle. See: Double-angle formulae

§Examples
use angle_sc::{Angle, Degrees};

let angle_30 = Angle::from(Degrees(30.0));
let result_60 = angle_30.double();

// Note: multiplication is not precise...
// assert_eq!(Degrees(60.0), Degrees::<f64>::from(result_60));
let delta_angle = (60.0 - Degrees::<f64>::from(result_60).0).abs();
assert!(delta_angle <= 32.0 * f64::EPSILON);
Source

pub fn half(self) -> Angle<T>

Half of the Angle. See: Half-angle formulae

§Examples
use angle_sc::{Angle, Degrees};

let angle_30 = Angle::from(Degrees(30.0));
let angle_60 = Angle::from(Degrees(60.0));

assert_eq!(angle_30, angle_60.half());

Trait Implementations§

Source§

impl<T> Add for Angle<T>
where T: Float,

Source§

fn add(self, other: Angle<T>) -> <Angle<T> as Add>::Output

Add two Angles, i.e. a + b Uses trigonometric identity functions, see: angle sum and difference identities.

§Examples
use angle_sc::{Angle, Degrees};

let angle_30 = Angle::from(Degrees(30.0));
let angle_60 = Angle::from(Degrees(60.0));
let result_90 = angle_30 + angle_60;
assert_eq!(Degrees(90.0), Degrees::from(result_90));
Source§

type Output = Angle<T>

The resulting type after applying the + operator.
Source§

impl<T> AddAssign for Angle<T>
where T: Float,

Source§

fn add_assign(&mut self, other: Angle<T>)

Performs the += operation. Read more
Source§

impl<T> Clone for Angle<T>
where T: Clone + Float,

Source§

fn clone(&self) -> Angle<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Copy for Angle<T>
where T: Copy + Float,

Source§

impl<T> Debug for Angle<T>
where T: Debug + Float,

Source§

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

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

impl<T> Default for Angle<T>
where T: Float,

A default angle: zero degrees or radians.

Source§

fn default() -> Angle<T>

Implementation of Default for Angle returns Angle(0.0, 1.0), i.e. the Angle corresponding to zero degrees or radians.

§Examples
use angle_sc::Angle;

let zero = Angle::<f64>::default();
assert_eq!(0.0, zero.sin().0);
assert_eq!(1.0, zero.cos().0);
Source§

impl<'de, T> Deserialize<'de> for Angle<T>
where T: Float + FloatConst + Deserialize<'de>, f64: From<T>,

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Angle<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize an value in Degrees to an Angle.

Source§

impl<T> Eq for Angle<T>
where T: Eq + Float,

Source§

impl<T> From<(Degrees<T>, Degrees<T>)> for Angle<T>
where T: Float + FloatConst, f64: From<T>,

Source§

fn from(params: (Degrees<T>, Degrees<T>)) -> Angle<T>

Construct an Angle from the difference of a pair angles in Degrees: a - b

Examples:

use angle_sc::{Angle, Degrees, trig};

// Difference of Degrees(-155.0) - Degrees(175.0)
let angle = Angle::from((Degrees(-155.0), Degrees(175.0)));
assert_eq!(0.5, angle.sin().0);
assert_eq!(trig::COS_30_DEGREES, angle.cos().0);
assert_eq!(30.0, Degrees::from(angle).0);
Source§

impl<T> From<(Radians<T>, Radians<T>)> for Angle<T>
where T: Float + FloatConst, f64: From<T>,

Source§

fn from(params: (Radians<T>, Radians<T>)) -> Angle<T>

Construct an Angle from the difference of a pair angles in Radians: a - b

Examples:

use angle_sc::{Angle, Radians, trig};

// 6*π - π/3 radians round trip
let angle = Angle::from((
    Radians(3.0 * core::f64::consts::TAU),
    Radians(core::f64::consts::FRAC_PI_3),
));
assert_eq!(-core::f64::consts::FRAC_PI_3, Radians::from(angle).0);
Source§

impl<T> From<Angle<T>> for Radians<T>
where T: Float + FloatConst,

Source§

fn from(a: Angle<T>) -> Radians<T>

Convert an Angle to Radians.

Source§

impl<T> From<Angle<T>> for Degrees<T>
where T: Float + FloatConst,

Source§

fn from(a: Angle<T>) -> Degrees<T>

Convert an Angle to Degrees.

Source§

impl<T> From<Degrees<T>> for Angle<T>
where T: Float + FloatConst, f64: From<T>,

Source§

fn from(a: Degrees<T>) -> Angle<T>

Construct an Angle from an angle in Degrees.

Examples:

use angle_sc::{Angle, Degrees, is_within_tolerance, trig};

let angle = Angle::from(Degrees(60.0));
assert_eq!(trig::COS_30_DEGREES, angle.sin().0);
assert_eq!(0.5, angle.cos().0);
assert_eq!(60.0, Degrees::from(angle).0);
Source§

impl<T> From<Radians<T>> for Angle<T>
where T: Float + FloatConst, f64: From<T>,

Source§

fn from(a: Radians<T>) -> Angle<T>

Construct an Angle from an angle in Radians.

Examples:

use angle_sc::{Angle, Radians, trig};

let angle = Angle::from(Radians(-core::f64::consts::FRAC_PI_6));
assert_eq!(-0.5, angle.sin().0);
assert_eq!(trig::COS_30_DEGREES, angle.cos().0);
assert_eq!(-core::f64::consts::FRAC_PI_6, Radians::from(angle).0);
Source§

impl<T> Neg for Angle<T>
where T: Float,

Source§

fn neg(self) -> Angle<T>

An implementation of Neg for Angle, i.e. -angle. Negates the sine of the Angle, does not affect the cosine.

§Examples
use angle_sc::{Angle, Degrees};

let angle_45 = Angle::from(Degrees(45.0));
let result_m45 = -angle_45;
assert_eq!(Degrees(-45.0), Degrees::from(result_m45));
Source§

type Output = Angle<T>

The resulting type after applying the - operator.
Source§

impl<T> PartialEq for Angle<T>
where T: PartialEq + Float,

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T> PartialOrd for Angle<T>
where T: Float,

Source§

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

Compare two Angles, i.e. a < b. It compares whether an Angle is clockwise of the other Angle on the unit circle.

§Examples
use angle_sc::{Angle, Degrees};
let degrees_120 = Angle::from(Degrees(120.0));
let degrees_m120 = -degrees_120;
assert!(degrees_120 < degrees_m120);
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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<T> Serialize for Angle<T>
where T: Float + FloatConst + Serialize,

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize an Angle to an value in Degrees.

Source§

impl<T> StructuralPartialEq for Angle<T>
where T: PartialEq + Float,

Source§

impl<T> Sub for Angle<T>
where T: Float,

Source§

fn sub(self, other: Angle<T>) -> <Angle<T> as Sub>::Output

Subtract two Angles, i.e. a - b Uses trigonometric identity functions, see: angle sum and difference identities.

§Examples
use angle_sc::{Angle, Degrees, is_within_tolerance};

let angle_30 = Angle::from(Degrees(30.0));
let angle_60 = Angle::from(Degrees(60.0));
let result_30 = angle_60 - angle_30;

assert!(is_within_tolerance(Degrees(30.0).0, Degrees::from(result_30).0, 32.0 * f64::EPSILON));
Source§

type Output = Angle<T>

The resulting type after applying the - operator.
Source§

impl<T> SubAssign for Angle<T>
where T: Float,

Source§

fn sub_assign(&mut self, other: Angle<T>)

Performs the -= operation. Read more
Source§

impl<T> Validate for Angle<T>
where T: Float,

Source§

fn is_valid(&self) -> bool

Test whether an Angle is valid, i.e. both sin and cos are valid UnitNegRanges and the length of their hypotenuse is approximately 1.0.

Auto Trait Implementations§

§

impl<T> Freeze for Angle<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Angle<T>
where T: RefUnwindSafe,

§

impl<T> Send for Angle<T>
where T: Send,

§

impl<T> Sync for Angle<T>
where T: Sync,

§

impl<T> Unpin for Angle<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Angle<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Angle<T>
where T: UnwindSafe,

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, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T, Right> ClosedAddAssign<Right> for T
where T: ClosedAdd<Right> + AddAssign<Right>,

Source§

impl<T> ClosedNeg for T
where T: Neg<Output = T>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T, Right> ClosedSubAssign<Right> for T
where T: ClosedSub<Right> + SubAssign<Right>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

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