Struct Vect

Source
pub struct Vect {
    pub x: f32,
    pub y: f32,
}
Expand description

Vect is 2D vector and is used all over the place. I choose to use f32 because opengl also accepts only f32

Fields§

§x: f32§y: f32

Implementations§

Source§

impl Vect

Source

pub const ZERO: Self

Source

pub const LEFT: Self

Source

pub const RIGHT: Self

Source

pub const UP: Self

Source

pub const DOWN: Self

Source

pub const MAX: Self

Source

pub const MIN: Self

Source

pub fn average(arr: &[Vect]) -> Self

average returns average of slice of vectors

Source

pub fn new(x: f32, y: f32) -> Self

new is vector constructor

Source

pub fn mirror(m: f32) -> Self

mirror returns homogenous vector

Source

pub fn unit(a: f32) -> Self

unit returns vector of length 1.0 with given angle

Source

pub fn rad(a: f32, l: f32) -> Self

rad is same as unit but you can also specify length

Source

pub fn clamped(&self, min: f32, max: f32) -> Self

clamped clamps a vectors length

Source

pub fn lerp(self, o: Vect, t: f32) -> Vect

Source

pub fn ang(&self) -> f32

ang returns vectors angle

Source

pub fn len(&self) -> f32

len returns vectors length

Source

pub fn norm(self) -> Self

norm returns normalized vector with length 1.0

Source

pub fn normal(&self) -> Self

normal on the other hand returns normal vector to vector of same length

Source

pub fn swp(self) -> Self

swp swaps x and y of vector

Source

pub fn rot(self, a: f32) -> Self

rot rotates vector by a

Source

pub fn dist(self, b: Self) -> f32

dist returns distance to other vector

Source

pub fn to(self, b: Self) -> Self

to returns vector from self to b

Source

pub fn dot(self, b: Self) -> f32

dot returns vectors dot

Source

pub fn ang_to(self, b: Self) -> f32

ang_to returns smallest angle between two vectors

Source

pub fn trn<T: Fn(f32) -> f32>(&self, tr: T) -> Self

trn applies closure to both x and y of a vector

Source

pub fn inverted(&self) -> Self

inverted inverts vector

Source

pub fn round(&self) -> Self

round rounds a vector

Trait Implementations§

Source§

impl Add for Vect

Source§

type Output = Vect

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vect) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Vect

Source§

fn add_assign(&mut self, rhs: Vect)

Performs the += operation. Read more
Source§

impl Clone for Vect

Source§

fn clone(&self) -> Vect

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Vect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Vect

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Div<f32> for Vect

Source§

type Output = Vect

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for Vect

Source§

type Output = Vect

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vect) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Vect

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl DivAssign for Vect

Source§

fn div_assign(&mut self, rhs: Vect)

Performs the /= operation. Read more
Source§

impl Mul<f32> for Vect

Source§

type Output = Vect

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Vect

Source§

type Output = Vect

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vect) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Vect

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl MulAssign for Vect

Source§

fn mul_assign(&mut self, rhs: Vect)

Performs the *= operation. Read more
Source§

impl PartialEq for Vect

Source§

fn eq(&self, other: &Vect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for Vect

Source§

type Output = Vect

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vect) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign for Vect

Source§

fn sub_assign(&mut self, rhs: Vect)

Performs the -= operation. Read more
Source§

impl Copy for Vect

Source§

impl StructuralPartialEq for Vect

Auto Trait Implementations§

§

impl Freeze for Vect

§

impl RefUnwindSafe for Vect

§

impl Send for Vect

§

impl Sync for Vect

§

impl Unpin for Vect

§

impl UnwindSafe for Vect

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V