Skip to main content

Vector2

Struct Vector2 

Source
pub struct Vector2<T1, T2> {
    pub x_: T1,
    pub y_: T2,
}
Expand description

A 2D vector with x and y components.

       y
       ^
       |
       |
       *-----> x
      /|
     / | y_
    /  |
   /   |
  *----+-----> x
 (0,0) x_

§Examples

use physdes::vector2::Vector2;

let v = Vector2::new(3, 4);
assert_eq!(v.x_, 3);
assert_eq!(v.y_, 4);

Fields§

§x_: T1

x portion of the Vector2 object

§y_: T2

y portion of the Vector2 object

Implementations§

Source§

impl<T1, T2> Vector2<T1, T2>

Source

pub const fn new(x_: T1, y_: T2) -> Self

Creates a new Vector2 with the given x and y values.

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(1, 2), Vector2 { x_: 1, y_: 2 });
assert_eq!(Vector2::new(3, 4), Vector2 { x_: 3, y_: 4 });
Source§

impl<T1: Clone + Num> Vector2<T1, T1>

Source

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

Computes the dot product of two vectors.

$$\vec{a} \cdot \vec{b} = a_x b_x + a_y b_y$$

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(1, 2).dot(&Vector2::new(3, 4)), 11);
assert_eq!(Vector2::new(3, 4).dot(&Vector2::new(1, 2)), 11);
Source

pub fn cross(&self, other: &Self) -> T1

Computes the cross product (2D scalar) of two vectors.

$$\vec{a} \times \vec{b} = a_x b_y - a_y b_x$$

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(1, 2).cross(&Vector2::new(3, 4)), -2);
assert_eq!(Vector2::new(3, 4).cross(&Vector2::new(1, 2)), 2);
Source

pub fn scale(&self, factor: T1) -> Self

Multiplies the vector by a scalar factor.

$$\vec{v}’ = \vec{v} \times f = (v_x \cdot f,; v_y \cdot f)$$

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(1, 2).scale(3), Vector2::new(3, 6));
assert_eq!(Vector2::new(3, 4).scale(2), Vector2::new(6, 8));
Source

pub fn unscale(&self, factor: T1) -> Self

Divides the vector by a scalar factor.

$$\vec{v}’ = \vec{v} / f = (v_x / f,; v_y / f)$$

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(3, 6).unscale(3), Vector2::new(1, 2));
assert_eq!(Vector2::new(6, 8).unscale(2), Vector2::new(3, 4));
Source§

impl<T1: Clone + Signed> Vector2<T1, T1>

Source

pub fn l1_norm(&self) -> T1

Computes the L1 norm (Manhattan distance from origin): |x_| + |y_|.

$$|\vec{v}|_1 = |v_x| + |v_y|$$

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(1, 2).l1_norm(), 3);
assert_eq!(Vector2::new(3, 4).l1_norm(), 7);
Source§

impl<T1: Clone + PartialOrd> Vector2<T1, T1>

Source

pub fn norm_inf(&self) -> T1

Computes the Chebyshev (infinity) norm: max(x_, y_).

$$|\vec{v}|_\infty = \max(v_x, v_y)$$

Assumes non-negative coordinate values (does not take absolute values internally).

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(1, 2).norm_inf(), 2);
assert_eq!(Vector2::new(3, 4).norm_inf(), 4);

Trait Implementations§

Source§

impl<T1: Clone + Num, T2: Clone + Num> Add for Vector2<T1, T2>

Source§

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

Adds two vectors component-wise.

$$\vec{a} + \vec{b} = (a_x + b_x,; a_y + b_y)$$

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(1, 2) + Vector2::new(3, 4), Vector2::new(4, 6));
Source§

type Output = Vector2<T1, T2>

The resulting type after applying the + operator.
Source§

impl<'a, T1: Clone + Num, T2: Clone + Num> Add<&'a Vector2<T1, T2>> for Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the + operator.
Source§

