Trait vector2math::Vector2

source ·
pub trait Vector2: Copy {
    type Scalar: Scalar;

Show 28 methods // Required methods fn x(&self) -> Self::Scalar; fn y(&self) -> Self::Scalar; fn new(x: Self::Scalar, y: Self::Scalar) -> Self; // Provided methods fn set_x(&mut self, x: Self::Scalar) { ... } fn set_y(&mut self, y: Self::Scalar) { ... } fn with_x(self, x: Self::Scalar) -> Self { ... } fn with_y(self, y: Self::Scalar) -> Self { ... } fn square(s: Self::Scalar) -> Self { ... } fn map_into<V>(self) -> V where V: Vector2, V::Scalar: From<Self::Scalar> { ... } fn map_vec2(self) -> [Self::Scalar; 2] { ... } fn map_dims<F>(self, f: F) -> Self where F: FnMut(Self::Scalar) -> Self::Scalar { ... } fn map_with<V, F>(self, f: F) -> V where V: Vector2, F: FnMut(Self::Scalar) -> V::Scalar { ... } fn neg(self) -> Self where Self::Scalar: Neg<Output = Self::Scalar> { ... } fn add(self, other: Self) -> Self { ... } fn sub(self, other: Self) -> Self { ... } fn mul(self, by: Self::Scalar) -> Self { ... } fn mul2(self, other: Self) -> Self { ... } fn div(self, by: Self::Scalar) -> Self { ... } fn div2(self, other: Self) -> Self { ... } fn add_assign(&mut self, other: Self) { ... } fn sub_assign(&mut self, other: Self) { ... } fn mul_assign(&mut self, by: Self::Scalar) { ... } fn mul2_assign(&mut self, other: Self) { ... } fn div_assign(&mut self, by: Self::Scalar) { ... } fn div2_assign(&mut self, other: Self) { ... } fn max_dim(self) -> Self::Scalar { ... } fn min_dim(self) -> Self::Scalar { ... } fn dot(self, other: Self) -> Self::Scalar { ... }
}
Expand description

Trait for manipulating 2D vectors

Required Associated Types§

source

type Scalar: Scalar

The scalar type

Required Methods§

source

fn x(&self) -> Self::Scalar

Get the x component

source

fn y(&self) -> Self::Scalar

Get the y component

source

fn new(x: Self::Scalar, y: Self::Scalar) -> Self

Create a new vector from an x and y component

Provided Methods§

source

fn set_x(&mut self, x: Self::Scalar)

Set the x component

source

fn set_y(&mut self, y: Self::Scalar)

Set the y component

source

fn with_x(self, x: Self::Scalar) -> Self

Get this vector with a different x component

source

fn with_y(self, y: Self::Scalar) -> Self

Get this vector with a different y component

source

fn square(s: Self::Scalar) -> Self

Create a new square vector

source

fn map_into<V>(self) -> Vwhere V: Vector2, V::Scalar: From<Self::Scalar>,

Map this vector to a vector of another type

source

fn map_vec2(self) -> [Self::Scalar; 2]

Map this vector to a [Self::Scalar; 2]

This is an alias for Vector2::map_into::<[Self::Scalar; 2]>() that is more concise

source

fn map_dims<F>(self, f: F) -> Selfwhere F: FnMut(Self::Scalar) -> Self::Scalar,

Map the individual components of this vector

source

fn map_with<V, F>(self, f: F) -> Vwhere V: Vector2, F: FnMut(Self::Scalar) -> V::Scalar,

Map this vector to a vector of another type using a function

source

fn neg(self) -> Selfwhere Self::Scalar: Neg<Output = Self::Scalar>,

Negate the vector

source

fn add(self, other: Self) -> Self

Add this vector to another

source

fn sub(self, other: Self) -> Self

Subtract another vector from this one

source

fn mul(self, by: Self::Scalar) -> Self

Multiply this vector by a scalar

source

fn mul2(self, other: Self) -> Self

Multiply this vector component-wise by another

source

fn div(self, by: Self::Scalar) -> Self

Divide this vector by a scalar

source

fn div2(self, other: Self) -> Self

Divide this vector component-wise by another

source

fn add_assign(&mut self, other: Self)

Add another vector into this one

source

fn sub_assign(&mut self, other: Self)

Subtract another vector into this one

source

fn mul_assign(&mut self, by: Self::Scalar)

Multiply a scalar into this vector

source

fn mul2_assign(&mut self, other: Self)

Multiply another vector component-wise into this one

source

fn div_assign(&mut self, by: Self::Scalar)

Divide a scalar into this vector

source

fn div2_assign(&mut self, other: Self)

Divide another vector component-wise into this one

source

fn max_dim(self) -> Self::Scalar

Get the value of the dimension with the higher magnitude

source

fn min_dim(self) -> Self::Scalar

Get the value of the dimension with the lower magnitude

source

fn dot(self, other: Self) -> Self::Scalar

Get the dot product of this vector and another

Implementors§

source§

impl Vector2 for f32x2

Available on crate feature simd only.
§

type Scalar = f32

source§

impl Vector2 for f64x2

Available on crate feature simd only.
§

type Scalar = f64

source§

impl Vector2 for i8x2

Available on crate feature simd only.
§

type Scalar = i8

source§

impl Vector2 for i16x2

Available on crate feature simd only.
§

type Scalar = i16

source§

impl Vector2 for i32x2

Available on crate feature simd only.
§

type Scalar = i32

source§

impl Vector2 for i64x2

Available on crate feature simd only.
§

type Scalar = i64

source§

impl Vector2 for u8x2

Available on crate feature simd only.
§

type Scalar = u8

source§

impl Vector2 for u16x2

Available on crate feature simd only.
§

type Scalar = u16

source§

impl Vector2 for u32x2

Available on crate feature simd only.
§

type Scalar = u32

source§

impl Vector2 for u64x2

Available on crate feature simd only.
§

type Scalar = u64

source§

impl<P> Vector2 for Pwhere P: Pair + Copy, P::Item: Scalar,

§

type Scalar = <P as Pair>::Item