Struct Vector

Source
pub struct Vector {
    pub x: Fp,
    pub y: Fp,
}
Expand description

Represents a vector in a 2D space.

Fields§

§x: Fp§y: Fp

Implementations§

Source§

impl Vector

Source

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

Creates a new Vector with the specified x and y components.

§Parameters
  • x: The x-coordinate of the vector.
  • y: The y-coordinate of the vector.
§Returns

A Vector instance with the given x and y components.

§Examples
use fixed32::Fp;
use fixed32_math::Vector;

let v = Vector::new(Fp::from(2), Fp::from(3));
assert_eq!(v.x, Fp::from(2));
assert_eq!(v.y, Fp::from(3));
Source

pub const fn left() -> Self

Returns a Vector pointing to the left (negative x-axis direction).

This is a convenience method to create a vector that represents a direction to the left in 2D space.

§Returns

A Vector instance with x set to -1 and y set to 0.

§Examples
use fixed32::Fp;
use fixed32_math::Vector;

let left = Vector::left();
assert_eq!(left.x, Fp::neg_one());
assert_eq!(left.y, Fp::zero());
Source

pub const fn right() -> Self

Returns a Vector pointing to the right (positive x-axis direction).

This is a convenience method to create a vector that represents a direction to the right in 2D space.

§Returns

A Vector instance with x set to 1 and y set to 0.

§Examples
use fixed32::Fp;
use fixed32_math::Vector;

let right = Vector::right();
assert_eq!(right.x, Fp::one());
assert_eq!(right.y, Fp::zero());
Source

pub const fn up() -> Self

Returns a Vector pointing upwards (positive y-axis direction).

This is a convenience method to create a vector that represents a direction upwards in 2D space.

§Returns

A Vector instance with x set to 0 and y set to 1.

§Examples
use fixed32::Fp;
use fixed32_math::Vector;

let up = Vector::up();
assert_eq!(up.x, Fp::zero());
assert_eq!(up.y, Fp::one());
Source

pub const fn down() -> Self

Returns a Vector pointing downwards (negative y-axis direction).

This is a convenience method to create a vector that represents a direction downwards in 2D space.

§Returns

A Vector instance with x set to 0 and y set to -1.

§Examples
use fixed32::Fp;
use fixed32_math::Vector;

let down = Vector::down();
assert_eq!(down.x, Fp::zero());
assert_eq!(down.y, Fp::neg_one());
Source

pub fn sqr_len(&self) -> Fp

Computes the squared length (magnitude) of the vector.

This method calculates the squared length of the vector, which is the sum of the squares of its x and y components. It is often used for performance reasons when the actual length is not needed, as computing the square root can be costly.

§Returns

The squared length of the vector as an Fp value.

§Examples
use fixed32::Fp;
use fixed32_math::Vector;

let v = Vector::new(Fp::from(3), Fp::from(4));
let sqr_len = v.sqr_len();
assert_eq!(sqr_len, Fp::from(25));
Source

pub fn len(&self) -> Fp

Returns the length of the vector.

Source

pub fn normalize(&self) -> Option<Self>

Returns a normalized vector with length 1. Returns None if the vector is zero-length.

Source

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

Computes the dot product of this vector with another.

Source

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

Computes the magnitude of the cross product in 2D (which is a scalar value).

Source

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

Scales the vector by another vector component-wise.

Source

pub fn rotate(&self, angle: Fp) -> Self

Rotates the vector by the given angle in radians.

Source

pub const fn abs(&self) -> Self

Returns the absolute value of each component of the vector.

Trait Implementations§

Source§

impl Add for Vector

Source§

type Output = Vector

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Vector

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Vector

Source§

fn clone(&self) -> Vector

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 Debug for Vector

Source§

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

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

impl Default for Vector

Source§

fn default() -> Vector

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

impl Display for Vector

Source§

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

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

impl Div<Fp> for Vector

Source§

type Output = Vector

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Fp) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Vector> for i16

Source§

type Output = Vector

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vector) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<i16> for Vector

Source§

type Output = Vector

The resulting type after applying the / operator.
Source§

fn div(self, rhs: i16) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for Vector

Source§

type Output = Vector

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl From<(f32, f32)> for Vector

Source§

fn from(values: (f32, f32)) -> Self

Converts to this type from the input type.
Source§

impl From<(i16, i16)> for Vector

Source§

fn from(values: (i16, i16)) -> Self

Converts to this type from the input type.
Source§

impl Mul<Fp> for Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Fp) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vector> for Fp

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vector> for i16

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<i16> for Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: i16) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Vector

Source§

type Output = Vector

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector

Source§

fn eq(&self, other: &Vector) -> 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 Sub for Vector

Source§

type Output = Vector

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Copy for Vector

Source§

impl Eq for Vector

Source§

impl StructuralPartialEq for Vector

Auto Trait Implementations§

§

impl Freeze for Vector

§

impl RefUnwindSafe for Vector

§

impl Send for Vector

§

impl Sync for Vector

§

impl Unpin for Vector

§

impl UnwindSafe for Vector

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