Skip to main content

Vec2

Struct Vec2 

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

Vec2 vector.

Fields§

§x: T§y: T

Implementations§

Source§

impl<T> Vec2<T>

Source

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

Constructs a new vector from components.

Source

pub const fn dup(u: T) -> Vec2<T>
where T: Copy,

Constructs a new vector by broadcasting to all its components.

Source§

impl<T: Zero> Vec2<T>

Source

pub const ZERO: Vec2<T>

Vec2 of all zero.

Source

pub const fn zero() -> Vec2<T>

Returns the origin for the vector space.

Source§

impl<T: One> Vec2<T>

Source

pub const ONE: Vec2<T>

Vec2 of all one.

Source§

impl<T: Zero + One> Vec2<T>

Source

pub const X: Vec2<T>

Unit vector in the x direction.

Source

pub const Y: Vec2<T>

Unit vector in the y direction.

Source§

impl<T> Vec2<T>

Source

pub fn set_x(self, x: T) -> Vec2<T>

Sets the x component.

Source

pub fn set_y(self, y: T) -> Vec2<T>

Sets the y component.

Source

pub fn vec3(self, z: T) -> Vec3<T>

Extends the 2D vector with a z component.

Source

pub fn vec4(self, z: T, w: T) -> Vec4<T>

Extends the 2D vector with a z and w component.

Source§

impl<T: Copy> Vec2<T>

Source

pub fn get<C>(self, _: C) -> T
where Self: ComponentImpl<T, C>,

Gets a component generically.

Source

pub fn shuffle<X, Y>(self, x: X, y: Y) -> Vec2<T>
where Self: ComponentImpl<T, X> + ComponentImpl<T, Y>,

Shuffles the components.

Source§

impl<T> Vec2<T>

Source

pub fn cast<U>(self) -> Vec2<U>
where T: CastTo<U>,

Casts to a vector of different type with the same dimensions.

Source

pub fn map<U, F>(self, f: F) -> Vec2<U>
where F: FnMut(T) -> U,

Maps a callable over the components.

Source

pub fn zip<U, F>(self, rhs: Vec2<T>, f: F) -> Vec2<U>
where F: FnMut(T, T) -> U,

Zips two vectors together.

Source

pub fn reduce<F>(self, f: F) -> T
where F: Fn(T, T) -> T,

Reduces the vector.

Source

pub fn fold<A, F>(self, acc: A, f: F) -> A
where F: Fn(A, T) -> A,

Folds the vector.

Source§

impl<T> Vec2<T>

Source

pub fn as_bytes(&self) -> &[u8]

Source§

impl<T: Scalar> Vec2<T>

Operations on vectors of scalars.

Source

pub fn sqr(self) -> Vec2<T>

Squares the components.

use cvmath::{Vec2, Vec3};

let this = Vec2 { x: -3, y: 4 };
assert_eq!(Vec2(9, 16), this.sqr());

let this = Vec3 { x: 2, y: 3, z: -6 };
assert_eq!(Vec3(4, 9, 36), this.sqr());
Source

pub fn len_sqr(self) -> T

Calculates the squared length of the vector.

use cvmath::{Vec2, Vec3};

let this = Vec2 { x: -3, y: 4 };
assert_eq!(25, this.len_sqr());

let this = Vec3 { x: 2, y: -3, z: 6 };
assert_eq!(49, this.len_sqr());
Source

pub fn len(self) -> T
where T: Float,

Calculates the length of the vector.

use cvmath::{Vec2, Vec3};

let this = Vec2 { x: -3.0, y: 4.0 };
assert_eq!(5.0, this.len());

let this = Vec3 { x: -2.0, y: 3.0, z: -6.0 };
assert_eq!(7.0, this.len());
Source

pub fn len_hat(self) -> T

Calculates the manhattan length of the vector.

thisxy
use cvmath::{Vec2, Vec3};

let this = Vec2 { x: 3, y: 4 };
assert_eq!(7, this.len_hat());

