From c077e107f2eea618ea644652707254a402527de3 Mon Sep 17 00:00:00 2001 From: kxie Date: Tue, 15 Aug 2023 17:05:46 +0800 Subject: Use `Radians` in arc and ellipse types --- core/src/angle.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'core/src/angle.rs') diff --git a/core/src/angle.rs b/core/src/angle.rs index 102b69cf..e63df726 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::RangeInclusive; +use std::ops::{Add, AddAssign, Div, Mul, RangeInclusive, Sub, SubAssign}; /// Degrees #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] @@ -71,3 +71,47 @@ impl Radians { (start, end) } } + +impl SubAssign for Radians { + fn sub_assign(&mut self, rhs: Radians) { + self.0 = self.0 - rhs.0; + } +} + +impl AddAssign for Radians { + fn add_assign(&mut self, rhs: Radians) { + self.0 = self.0 + rhs.0; + } +} + +impl Add for Radians { + type Output = Radians; + + fn add(self, rhs: Radians) -> Self::Output { + Radians(self.0 + rhs.0) + } +} + +impl Sub for Radians { + type Output = Radians; + + fn sub(self, rhs: Radians) -> Self::Output { + Radians(self.0 - rhs.0) + } +} + +impl Mul for Radians { + type Output = Radians; + + fn mul(self, rhs: f32) -> Self::Output { + Radians(self.0 * rhs) + } +} + +impl Div for Radians { + type Output = Radians; + + fn div(self, rhs: f32) -> Self::Output { + Radians(self.0 / rhs) + } +} -- cgit