[][src]Struct duku::Vector2

#[repr(C)]pub struct Vector2 {
    pub x: f32,
    pub y: f32,
}

2-component Vector.

Used for 2D sizing and positioning.

Example

This example is not tested
let point_1 = Vector2::new(-10.0, -10.0);
let point_2 = Vector2::new(10.0, 10.0);

target.draw_lines(&[point_1, point_2], false);

Fields

x: f32

the X component

y: f32

the Y component

Implementations

impl Vector2[src]

pub const fn new(x: f32, y: f32) -> Self[src]

Create a new vector

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.

Note: may not be unit length

pub fn angle_between(&self, other: impl Into<Self>) -> f32[src]

Calculate the angle between 2 vectors

Note: resulting angle is in degrees

Example

This example is not tested
let up = Vector2::UP;
let right = Vector2::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

pub const UP: Self[src]

Shorthand for Vector2::new(0.0, 1.0)

pub const DOWN: Self[src]

Shorthand for Vector2::new(0.0, -1.0)

pub const LEFT: Self[src]

Shorthand for Vector2::new(-1.0, 0.0)

pub const RIGHT: Self[src]

Shorthand for Vector2::new(1.0, 0.0)

Trait Implementations

impl Add<Vector2> for Vector2[src]

type Output = Self

The resulting type after applying the + operator.

impl AddAssign<Vector2> for Vector2[src]

impl Clone for Vector2[src]

impl Copy for Vector2[src]

impl Debug for Vector2[src]

impl Default for Vector2[src]

impl Div<f32> for Vector2[src]

type Output = Self

The resulting type after applying the / operator.

impl DivAssign<f32> for Vector2[src]

impl From<[f32; 2]> for Vector2[src]

impl Index<usize> for Vector2[src]

type Output = f32

The returned type after indexing.

impl IndexMut<usize> for Vector2[src]

impl Mul<f32> for Vector2[src]

type Output = Self

The resulting type after applying the * operator.

impl MulAssign<f32> for Vector2[src]

impl Neg for Vector2[src]

type Output = Self

The resulting type after applying the - operator.

impl PartialEq<Vector2> for Vector2[src]

impl StructuralPartialEq for Vector2[src]

impl Sub<Vector2> for Vector2[src]

type Output = Self

The resulting type after applying the - operator.

impl SubAssign<Vector2> for Vector2[src]

Auto Trait Implementations

impl RefUnwindSafe for Vector2

impl Send for Vector2

impl Sync for Vector2

impl Unpin for Vector2

impl UnwindSafe for Vector2

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.