fn add(self, other: &Vector2<T1, T2>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, 'b, T1: Clone + Num, T2: Clone + Num> Add<&'b Vector2<T1, T2>> for &'a Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the + operator.
Source§

fn add(self, other: &Vector2<T1, T2>) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, T1: Clone + Num, T2: Clone + Num> Add<Vector2<T1, T2>> for &'a Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector2<T1, T2>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T1: Clone + Num, T2: Clone + Num> Add<Vector2<T1, T2>> for Point<T1, T2>

Source§

fn add(self, other: Vector2<T1, T2>) -> Self::Output

Translate a point by a vector

$$P’ = (x + v_x,; y + v_y)$$

§Examples
use physdes::point::Point;
use physdes::vector2::Vector2;

assert_eq!(Point::new(3, 4) + Vector2::new(5, 3), Point::new(8, 7));
assert_eq!(Point::new(3, 4) + Vector2::new(-5, -3), Point::new(-2, 1));
assert_eq!(Point::new(3, 4) + Vector2::new(5, -3), Point::new(8, 1));
assert_eq!(Point::new(3, 4) + Vector2::new(-5, 3), Point::new(-2, 7));
assert_eq!(Point::new(3, 4) + Vector2::new(0, 0), Point::new(3, 4));
assert_eq!(Point::new(3, 4) + Vector2::new(0, 5), Point::new(3, 9));
Source§

type Output = Point<T1, T2>

The resulting type after applying the + operator.
Source§

impl<T1: Clone + NumAssign, T2: Clone + NumAssign> AddAssign for Vector2<T1, T2>

Source§

fn add_assign(&mut self, other: Self)

Adds another vector to this one component-wise.

$$\vec{a} \mathrel{+}= \vec{b} \implies (a_x + b_x,; a_y + b_y)$$

§Example
use physdes::vector2::Vector2;
use std::ops::AddAssign;

let mut v = Vector2::new(1, 2);
let v2 = Vector2::new(3, 4);
v.add_assign(v2);
assert_eq!(v, Vector2::new(4, 6));
Source§

impl<'a, T1: Clone + Num + AddAssign, T2: Clone + Num + AddAssign> AddAssign<&'a Vector2<T1, T2>> for Point<T1, T2>

Translates the point by adding a vector reference to its coordinates

Source§

fn add_assign(&mut self, other: &'a Vector2<T1, T2>)

Performs the += operation. Read more
Source§

impl<'a, T1: Clone + NumAssign, T2: Clone + NumAssign> AddAssign<&'a Vector2<T1, T2>> for Vector2<T1, T2>

Source§

fn add_assign(&mut self, other: &Self)

Performs the += operation. Read more
Source§

impl<T1: Clone + Num + AddAssign, T2: Clone + Num + AddAssign> AddAssign<Vector2<T1, T2>> for Point<T1, T2>

Translates the point by adding a vector to its coordinates

$$P \mathrel{+}= (v_x, v_y) \implies (x + v_x,; y + v_y)$$

Source§

fn add_assign(&mut self, other: Vector2<T1, T2>)

Performs the += operation. Read more
Source§

impl<T: AddAssign + Clone + Num> AddAssign<Vector2<T, T>> for Polygon<T>

Source§

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

Translates the polygon by adding a vector to its origin.

Source§

impl<T1: Clone, T2: Clone> Clone for Vector2<T1, T2>

Source§

fn clone(&self) -> Vector2<T1, T2>

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<T1: Copy, T2: Copy> Copy for Vector2<T1, T2>

Source§

impl<T1: Debug, T2: Debug> Debug for Vector2<T1, T2>

Source§

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

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

impl<T1: Default, T2: Default> Default for Vector2<T1, T2>

Source§

fn default() -> Vector2<T1, T2>

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

impl<T1: Clone + Num> Div<T1> for Vector2<T1, T1>

Source§

fn div(self, other: T1) -> Self::Output

Scalar division: $\vec{v} / s = (v_x / s,; v_y / s)$

Source§

type Output = Vector2<T1, T1>

The resulting type after applying the / operator.
Source§

impl<'a, T1: Clone + NumAssign> DivAssign<&'a T1> for Vector2<T1, T1>

Source§

fn div_assign(&mut self, other: &T1)

Performs the /= operation. Read more
Source§

impl<T1: Clone + NumAssign> DivAssign<T1> for Vector2<T1, T1>

Source§

fn div_assign(&mut self, other: T1)

Divides each component of the vector by a scalar.

$$\vec{v} \mathrel{/}= s \implies (v_x / s,; v_y / s)$$

§Example
use physdes::vector2::Vector2;
use std::ops::DivAssign;

let mut v = Vector2::new(3, 6);
v.div_assign(3);
assert_eq!(v, Vector2::new(1, 2));
Source§

impl<T1: Eq, T2: Eq> Eq for Vector2<T1, T2>

Source§

impl<T1: Hash, T2: Hash> Hash for Vector2<T1, T2>

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<'a, T1: Clone + Num> Mul<&'a T1> for Vector2<T1, T1>

Source§

type Output = Vector2<T1, T1>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &T1) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, 'b, T1: Clone + Num> Mul<&'a T1> for &'b Vector2<T1, T1>

Source§

type Output = Vector2<T1, T1>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &T1) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<f32, f32>> for f32

