Struct Vector2D

Source
#[repr(C)]
pub struct Vector2D<S = f32, Unit = ()> { pub x: S, pub y: S, /* private fields */ }
Expand description

2D vector.

Fields§

§x: S§y: S

Implementations§

Source§

impl<S: Copy + PartialEq + Zero, U: Copy> Vector2D<S, U>

Source

pub fn zero() -> Self

Source§

impl<U> Vector2D<f32, U>

Source

pub fn angle(&self, other: &Vector2D<f32>) -> f32

Returns the angle between two vectors, in radians.

Source§

impl<S: Sized, U: Copy> Vector2D<S, U>

Source

pub const fn new(x: S, y: S) -> Self

Source

pub fn normalize(self) -> Self
where S: One + Float + Div + Mul,

Returns a vector with the same direction and a given magnitude.

Source

pub fn magnitude(self) -> S
where S: Float,

The distance from the tail to the tip of the vector.

Source

pub fn dot(a: Self, b: Self) -> <S as Add>::Output
where S: Mul<Output = S> + Add,

Dot product of two vectors.

use rgx::math::*;

let v1 = Vector4D::<i32, ()>::new(1, 3, -5, 4);
let v2 = Vector4D::<i32, ()>::new(4, -2, -1, 3);

assert_eq!(v1 * v2, 15);
Source

pub fn distance(self, other: Self) -> S
where S: Float,

Distance between two vectors.

Source

pub fn extend(self, z: S) -> Vector3D<S, U>

Extend vector to three dimensions.

Source

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

Trait Implementations§

Source§

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

Source§

type Output = Rect<T>

The resulting type after applying the + operator.
Source§

fn add(self, vec: Vector2D<T>) -> Self

Performs the + operation. Read more
Source§

impl Add<Vector2D> for Line

Source§

type Output = Line

The resulting type after applying the + operator.
Source§

fn add(self, vec: Vector2D<f32>) -> Self

Performs the + operation. Read more
Source§

impl<S, U> Add for Vector2D<S, U>
where S: Add<Output = S> + Copy,

Source§

type Output = Vector2D<S, U>

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector2D<S, U>) -> Self

Performs the + operation. Read more
Source§

impl<T> AddAssign<Vector2D<T>> for Rect<T>
where T: Add<Output = T> + Copy,

Source§

fn add_assign(&mut self, vec: Vector2D<T>)

Performs the += operation. Read more
Source§

impl<S: Clone, Unit: Clone> Clone for Vector2D<S, Unit>

Source§

fn clone(&self) -> Vector2D<S, Unit>

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<S: Debug, Unit: Debug> Debug for Vector2D<S, Unit>

Source§

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

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

impl<S: Default, Unit: Default> Default for Vector2D<S, Unit>

Source§

fn default() -> Vector2D<S, Unit>

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

impl<S, U> Display for Vector2D<S, U>
where S: Display,

Source§

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

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

impl<S, U> Div<S> for Vector2D<S, U>
where S: Div<Output = S> + Copy,

Source§

type Output = Vector2D<S, U>

The resulting type after applying the / operator.
Source§

fn div(self, s: S) -> Self

Performs the / operation. Read more
Source§

impl<T: Copy> From<[T; 2]> for Vector2D<T>

Source§

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

Converts to this type from the input type.
Source§

impl<S, U: Copy> From<Point2D<S, U>> for Vector2D<S, U>

Source§

fn from(p: Point2D<S, U>) -> Self

Converts to this type from the input type.
Source§

impl<T: Copy> From<T> for Vector2D<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<S: One + Zero + Copy> From<Vector2D<S>> for Transform3D<S>

Source§

fn from(other: Vector2D<S>) -> Self

Converts to this type from the input type.
Source§

impl<S, U> From<Vector2D<S, U>> for Point2D<S, U>

Source§

fn from(v: Vector2D<S, U>) -> Self

Converts to this type from the input type.
Source§

