summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-03 07:23:55 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-03 07:23:55 +0200
commit4010e3983d40e24a5d7b590d8fec9801651199ce (patch)
treee0deb67cf993a2b67417d7e764c0685f03b50ddf /core
parenteac5bcb64f17dfbb52b64ea4f95693462986bb69 (diff)
downloadiced-4010e3983d40e24a5d7b590d8fec9801651199ce.tar.gz
iced-4010e3983d40e24a5d7b590d8fec9801651199ce.tar.bz2
iced-4010e3983d40e24a5d7b590d8fec9801651199ce.zip
Add `spin` mode to `ferris` example :crab:
Diffstat (limited to 'core')
-rw-r--r--core/src/angle.rs26
-rw-r--r--core/src/rotation.rs7
2 files changed, 32 insertions, 1 deletions
diff --git a/core/src/angle.rs b/core/src/angle.rs
index 8322273c..9c8a9b24 100644
--- a/core/src/angle.rs
+++ b/core/src/angle.rs
@@ -1,7 +1,7 @@
use crate::{Point, Rectangle, Vector};
use std::f32::consts::{FRAC_PI_2, PI};
-use std::ops::{Add, AddAssign, Div, Mul, RangeInclusive, Sub, SubAssign};
+use std::ops::{Add, AddAssign, Div, Mul, RangeInclusive, Rem, Sub, SubAssign};
/// Degrees
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
@@ -48,6 +48,14 @@ impl From<Degrees> for f64 {
}
}
+impl Mul<f32> for Degrees {
+ type Output = Degrees;
+
+ fn mul(self, rhs: f32) -> Self::Output {
+ Self(self.0 * rhs)
+ }
+}
+
impl num_traits::FromPrimitive for Degrees {
fn from_i64(n: i64) -> Option<Self> {
Some(Self(n as f32))
@@ -156,6 +164,14 @@ impl Add for Radians {
}
}
+impl Add<Degrees> for Radians {
+ type Output = Self;
+
+ fn add(self, rhs: Degrees) -> Self::Output {
+ Self(self.0 + rhs.0.to_radians())
+ }
+}
+
impl AddAssign for Radians {
fn add_assign(&mut self, rhs: Radians) {
self.0 = self.0 + rhs.0;
@@ -202,6 +218,14 @@ impl Div for Radians {
}
}
+impl Rem for Radians {
+ type Output = Self;
+
+ fn rem(self, rhs: Self) -> Self::Output {
+ Self(self.0 % rhs.0)
+ }
+}
+
impl PartialEq<f32> for Radians {
fn eq(&self, other: &f32) -> bool {
self.0.eq(other)
diff --git a/core/src/rotation.rs b/core/src/rotation.rs
index 00a8c302..afa8d79e 100644
--- a/core/src/rotation.rs
+++ b/core/src/rotation.rs
@@ -31,6 +31,13 @@ impl Rotation {
}
}
+ /// Returns a mutable reference to the angle of the [`Rotation`] in [`Radians`].
+ pub fn radians_mut(&mut self) -> &mut Radians {
+ match self {
+ Rotation::Floating(radians) | Rotation::Solid(radians) => radians,
+ }
+ }
+
/// Returns the angle of the [`Rotation`] in [`Degrees`].
pub fn degrees(self) -> Degrees {
Degrees(self.radians().0.to_degrees())