pub struct Angle { /* private fields */ }Expand description
A struct for working with angles in different units (radians, degrees, or rotations).
Angles are stored internally as radians.
let angle_deg = Angle::from_degrees(90.0);
let angle_rad = Angle::from_rad(std::f32::consts::PI / 2.0);
let angle_rot = Angle::from_rotations(0.25);
assert_eq!(angle_deg, angle_rad);
assert_eq!(angle_deg, angle_rot);Implementations§
Source§impl Angle
impl Angle
Sourcepub fn from_degrees(degree: f32) -> Self
pub fn from_degrees(degree: f32) -> Self
Creates a new angle from degrees.
Sourcepub fn from_rotations(rotations: f32) -> Self
pub fn from_rotations(rotations: f32) -> Self
Creates a new angle from number of rotations.
let angle = Angle::from_rotations(0.25);
assert_eq!(angle.to_degree(), 90.0);Sourcepub fn quarter_rotation() -> Self
pub fn quarter_rotation() -> Self
Returns an angle representing a quarter rotation (90°).
Sourcepub fn half_rotation() -> Self
pub fn half_rotation() -> Self
Returns an angle representing a half rotation (180°).
Sourcepub fn full_rotation() -> Self
pub fn full_rotation() -> Self
Returns an angle representing a full rotation (360°).
Sourcepub fn right_cc() -> Self
pub fn right_cc() -> Self
Returns an angle representing a direction to the right. Equivalent to Angle::zero(). see also crate::V2::right()
Sourcepub fn right_cw() -> Self
pub fn right_cw() -> Self
Returns an angle representing a direction to the right. Equivalent to Angle::zero(). see also crate::V2::right()
Sourcepub fn up_cc() -> Self
pub fn up_cc() -> Self
Returns an angle representing a direction upwards, counter clockwise (left / positive) from Angle::zero(). see also crate::V2::up()
Sourcepub fn up_cw() -> Self
pub fn up_cw() -> Self
Returns an angle representing a direction upwards, clockwise (right / negative) from Angle::zero(). see also crate::V2::up()
Sourcepub fn left_cc() -> Self
pub fn left_cc() -> Self
Returns an angle representing a direction to the left, counter clockwise (left / positive) from Angle::zero(). see also crate::V2::left()
Sourcepub fn left_cw() -> Self
pub fn left_cw() -> Self
Returns an angle representing a direction to the left, clockwise (right / negative) from Angle::zero(). see also crate::V2::left()
Sourcepub fn down_cc() -> Self
pub fn down_cc() -> Self
Returns an angle representing a direction downwards, counter clockwise (left / positive) from Angle::zero(). see also crate::V2::down()
Sourcepub fn down_cw() -> Self
pub fn down_cw() -> Self
Returns an angle representing a direction downwards, clockwise (right / negative) from Angle::zero(). see also crate::V2::down()
Sourcepub fn golden_ratio() -> Self
pub fn golden_ratio() -> Self
Creates an angle with the golden ratio number of rotations. See GR.
Sourcepub fn golden_ratio_inverse() -> Self
pub fn golden_ratio_inverse() -> Self
Creates an angle with 1.0 / golden ratio number of rotations. See GR.
Sourcepub fn root_two_inverse() -> Self
pub fn root_two_inverse() -> Self
Creates an angle with 1.0 / √2 number of rotations.
Sourcepub fn to_rotations(&self) -> f32
pub fn to_rotations(&self) -> f32
Gets the angle as a number of rotations.
Sourcepub fn rad_sin_cos(&self) -> (f32, f32)
pub fn rad_sin_cos(&self) -> (f32, f32)
Gets both sine and cosine of this angle in radians: (self.to_rad().sin(), self.to_rad().cos()).
Sourcepub fn mod_one_rotation(&self) -> Self
pub fn mod_one_rotation(&self) -> Self
Returns a new angle modulo 2π (360°), resulting in a positive angle between 0 and 2π.
Sourcepub fn modulo(&self, other: Angle) -> Self
pub fn modulo(&self, other: Angle) -> Self
Returns a new angle modulo other, resulting in a positive angle between Angle::zero and other.
Sourcepub fn positive(&self) -> Self
pub fn positive(&self) -> Self
Returns a new angle with the same direction but positive value.
let angle = Angle::from_degrees(-90.0);
assert_eq!(angle.positive().to_degree(), 270.0);Sourcepub fn normal_right(&self) -> Self
pub fn normal_right(&self) -> Self
Returns a new angle orthogonal to this one (to the right). Equivalent to self + Angle::quarter_rotation().
Sourcepub fn lerp(&self, end: Angle, t: f32) -> Angle
pub fn lerp(&self, end: Angle, t: f32) -> Angle
Interpolates between self and other with t as the interpolation factor.
A value of t = 0.0 returns self, a value of t = 1.0 returns other.
Values between 0.0 and 1.0 return points between self and other.
§Example
let a1 = Angle::zero();
let a2 = Angle::from_degrees(180.0);
assert_eq!(a1.lerp(a2, 0.5), Angle::from_degrees(90.0));Sourcepub fn lerp_iter_fixed(&self, end: Angle, steps: usize) -> AngleInterpolator ⓘ
pub fn lerp_iter_fixed(&self, end: Angle, steps: usize) -> AngleInterpolator ⓘ
Returns an iterator to interpolate from self to end in steps number of steps.
The iterator will return steps + 1 angles, including both self and end.
§Example
let a1 = Angle::zero();
let a2 = Angle::from_degrees(90.0);
for angle in a1.lerp_iter_fixed(a2, 9) {
println!("{:?}", angle);
}Sourcepub fn lerp_iter(
&self,
end: Angle,
sample_settings: SampleSettings,
radius: f32,
) -> AngleInterpolator ⓘ
pub fn lerp_iter( &self, end: Angle, sample_settings: SampleSettings, radius: f32, ) -> AngleInterpolator ⓘ
Returns an iterator to interpolate from self to end.
The number of steps is determined by sample_settings.points_per_unit and the given radius.
The arc length of the arc with radius radius is used as the distance between self and end.
§Example
let a1 = Angle::zero();
let a2 = Angle::from_degrees(90.0);
for angle in a1.lerp_iter(a2, SampleSettings::new(10.0), 1.0) {
println!("{:?}", angle);
}Sourcepub fn with_smallest_rotation_to(&self, other: Angle) -> Angle
pub fn with_smallest_rotation_to(&self, other: Angle) -> Angle
Returns a new angle that represents the smallest rotation to other.
Sourcepub fn dist_mod_one_rotation(&self, other: Angle) -> Angle
pub fn dist_mod_one_rotation(&self, other: Angle) -> Angle
Returns the smallest angular difference between two angles, accounting for wrapping around a full rotation.
Trait Implementations§
Source§impl AddAssign for Angle
impl AddAssign for Angle
Source§fn add_assign(&mut self, rhs: Angle)
fn add_assign(&mut self, rhs: Angle)
+= operation. Read moreSource§impl AddAssign<&Angle> for Angle
impl AddAssign<&Angle> for Angle
Source§fn add_assign(&mut self, rhs: &Angle)
fn add_assign(&mut self, rhs: &Angle)
+= operation. Read moreimpl Copy for Angle
Source§impl<'de> Deserialize<'de> for Angle
impl<'de> Deserialize<'de> for Angle
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl DivAssign<f32> for Angle
impl DivAssign<f32> for Angle
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl MulAssign<f32> for Angle
impl MulAssign<f32> for Angle
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl PartialOrd for Angle
impl PartialOrd 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more