let this = Vec3 { x: 2, y: -3, z: -6 };
assert_eq!(11, this.len_hat());
Source

pub fn distance_sqr(self, to: Vec2<T>) -> T

Calculates the squared euclidean distance to another vector.

use cvmath::Vec2;

let this = Vec2 { x: 1, y: 1 };
let to = Vec2 { x: 2, y: 2 };
assert_eq!(2, this.distance_sqr(to));
Source

pub fn distance(self, to: Vec2<T>) -> T
where T: Float,

Calculates the euclidean distance to another vector.

use cvmath::Vec2;

let this = Vec2 { x: 10.0, y: 10.0 };
let to = Vec2 { x: 13.0, y: 14.0 };
assert_eq!(5.0, this.distance(to));
Source

pub fn distance_hat(self, to: Vec2<T>) -> T

Calculates the manhattan distance to another vector.

thistoxy
use cvmath::{Vec2, Vec3};

let this = Vec2 { x: 1.0, y: 5.0 };
let to = Vec2 { x: 5.0, y: 2.0 };
assert_eq!(7.0, this.distance_hat(to));

let this = Vec3 { x: 1.0, y: 5.0, z: -1.0 };
let to = Vec3 { x: 2.0, y: 3.0, z: 1.0 };
assert_eq!(5.0, this.distance_hat(to));
Source

pub fn norm(self) -> Vec2<T>
where T: Float,

Normalizes the vector.

After normalizing the vector has the length 1.0 except the zero vector remains zero.

use cvmath::{Vec2, Vec3};

let this: Vec2<f32> = Vec2 { x: 3.0, y: -4.0 };
assert_eq!(Vec2(0.6, -0.8), this.norm());

let this = Vec3 { x: 0.0, y: 0.0, z: 0.0 };
assert_eq!(this, this.norm());
Source

pub fn norm_len(self) -> (Vec2<T>, T)
where T: Float,

Calculates the normalized vector and its length.

After normalizing the vector has the length 1.0 except the zero vector remains zero.

use cvmath::{Vec2, Vec3};

let this: Vec2<f32> = Vec2 { x: 3.0, y: -4.0 };
assert_eq!((Vec2(0.6, -0.8), 5.0), this.norm_len());

let this = Vec3 { x: 0.0, y: 0.0, z: 0.0 };
assert_eq!((this, 0.0), this.norm_len());
Source

pub fn resize(self, len: T) -> Vec2<T>
where T: Float,

Resizes the vector to the given length.

The zero vector remains zero.

use cvmath::{Vec2, Vec3};

let this = Vec2 { x: -3.0, y: -4.0 };
assert_eq!(Vec2(-1.5, -2.0), this.resize(2.5));

let this = Vec3 { x: 0.0, y: 0.0, z: 0.0 };
assert_eq!(Vec3(0.0, 0.0, 0.0), this.resize(2.0));
Source

pub fn project_scalar(self, v: Vec2<T>) -> T
where T: Float,

Calculates the length of self projected onto v.

selfv
use cvmath::{Vec2, Vec3};

let this = Vec2 { x: 1.0, y: 2.0 };
let v = Vec2 { x: 3.0, y: 4.0 };
assert_eq!(2.2, this.project_scalar(v));

let this = Vec3 { x: 1.0, y: 4.0, z: 0.0 };
let v = Vec3 { x: 4.0, y: 2.0, z: 4.0 };
assert_eq!(2.0, this.project_scalar(v));
Source

pub fn project(self, v: Vec2<T>) -> Vec2<T>
where T: Float,

Projection of self onto v.

use cvmath::{Vec2, Vec3};

let this = Vec2 { x: -5.0, y: -2.5 };
let v = Vec2 { x: 3.0, y: 4.0 };
assert_eq!(Vec2(-3.0, -4.0), this.project(v));

let this = Vec3 { x: -5.0, y: -2.5, z: 0.0 };
let v = Vec3 { x: 3.0, y: 4.0, z: 0.0 };
assert_eq!(Vec3(-3.0, -4.0, 0.0), this.project(v));
Source

