Struct Vector2

Source
#[repr(C)]
pub struct Vector2<T: Primitive> { pub x: T, pub y: T, }

Fields§

§x: T§y: T

Implementations§

Source§

impl<T: Primitive> Vector2<T>

Source

pub fn new(x: T, y: T) -> Vector2<T>

Source

pub fn from_array(ary: &[T; 2]) -> &Vector2<T>

Source

pub fn from_array_mut(ary: &mut [T; 2]) -> &mut Vector2<T>

Source

pub fn as_array(&self) -> &[T; 2]

Source

pub fn as_array_mut(&mut self) -> &mut [T; 2]

Source§

impl<T: Primitive> Vector2<T>

Source

pub fn extend(&self, z: T) -> Vector3<T>

Extends self to a Vector3 by appending z.

§Example
use glm::*;

let v2 = vec2(1., 2.);
let v3 = vec3(1., 2., 3.);
assert_eq!(v2.extend(3.), v3);

Trait Implementations§

Source§

impl<T: BaseNum> Add<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Vector2<T>

Performs the + operation. Read more
Source§

impl<T: BaseNum> Add for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector2<T>) -> Vector2<T>

Performs the + operation. Read more
Source§

impl<T: BaseFloat> ApproxEq for Vector2<T>

Source§

type BaseType = T

Source§

fn is_close_to(&self, rhs: &Vector2<T>, max_diff: T) -> bool

Returns true if the difference between x and y is less than max_diff. Read more
Source§

fn is_approx_eq(&self, rhs: &Self) -> bool

Returns true if the difference between x and y is less than machine epsilon. Read more
Source§

impl<T: Primitive + Arbitrary> Arbitrary for Vector2<T>

Source§

fn arbitrary<G: Gen>(g: &mut G) -> Vector2<T>

Source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

Source§

impl<T: BaseInt> BitAnd<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: T) -> Self

Performs the & operation. Read more
Source§

impl<T: BaseInt> BitAnd for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self

Performs the & operation. Read more
Source§

impl<T: BaseInt> BitOr<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: T) -> Self

Performs the | operation. Read more
Source§

impl<T: BaseInt> BitOr for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
Source§

impl<T: BaseInt> BitXor<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: T) -> Self

Performs the ^ operation. Read more
Source§

impl<T: BaseInt> BitXor for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self

Performs the ^ operation. Read more
Source§

impl<T: Clone + Primitive> 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 + Primitive> Debug for Vector2<T>

Source§

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

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

impl<T: BaseNum> Div<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Vector2<T>

Performs the / operation. Read more
Source§

impl<T: BaseNum> Div for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vector2<T>) -> Vector2<T>

Performs the / operation. Read more
Source§

impl GenBVec for Vector2<bool>

Source§

fn all(&self) -> bool

Returns true if all components of the receiver are true. Read more
Source§

fn any(&self) -> bool

Returns true if there is any component of the receiver is true. Read more
Source§

fn not(&self) -> Vector2<bool>

Returns the component-wise logical complement of the receiver. Read more
Source§

impl<T: BaseFloat> GenFloat<T> for Vector2<T>

Source§

fn fma(&self, b: &Vector2<T>, c: &Vector2<T>) -> Vector2<T>

Computes and returns a * b + c.
Source§

impl<T: BaseFloat> GenMat<T, Vector2<T>> for Matrix2<T>

Source§

type R = Vector2<T>

Type of row vectors.
Source§

type Transpose = Matrix2<T>

Type of transpose matrix.
Source§

fn transpose(&self) -> Matrix2<T>

Returns the transpose matrix. Read more
Source§

fn mul_c(&self, rhs: &Matrix2<T>) -> Matrix2<T>

Component-wise multiplication. Read more
Source§

impl<T: BaseFloat> GenMat<T, Vector2<T>> for Matrix3x2<T>

Source§

type R = Vector3<T>

Type of row vectors.
Source§

type Transpose = Matrix2x3<T>

Type of transpose matrix.
Source§

fn transpose(&self) -> Matrix2x3<T>

Returns the transpose matrix. Read more
Source§

fn mul_c(&self, rhs: &Matrix3x2<T>) -> Matrix3x2<T>

Component-wise multiplication. Read more
Source§

impl<T: BaseFloat> GenMat<T, Vector2<T>> for Matrix4x2<T>

Source§

type R = Vector4<T>

Type of row vectors.
Source§

type Transpose = Matrix2x4<T>

Type of transpose matrix.
Source§

fn transpose(&self) -> Matrix2x4<T>

Returns the transpose matrix. Read more
Source§

