#[repr(C)]pub struct Vector3 {
pub x: f32,
pub y: f32,
pub z: f32,
}Expand description
An owning representation of a 3-component Euclidean vector.
Like Vec3, the Vector3 object represents a Euclidean vector in
3D. Unlike the Vec3, this is an owning representation that stores the
actual content of the vector.
Fields§
§x: f32The X-component of the vector.
y: f32The Y-component of the vector.
z: f32The Z-component of the vector.
Implementations§
source§impl Vector3
impl Vector3
sourcepub fn from_points(from: &Point3, to: &Point3) -> Self
pub fn from_points(from: &Point3, to: &Point3) -> Self
Create a new vector from two points
§Parameters
from- The point to begin drawing the vector fromto- The point to end drawing the vector at`
source§impl Vector3
impl Vector3
sourcepub const ZERO: Vector3 = _
pub const ZERO: Vector3 = _
A constant for a Null vector, which has magnitude 0 and exists at the origin.
sourcepub const UNIT_X: Vector3 = _
pub const UNIT_X: Vector3 = _
A constant for a unit vector in the positive X-direction.
sourcepub const UNIT_Y: Vector3 = _
pub const UNIT_Y: Vector3 = _
A constant for a unit vector in the positive Y-direction.
sourcepub const UNIT_Z: Vector3 = _
pub const UNIT_Z: Vector3 = _
A constant for a unit vector in the positive Z-direction.
sourcepub const NEG_UNIT_X: Vector3 = _
pub const NEG_UNIT_X: Vector3 = _
A constant for a unit vector in the negative X-direction.
sourcepub const NEG_UNIT_Y: Vector3 = _
pub const NEG_UNIT_Y: Vector3 = _
A constant for a unit vector in the negative Y-direction.
sourcepub const NEG_UNIT_Z: Vector3 = _
pub const NEG_UNIT_Z: Vector3 = _
A constant for a unit vector in the negative Z-direction.
sourcepub const fn new(x: f32, y: f32, z: f32) -> Self
pub const fn new(x: f32, y: f32, z: f32) -> Self
Constructs this vector from an x, y, and z coordinate.
§Parameters
x- the x-componenty- the y-componentz- the z-component
sourcepub const fn from_array(array: &[f32; 3]) -> Self
pub const fn from_array(array: &[f32; 3]) -> Self
sourcepub const fn from_slice(slice: &[f32]) -> Result<Self, VecError>
pub const fn from_slice(slice: &[f32]) -> Result<Self, VecError>
sourcepub const unsafe fn from_slice_unchecked(slice: &[f32]) -> Self
pub const unsafe fn from_slice_unchecked(slice: &[f32]) -> Self
sourcepub fn from_vec3i(other: &Vec3i) -> Self
pub fn from_vec3i(other: &Vec3i) -> Self
sourcepub fn from_vec3u(other: &Vec3u) -> Self
pub fn from_vec3u(other: &Vec3u) -> Self
sourcepub fn as_mut_vec3(&mut self) -> &mut Vec3
pub fn as_mut_vec3(&mut self) -> &mut Vec3
Returns this vector as a mutable Vec3.
sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
Returns this vector as a mutable slice of f32.
Methods from Deref<Target = Vec3>§
sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
sourcepub fn as_mut_ptr(&mut self) -> *mut f32
pub fn as_mut_ptr(&mut self) -> *mut f32
Returns this vector as a mutable ptr of f32.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut f32>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut f32>
Returns a mutable iterator over the vector.
sourcepub fn x_mut(&mut self) -> &mut f32
pub fn x_mut(&mut self) -> &mut f32
Returns a mutable reference to the X-coordinate of this 3-component vector.
sourcepub fn y_mut(&mut self) -> &mut f32
pub fn y_mut(&mut self) -> &mut f32
Returns a mutable reference to the Y-coordinate of this 3-component vector.
sourcepub fn z_mut(&mut self) -> &mut f32
pub fn z_mut(&mut self) -> &mut f32
Returns a mutable reference to the Z-coordinate of this 3-component vector.
sourcepub fn xy_mut(&mut self) -> &mut Vec2
pub fn xy_mut(&mut self) -> &mut Vec2
Returns a mutable reference to the xy coordinates of this vector.
sourcepub fn yz_mut(&mut self) -> &mut Vec2
pub fn yz_mut(&mut self) -> &mut Vec2
Returns a mutable reference to the yz coordinates of this vector.
sourcepub fn square_magnitude(&self) -> f32
pub fn square_magnitude(&self) -> f32
Computes the square magnitude of this two-component vector.
sourcepub fn magnitude(&self) -> f32
pub fn magnitude(&self) -> f32
Computes the magnitude of this vector.
Where possible, consider using Vec3::square_magnitude as this will
avoid the need to compute the square-root.
sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Queries whether this vector is normalized (e.g. has a magnitude of 1).
sourcepub fn normalized(&self) -> Vector3
pub fn normalized(&self) -> Vector3
Returns normalized vector.
sourcepub fn is_finite(&self) -> bool
pub fn is_finite(&self) -> bool
Returns whether all components of this Vec are finite.
§Example
Basic use:
let finite = Vector3::UNIT_X;
let not_finite = Vector3::new(f32::INFINITY, 3.0, 0.0);
assert!(finite.is_finite());
assert!(!not_finite.is_finite());sourcepub fn is_infinite(&self) -> bool
pub fn is_infinite(&self) -> bool
Trait Implementations§
source§impl AddAssign<&Vec3> for Vector3
impl AddAssign<&Vec3> for Vector3
source§fn add_assign(&mut self, rhs: &Vec3)
fn add_assign(&mut self, rhs: &Vec3)
+= operation. Read moresource§impl AddAssign<&Vector3> for Vector3
impl AddAssign<&Vector3> for Vector3
source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+= operation. Read moresource§impl AddAssign for Vector3
impl AddAssign for Vector3
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl BorrowMut<Vec3> for Vector3
impl BorrowMut<Vec3> for Vector3
source§fn borrow_mut(&mut self) -> &mut Vec3
fn borrow_mut(&mut self) -> &mut Vec3
source§impl DivAssign<f32> for Vector3
impl DivAssign<f32> for Vector3
source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moresource§impl MulAssign<f32> for Vector3
impl MulAssign<f32> for Vector3
source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moresource§impl PartialOrd for Vector3
impl PartialOrd for Vector3
source§impl RemAssign<f32> for Vector3
impl RemAssign<f32> for Vector3
source§fn rem_assign(&mut self, rhs: f32)
fn rem_assign(&mut self, rhs: f32)
%= operation. Read moresource§impl SubAssign<&Vec3> for Vector3
impl SubAssign<&Vec3> for Vector3
source§fn sub_assign(&mut self, rhs: &Vec3)
fn sub_assign(&mut self, rhs: &Vec3)
-= operation. Read moresource§impl SubAssign<&Vector3> for Vector3
impl SubAssign<&Vector3> for Vector3
source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-= operation. Read moresource§impl SubAssign for Vector3
impl SubAssign for Vector3
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreimpl Copy for Vector3
impl StructuralPartialEq for Vector3
Auto Trait Implementations§
impl Freeze for Vector3
impl RefUnwindSafe for Vector3
impl Send for Vector3
impl Sync for Vector3
impl Unpin for Vector3
impl UnwindSafe for Vector3
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)