Struct fixed32_math::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
impl Vector
sourcepub fn new(x: Fp, y: Fp) -> Self
pub 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));
sourcepub fn left() -> Self
pub 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());
sourcepub fn right() -> Self
pub 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());
sourcepub fn up() -> Self
pub 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());
sourcepub fn down() -> Self
pub 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());
sourcepub fn sqr_len(&self) -> Fp
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));
sourcepub fn normalize(&self) -> Option<Self>
pub fn normalize(&self) -> Option<Self>
Returns a normalized vector with length 1. Returns None
if the vector is zero-length.
Trait Implementations§
source§impl AddAssign for Vector
impl AddAssign for Vector
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreimpl Copy for Vector
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)