Struct speedy2d::dimen::Vector2

source ·
#[repr(C)]
pub struct Vector2<T> { pub x: T, pub y: T, }
Expand description

A vector containing two numeric values. This may represent a size or position.

Fields§

§x: T

The horizontal component of the vector.

§y: T

The vertical component of the vector.

Implementations§

source§

impl<T> Vector2<T>

source

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

Instantiates a new Vector2 from the specified horizontal and vertical components.

source§

impl<T: PrimitiveZero> Vector2<T>

source

pub const ZERO: Vector2<T> = _

A constant representing a vector of zero magnitude. Each component is set to zero.

source

pub fn new_x(x: T) -> Self

Instantiates a new Vector2 from the specified horizontal component, setting the vertical component to zero.

source

pub fn new_y(y: T) -> Self

Instantiates a new Vector2 from the specified vertical component, setting the horizontal component to zero.

source§

impl<T> Vector2<T>
where T: Copy + Mul<Output = T> + Add<Output = T>,

source

pub fn magnitude_squared(&self) -> T

Returns the magnitude of the vector, squared.

source§

impl<T> Vector2<T>
where T: AsPrimitive<f32> + Copy + Mul<Output = T> + Add<Output = T> + Div<f32, Output = T>,

source

pub fn magnitude(&self) -> f32

Returns the magnitude of the vector.

source

pub fn normalize(&self) -> Option<Vector2<T>>

Normalizes the vector so that the magnitude is 1.0. If the current magnitude of the vector is 0.0, then None is returned to avoid a division by zero.

source§

impl<T: Neg<Output = T> + Copy> Vector2<T>

source

pub fn rotate_90_degrees_clockwise(&self) -> Vector2<T>

Rotates the vector by 90 degrees in the clockwise direction.

source

pub fn rotate_90_degrees_anticlockwise(&self) -> Vector2<T>

Rotates the vector by 90 degrees in the anti-clockwise direction.

source§

impl<T: AsPrimitive<f32>> Vector2<T>

source

pub fn into_f32(self) -> Vec2

Returns a new vector with each element cast to f32, using the as operator.

source§

impl<T: AsPrimitive<i32>> Vector2<T>

source

pub fn into_i32(self) -> IVec2

Returns a new vector with each element cast to i32, using the as operator.

source§

impl<T: AsPrimitive<u32>> Vector2<T>

source

pub fn into_u32(self) -> UVec2

Returns a new vector with each element cast to u32, using the as operator.

source§

impl<T: TryInto<i32>> Vector2<T>

source

pub fn try_into_i32(self) -> Result<IVec2, T::Error>

Attempts to convert each element of this vector to an i32, returning an error if this fails.

Trait Implementations§

source§

impl<T: Copy + Add<Output = T>, R: Into<Vector2<T>>> Add<R> for &Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T: Copy + Add<Output = T>, R: Into<Self>> Add<R> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<T: Copy + AddAssign, R: Into<Vector2<T>>> AddAssign<R> for &mut Vector2<T>

source§

fn add_assign(&mut self, rhs: R)

Performs the += operation. Read more
source§

impl<T: Copy + AddAssign, R: Into<Vector2<T>>> AddAssign<R> for Vector2<T>

source§

fn add_assign(&mut self, rhs: R)

Performs the += operation. Read more
source§

impl<T: Clone> Clone for Vector2<T>

source§

fn clone(&self) -> Vector2<T>

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<T: Debug> Debug for Vector2<T>

source§

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

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

impl<T: Copy + Div<Output = T>> Div<T> for &Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T: Copy + Div<Output = T>> Div<T> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<T: Copy + DivAssign> DivAssign<T> for &mut Vector2<T>

source§

fn div_assign(&mut self, divisor: T)

Performs the /= operation. Read more
source§

impl<T: Copy + DivAssign> DivAssign<T> for Vector2<T>

source§

fn div_assign(&mut self, divisor: T)

Performs the /= operation. Read more
source§

impl<T> From<&(T, T)> for Vector2<T>
where T: Copy,

source§

fn from(value: &(T, T)) -> Self

Converts to this type from the input type.
source§

impl<T> From<&Vector2<T>> for Vector2<T>
where T: Copy,

source§

fn from(value: &Self) -> Self

Converts to this type from the input type.
source§

impl<T> From<&mut Vector2<T>> for Vector2<T>
where T: Copy,

source§

fn from(value: &mut Self) -> Self

Converts to this type from the input type.
source§

impl<T> From<(T, T)> for Vector2<T>
where T: Copy,

source§

fn from(value: (T, T)) -> Self

Converts to this type from the input type.
source§

impl<T> From<Point<T>> for Vector2<T>

source§

fn from(point: Point<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for Vector2<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: Copy + Mul<Output = T>> Mul<T> for &Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T: Copy + Mul<Output = T>> Mul<T> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<T: Copy + MulAssign> MulAssign<T> for &mut Vector2<T>

source§

fn mul_assign(&mut self, factor: T)

Performs the *= operation. Read more
source§

impl<T: Copy + MulAssign> MulAssign<T> for Vector2<T>

source§

fn mul_assign(&mut self, factor: T)

Performs the *= operation. Read more
source§

impl<T: PartialEq> PartialEq for Vector2<T>

source§

fn eq(&self, other: &Vector2<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: RoundFloat> RoundFloat for Vector2<T>

source§

fn round(&self) -> Self

Round this value to the nearest integer. In the case of vectors or other types containing multiple elements, each element will be individually rounded.
source§

impl<T: Copy + Sub<Output = T>, R: Into<Vector2<T>>> Sub<R> for &Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T: Copy + Sub<Output = T>, R: Into<Self>> Sub<R> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<T: Copy + SubAssign, R: Into<Vector2<T>>> SubAssign<R> for &mut Vector2<T>

source§

fn sub_assign(&mut self, rhs: R)

Performs the -= operation. Read more
source§

impl<T: Copy + SubAssign, R: Into<Vector2<T>>> SubAssign<R> for Vector2<T>

source§

fn sub_assign(&mut self, rhs: R)

Performs the -= operation. Read more
source§

impl<T: Copy> Copy for Vector2<T>

source§

impl<T: Eq> Eq for Vector2<T>

source§

impl<T> StructuralPartialEq for Vector2<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector2<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector2<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector2<T>
where T: Send,

§

impl<T> Sync for Vector2<T>
where T: Sync,

§

impl<T> Unpin for Vector2<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector2<T>
where T: UnwindSafe,

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> 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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,

§

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>,

§

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>,

§

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.