pub fn project_sat(self, v: Vec2<T>) -> Vec2<T>

Projection of self onto v clamped to v.

use cvmath::Vec2;

let this = Vec2 { x: -5.0, y: -2.5 };
let v = Vec2 { x: 3.0, y: 4.0 };
assert_eq!(Vec2(0.0, 0.0), this.project_sat(v));
Source

pub fn reflect(self, v: Vec2<T>) -> Vec2<T>
where T: Float,

Reflects self around v.

vselfpresult-self+p
use cvmath::Vec2;

let this = Vec2 { x: 1.0, y: 3.0 };
let v = Vec2 { x: 4.0, y: 4.0 };
assert_eq!(Vec2(3.0, 1.0), this.reflect(v));
Source

pub fn reverse(self) -> Vec2<T>

Reverses the component order.

use cvmath::Vec2;

let this = Vec2 { x: 1, y: 2 };
assert_eq!(Vec2(2, 1), this.reverse());
Source

pub fn polar_angle(self) -> Angle<T>
where T: Float,

Calculates the polar angle.

use cvmath::Vec2;

let this = Vec2 { x: 1.0, y: 1.0 };
assert_eq!(45.0, this.polar_angle().to_deg());
Source

pub fn signed_angle(self, rhs: Vec2<T>) -> Angle<T>
where T: Float,

Returns the signed angle between two 2D vectors.

The sign of the angle follows the right-hand rule (counter-clockwise is positive).

use cvmath::Vec2;

let a = Vec2::X;
let b = Vec2::Y;
assert_eq!(90.0, a.signed_angle(b).to_deg());
assert_eq!(-90.0, b.signed_angle(a).to_deg());
Source

pub fn ccw(self) -> Vec2<T>

Rotates the vector counter-clockwise by 90°.

The resulting vector is perpendicular to the given vector.

use cvmath::Vec2;

let this = Vec2 { x: 3.0, y: 4.0 };
assert_eq!(Vec2(4.0, -3.0), this.ccw());
Source

pub fn cw(self) -> Vec2<T>

Rotates the vector clockwise by 90°.

The resulting vector is perpendicular to the given vector.

use cvmath::Vec2;

let this = Vec2 { x: 3.0, y: 4.0 };
assert_eq!(Vec2(-4.0, 3.0), this.cw());
Source

pub fn cross(self, rhs: Vec2<T>) -> T

Calculates the magnitude of the 3D cross product where the inputs are extended with z = 0.

This result is equal to the area of the parallelogram between the two vectors. This result is equal to twice the area of the triangle between the two vectors.

Furthermore this area is signed; a positive value means the rhs is on the left side of self and a negative value means rhs is on the right side.

use cvmath::Vec2;

let lhs = Vec2 { x: -3, y: -4 };
let rhs = Vec2 { x: -1, y: 2 };
assert_eq!(-10, lhs.cross(rhs));
// Area under the parallelogram defined by (origin, lhs, rhs, lhs + rhs) equals 10
// Area under the triangle defined by (origin, lhs, rhs) equals 5
Source

pub fn hsub(self) -> T

Horizontal subtracts the components.

use cvmath::Vec2;

let this = Vec2 { x: 3, y: 4 };
assert_eq!(-1, this.hsub());
Source

pub fn y_intercept(self, x: T) -> Option<T>

Intercepts the vector with x = constant returning the y.

Source

pub fn x_intercept(self, y: T) -> Option<T>

Intercepts the vector with y = constant returning the x.

Source

pub fn dot(self, rhs: Vec2<T>) -> T

Calculates the dot product.

use cvmath::Vec3;

let lhs = Vec3 { x: 1, y: 2, z: 3 };
let rhs = Vec3 { x: 4, y: -5, z: 6 };
assert_eq!(12, Vec3::dot(lhs, rhs));
Source

pub fn cos_angle(self, rhs: Vec2<T>) -> T
where T: Float,

Calculates the cosine of the angle between two vectors.

use cvmath::Vec2;

