Struct rgx::math::algebra::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) -> Selfwhere S: One + Float + Div + Mul,

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

source

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

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

source

pub fn dot(a: Self, b: Self) -> <S as Add>::Outputwhere 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) -> Swhere 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<S, U> Add<Vector2D<S, U>> for Vector2D<S, U>where S: Add<Output = S> + Copy,

§

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> Add<Vector2D<T, ()>> for Rect<T>where T: Add<Output = T> + Copy,

§

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<f32, ()>> for Line

§

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<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,

§

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<f32, ()>> 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,

§

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<f32, ()>> for Transform2D

§

type Output = Vector2D<f32, ()>

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<f32, ()>> 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.));
§

type Output = Vector2D<f32, ()>

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<Vector2D<S, U>> for Vector2D<S, U>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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,

§

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

§

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> Sub<Vector2D<T, ()>> for Rect<T>where T: Sub<Output = T> + Copy,

§

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<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> 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.