Source§

type Output = Vector2<f32, f32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<f32, f32>> for &'b f32

Source§

type Output = Vector2<f32, f32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<f64, f64>> for f64

Source§

type Output = Vector2<f64, f64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<f64, f64>> for &'b f64

Source§

type Output = Vector2<f64, f64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<i8, i8>> for i8

Source§

type Output = Vector2<i8, i8>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i8, i8>) -> Vector2<i8, i8>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<i8, i8>> for &'b i8

Source§

type Output = Vector2<i8, i8>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i8, i8>) -> Vector2<i8, i8>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<i16, i16>> for i16

Source§

type Output = Vector2<i16, i16>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i16, i16>) -> Vector2<i16, i16>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<i16, i16>> for &'b i16

Source§

type Output = Vector2<i16, i16>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i16, i16>) -> Vector2<i16, i16>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<i32, i32>> for i32

Source§

type Output = Vector2<i32, i32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i32, i32>) -> Vector2<i32, i32>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<i32, i32>> for &'b i32

Source§

type Output = Vector2<i32, i32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i32, i32>) -> Vector2<i32, i32>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<i64, i64>> for i64

Source§

type Output = Vector2<i64, i64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i64, i64>) -> Vector2<i64, i64>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<i64, i64>> for &'b i64

Source§

type Output = Vector2<i64, i64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i64, i64>) -> Vector2<i64, i64>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<i128, i128>> for i128

Source§

type Output = Vector2<i128, i128>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i128, i128>) -> Vector2<i128, i128>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<i128, i128>> for &'b i128

Source§

type Output = Vector2<i128, i128>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<i128, i128>) -> Vector2<i128, i128>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<isize, isize>> for isize

Source§

type Output = Vector2<isize, isize>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<isize, isize>) -> Vector2<isize, isize>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<isize, isize>> for &'b isize

Source§

type Output = Vector2<isize, isize>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<isize, isize>) -> Vector2<isize, isize>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<u8, u8>> for u8

Source§

type Output = Vector2<u8, u8>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u8, u8>) -> Vector2<u8, u8>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<u8, u8>> for &'b u8

Source§

type Output = Vector2<u8, u8>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u8, u8>) -> Vector2<u8, u8>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<u16, u16>> for u16

Source§

type Output = Vector2<u16, u16>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u16, u16>) -> Vector2<u16, u16>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<u16, u16>> for &'b u16

Source§

type Output = Vector2<u16, u16>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u16, u16>) -> Vector2<u16, u16>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<u32, u32>> for u32

Source§

type Output = Vector2<u32, u32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u32, u32>) -> Vector2<u32, u32>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<u32, u32>> for &'b u32

Source§

type Output = Vector2<u32, u32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u32, u32>) -> Vector2<u32, u32>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<u64, u64>> for u64

Source§

type Output = Vector2<u64, u64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u64, u64>) -> Vector2<u64, u64>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<u64, u64>> for &'b u64

Source§

type Output = Vector2<u64, u64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u64, u64>) -> Vector2<u64, u64>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<u128, u128>> for u128

Source§

type Output = Vector2<u128, u128>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u128, u128>) -> Vector2<u128, u128>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<u128, u128>> for &'b u128

Source§

type Output = Vector2<u128, u128>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<u128, u128>) -> Vector2<u128, u128>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a Vector2<usize, usize>> for usize

