diff options
| author | Arne Dußin | 2020-11-10 18:52:08 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-10 18:52:08 +0100 |
| commit | 178d716232468e5ae3292f39ccc5abd9c147094e (patch) | |
| tree | f262ee32f8d7407a460c578c0f027f5cc3f919cb /src/math | |
| parent | f2caebd11512fce214338b054c1b061b86d84aee (diff) | |
| download | graf_karto-178d716232468e5ae3292f39ccc5abd9c147094e.tar.gz graf_karto-178d716232468e5ae3292f39ccc5abd9c147094e.zip | |
Add dimension indicator without direct value editing
Diffstat (limited to 'src/math')
| -rw-r--r-- | src/math/vec2.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/math/vec2.rs b/src/math/vec2.rs index ea549d7..7834ffc 100644 --- a/src/math/vec2.rs +++ b/src/math/vec2.rs @@ -1,11 +1,12 @@ use crate::math::Rect; use alga::general::{ClosedAdd, ClosedSub}; use nalgebra::{RealField, Scalar}; +use num_traits::One; use serde::{Deserialize, Serialize}; use std::cmp::Ordering; use std::convert::{From, Into}; -use std::fmt; -use std::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign}; +use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; +use std::{fmt, mem}; #[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Serialize, Deserialize, Eq)] pub struct Vec2<T: Scalar + Copy> { @@ -24,6 +25,24 @@ impl<T: Scalar + Copy> Vec2<T> { { (self.x * self.x + self.y * self.y).sqrt() } + + pub fn rotated_90_clockwise(mut self) -> Vec2<T> + where + T: One + Neg<Output = T> + MulAssign, + { + mem::swap(&mut self.x, &mut self.y); + self.y *= -T::one(); + self + } + + pub fn rotated_90_counterclockwise(mut self) -> Vec2<T> + where + T: One + Neg<Output = T> + MulAssign, + { + mem::swap(&mut self.x, &mut self.y); + self.x *= -T::one(); + self + } } // This is sad, but also sadly necessary :/ |
