pub struct Vec3 {
pub x: f64,
pub y: f64,
pub z: f64,
}Expand description
A 3-dimensional vector type.
Provides common vector operations such as addition, subtraction, scalar and component-wise multiplication, normalization, dot and cross products.
§Examples
use lars::Vec3;
let a = Vec3::new(1.0, 0.0, 0.0);
let b = Vec3::new(0.0, 1.0, 0.0);
let cross = a.cross(&b); // Vec3 { x: 0.0, y: 0.0, z: 1.0 }
let dot = a.dot(&b); // 0.0Fields§
§x: f64X component of the vector.
y: f64Y component of the vector.
z: f64Z component of the vector.
Implementations§
Source§impl Vec3
impl Vec3
Sourcepub fn mag(&self) -> f64
pub fn mag(&self) -> f64
Returns the magnitude (length) of the vector.
§Examples
use lars::Vec3;
let v = Vec3::new(3.0, 4.0, 0.0);
assert_eq!(v.mag(), 5.0);Sourcepub fn map<F>(&self, f: F) -> Vec3
pub fn map<F>(&self, f: F) -> Vec3
Applies a function f to each component (x, y, and z) of the vector.
§Examples
use lars::Vec3;
let v = Vec3::new(1.0, 2.0, 3.0);
let squared = v.map(|x| x * x);
assert_eq!(squared, Vec3::new(1.0, 4.0, 9.0));Trait Implementations§
Source§impl Mul<Vec3> for f64
Implements scalar multiplication of a vector by a float (f64).
impl Mul<Vec3> for f64
Implements scalar multiplication of a vector by a float (f64).
This enables f64 * Vec3 syntax.
§Examples
use lars::Vec3;
let v = Vec3::new(1.0, 2.0, 3.0);
let scaled = 2.0 * v;
assert_eq!(scaled, Vec3::new(2.0, 4.0, 6.0));Source§impl Mul for Vec3
Implements component-wise multiplication between two Vec3s.
impl Mul for Vec3
Implements component-wise multiplication between two Vec3s.
This is useful for operations such as color blending or per-component scaling.
§Examples
use lars::Vec3;
let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(2.0, 0.5, 4.0);
assert_eq!(a * b, Vec3::new(2.0, 1.0, 12.0));Source§impl PartialOrd for Vec3
impl PartialOrd for Vec3
impl Copy for Vec3
Auto Trait Implementations§
impl Freeze for Vec3
impl RefUnwindSafe for Vec3
impl Send for Vec3
impl Sync for Vec3
impl Unpin for Vec3
impl UnwindSafe for Vec3
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
Mutably borrows from an owned value. Read more