Source§

type Output = Vector2<usize, usize>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<usize, usize>) -> Vector2<usize, usize>

Performs the * operation. Read more
Source§

impl<'a, 'b> Mul<&'a Vector2<usize, usize>> for &'b usize

Source§

type Output = Vector2<usize, usize>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Vector2<usize, usize>) -> Vector2<usize, usize>

Performs the * operation. Read more
Source§

impl<T1: Clone + Num> Mul<T1> for Vector2<T1, T1>

Source§

fn mul(self, other: T1) -> Self::Output

Scalar multiplication: $\vec{v} \cdot s = (v_x \cdot s,; v_y \cdot s)$

Source§

type Output = Vector2<T1, T1>

The resulting type after applying the * operator.
Source§

impl<'a, T1: Clone + Num> Mul<T1> for &'a Vector2<T1, T1>

Source§

type Output = Vector2<T1, T1>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T1) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<f32, f32>> for &'a f32

Source§

type Output = Vector2<f32, f32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<f32, f32>> for f32

Source§

type Output = Vector2<f32, f32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<f32, f32>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<f64, f64>> for &'a f64

Source§

type Output = Vector2<f64, f64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vector2<f64, f64>> for f64

Source§

type Output = Vector2<f64, f64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<f64, f64>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<i8, i8>> for &'a i8

Source§

type Output = Vector2<i8, i8>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i8, i8>) -> Vector2<i8, i8>

Performs the * operation. Read more
Source§

impl Mul<Vector2<i8, i8>> for i8

Source§

type Output = Vector2<i8, i8>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i8, i8>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<i16, i16>> for &'a i16

Source§

type Output = Vector2<i16, i16>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i16, i16>) -> Vector2<i16, i16>

Performs the * operation. Read more
Source§

impl Mul<Vector2<i16, i16>> for i16

Source§

type Output = Vector2<i16, i16>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i16, i16>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<i32, i32>> for &'a i32

Source§

type Output = Vector2<i32, i32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i32, i32>) -> Vector2<i32, i32>

Performs the * operation. Read more
Source§

impl Mul<Vector2<i32, i32>> for i32

Source§

type Output = Vector2<i32, i32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i32, i32>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<i64, i64>> for &'a i64

Source§

type Output = Vector2<i64, i64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i64, i64>) -> Vector2<i64, i64>

Performs the * operation. Read more
Source§

impl Mul<Vector2<i64, i64>> for i64

Source§

type Output = Vector2<i64, i64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i64, i64>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<i128, i128>> for &'a i128

Source§

type Output = Vector2<i128, i128>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i128, i128>) -> Vector2<i128, i128>

Performs the * operation. Read more
Source§

impl Mul<Vector2<i128, i128>> for i128

Source§

type Output = Vector2<i128, i128>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<i128, i128>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<isize, isize>> for &'a isize

Source§

type Output = Vector2<isize, isize>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<isize, isize>) -> Vector2<isize, isize>

Performs the * operation. Read more
Source§

impl Mul<Vector2<isize, isize>> for isize

Source§

type Output = Vector2<isize, isize>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<isize, isize>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<u8, u8>> for &'a u8

Source§

type Output = Vector2<u8, u8>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u8, u8>) -> Vector2<u8, u8>

Performs the * operation. Read more
Source§

impl Mul<Vector2<u8, u8>> for u8

Source§

type Output = Vector2<u8, u8>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u8, u8>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<u16, u16>> for &'a u16

Source§

type Output = Vector2<u16, u16>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u16, u16>) -> Vector2<u16, u16>

Performs the * operation. Read more
Source§

impl Mul<Vector2<u16, u16>> for u16

Source§

type Output = Vector2<u16, u16>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u16, u16>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<u32, u32>> for &'a u32

Source§

type Output = Vector2<u32, u32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u32, u32>) -> Vector2<u32, u32>

Performs the * operation. Read more
Source§

impl Mul<Vector2<u32, u32>> for u32

Source§

type Output = Vector2<u32, u32>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u32, u32>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<u64, u64>> for &'a u64

Source§

type Output = Vector2<u64, u64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u64, u64>) -> Vector2<u64, u64>