let lhs = Vec2 { x: 1.0, y: 1.0 };
let rhs = Vec2 { x: 1.0, y: 0.0 };
let sqrt_2_div_2 = 1.0 / 2_f32.sqrt(); // √2 ÷ 2
assert_eq!(sqrt_2_div_2, lhs.cos_angle(rhs));
Source

pub fn angle(self, rhs: Vec2<T>) -> Angle<T>
where T: Float,

Calculates the angle between two vectors.

use cvmath::Vec2;

let lhs = Vec2 { x: 1.0, y: 1.0 };
let rhs = Vec2 { x: 1.0, y: 0.0 };
assert_eq!(45.0, lhs.angle(rhs).to_deg());
Source

pub fn hadd(self) -> T

Horizontal adds all components.

use cvmath::{Vec2, Vec3};

let this = Vec2 { x: -2, y: 7 };
assert_eq!(5, this.hadd());

let this = Vec3 { x: 3, y: 4, z: 5 };
assert_eq!(12, this.hadd());
Source

pub fn abs(self) -> Vec2<T>

Component-wise absolute value.

use cvmath::Vec2;

let this = Vec2 { x: -3, y: 5 };
assert_eq!(Vec2(3, 5), this.abs());
Source

pub fn min(self, rhs: Vec2<T>) -> Vec2<T>

Component-wise minimum value.

use cvmath::Vec2;

let lhs = Vec2 { x: -3, y: 5 };
let rhs = Vec2 { x: 0, y: 2 };
assert_eq!(Vec2(-3, 2), lhs.min(rhs));
Source

pub fn vmin(self) -> T

Horizontal minimum value.

Source

pub fn max(self, rhs: Vec2<T>) -> Vec2<T>

Component-wise maximum value.

use cvmath::Vec2;

let lhs = Vec2 { x: -3, y: 5 };
let rhs = Vec2 { x: 0, y: 2 };
assert_eq!(Vec2(0, 5), lhs.max(rhs));
Source

pub fn vmax(self) -> T

Horizontal maximum value.

Source

pub fn mul_add(self, vec: Vec2<T>, scale: T) -> Vec2<T>

Adds the scaled vector.

Equivalent to self + (vec * scale) with less rounding errors.

Source

pub fn lerp(self, rhs: Vec2<T>, t: T) -> Vec2<T>

Linear interpolation between the vectors.

selfrhst = 0.2t = 0.5
Source

pub fn slerp(self, rhs: Vec2<T>, t: T) -> Vec2<T>
where T: Float,

Spherical interpolation between the vectors with constant velocity.

The result is linear interpolation of the angles between the vectors and their lengths.

This is fairly expensive to calculate requiring trigonometric functions. If constant velocity isn’t required, see the less expensive nlerp.

t = 0.25t = 0.50t = 0.75lerpslerpselfrhs
Source

pub fn nlerp(self, rhs: Vec2<T>, t: T) -> Vec2<T>
where T: Float,

Cheap spherical interpolation between the vectors without constant velocity.

t = 0.25t = 0.50t = 0.75lerpnlerpselfrhs
Source

pub fn exp_decay(self, rhs: Vec2<T>, decay: T, dt: T) -> Vec2<T>
where T: Float,

Exponential decay smoothing.

Also known as lerp smoothing. Useful decay values range from approx 1.0 to 25.0, slow to fast.

use cvmath::Vec2;

struct Entity {
	pos: Vec2<f32>,
	target: Vec2<f32>,
}
impl Entity {
	fn update(&mut self, dt: f32) {
		// Smoothly move towards the target.
		self.pos = self.pos.exp_decay(self.target, 5.0, dt);
	}
}
Source§

impl<T: Float> Vec2<T>

Source

pub fn floor(self) -> Vec2<T>

Component-wise floor.

Source

pub fn ceil(self) -> Vec2<T>

Component-wise ceil.

Source

pub fn round(self) -> Vec2<T>

Component-wise round.

Source

pub fn fract(self) -> Vec2<T>

Component-wise fract.

Source§

