Struct vec3_rs::Vector3

source ·
pub struct Vector3 { /* private fields */ }
Expand description

Represents a vector in 3D space.

Doesn’t allow for NaN coordinates.

Implementations§

source§

impl Vector3

source

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

Creates a new Vector3 with the specified coordinates.

Panics

Panics if any of the coordinates is NaN.

Examples
use vec3_rs::Vector3;

let v = Vector3::new(1.0, 2.0, 3.0);
source

pub fn from_i32(x: i32, y: i32, z: i32) -> Self

source

pub fn from_u32(x: u32, y: u32, z: u32) -> Self

source

pub fn from_i64(x: i64, y: i64, z: i64) -> Self

source

pub fn from_u64(x: u64, y: u64, z: u64) -> Self

source

pub fn random() -> Self

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

source

pub fn normalize(&mut self)

Scales the vector such that its magnitude becomes 1.

source

pub fn magnitude(&self) -> f64

Computes the magnitude (length) of the vector.

source

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

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

source

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

Computes the dot product between this vector and another vector.

source

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

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 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 get_x(&self) -> f64

Retrieves the X component of the vector.

source

pub fn get_y(&self) -> f64

Retrieves the Y component of the vector.

source

pub fn get_z(&self) -> f64

Retrieves the Z component of the vector.

Trait Implementations§

source§

impl Add<Vector3> for Vector3

Implementation of addition (+) operation between two Vector3 instances.

source§

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

Adds two Vector3 instances component-wise.

§

type Output = Vector3

The resulting type after applying the + operator.
source§

impl AddAssign<Vector3> for Vector3

Implementation of addition assignment (+=) operation for Vector3.

source§

fn add_assign(&mut self, rhs: Self)

Adds the components of another Vector3 to this Vector3 instance in-place.

source§

impl Clone for Vector3

source§

fn clone(&self) -> Vector3

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 Vector3

source§

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

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

impl Default for Vector3

source§

fn default() -> Vector3

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

impl Display for Vector3

source§

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

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

impl Div<Vector3> for Vector3

Implementation of division (/) operation between two Vector3 instances.

source§

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

Divides each component of a Vector3 by the corresponding component of another. Returns None if any component of the divisor is NaN.

§

type Output = Option<Vector3>

The resulting type after applying the / operator.
source§

impl Div<f64> for Vector3

Implementation of division (/) operation between a Vector3 and a scalar value.

source§

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

Divides each component of a Vector3 by a scalar value. Returns None if the divisor is NaN.

§

type Output = Option<Vector3>

The resulting type after applying the / operator.
source§

impl DivAssign<Vector3> for Vector3

Implementation of division assignment (/=) operation between two Vector3 instances.

source§

fn div_assign(&mut self, rhs: Vector3)

Divides each component of this Vector3 instance by the corresponding component of another in-place.

Panics

Panics if any component of the divisor becomes NaN.

source§

impl DivAssign<f64> for Vector3

Implementation of division assignment (/=) operation for Vector3 with a scalar.

source§

fn div_assign(&mut self, rhs: f64)

Divides each component of this Vector3 instance by a scalar value in-place.

Panics

Panics if any resulting component becomes NaN.

source§

impl From<[f64; 3]> for Vector3

source§

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

Converts to this type from the input type.
source§

impl From<(f64, f64, f64)> for Vector3

source§

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

Converts to this type from the input type.
source§

impl From<Vector3> for [f64; 3]

source§

fn from(value: Vector3) -> Self

Converts to this type from the input type.
source§

impl From<Vector3> for (f64, f64, f64)

source§

fn from(value: Vector3) -> Self

Converts to this type from the input type.
source§

impl Mul<Vector3> for Vector3

Implementation of multiplication (*) operation between two Vector3 instances.

source§

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

Multiplies two Vector3 instances component-wise.

§

type Output = Vector3

The resulting type after applying the * operator.
source§

impl Mul<f64> for Vector3

Implementation of multiplication (*) operation between a Vector3 and a scalar value.

source§

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

Multiplies each component of a Vector3 by a scalar value.

§

type Output = Vector3

The resulting type after applying the * operator.
source§

impl MulAssign<Vector3> for Vector3

Implementation of multiplication assignment (*=) operation between two Vector3 instances.

source§

fn mul_assign(&mut self, rhs: Vector3)

Multiplies each component of this Vector3 instance by the corresponding component of another in-place.

source§

impl MulAssign<f64> for Vector3

Implementation of multiplication assignment (*=) operation for Vector3 with a scalar.

source§

fn mul_assign(&mut self, rhs: f64)

Multiplies each component of this Vector3 instance by a scalar value in-place.

source§

impl PartialEq<Vector3> for Vector3

source§

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

Implementation of subtraction (-) operation between two Vector3 instances.

source§

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

Subtracts the components of the second Vector3 from the first Vector3 component-wise.

§

type Output = Vector3

The resulting type after applying the - operator.
source§

impl SubAssign<Vector3> for Vector3

Implementation of subtraction assignment (-=) operation for Vector3.

source§

fn sub_assign(&mut self, rhs: Self)

Subtracts the components of another Vector3 from this Vector3 instance in-place.

source§

impl TryFrom<&str> for Vector3

§

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 TryFrom<Vec<f64, Global>> for Vector3

§

type Error = ParseVector3Error

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

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

Performs the conversion.
source§

impl StructuralPartialEq for Vector3

Auto Trait Implementations§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V