Performs the * operation. Read more
Source§

impl Mul<Vector2<u64, u64>> for u64

Source§

type Output = Vector2<u64, u64>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u64, u64>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<u128, u128>> for &'a u128

Source§

type Output = Vector2<u128, u128>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u128, u128>) -> Vector2<u128, u128>

Performs the * operation. Read more
Source§

impl Mul<Vector2<u128, u128>> for u128

Source§

type Output = Vector2<u128, u128>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<u128, u128>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a> Mul<Vector2<usize, usize>> for &'a usize

Source§

type Output = Vector2<usize, usize>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<usize, usize>) -> Vector2<usize, usize>

Performs the * operation. Read more
Source§

impl Mul<Vector2<usize, usize>> for usize

Source§

type Output = Vector2<usize, usize>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Vector2<usize, usize>) -> Self::Output

Performs the * operation. Read more
Source§

impl<'a, T1: Clone + NumAssign> MulAssign<&'a T1> for Vector2<T1, T1>

Source§

fn mul_assign(&mut self, other: &T1)

Performs the *= operation. Read more
Source§

impl<T1: Clone + NumAssign> MulAssign<T1> for Vector2<T1, T1>

Source§

fn mul_assign(&mut self, other: T1)

Multiplies each component of the vector by a scalar.

$$\vec{v} \mathrel{*}= s \implies (v_x \cdot s,; v_y \cdot s)$$

§Example
use physdes::vector2::Vector2;
use std::ops::MulAssign;

let mut v = Vector2::new(1, 2);
v.mul_assign(3);
assert_eq!(v, Vector2::new(3, 6));
Source§

impl<T1: Clone + Num + Neg<Output = T1>, T2: Clone + Num + Neg<Output = T2>> Neg for Vector2<T1, T2>

Source§

fn neg(self) -> Self::Output

Negates both components of the vector.

$$-\vec{v} = (-v_x,; -v_y)$$

§Example
use physdes::vector2::Vector2;

let v = Vector2::new(1, 2);
assert_eq!(-v, Vector2::new(-1, -2));
Source§

type Output = Vector2<T1, T2>

The resulting type after applying the - operator.
Source§

impl<T1: Clone + Num + Neg<Output = T1>, T2: Clone + Num + Neg<Output = T2>> Neg for &Vector2<T1, T2>

Source§

fn neg(self) -> Self::Output

Negates both components of a borrowed vector.

$$-\vec{v} = (-v_x,; -v_y)$$

Source§

type Output = Vector2<T1, T2>

The resulting type after applying the - operator.
Source§

impl<T1: PartialEq, T2: PartialEq> PartialEq for Vector2<T1, T2>

Source§

fn eq(&self, other: &Vector2<T1, T2>) -> 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<T1: Clone + Num> Rem<T1> for Vector2<T1, T1>

Source§

fn rem(self, other: T1) -> Self::Output

Scalar remainder: $\vec{v} \bmod s = (v_x \bmod s,; v_y \bmod s)$

Source§

type Output = Vector2<T1, T1>

The resulting type after applying the % operator.
Source§

impl<T1: PartialEq, T2: PartialEq> StructuralPartialEq for Vector2<T1, T2>

Source§

impl<T1: Clone + Num, T2: Clone + Num> Sub for Vector2<T1, T2>

Source§

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

Subtracts two vectors component-wise.

$$\vec{a} - \vec{b} = (a_x - b_x,; a_y - b_y)$$

§Example
use physdes::vector2::Vector2;

assert_eq!(Vector2::new(1, 2) - Vector2::new(3, 4), Vector2::new(-2, -2));
Source§

type Output = Vector2<T1, T2>

The resulting type after applying the - operator.
Source§

impl<'a, T1: Clone + Num, T2: Clone + Num> Sub<&'a Vector2<T1, T2>> for Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Vector2<T1, T2>) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, 'b, T1: Clone + Num, T2: Clone + Num> Sub<&'b Vector2<T1, T2>> for &'a Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Vector2<T1, T2>) -> Self::Output

Performs the - operation. Read more
Source§