impl<T: PartialOrd> Vec2<T>

Source

pub fn spatial_lt(&self, rhs: &Vec2<T>) -> bool

Source

pub fn spatial_le(&self, rhs: &Vec2<T>) -> bool

Source

pub fn spatial_gt(&self, rhs: &Vec2<T>) -> bool

Source

pub fn spatial_ge(&self, rhs: &Vec2<T>) -> bool

Source§

impl<T> Vec2<T>

Source

pub fn is_finite(self) -> Bool2
where T: Float,

Creates a mask for finite components.

Source

pub fn is_infinite(self) -> Bool2
where T: Float,

Creates a mask for infinite components.

Source

pub fn eq(self, rhs: Vec2<T>) -> Bool2
where T: PartialEq,

Creates a mask for equal components.

Source

pub fn ne(self, rhs: Vec2<T>) -> Bool2
where T: PartialEq,

Creates a mask for inequal components.

Source

pub fn lt(self, rhs: Vec2<T>) -> Bool2
where T: PartialOrd,

Creates a mask for left-hand side components are less than the right-hand side.

Source

pub fn le(self, rhs: Vec2<T>) -> Bool2
where T: PartialOrd,

Creates a mask for left-hand side components are less than or equal the right-hand side.

Source

pub fn gt(self, rhs: Vec2<T>) -> Bool2
where T: PartialOrd,

Creates a mask for left-hand side components are greater than the right-hand side.

Source

pub fn ge(self, rhs: Vec2<T>) -> Bool2
where T: PartialOrd,

Creates a mask for left-hand side components are greater than or equal the right-hand side.

Source§

impl<T> Vec2<T>

Source

pub fn is_close(self, rhs: Vec2<T>) -> Bool2
where T: Float,

Creates a mask for approximately equal components.

Source

pub fn all_close(self, rhs: Vec2<T>) -> bool
where T: Float,

Returns true if the values are approximately equal.

Source§

impl Vec2<bool>

Source

pub const fn any(self) -> bool

Returns true if any of the components are true.

Source

pub const fn all(self) -> bool

Returns true if all the components are true.

Source

pub const fn none(self) -> bool

Returns true if none of the components are true.

Source

pub fn select<T>(self, lhs: Vec2<T>, rhs: Vec2<T>) -> Vec2<T>

Combines two vectors based on the bools, selecting components from the left-hand side if true and right-hand side if false.

Source§

impl Vec2<u64>

Source

pub const fn unpack64(v: u128) -> Vec2<u64>

Unpacks u128 into u64 u64.

use cvmath::Vec2;

assert_eq!(
	Vec2 { x: 0x01010101_01010101, y: 0xFEFEFEFE_FEFEFEFE },
	Vec2::unpack64(0xFEFEFEFE_FEFEFEFE_01010101_01010101)
);
Source

pub const fn pack(self) -> u128

Packs into u128.

use cvmath::Vec2;

let this: Vec2<u64> = Vec2 { x: 0x01010101_01010101, y: 0xFEFEFEFE_FEFEFEFE };
assert_eq!(0xFEFEFEFE_FEFEFEFE_01010101_01010101, this.pack());
Source§

impl Vec2<u32>

Source

pub const fn unpack32(v: u64) -> Vec2<u32>

Unpacks u64 into u32 u32.

use cvmath::Vec2;

assert_eq!(
	Vec2 { x: 0x01010101, y: 0xFEFEFEFE },
	Vec2::unpack32(0xFEFEFEFE_01010101)
);
Source

pub const fn pack(self) -> u64

Packs into u64.

use cvmath::Vec2;

let this: Vec2<u32> = Vec2 { x: 0x01010101, y: 0xFEFEFEFE };
assert_eq!(0xFEFEFEFE_01010101, this.pack());
Source§

impl Vec2<u16>

Source

pub const fn unpack16(v: u32) -> Vec2<u16>

Unpacks u32 into u16 u16.

use cvmath::Vec2;

