#[repr(C)]pub struct Vector4 {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}
Expand description
A 4-dimensional vector with x
, y
, z
and w
components.
Fields§
§x: f32
§y: f32
§z: f32
§w: f32
Implementations§
source§impl Vector4
impl Vector4
sourcepub fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4
pub fn new(x: f32, y: f32, z: f32, w: f32) -> Vector4
Creates a new Vector4
with the given x
, y
, z
, and w
components.
Arguments
x
- Thex
component of the newVector4
.y
- They
component of the newVector4
.z
- Thez
component of the newVector4
.w
- Thew
component of the newVector4
.
Examples
use cgl_rs::math::Vector4;
let vec = Vector4::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(vec.x, 1.0);
assert_eq!(vec.y, 2.0);
assert_eq!(vec.z, 3.0);
assert_eq!(vec.w, 4.0);
sourcepub fn from_vec3(vec: Vector3, w: f32) -> Vector4
pub fn from_vec3(vec: Vector3, w: f32) -> Vector4
Creates a new Vector4
from a Vector3
and a w
component.
Arguments
vec
- TheVector3
to use as thex
,y
, andz
components of the newVector4
.w
- Thew
component of the newVector4
.
Examples
use cgl_rs::math::{Vector3, Vector4};
let vec3 = Vector3::new(1.0, 2.0, 3.0);
let vec4 = Vector4::from_vec3(vec3, 4.0);
assert_eq!(vec4.x, 1.0);
assert_eq!(vec4.y, 2.0);
assert_eq!(vec4.z, 3.0);
assert_eq!(vec4.w, 4.0);
sourcepub fn from_vec2(vec: Vector2, z: f32, w: f32) -> Vector4
pub fn from_vec2(vec: Vector2, z: f32, w: f32) -> Vector4
Creates a new Vector4
from a Vector2
, z
, and w
components.
Arguments
vec
- TheVector2
to use as thex
andy
components of the newVector4
.z
- Thez
component of the newVector4
.w
- Thew
component of the newVector4
.
Examples
use cgl_rs::math::{Vector2, Vector4};
let vec2 = Vector2::new(1.0, 2.0);
let vec4 = Vector4::from_vec2(vec2, 3.0, 4.0);
assert_eq!(vec4.x, 1.0);
assert_eq!(vec4.y, 2.0);
assert_eq!(vec4.z, 3.0);
assert_eq!(vec4.w, 4.0);
sourcepub fn zero() -> Vector4
pub fn zero() -> Vector4
Returns a new Vector4
with all components set to 0.0
.
Examples
use cgl_rs::math::Vector4;
let vec = Vector4::zero();
assert_eq!(vec.x, 0.0);
assert_eq!(vec.y, 0.0);
assert_eq!(vec.z, 0.0);
assert_eq!(vec.w, 0.0);
Trait Implementations§
source§impl IndexMut<usize> for Vector4
impl IndexMut<usize> for Vector4
source§fn index_mut(&mut self, index: usize) -> &mut Self::Output
fn index_mut(&mut self, index: usize) -> &mut Self::Output
Returns a mutable reference to the element at the given index
of this Vector4
.
Arguments
index
- The index of the element to retrieve.
Panics
Panics if index
is greater than or equal to 4.
Examples
use cgl_rs::math::Vector4;
let mut vec = Vector4::new(1.0, 2.0, 3.0, 4.0);
vec[0] = 5.0;
assert_eq!(vec[0], 5.0);
source§impl PartialEq<Vector4> for Vector4
impl PartialEq<Vector4> for Vector4
impl Copy for Vector4
impl StructuralPartialEq for Vector4
Auto Trait Implementations§
impl RefUnwindSafe for Vector4
impl Send for Vector4
impl Sync for Vector4
impl Unpin for Vector4
impl UnwindSafe for Vector4
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