Struct Vec2

Source
pub struct Vec2<T = f32>(pub T, pub T);
Expand description

A 2-dimensional vector.

Tuple Fields§

§0: T§1: T

Implementations§

Source§

impl<T> Vec2<T>
where T: Float,

Source

pub fn new() -> Self

Creates a new instances.

Source

pub fn len(&self) -> T

Returns the length of the vector

Source

pub fn dot(&self, other: &Self) -> T

Returns the dot-product of the vectors.

Source

pub fn to_radians(&self) -> T

👎Deprecated since 0.2.2: use Angle::from().to_radians() instead

Returns the direction of the vector in radians.

Source

pub fn to_degrees(&self) -> T

👎Deprecated since 0.2.2: use Angle::from().to_degrees() instead

Returns the direction of the vector in degrees.

Source

pub fn to_angle(&self) -> Angle<T>

👎Deprecated since 0.2.2: use Angle::from() instead

Returns the direction of the vector as an angle instance.

Source

pub fn from_radians(radians: T) -> Self

👎Deprecated since 0.2.2: use Vec2::from(Angle::from_radians()) instead

Creates a unit-vector from the angle given in radians.

Source

pub fn from_degrees(degrees: T) -> Self

👎Deprecated since 0.2.2: use Vec2::from(Angle::from_degrees()) instead

Creates a unit-vector from the angle given in degrees.

Source

pub fn from_angle(angle: Angle<T>) -> Self

👎Deprecated since 0.2.2: use Vec2::from() instead

Creates a unit-vector from given angle.

Source

pub fn normalize(self) -> Self

Normalizes the vector.

Source

pub fn left(self) -> Self

The left pointing normal of the vector.

Source

pub fn right(self) -> Self

The right pointing normal of the vector.

Source

pub fn extend(self, extension_len: T) -> Self

Extends the vector by given length.

Source

pub fn rotate(self, angle: Angle<T>) -> Self

Rotates the vector by given angle.

Source

pub fn outbound(&self, bounding: ((T, T), (T, T))) -> Option<Self>

Returns outbound vector for this point and given bounding box. Subtracting it from this point will result in a point on the bounding box.

Source

pub fn is_zero(&self) -> bool

Returns true if the vecor is a zero-vector.

Source

pub fn distance(&self, other: &Self) -> T

Returns distance to other point.

Trait Implementations§

Source§

impl<T> Add for Vec2<T>
where T: Float,

Source§

type Output = Vec2<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Vec2<T>) -> Vec2<T>

Performs the + operation. Read more
Source§

impl<T> AddAssign for Vec2<T>
where T: Float,

Source§

fn add_assign(&mut self, other: Vec2<T>)

Performs the += operation. Read more
Source§

impl<T: Clone> Clone for Vec2<T>

Source§

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

Returns a duplicate 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 for Vec2<T>
where T: Debug,

Source§

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

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

impl<T> Default for Vec2<T>
where T: Float,

Source§

fn default() -> Self

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

impl<T> Div<T> for Vec2<T>
where T: Float,

Source§

fn div(self, other: T) -> Vec2<T>

Divides the vector by given scalar operand.

Source§

type Output = Vec2<T>

The resulting type after applying the / operator.
Source§

impl<T> Div for Vec2<T>
where T: Float,

Source§

fn div(self, other: Vec2<T>) -> Vec2<T>

Divides individual vector components with those of the given vector.

Source§

type Output = Vec2<T>

The resulting type after applying the / operator.
Source§

impl<T> DivAssign<T> for Vec2<T>
where T: Float,

Source§

fn div_assign(&mut self, other: T)

Mutates the vector by dividing it by given scalar.

Source§

impl<T> DivAssign for Vec2<T>
where T: Float,

Source§

fn div_assign(&mut self, other: Vec2<T>)

Mutates the vector by dividing its components with those of the given vector.

Source§

impl<T> From<[T; 2]> for Vec2<T>
where T: Copy,

Source§

fn from(source: [T; 2]) -> Self

Converts to this type from the input type.
Source§

impl<T> From<(T, T)> for Vec2<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<Angle<T>> for Vec2<T>
where T: Float,

Source§

fn from(angle: Angle<T>) -> Vec2<T>

Converts to this type from the input type.
Source§

impl<T> From<Vec2<T>> for Angle<T>
where T: Float,

Source§

fn from(vec: Vec2<T>) -> Angle<T>

Converts to this type from the input type.
Source§

impl From<Vec2<f64>> for [f64; 2]

Source§

fn from(source: Vec2<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec2<f64>> for (f64, f64)

Source§

fn from(source: Vec2<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec2> for [f32; 2]

Source§

fn from(source: Vec2<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec2> for (f32, f32)

Source§

fn from(source: Vec2<f32>) -> Self

Converts to this type from the input type.
Source§

impl<T> Mul<T> for Vec2<T>
where T: Float,

Source§

fn mul(self, other: T) -> Vec2<T>

Multiplies the vector with given scalar operand.

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

impl<T> Mul<Vec2<T>> for Mat4<T>
where T: Float,

Source§

fn mul(self, other: Vec2<T>) -> Vec2<T>

Multiplies the matrix with given vector operand, using 0 as z-component and 1 as w-component of the vector.

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

impl Mul<Vec2<f64>> for f64

Source§

type Output = Vec2<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vec2<f64>) -> Vec2<f64>

Performs the * operation. Read more
Source§

impl Mul<Vec2> for f32

Source§

type Output = Vec2

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vec2<f32>) -> Vec2<f32>

Performs the * operation. Read more
Source§

impl<T> Mul for Vec2<T>
where T: Float,

Source§

fn mul(self, other: Vec2<T>) -> Vec2<T>

Multiplies individual vector components with those of the given vector.

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

impl<T> MulAssign<T> for Vec2<T>
where T: Float,

Source§

fn mul_assign(&mut self, other: T)

Mutates the vector by multiplying it with the scalar operand.

Source§

impl<T> MulAssign for Vec2<T>
where T: Float,

Source§

fn mul_assign(&mut self, other: Vec2<T>)

Mutates the vector by multiplying its components with those of the given vector.

Source§

impl<T> Neg for Vec2<T>
where T: Float,

Source§

type Output = Vec2<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vec2<T>

Performs the unary - operation. Read more
Source§

impl<T> Sub for Vec2<T>
where T: Float,

Source§

type Output = Vec2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vec2<T>) -> Vec2<T>

Performs the - operation. Read more
Source§

impl<T> SubAssign for Vec2<T>
where T: Float,

Source§

fn sub_assign(&mut self, other: Vec2<T>)

Performs the -= operation. Read more
Source§

impl<T> Vector<T> for Vec2<T>
where T: Copy,

Source§

fn as_vec3(&self, neutral: T) -> Vec3<T>

Returns the given value as a Vec3
Source§

impl<T: Copy> Copy for Vec2<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Vec2<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> 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> Vector<T> for T
where T: Copy,

Source§

fn as_vec3(&self, _: T) -> Vec3<T>

Returns the given value as a Vec3