assert_eq!(
	Vec2 { x: 0x0101, y: 0xFEFE },
	Vec2::unpack16(0xFEFE_0101)
);
Source

pub const fn pack(self) -> u32

Packs into u32.

use cvmath::Vec2;

let this: Vec2<u16> = Vec2 { x: 0x0101, y: 0xFEFE };
assert_eq!(0xFEFE_0101, this.pack());
Source§

impl Vec2<u8>

Source

pub const fn unpack8(v: u16) -> Vec2<u8>

Unpacks u16 into u8 u8.

use cvmath::Vec2;

assert_eq!(
	Vec2 { x: 0x01, y: 0xFE },
	Vec2::unpack8(0xFE_01)
);
Source

pub const fn pack(self) -> u16

Packs into u16.

use cvmath::Vec2;

let this: Vec2<u8> = Vec2 { x: 0x01, y: 0xFE };
assert_eq!(0xFE_01, this.pack());

Trait Implementations§

Source§

impl<T: Copy + Add<T, Output = T>> Add<Vec2<T>> for Bounds2<T>

Source§

type Output = Bounds2<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Copy + Add<T, Output = T>> Add<Vec2<T>> for Rect<T>

Source§

type Output = Rect<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<U, T: Add<U>> Add<Vec2<U>> for Vec2<T>

Source§

type Output = Vec2<<T as Add<U>>::Output>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vec2<U>) -> Vec2<T::Output>

Performs the + operation. Read more
Source§

impl<T: Copy + AddAssign<T>> AddAssign<Vec2<T>> for Bounds2<T>

Source§

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

Performs the += operation. Read more
Source§

impl<T: Copy + AddAssign<T>> AddAssign<Vec2<T>> for Rect<T>

Source§

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

Performs the += operation. Read more
Source§

impl<U, T: AddAssign<U>> AddAssign<Vec2<U>> for Vec2<T>

Source§

fn add_assign(&mut self, rhs: Vec2<U>)

Performs the += operation. Read more
Source§

impl<T> AsMut<[T; 2]> for Vec2<T>

Source§

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

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T> AsMut<[T]> for Vec2<T>

Source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T> AsRef<[T; 2]> for Vec2<T>

Source§

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

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<[T]> for Vec2<T>

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Binary> Binary for Vec2<T>

Source§

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

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

impl<U, T: BitAnd<U>> BitAnd<Vec2<U>> for Vec2<T>

Source§

type Output = Vec2<<T as BitAnd<U>>::Output>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Vec2<U>) -> Vec2<T::Output>

Performs the & operation. Read more
Source§

impl<U, T: BitOr<U>> BitOr<Vec2<U>> for Vec2<T>

Source§

type Output = Vec2<<T as BitOr<U>>::Output>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Vec2<U>) -> Vec2<T::Output>

Performs the | operation. Read more
Source§

impl<U, T: BitXor<U>> BitXor<Vec2<U>> for Vec2<T>

Source§

type Output = Vec2<<T as BitXor<U>>::Output>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Vec2<U>) -> Vec2<T::Output>

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 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

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

Source§

impl<T: Scalar> Cross for Vec2<T>

Source§

type Output = T

Source§

fn cross(self, rhs: Vec2<T>) -> T

Source§

impl<T: Debug> Debug for Vec2<T>

Source§

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

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

impl<T: Default> Default for Vec2<T>

Source§

fn default() -> Vec2<T>

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

impl<T: Display> Display for Vec2<T>

Source§

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

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

impl<T: Float> Distance for Vec2<T>

Source§

type T = T

Source§

fn distance(self, rhs: Vec2<T>) -> T

Source§

impl<T: Float> Distance<Vec2<T>> for Line2<T>

Source§

type T = T

Source§

fn distance(self, pt: Point2<T>) -> T

Source§

impl<T: Float> Distance<Vec2<T>> for Plane2<T>

Source§

type T = T

Source§

fn distance(self, pt: Point2<T>) -> T

Source§

impl<U: Scalar, T: Div<U>> Div<U> for Vec2<T>

Source§

