[−][src]Struct duku::Vec2
2-component Vector.
Used for 2D sizing and positioning.
Examples
let point1 = Vec2::new(-10.0, -10.0); let point2 = Vec2::new(10.0, 10.0); // when drawing t.line(point1, point2);
Fields
x: f32
the X component
y: f32
the Y component
Implementations
impl Vec2
[src]
pub const fn new(x: f32, y: f32) -> Self
[src]
Create a vector
pub const fn up() -> Self
[src]
Create a vector facing up
pub const fn down() -> Self
[src]
Create a vector facing down
pub const fn left() -> Self
[src]
Create a vector facing left
pub const fn right() -> Self
[src]
Create a vector facing right
pub fn dot(&self, other: impl Into<Self>) -> f32
[src]
Calculate the dot-product of the vector
pub fn sqr_length(&self) -> f32
[src]
Calculate the squared length of a vector
Can sometimes be used instead of length, because this is faster.
pub fn length(&self) -> f32
[src]
Calculate the length of a vector
pub fn unit(&self) -> Self
[src]
Calculate the unit vector
The unit vector is of length 1 and can also be thought of as the direction of the vector.
pub fn normal(&self) -> Self
[src]
Calculate the normal vector
The normal vector is a vector perpendicular to the original.
May not be unit length
pub fn angle_between(&self, other: impl Into<Self>) -> f32
[src]
Calculate the angle between 2 vectors
Resulting angle is in degrees
Examples
let up = Vec2::up(); let right = Vec2::right(); let angle = up.angle_between(right); // angle is ~90 degrees
pub fn floor(&self) -> Self
[src]
Floor every component of the vector
pub fn ceil(&self) -> Self
[src]
Ceil every component of the vector
pub fn round(&self) -> Self
[src]
Round every component of the vector
Trait Implementations
impl Add<Vec2> for Vec2
[src]
type Output = Self
The resulting type after applying the +
operator.
pub fn add(self, rhs: Self) -> Self
[src]
impl AddAssign<Vec2> for Vec2
[src]
pub fn add_assign(&mut self, rhs: Self)
[src]
impl Clone for Vec2
[src]
impl Copy for Vec2
[src]
impl Debug for Vec2
[src]
impl Default for Vec2
[src]
impl Div<f32> for Vec2
[src]
type Output = Self
The resulting type after applying the /
operator.
pub fn div(self, rhs: f32) -> Self
[src]
impl DivAssign<f32> for Vec2
[src]
pub fn div_assign(&mut self, rhs: f32)
[src]
impl From<[f32; 2]> for Vec2
[src]
impl Index<usize> for Vec2
[src]
impl IndexMut<usize> for Vec2
[src]
impl Mul<f32> for Vec2
[src]
type Output = Self
The resulting type after applying the *
operator.
pub fn mul(self, rhs: f32) -> Self
[src]
impl MulAssign<f32> for Vec2
[src]
pub fn mul_assign(&mut self, rhs: f32)
[src]
impl Neg for Vec2
[src]
impl PartialEq<Vec2> for Vec2
[src]
impl StructuralPartialEq for Vec2
[src]
impl Sub<Vec2> for Vec2
[src]
type Output = Self
The resulting type after applying the -
operator.
pub fn sub(self, rhs: Self) -> Self
[src]
impl SubAssign<Vec2> for Vec2
[src]
pub fn sub_assign(&mut self, rhs: Self)
[src]
Auto Trait Implementations
impl RefUnwindSafe for Vec2
impl Send for Vec2
impl Sync for Vec2
impl Unpin for Vec2
impl UnwindSafe for Vec2
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,