pub struct Angle { /* private fields */ }Expand description
An angle represented by it’s sine and cosine as UnitNegRanges.
Implementations§
Source§impl Angle
impl Angle
Sourcepub const fn new(sin: UnitNegRange, cos: UnitNegRange) -> Angle
pub const fn new(sin: UnitNegRange, cos: UnitNegRange) -> Angle
Construct an Angle from sin and cos values.
Sourcepub fn from_y_x(y: f64, x: f64) -> Angle
pub fn from_y_x(y: f64, x: f64) -> Angle
Construct an Angle from y and x values. Normalizes the values.
Sourcepub const fn sin(self) -> UnitNegRange
pub const fn sin(self) -> UnitNegRange
The sine of the Angle.
Sourcepub const fn cos(self) -> UnitNegRange
pub const fn cos(self) -> UnitNegRange
The cosine of the Angle.
Sourcepub fn tan(self) -> Option<f64>
pub fn tan(self) -> Option<f64>
The tangent of the Angle.
returns the tangent or None if self.cos < SQ_EPSILON
Sourcepub fn csc(self) -> Option<f64>
pub fn csc(self) -> Option<f64>
The cosecant of the Angle.
returns the cosecant or None if self.sin < SQ_EPSILON
Sourcepub fn sec(self) -> Option<f64>
pub fn sec(self) -> Option<f64>
The secant of the Angle.
returns the secant or None if self.cos < SQ_EPSILON
Sourcepub fn cot(self) -> Option<f64>
pub fn cot(self) -> Option<f64>
The cotangent of the Angle.
returns the cotangent or None if self.sin < SQ_EPSILON
Sourcepub const fn abs(self) -> Angle
pub const fn abs(self) -> Angle
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));Sourcepub fn opposite(self) -> Angle
pub fn opposite(self) -> Angle
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));Sourcepub fn quarter_turn_cw(self) -> Angle
pub fn quarter_turn_cw(self) -> Angle
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);Sourcepub fn quarter_turn_ccw(self) -> Angle
pub fn quarter_turn_ccw(self) -> Angle
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);Sourcepub fn negate_cos(self) -> Angle
pub fn negate_cos(self) -> Angle
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));Sourcepub fn double(self) -> Angle
pub fn double(self) -> Angle
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 = (60.0 - Degrees::from(result_60).0).abs();
assert!(delta_angle <= 32.0 * f64::EPSILON);Sourcepub fn half(self) -> Angle
pub fn half(self) -> Angle
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 Add for Angle
impl Add for Angle
Source§fn add(self, other: Angle) -> <Angle as Add>::Output
fn add(self, other: Angle) -> <Angle 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§impl AddAssign for Angle
impl AddAssign for Angle
Source§fn add_assign(&mut self, other: Angle)
fn add_assign(&mut self, other: Angle)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Angle
impl<'de> Deserialize<'de> for Angle
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Angle, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Angle, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize an value in Degrees to an Angle.
Source§impl From<(Degrees, Degrees)> for Angle
impl From<(Degrees, Degrees)> for Angle
Source§fn from(params: (Degrees, Degrees)) -> Angle
fn from(params: (Degrees, Degrees)) -> Angle
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 From<(Radians, Radians)> for Angle
impl From<(Radians, Radians)> for Angle
Source§fn from(params: (Radians, Radians)) -> Angle
fn from(params: (Radians, Radians)) -> Angle
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 From<Degrees> for Angle
impl From<Degrees> for Angle
Source§fn from(a: Degrees) -> Angle
fn from(a: Degrees) -> Angle
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 From<Radians> for Angle
impl From<Radians> for Angle
Source§fn from(a: Radians) -> Angle
fn from(a: Radians) -> Angle
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 Neg for Angle
impl Neg for Angle
Source§fn neg(self) -> Angle
fn neg(self) -> Angle
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§impl PartialOrd for Angle
impl PartialOrd for Angle
Source§fn partial_cmp(&self, other: &Angle) -> Option<Ordering>
fn partial_cmp(&self, other: &Angle) -> 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);Source§impl Serialize for Angle
impl Serialize for Angle
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
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 Sub for Angle
impl Sub for Angle
Source§fn sub(self, other: Angle) -> <Angle as Sub>::Output
fn sub(self, other: Angle) -> <Angle 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§impl SubAssign for Angle
impl SubAssign for Angle
Source§fn sub_assign(&mut self, other: Angle)
fn sub_assign(&mut self, other: Angle)
-= operation. Read moreimpl Copy for Angle
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 UnwindSafe for Angle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.