type Output = Vec2<<T as Div<U>>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: U) -> Vec2<T::Output>

Performs the / operation. Read more
Source§

impl<U, T: Div<U>> Div<Vec2<U>> for Vec2<T>

Source§

type Output = Vec2<<T as Div<U>>::Output>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vec2<U>) -> Vec2<T::Output>

Performs the / operation. Read more
Source§

impl<U: Scalar, T: DivAssign<U>> DivAssign<U> for Vec2<T>

Source§

fn div_assign(&mut self, rhs: U)

Performs the /= operation. Read more
Source§

impl<U, T: DivAssign<U>> DivAssign<Vec2<U>> for Vec2<T>

Source§

fn div_assign(&mut self, rhs: Vec2<U>)

Performs the /= operation. Read more
Source§

impl<T: Scalar> Dot for Vec2<T>

Source§

type T = T

Source§

fn dot(self, rhs: Vec2<T>) -> T

Source§

impl<T: Eq> Eq for Vec2<T>

Source§

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

Source§

fn from(val: (T, T)) -> Vec2<T>

Converts to this type from the input type.
Source§

impl<T> From<Complex<T>> for Vec2<T>

Source§

fn from(complex: Complex<T>) -> Vec2<T>

Converts to this type from the input type.
Source§

impl<T: Float> From<Polar<T>> for Vec2<T>

Source§

fn from(polar: Polar<T>) -> Vec2<T>

Converts to this type from the input type.
Source§

impl<T: Scalar> From<T> for Vec2<T>

Source§

fn from(val: T) -> Vec2<T>

Converts to this type from the input type.
Source§

impl<T> From<Vec2<T>> for Complex<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T: Float> From<Vec2<T>> for Polar<T>

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from(val: [T; 2]) -> Vec2<T>

Converts to this type from the input type.
Source§

impl<T: Float> FromIterator<Vec2<T>> for Bounds2<T>

Source§

fn from_iter<I: IntoIterator<Item = Point2<T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: FromStr> FromStr for Vec2<T>

Source§

type Err = ParseVecError<<T as FromStr>::Err>

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Vec2<T>, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<T: Hash> Hash for Vec2<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> Index<usize> for Vec2<T>

Source§

type Output = T

The returned type after indexing.
Source§

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

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

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

Source§

fn into(self) -> (T, T)

Converts this type into the (usually inferred) input type.
Source§

impl<T> Into<[T; 2]> for Vec2<T>

Source§

fn into(self) -> [T; 2]

Converts this type into the (usually inferred) input type.
Source§

impl<T: Scalar> Lerp for Vec2<T>

Source§

type T = T

Source§

fn lerp(self, rhs: Vec2<T>, t: T) -> Vec2<T>

Source§

impl<T: LowerExp> LowerExp for Vec2<T>

Source§

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

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

impl<T: LowerHex> LowerHex for Vec2<T>

Source§

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

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

impl<T> Mul<&Vec2<T>> for Mat2<T>
where Mat2<T>: Mul<Vec2<T>, Output = Vec2<T>>, Vec2<T>: Copy,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul<&Vec2<T>> for &Mat2<T>
where Mat2<T>: Copy + Mul<Vec2<T>, Output = Vec2<T>>, Vec2<T>: Copy,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul<&Vec2<T>> for Transform2<T>
where Transform2<T>: Mul<Vec2<T>, Output = Vec2<T>>, Vec2<T>: Copy,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul<&Vec2<T>> for &Transform2<T>
where Transform2<T>: Copy + Mul<Vec2<T>, Output = Vec2<T>>, Vec2<T>: Copy,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<U: Scalar, T: Mul<U>> Mul<U> for Vec2<T>

Source§

type Output = Vec2<<T as Mul<U>>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: U) -> Vec2<T::Output>

Performs the * operation. Read more
Source§

