Struct Vector3

Source
pub struct Vector3<T: Vector3Coordinate> { /* private fields */ }
Expand description

Represents a vector in 3D space.

Implementations§

Source§

impl<T: Vector3Coordinate + Float> Vector3<T>

Source

pub fn random() -> Self

Generates a random Vector3 with components in the range [0.0, 1.0).

Source

pub fn fuzzy_equal(&self, target: &Self, epsilon: f64) -> bool

Checks if this vector is approximately equal to another vector within a given epsilon.

§Examples
use vec3_rs::Vector3;

let v1 = Vector3::new(0.1, 0.2, 0.3);
let v2 = Vector3::new(0.101, 0.199, 0.299);

let epsilon = 0.01;
let is_approx_equal = v1.fuzzy_equal(&v2, epsilon);
println!("Are v1 and v2 approximately equal? {}", is_approx_equal);
Source

pub fn lerp(&self, target: &Self, alpha: T) -> Self

Linearly interpolates between this vector and another vector by a given ratio.

Source§

impl Vector3<f64>

Source

pub fn normalize(&mut self)

Scales the vector such that its magnitude becomes 1.

Source§

impl Vector3<f32>

Source

pub fn normalize(&mut self)

Scales the vector such that its magnitude becomes 1.

Source§

impl<T: Vector3Coordinate> Vector3<T>

Source

pub fn new(x: T, y: T, z: T) -> Self

Creates a new Vector3 with the specified coordinates.

§Examples
use vec3_rs::Vector3;

let vector3 = Vector3::new(1.0, 2.0, 3.0);
Source

pub fn magnitude(&self) -> f64

Computes the magnitude (length) of the vector.

Source

pub fn dot(&self, target: &Self) -> T

Computes the dot product between this vector and another vector.

Source

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

Computes the cross product between this vector and another vector.

Source

pub fn max(&self, target: &Self) -> Self

Computes the component-wise maximum of this vector and another vector.

Source

pub fn min(&self, target: &Self) -> Self

Computes the component-wise minimum of this vector and another vector.

Source

pub fn angle(&self, target: &Self) -> f64

Computes the angle in radians between this vector and another vector.

Source

pub fn angle_deg(&self, target: &Self) -> f64

Computes the angle in degrees between this vector and another vector.

Source

pub const fn get_x(&self) -> T

Retrieves the X component of the vector.

Source

pub const fn get_y(&self) -> T

Retrieves the Y component of the vector.

Source

pub const fn get_z(&self) -> T

Retrieves the Z component of the vector.

Trait Implementations§

Source§

impl<T: Vector3Coordinate> Add for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Vector3Coordinate> AddAssign for Vector3<T>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: Clone + Vector3Coordinate> Clone for Vector3<T>

Source§

fn clone(&self) -> Vector3<T>

Returns a duplicate 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 + Vector3Coordinate> Debug for Vector3<T>

Source§

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

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

impl<T: Default + Vector3Coordinate> Default for Vector3<T>

Source§

fn default() -> Vector3<T>

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

impl<T: Vector3Coordinate> Display for Vector3<T>

Source§

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

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

impl<T: Vector3Coordinate> Div<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: Vector3Coordinate> Div for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: Vector3Coordinate> DivAssign<T> for Vector3<T>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T: Vector3Coordinate> DivAssign for Vector3<T>

Source§

fn div_assign(&mut self, rhs: Vector3<T>)

Performs the /= operation. Read more
Source§

impl<T: Vector3Coordinate> From<[T; 3]> for Vector3<T>

Source§

fn from(value: [T; 3]) -> Self

Converts to this type from the input type.
Source§

impl<T: Vector3Coordinate> From<(T, T, T)> for Vector3<T>

Source§

fn from(value: (T, T, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: Vector3Coordinate> From<Vector3<T>> for [T; 3]

Source§

fn from(value: Vector3<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Vector3Coordinate> From<Vector3<T>> for (T, T, T)

Source§

fn from(value: Vector3<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Vector3Coordinate> Mul<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Vector3Coordinate> Mul for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: Vector3Coordinate> MulAssign<T> for Vector3<T>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T: Vector3Coordinate> MulAssign for Vector3<T>

Source§

fn mul_assign(&mut self, rhs: Vector3<T>)

Performs the *= operation. Read more
Source§

impl<T: PartialEq + Vector3Coordinate> PartialEq for Vector3<T>

Source§

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

Source§

fn partial_cmp(&self, other: &Vector3<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: Vector3Coordinate> Sub for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: Vector3Coordinate> SubAssign for Vector3<T>

Source§

fn sub_assign(&mut self, rhs: Vector3<T>)

Performs the -= operation. Read more
Source§

impl TryFrom<&str> for Vector3<f64>

Source§

type Error = ParseVector3Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: Vector3Coordinate> TryFrom<Vec<T>> for Vector3<T>

Source§

type Error = ParseVector3Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Vec<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: Copy + Vector3Coordinate> Copy for Vector3<T>

Source§

impl<T: Vector3Coordinate> StructuralPartialEq for Vector3<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector3<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector3<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector3<T>
where T: Send,

§

impl<T> Sync for Vector3<T>
where T: Sync,

§

impl<T> Unpin for Vector3<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector3<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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V