pub struct Angle { /* private fields */ }Expand description
Explicit angle value stored in radians.
Implementations§
Source§impl Angle
impl Angle
Sourcepub const fn from_radians(radians: f64) -> Self
pub const fn from_radians(radians: f64) -> Self
Creates an angle from a radians value.
Sourcepub const fn from_degrees(degrees: f64) -> Self
pub const fn from_degrees(degrees: f64) -> Self
Creates an angle from a degrees value.
Examples found in repository?
examples/basic_usage.rs (line 6)
5fn main() {
6 let acute = Angle::from_degrees(30.0);
7 let wrapped = Angle::from_degrees(765.0).normalized();
8 let signed = Angle::from_degrees(-450.0).normalized_signed();
9
10 assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
11 assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
12 assert!((acute.sin() - 0.5).abs() < 1.0e-12);
13 assert!((acute.cos() - cos_deg(30.0)).abs() < 1.0e-12);
14 assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
15 assert!((signed.degrees() + 90.0).abs() < 1.0e-12);
16 assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);
17 assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
18 assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);
19}Sourcepub const fn radians(self) -> f64
pub const fn radians(self) -> f64
Returns the angle in radians.
Examples found in repository?
examples/basic_usage.rs (line 10)
5fn main() {
6 let acute = Angle::from_degrees(30.0);
7 let wrapped = Angle::from_degrees(765.0).normalized();
8 let signed = Angle::from_degrees(-450.0).normalized_signed();
9
10 assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
11 assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
12 assert!((acute.sin() - 0.5).abs() < 1.0e-12);
13 assert!((acute.cos() - cos_deg(30.0)).abs() < 1.0e-12);
14 assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
15 assert!((signed.degrees() + 90.0).abs() < 1.0e-12);
16 assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);
17 assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
18 assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);
19}Sourcepub const fn degrees(self) -> f64
pub const fn degrees(self) -> f64
Returns the angle in degrees.
Examples found in repository?
examples/basic_usage.rs (line 11)
5fn main() {
6 let acute = Angle::from_degrees(30.0);
7 let wrapped = Angle::from_degrees(765.0).normalized();
8 let signed = Angle::from_degrees(-450.0).normalized_signed();
9
10 assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
11 assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
12 assert!((acute.sin() - 0.5).abs() < 1.0e-12);
13 assert!((acute.cos() - cos_deg(30.0)).abs() < 1.0e-12);
14 assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
15 assert!((signed.degrees() + 90.0).abs() < 1.0e-12);
16 assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);
17 assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
18 assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);
19}Sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
Returns the angle normalized into the interval [0, 2π).
Examples found in repository?
examples/basic_usage.rs (line 7)
5fn main() {
6 let acute = Angle::from_degrees(30.0);
7 let wrapped = Angle::from_degrees(765.0).normalized();
8 let signed = Angle::from_degrees(-450.0).normalized_signed();
9
10 assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
11 assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
12 assert!((acute.sin() - 0.5).abs() < 1.0e-12);
13 assert!((acute.cos() - cos_deg(30.0)).abs() < 1.0e-12);
14 assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
15 assert!((signed.degrees() + 90.0).abs() < 1.0e-12);
16 assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);
17 assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
18 assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);
19}Sourcepub fn normalized_signed(self) -> Self
pub fn normalized_signed(self) -> Self
Returns the angle normalized into the interval (-π, π].
Examples found in repository?
examples/basic_usage.rs (line 8)
5fn main() {
6 let acute = Angle::from_degrees(30.0);
7 let wrapped = Angle::from_degrees(765.0).normalized();
8 let signed = Angle::from_degrees(-450.0).normalized_signed();
9
10 assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
11 assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
12 assert!((acute.sin() - 0.5).abs() < 1.0e-12);
13 assert!((acute.cos() - cos_deg(30.0)).abs() < 1.0e-12);
14 assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
15 assert!((signed.degrees() + 90.0).abs() < 1.0e-12);
16 assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);
17 assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
18 assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);
19}Sourcepub fn sin(self) -> f64
pub fn sin(self) -> f64
Returns the sine of the angle.
Examples found in repository?
examples/basic_usage.rs (line 12)
5fn main() {
6 let acute = Angle::from_degrees(30.0);
7 let wrapped = Angle::from_degrees(765.0).normalized();
8 let signed = Angle::from_degrees(-450.0).normalized_signed();
9
10 assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
11 assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
12 assert!((acute.sin() - 0.5).abs() < 1.0e-12);
13 assert!((acute.cos() - cos_deg(30.0)).abs() < 1.0e-12);
14 assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
15 assert!((signed.degrees() + 90.0).abs() < 1.0e-12);
16 assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);
17 assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
18 assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);
19}Sourcepub fn cos(self) -> f64
pub fn cos(self) -> f64
Returns the cosine of the angle.
Examples found in repository?
examples/basic_usage.rs (line 13)
5fn main() {
6 let acute = Angle::from_degrees(30.0);
7 let wrapped = Angle::from_degrees(765.0).normalized();
8 let signed = Angle::from_degrees(-450.0).normalized_signed();
9
10 assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
11 assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
12 assert!((acute.sin() - 0.5).abs() < 1.0e-12);
13 assert!((acute.cos() - cos_deg(30.0)).abs() < 1.0e-12);
14 assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
15 assert!((signed.degrees() + 90.0).abs() < 1.0e-12);
16 assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);
17 assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
18 assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);
19}Trait Implementations§
impl 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 UnsafeUnpin 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
Mutably borrows from an owned value. Read more