impl<T: Copy + Mul<Output = T> + Add<Output = T> + Sub<Output = T>> Mul<Vec2<T>> for Complex<T>

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Vec2<T>> for Mat2<T>

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul<Vec2<T>> for &Mat2<T>
where Mat2<T>: Copy + Mul<Vec2<T>, Output = Vec2<T>>,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Copy + Add<Output = T> + Mul<Output = T>> Mul<Vec2<T>> for Transform2<T>

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T> Mul<Vec2<T>> for &Transform2<T>
where Transform2<T>: Copy + Mul<Vec2<T>, Output = Vec2<T>>,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<U, T: Mul<U>> Mul<Vec2<U>> for Vec2<T>

Source§

type Output = Vec2<<T as Mul<U>>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<U>) -> Vec2<T::Output>

Performs the * operation. Read more
Source§

impl<U: Scalar, T: MulAssign<U>> MulAssign<U> for Vec2<T>

Source§

fn mul_assign(&mut self, rhs: U)

Performs the *= operation. Read more
Source§

impl<U, T: MulAssign<U>> MulAssign<Vec2<U>> for Vec2<T>

Source§

fn mul_assign(&mut self, rhs: Vec2<U>)

Performs the *= operation. Read more
Source§

impl<T: Neg> Neg for Vec2<T>

Source§

type Output = Vec2<<T as Neg>::Output>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vec2<T::Output>

Performs the unary - operation. Read more
Source§

impl<T: Not> Not for Vec2<T>

Source§

type Output = Vec2<<T as Not>::Output>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Vec2<T::Output>

Performs the unary ! operation. Read more
Source§

impl<T: Octal> Octal for Vec2<T>

Source§

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

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

impl<T: Ord> Ord for Vec2<T>

Source§

fn cmp(&self, other: &Vec2<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for Vec2<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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: PartialOrd> PartialOrd for Vec2<T>

Source§

fn partial_cmp(&self, other: &Vec2<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<U: Scalar, T: Rem<U>> Rem<U> for Vec2<T>

Source§

type Output = Vec2<<T as Rem<U>>::Output>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: U) -> Vec2<T::Output>

Performs the % operation. Read more
Source§

impl<U, T: Rem<U>> Rem<Vec2<U>> for Vec2<T>

Source§

type Output = Vec2<<T as Rem<U>>::Output>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Vec2<U>) -> Vec2<T::Output>

Performs the % operation. Read more
Source§

impl<U: Scalar, T: RemAssign<U>> RemAssign<U> for Vec2<T>

Source§

fn rem_assign(&mut self, rhs: U)

Performs the %= operation. Read more
Source§

impl<U, T: RemAssign<U>> RemAssign<Vec2<U>> for Vec2<T>

Source§

fn rem_assign(&mut self, rhs: Vec2<U>)

Performs the %= operation. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Vec2<T>

Source§

impl<T: Copy + Sub<T, Output = T>> Sub<Vec2<T>> for Bounds2<T>

Source§

type Output = Bounds2<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: Copy + Sub<T, Output = T>> Sub<Vec2<T>> for Rect<T>

Source§

type Output = Rect<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<U, T: Sub<U>> Sub<Vec2<U>> for Vec2<T>

Source§

type Output = Vec2<<T as Sub<U>>::Output>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vec2<U>) -> Vec2<T::Output>

Performs the - operation. Read more
Source§

impl<T: Copy + SubAssign<T>> SubAssign<Vec2<T>> for Bounds2<T>

Source§

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

Performs the -= operation. Read more
Source§

impl<T: Copy + SubAssign<T>> SubAssign<Vec2<T>> for Rect<T>

Source§

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

Performs the -= operation. Read more
Source§

impl<U, T: SubAssign<U>> SubAssign<Vec2<U>> for Vec2<T>

Source§

fn sub_assign(&mut self, rhs: Vec2<U>)

Performs the -= operation. Read more
Source§

impl<T: UpperExp> UpperExp for Vec2<T>

Source§

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

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

impl<T: UpperHex> UpperHex for Vec2<T>

Source§

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

Formats the value using the given formatter. Read more

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> UnsafeUnpin for Vec2<T>
where T: UnsafeUnpin,

§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.