Struct angle_sc::Angle

source ·
pub struct Angle { /* private fields */ }
Expand description

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

Implementations§

source§

impl Angle

source

pub const fn new(sin: UnitNegRange, cos: UnitNegRange) -> Self

Construct an Angle from sin and cos values.

source

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

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

source

pub const fn sin(self) -> UnitNegRange

The sine of the Angle.

source

pub const fn cos(self) -> UnitNegRange

The cosine of the Angle.

source

pub fn abs(self) -> Self

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

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 negate_cos(self) -> Self

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

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::from(result_60));
let delta_angle = libm::fabs(60.0 - Degrees::from(result_60).0);
assert!(delta_angle <= 32.0 * std::f64::EPSILON);
source

pub fn half(self) -> Self

Half the Angle.

§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 Add for Angle

source§

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

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

type Output = Angle

The resulting type after applying the + operator.
source§

impl Clone for Angle

source§

fn clone(&self) -> Angle

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 Angle

source§

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

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

impl Default for Angle

A default angle: zero degrees or radians.

source§

fn default() -> Self

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::default();
assert_eq!(0.0, zero.sin().0);
assert_eq!(1.0, zero.cos().0);
source§

impl<'de> Deserialize<'de> for Angle

source§

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

Deserialize an value in Degrees to an Angle.

source§

impl From<Angle> for Degrees

source§

fn from(a: Angle) -> Self

Convert an Angle to Degrees.

source§

impl From<Angle> for Radians

source§

fn from(a: Angle) -> Self

Convert an Angle to Radians.

source§

impl From<Degrees> for Angle

source§

fn from(a: Degrees) -> Self

Construct an Angle from an angle in Degrees.
In order to minimize round-off errors, this function calculates sines of angles with sine values <= 1 / sqrt(2): see https://stackoverflow.com/questions/31502120/sin-and-cos-give-unexpected-results-for-well-known-angles
It is based on GeographicLib::Math::sincosd function.

source§

impl From<Radians> for Angle

source§

fn from(a: Radians) -> Self

Construct an Angle from an angle in Radians.
In order to minimize round-off errors, this function calculates sines of angles with sine values <= 1 / sqrt(2)

source§

impl Neg for Angle

source§

fn neg(self) -> Self

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

type Output = Angle

The resulting type after applying the - operator.
source§

impl PartialEq for Angle

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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: &Self) -> 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 · source§

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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Angle

source§

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

Serialize an Angle to an value in Degrees.

source§

impl Sub for Angle

source§

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

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 * std::f64::EPSILON));
§

type Output = Angle

The resulting type after applying the - operator.
source§

impl Validate for Angle

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.

source§

impl Copy for Angle

source§

impl StructuralPartialEq for Angle

Auto Trait Implementations§

§

impl RefUnwindSafe for Angle

§

impl Send for Angle

§

impl Sync for Angle

§

impl Unpin 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

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