Struct Vec2

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

2D generic vector Implemented for f32, f64, i32

Fields§

§x: T§y: T

Implementations§

Source§

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

Source

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

Constructs a new Vec2 from the given components

Source

pub fn broadcast(a: T) -> Vec2<T>

Constructs a new Vec2 from a scalar value by copying that value to all members

§Examples
// V2f32 is a type alias for Vec2::<f32>
use imath::vec::V2f32;
let v = V2f32::broadcast(1.0);
assert!(v.x == 1.0 && v.y == 1.0)
Source

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

Dot product

Source

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

Right-handed cross product

Source

pub fn equal_with_abs_error(self, v: Vec2<T>, e: T) -> bool
where T: Scalar,

Returns true if self and v are equal with error no greater than e

Source

pub fn equal_with_rel_error(self, v: Vec2<T>, e: T) -> bool
where T: Real,

Returns true if self and v are equal with a relative error no greater than e

Source

pub fn length2(self) -> T
where T: Scalar,

Calculate the squared length of the vector

Source§

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

Source

pub fn length(self) -> T

Length of the vector

Source

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

Returns a normalized copy of this vector

Trait Implementations§

Source§

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

Addition by a T

Source§

type Output = Vec2<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Vec2<f32>> for f32

Source§

type Output = Vec2<f32>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Vec2<f64>> for f64

Source§

type Output = Vec2<f64>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Vec2<i32>> for i32

Source§

type Output = Vec2<i32>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Addition operator

Source§

type Output = Vec2<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T> Bounded for Vec2<T>
where T: Scalar,

Source§

fn min_value() -> Vec2<T>

Returns the smallest finite number this type can represent
Source§

fn max_value() -> Vec2<T>

Returns the largest finite number this type can represent
Source§

impl<T> Clone for Vec2<T>
where T: Copy + Clone,

Source§

fn clone(&self) -> Vec2<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 for Vec2<T>
where T: Copy + 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: Copy + Default,

Source§

fn default() -> Vec2<T>

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

impl<T> Display for Vec2<T>
where T: Scalar + Display,

Source§

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

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

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

Division by a T

Source§

type Output = Vec2<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div<Vec2<f32>> for f32

Source§

type Output = Vec2<f32>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vec2<f32>) -> Vec2<f32>

Performs the / operation. Read more
Source§

impl Div<Vec2<f64>> for f64

Source§

type Output = Vec2<f64>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vec2<f64>) -> Vec2<f64>

Performs the / operation. Read more
Source§

impl Div<Vec2<i32>> for i32

Source§

type Output = Vec2<i32>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vec2<i32>) -> Vec2<i32>

Performs the / operation. Read more
Source§

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

Division operator

Source§

type Output = Vec2<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T> From<Vec2<T>> for Vec3<T>
where T: Scalar,

Source§

fn from(v: Vec2<T>) -> Self

Converts a Vec2 to a Vec3, adding a 0 z element

Source§

impl<T> From<Vec2<T>> for Vec4<T>
where T: Scalar,

Source§

fn from(v: Vec2<T>) -> Self

Converts a Vec2 to a Vec4, adding 0 z and w elements

Source§

impl<T> From<Vec3<T>> for Vec2<T>
where T: Scalar,

Source§

fn from(v: Vec3<T>) -> Self

Converts a Vec3 to a Vec2, dropping the z element

Source§

impl<T> From<Vec4<T>> for Vec2<T>
where T: Scalar,

Source§

fn from(v: Vec4<T>) -> Self

Converts a Vec4 to a Vec2, dropping the z element

Source§

impl<T> Index<usize> for Vec2<T>
where T: Scalar,

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> IndexMut<usize> for Vec2<T>
where T: Scalar,

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

Multiplication by a T

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vec2<f32>> for f32

Source§

type Output = Vec2<f32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vec2<f64>> for f64

Source§

type Output = Vec2<f64>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Vec2<i32>> for i32

Source§

type Output = Vec2<i32>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Multiplication operator

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

Unary negation

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

Source§

fn one() -> Vec2<T>
where T: Scalar,

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 for Vec2<T>
where T: Copy + PartialEq,

Source§

fn eq(&self, other: &Vec2<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> PartialOrd for Vec2<T>
where T: Copy + PartialOrd,

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 · 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 · 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 · 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 · 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<T> Sub<T> for Vec2<T>
where T: Scalar,

Subtraction by a T

Source§

type Output = Vec2<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Vec2<f32>> for f32

Source§

type Output = Vec2<f32>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Vec2<f64>> for f64

Source§

type Output = Vec2<f64>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Vec2<i32>> for i32

Source§

type Output = Vec2<i32>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Subtraction operator

Source§

type Output = Vec2<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

type Component = T

Source§

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

Source§

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

Source§

fn major_axis(self) -> usize
where T: Scalar,

Source§

fn dot(a: Vec2<T>, b: Vec2<T>) -> T

Source§

fn length2(self) -> T

Source§

impl<T> Zero for Vec2<T>
where T: Scalar,

Source§

fn zero() -> Vec2<T>
where T: Scalar,

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

fn is_zero(&self) -> bool
where T: Scalar,

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

Source§

impl<T> Eq for Vec2<T>
where T: Copy + Eq,

Source§

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

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> LowerBounded for T
where T: Bounded,

Source§

fn min_value() -> T

Returns the smallest finite number this type can represent
Source§

impl<T> Scalar for T
where T: Neg<Output = T> + PartialOrd + PartialEq + Add<Output = T> + Copy + Sub<Output = T> + Zero + Mul<Output = T> + One + Div<Output = T> + Bounded,

Source§

fn min(self, other: T) -> T

Source§

fn max(self, other: T) -> T

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.
Source§

impl<T> UpperBounded for T
where T: Bounded,

Source§

fn max_value() -> T

Returns the largest finite number this type can represent