fn mul_c(&self, rhs: &Matrix4x2<T>) -> Matrix4x2<T>

Component-wise multiplication. Read more
Source§

impl<T: BaseNum> GenNum<T> for Vector2<T>

Source§

fn from_s(x: T) -> Self

Constructs from a scalar number.
Source§

fn map<F: Fn(T) -> T>(self, f: F) -> Vector2<T>

Source§

fn zip<F: Fn(T, T) -> T>(self, y: Vector2<T>, f: F) -> Vector2<T>

Source§

fn split<F: Fn(T) -> (T, T)>(self, f: F) -> (Vector2<T>, Vector2<T>)

Source§

fn map2<F: Fn(T, T) -> (T, T)>(self, y: Self, f: F) -> (Self, Self)

Source§

impl<T: BaseNum> GenNumVec<T> for Vector2<T>

Source§

fn sum(&self) -> T

Returns the sum of all components. Read more
Source§

fn product(&self) -> T

Multiplies all components. Read more
Source§

fn min(&self) -> T

Returns the minimal value of all components. Read more
Source§

fn max(&self) -> T

Returns the maximal value of all components. Read more
Source§

impl<T: BaseFloat> GenSquareMat<T, Vector2<T>> for Matrix2<T>

Source§

fn determinant(&self) -> T

Returns the determinant of a square matrix. Read more
Source§

fn inverse(&self) -> Option<Matrix2<T>>

Returns the inverse matrix of a square matrix, or None if the matrix is not invertible.
Source§

impl<T: Primitive> GenVec<T> for Vector2<T>

Source§

fn dim() -> usize

Returns the dimension of the vector. Read more
Source§

impl<T: Primitive> Index<usize> for Vector2<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index<'a>(&'a self, i: usize) -> &'a T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Primitive> IndexMut<usize> for Vector2<T>

Source§

fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: BaseNum> Mul<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Vector2<T>

Performs the * operation. Read more
Source§

impl<T: BaseFloat> Mul<Vector2<T>> for Matrix2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<T>) -> Vector2<T>

Performs the * operation. Read more
Source§

impl<T: BaseFloat> Mul<Vector2<T>> for Matrix2x3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<T>) -> Vector3<T>

Performs the * operation. Read more
Source§

impl<T: BaseFloat> Mul<Vector2<T>> for Matrix2x4<T>

Source§

type Output = Vector4<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<T>) -> Vector4<T>

Performs the * operation. Read more
Source§

impl<T: BaseNum> Mul for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector2<T>) -> Vector2<T>

Performs the * operation. Read more
Source§

impl<T: SignedNum + BaseNum> Neg for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector2<T>

Performs the unary - operation. Read more
Source§

impl<T: BaseInt> Not for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl<T: BaseNum> One for Vector2<T>

Source§

fn one() -> Vector2<T>

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

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

Source§

fn eq(&self, other: &Vector2<T>) -> 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<T: Primitive> Rand for Vector2<T>

Source§

fn rand<R: Rng>(rng: &mut R) -> Vector2<T>

Generates a random instance of this type using the specified source of randomness.
Source§

impl<T: BaseNum> Rem<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: T) -> Vector2<T>

Performs the % operation. Read more
Source§

impl<T: BaseNum> Rem for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Vector2<T>) -> Vector2<T>

Performs the % operation. Read more
Source§

impl<T: BaseInt> Shl<usize> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: usize) -> Self

Performs the << operation. Read more
Source§

impl<T: BaseInt> Shr<usize> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: usize) -> Self

Performs the >> operation. Read more
Source§

impl<T: SignedNum + BaseNum> SignedNum for Vector2<T>

Source§

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

Returns the absolute value of the receiver.
Source§

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

Returns the sign number of the receiver. Read more
Source§

impl<T: SignedNum + BaseNum> Sub<T> for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> Vector2<T>

Performs the - operation. Read more
Source§

impl<T: SignedNum + BaseNum> Sub for Vector2<T>

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector2<T>) -> Vector2<T>

Performs the - operation. Read more
Source§

impl<T: BaseNum> Zero for Vector2<T>

Source§

fn zero() -> Vector2<T>

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

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

Source§

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

Source§

impl Eq for Vector2<bool>

Source§

impl<T: BaseFloat> GenFloatVec<T> for Vector2<T>

Source§

impl<T: BaseInt> GenInt<T> for Vector2<T>

Source§

impl<T: Primitive> 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>

§

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> 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> Consts<f32> for T
where T: GenFloat<f32>,

Source§

impl<T> Consts<f64> for T
where T: GenFloat<f64>,

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> 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<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,