pub struct Vector3 { /* private fields */ }
Expand description
Represents a vector in 3D space.
Doesn’t allow for NaN coordinates.
Implementations§
source§impl Vector3
impl Vector3
pub fn from_i32(x: i32, y: i32, z: i32) -> Self
pub fn from_u32(x: u32, y: u32, z: u32) -> Self
pub fn from_i64(x: i64, y: i64, z: i64) -> Self
pub fn from_u64(x: u64, y: u64, z: u64) -> Self
sourcepub fn lerp(&self, target: &Self, alpha: f64) -> Self
pub fn lerp(&self, target: &Self, alpha: f64) -> Self
Linearly interpolates between this vector and another vector by a given ratio.
sourcepub fn dot(&self, target: &Self) -> f64
pub fn dot(&self, target: &Self) -> f64
Computes the dot product between this vector and another vector.
sourcepub fn cross(&self, target: &Self) -> Vector3
pub fn cross(&self, target: &Self) -> Vector3
Computes the cross product between this vector and another vector.
sourcepub fn max(&self, target: &Self) -> Self
pub fn max(&self, target: &Self) -> Self
Computes the component-wise maximum of this vector and another vector.
sourcepub fn min(&self, target: &Self) -> Self
pub fn min(&self, target: &Self) -> Self
Computes the component-wise minimum of this vector and another vector.
sourcepub fn angle(&self, target: &Self) -> f64
pub fn angle(&self, target: &Self) -> f64
Computes the angle in radians between this vector and another vector.
sourcepub fn angle_deg(&self, target: &Self) -> f64
pub fn angle_deg(&self, target: &Self) -> f64
Computes the angle in degrees between this vector and another vector.
sourcepub fn fuzzy_equal(&self, target: &Self, epsilon: f64) -> bool
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);
Trait Implementations§
source§impl Add<Vector3> for Vector3
impl Add<Vector3> for Vector3
Implementation of addition (+
) operation between two Vector3
instances.
source§impl AddAssign<Vector3> for Vector3
impl AddAssign<Vector3> for Vector3
Implementation of addition assignment (+=
) operation for Vector3
.
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Adds the components of another Vector3
to this Vector3
instance in-place.
source§impl Div<Vector3> for Vector3
impl Div<Vector3> for Vector3
Implementation of division (/
) operation between two Vector3
instances.
source§impl Div<f64> for Vector3
impl Div<f64> for Vector3
Implementation of division (/
) operation between a Vector3
and a scalar value.
source§impl DivAssign<Vector3> for Vector3
impl DivAssign<Vector3> for Vector3
Implementation of division assignment (/=
) operation between two Vector3
instances.
source§fn div_assign(&mut self, rhs: Vector3)
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
impl DivAssign<f64> for Vector3
Implementation of division assignment (/=
) operation for Vector3
with a scalar.
source§fn div_assign(&mut self, rhs: f64)
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 Mul<Vector3> for Vector3
impl Mul<Vector3> for Vector3
Implementation of multiplication (*
) operation between two Vector3
instances.
source§impl Mul<f64> for Vector3
impl Mul<f64> for Vector3
Implementation of multiplication (*
) operation between a Vector3
and a scalar value.
source§impl MulAssign<Vector3> for Vector3
impl MulAssign<Vector3> for Vector3
Implementation of multiplication assignment (*=
) operation between two Vector3
instances.
source§fn mul_assign(&mut self, rhs: Vector3)
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
impl MulAssign<f64> for Vector3
Implementation of multiplication assignment (*=
) operation for Vector3
with a scalar.
source§fn mul_assign(&mut self, rhs: f64)
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
impl PartialEq<Vector3> for Vector3
source§impl Sub<Vector3> for Vector3
impl Sub<Vector3> for Vector3
Implementation of subtraction (-
) operation between two Vector3
instances.
source§impl SubAssign<Vector3> for Vector3
impl SubAssign<Vector3> for Vector3
Implementation of subtraction assignment (-=
) operation for Vector3
.
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Subtracts the components of another Vector3
from this Vector3
instance in-place.