impl<S: Zero, U: Copy> From<Vector2D<S, U>> for Vector3D<S, U>

Source§

fn from(other: Vector2D<S, U>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(vec: Vector2D<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vector2D<T>> for Size<T>

Source§

fn from(other: Vector2D<T>) -> Self

Converts to this type from the input type.
Source§

impl From<Vector2D> for Vector4D<f32>

Source§

fn from(other: Vector2D<f32>) -> Self

Converts to this type from the input type.
Source§

impl<S, U: Copy> From<Vector3D<S, U>> for Vector2D<S, U>

Source§

fn from(other: Vector3D<S, U>) -> Self

Converts to this type from the input type.
Source§

impl<S: Hash, Unit: Hash> Hash for Vector2D<S, Unit>

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<S, U> Mul<S> for Vector2D<S, U>
where S: Mul<Output = S> + Copy,

Source§

type Output = Vector2D<S, U>

The resulting type after applying the * operator.
Source§

fn mul(self, s: S) -> Self

Performs the * operation. Read more
Source§

impl Mul<Vector2D> for Transform2D

Source§

type Output = Vector2D

The resulting type after applying the * operator.
Source§

fn mul(self, v: Vector2D<f32>) -> Vector2D<f32>

Performs the * operation. Read more
Source§

impl Mul<Vector2D> for Transform3D<f32>

Transform a Vector2D with a Transform3D.

use rgx::math::*;
let m = Transform3D::from_translation(Vector3D::new(8., 8., 0.));
let v = Vector2D::new(1., 1.);

assert_eq!(m * v, Vector2D::new(9., 9.));
Source§

type Output = Vector2D

The resulting type after applying the * operator.
Source§

fn mul(self, vec: Vector2D<f32>) -> Vector2D<f32>

Performs the * operation. Read more
Source§

impl<S: PartialEq, U> PartialEq for Vector2D<S, U>

Source§

fn eq(&self, other: &Self) -> 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<S, U> Sub<Vector2D<S, U>> for Point2D<S, U>
where S: Sub<Output = S> + Copy,

Source§

type Output = Point2D<S, U>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector2D<S, U>) -> Self

Performs the - operation. Read more
Source§

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

Source§

type Output = Rect<T>

The resulting type after applying the - operator.
Source§

fn sub(self, vec: Vector2D<T>) -> Self

Performs the - operation. Read more
Source§

impl<S, U> Sub for Vector2D<S, U>
where S: Sub<Output = S> + Copy,

Source§

type Output = Vector2D<S, U>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector2D<S, U>) -> Self

Performs the - operation. Read more
Source§

impl<T> SubAssign<Vector2D<T>> for Rect<T>
where T: Sub<Output = T> + Copy,

Source§

fn sub_assign(&mut self, vec: Vector2D<T>)

Performs the -= operation. Read more
Source§

impl<S: Zero + Copy + PartialEq, U: Copy> Zero for Vector2D<S, U>

Source§

const ZERO: Self

Source§

fn is_zero(&self) -> bool

Source§

impl<S: Copy, Unit: Copy> Copy for Vector2D<S, Unit>

Source§

impl<S: Eq, U> Eq for Vector2D<S, U>

Auto Trait Implementations§

§

impl<S, Unit> Freeze for Vector2D<S, Unit>
where S: Freeze,

§

impl<S, Unit> RefUnwindSafe for Vector2D<S, Unit>
where S: RefUnwindSafe, Unit: RefUnwindSafe,

§

impl<S, Unit> Send for Vector2D<S, Unit>
where S: Send, Unit: Send,

§

impl<S, Unit> Sync for Vector2D<S, Unit>
where S: Sync, Unit: Sync,

§

impl<S, Unit> Unpin for Vector2D<S, Unit>
where S: Unpin, Unit: Unpin,

§

impl<S, Unit> UnwindSafe for Vector2D<S, Unit>
where S: UnwindSafe, Unit: 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<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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.