pub struct Vec2<T> {
pub x: T,
pub y: T,
}Fields§
§x: T§y: TImplementations§
Source§impl<T: Copy + Zero + PartialOrd + Mul<Output = T> + Sub<Output = T>> Vec2<T>
impl<T: Copy + Zero + PartialOrd + Mul<Output = T> + Sub<Output = T>> Vec2<T>
Sourcepub fn orientation_of(&self, other: Self) -> Orientation
pub fn orientation_of(&self, other: Self) -> Orientation
Check if other is oriented clockwise or counter-clockwise respective to self.
§Examples
use reda_geometry::base::Vec2;
use reda_geometry::base::Orientation;
let a = Vec2::new(1, 0);
let b = Vec2::new(1, 1);
let c = Vec2::new(1, -1);
let d = Vec2::new(2, 0);
assert_eq!(a.orientation_of(b), Orientation::CounterClockWise);
assert_eq!(a.orientation_of(c), Orientation::ClockWise);
assert_eq!(a.orientation_of(d), Orientation::Straight);Source§impl<T: Copy + Mul<Output = T> + Sub<Output = T>> Vec2<T>
impl<T: Copy + Mul<Output = T> + Sub<Output = T>> Vec2<T>
Sourcepub fn cross_prod(&self, other: Self) -> T
pub fn cross_prod(&self, other: Self) -> T
Calculate cross product.
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(2, 0);
let b = Vec2::new(0, 2);
assert_eq!(a.cross_prod(b), 4);
assert_eq!(b.cross_prod(a), -4);Source§impl<T: Copy + Mul<Output = T> + Add<Output = T>> Vec2<T>
impl<T: Copy + Mul<Output = T> + Add<Output = T>> Vec2<T>
Sourcepub fn norm2_squared(&self) -> T
pub fn norm2_squared(&self) -> T
Get squared 2-norm of vec2.
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(2, 3);
assert_eq!(a.norm2_squared(), 2*2+3*3);Source§impl<T> Vec2<T>
impl<T> Vec2<T>
Sourcepub fn norm2(&self) -> T
pub fn norm2(&self) -> T
Get 2-norm of vec2 (length of vec2).
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(2.0, 3.0);
let norm2 = a.norm2();
let norm2_sq = norm2 * norm2;
let expected = a.norm2_squared();
assert!(norm2_sq < expected + 1e-12);
assert!(norm2_sq > expected - 1e-12);Sourcepub fn normalized(&self) -> Self
pub fn normalized(&self) -> Self
Source§impl<T: Copy + NumCast> Vec2<T>
impl<T: Copy + NumCast> Vec2<T>
Sourcepub fn length<F: Float>(&self) -> F
pub fn length<F: Float>(&self) -> F
Calculate length of vec2.
Similar to Vec2::norm2 but does potentially return another data type for the length.
§Examples
use reda_geometry::base::Vec2;
let a = Vec2::new(2.0, 3.0);
let length: f64 = a.length();
let norm2_sq = length * length;
let expected = a.norm2_squared();
assert!(norm2_sq < expected + 1e-12);
assert!(norm2_sq > expected - 1e-12);Trait Implementations§
Source§impl<T> AddAssign for Vec2<T>where
T: AddAssign,
impl<T> AddAssign for Vec2<T>where
T: AddAssign,
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreimpl<T: Copy> Copy for Vec2<T>
Source§impl<T, D> DivAssign<D> for Vec2<T>
Assigning scalar division.
impl<T, D> DivAssign<D> for Vec2<T>
Assigning scalar division.
Source§fn div_assign(&mut self, rhs: D)
fn div_assign(&mut self, rhs: D)
Performs the
/= operation. Read moreimpl<T: Eq> Eq for Vec2<T>
Source§impl<T, M> MulAssign<M> for Vec2<T>
In-place scalar multiplication.
impl<T, M> MulAssign<M> for Vec2<T>
In-place scalar multiplication.
Source§fn mul_assign(&mut self, rhs: M)
fn mul_assign(&mut self, rhs: M)
Performs the
*= operation. Read moreimpl<T: PartialEq> StructuralPartialEq for Vec2<T>
Auto Trait Implementations§
impl<T> Freeze for Vec2<T>where
T: Freeze,
impl<T> RefUnwindSafe for Vec2<T>where
T: RefUnwindSafe,
impl<T> Send for Vec2<T>where
T: Send,
impl<T> Sync for Vec2<T>where
T: Sync,
impl<T> Unpin for Vec2<T>where
T: Unpin,
impl<T> UnsafeUnpin for Vec2<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Vec2<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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