impl<'a, T1: Clone + Num, T2: Clone + Num> Sub<Vector2<T1, T2>> for &'a Point<T1, T2>

Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector2<T1, T2>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T1: Clone + Num, T2: Clone + Num> Sub<Vector2<T1, T2>> for Point<T1, T2>

Source§

fn sub(self, other: Vector2<T1, T2>) -> Self::Output

Translate a point by a vector (subtraction)

$$P’ = (x - v_x,; y - v_y)$$

§Examples
use physdes::point::Point;
use physdes::vector2::Vector2;
assert_eq!(Point::new(3, 4) - Vector2::new(5, 3), Point::new(-2, 1));
assert_eq!(Point::new(3, 4) - Vector2::new(-5, -3), Point::new(8, 7));
assert_eq!(Point::new(3, 4) - Vector2::new(5, -3), Point::new(-2, 7));
assert_eq!(Point::new(3, 4) - Vector2::new(-5, 3), Point::new(8, 1));
assert_eq!(Point::new(3, 4) - Vector2::new(0, 0), Point::new(3, 4));
assert_eq!(Point::new(3, 4) - Vector2::new(0, 5), Point::new(3, -1));
assert_eq!(Point::new(3, 4) - Vector2::new(5, 0), Point::new(-2, 4));
Source§

type Output = Point<T1, T2>

The resulting type after applying the - operator.
Source§

impl<T1: Clone + NumAssign, T2: Clone + NumAssign> SubAssign for Vector2<T1, T2>

Source§

fn sub_assign(&mut self, other: Self)

Subtracts another vector from this one component-wise.

$$\vec{a} \mathrel{-}= \vec{b} \implies (a_x - b_x,; a_y - b_y)$$

§Example
use physdes::vector2::Vector2;
use std::ops::SubAssign;
let mut v = Vector2::new(1, 2);
let v2 = Vector2::new(3, 4);
v.sub_assign(v2);
assert_eq!(v, Vector2::new(-2, -2));
Source§

impl<'a, T1: Clone + Num + SubAssign, T2: Clone + Num + SubAssign> SubAssign<&'a Vector2<T1, T2>> for Point<T1, T2>

Translates the point by subtracting a vector reference from its coordinates

Source§

fn sub_assign(&mut self, other: &'a Vector2<T1, T2>)

Performs the -= operation. Read more
Source§

impl<'a, T1: Clone + NumAssign, T2: Clone + NumAssign> SubAssign<&'a Vector2<T1, T2>> for Vector2<T1, T2>

Source§

fn sub_assign(&mut self, other: &Self)

Performs the -= operation. Read more
Source§

impl<T1: Clone + Num + SubAssign, T2: Clone + Num + SubAssign> SubAssign<Vector2<T1, T2>> for Point<T1, T2>

Translates the point by subtracting a vector from its coordinates

$$P \mathrel{-}= (v_x, v_y) \implies (x - v_x,; y - v_y)$$

Source§

fn sub_assign(&mut self, other: Vector2<T1, T2>)

Performs the -= operation. Read more
Source§

impl<T: SubAssign + Clone + Num> SubAssign<Vector2<T, T>> for Polygon<T>

Source§

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

Translates the polygon by subtracting a vector from its origin.

Source§

impl<T1: Clone + Num + Add, T2: Clone + Num + Add> Zero for Vector2<T1, T2>

Source§

fn zero() -> Self

Zero vector: $\vec{0} = (0, 0)$

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.

Auto Trait Implementations§

§

impl<T1, T2> Freeze for Vector2<T1, T2>
where T1: Freeze, T2: Freeze,

§

impl<T1, T2> RefUnwindSafe for Vector2<T1, T2>

§

impl<T1, T2> Send for Vector2<T1, T2>
where T1: Send, T2: Send,

§

impl<T1, T2> Sync for Vector2<T1, T2>
where T1: Sync, T2: Sync,

§

impl<T1, T2> Unpin for Vector2<T1, T2>
where T1: Unpin, T2: Unpin,

§

impl<T1, T2> UnsafeUnpin for Vector2<T1, T2>
where T1: UnsafeUnpin, T2: UnsafeUnpin,

§

impl<T1, T2> UnwindSafe for Vector2<T1, T2>
where T1: UnwindSafe, T2: 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.