Struct cgl_rs::math::Vector4

source ·
#[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

source

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 - The x component of the new Vector4.
  • y - The y component of the new Vector4.
  • z - The z component of the new Vector4.
  • w - The w component of the new Vector4.
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);
source

pub fn from_vec3(vec: Vector3, w: f32) -> Vector4

Creates a new Vector4 from a Vector3 and a w component.

Arguments
  • vec - The Vector3 to use as the x, y, and z components of the new Vector4.
  • w - The w component of the new Vector4.
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);
source

pub fn from_vec2(vec: Vector2, z: f32, w: f32) -> Vector4

Creates a new Vector4 from a Vector2, z, and w components.

Arguments
  • vec - The Vector2 to use as the x and y components of the new Vector4.
  • z - The z component of the new Vector4.
  • w - The w component of the new Vector4.
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);
source

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);
source

pub fn one() -> Vector4

Returns a new Vector4 with all components set to 1.0.

Examples
use cgl_rs::math::Vector4;

let vec = Vector4::one();
assert_eq!(vec.x, 1.0);
assert_eq!(vec.y, 1.0);
assert_eq!(vec.z, 1.0);
assert_eq!(vec.w, 1.0);
source

pub fn xyz(&self) -> Vector3

Extracts the x, y, and z components of the Vector4 as a new Vector3.

Examples
use cgl_rs::math::{Vector3, Vector4};

let vec4 = Vector4::new(1.0, 2.0, 3.0, 4.0);
let vec3 = vec4.xyz();
assert_eq!(vec3.x, 1.0);
assert_eq!(vec3.y, 2.0);
assert_eq!(vec3.z, 3.0);

Trait Implementations§

source§

impl Add<Vector4> for Vector4

§

type Output = Vector4

The resulting type after applying the + operator.
source§

fn add(self, rhs: Vector4) -> Vector4

Performs the + operation. Read more
source§

impl Clone for Vector4

source§

fn clone(&self) -> Vector4

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 Vector4

source§

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

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

impl Div<Vector4> for Vector4

§

type Output = Vector4

The resulting type after applying the / operator.
source§

fn div(self, rhs: Vector4) -> Vector4

Performs the / operation. Read more
source§

impl Div<f32> for Vector4

§

type Output = Vector4

The resulting type after applying the / operator.
source§

fn div(self, rhs: f32) -> Vector4

Performs the / operation. Read more
source§

impl Index<usize> for Vector4

source§

fn index(&self, index: usize) -> &Self::Output

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 vec = Vector4::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(vec[0], 1.0);
assert_eq!(vec[1], 2.0);
assert_eq!(vec[2], 3.0);
assert_eq!(vec[3], 4.0);
§

type Output = f32

The returned type after indexing.
source§

impl IndexMut<usize> for Vector4

source§

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 Mul<Vector4> for Vector4

§

type Output = Vector4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Vector4) -> Vector4

Performs the * operation. Read more
source§

impl Mul<f32> for Vector4

§

type Output = Vector4

The resulting type after applying the * operator.
source§

fn mul(self, rhs: f32) -> Vector4

Performs the * operation. Read more
source§

impl Neg for Vector4

§

type Output = Vector4

The resulting type after applying the - operator.
source§

fn neg(self) -> Vector4

Performs the unary - operation. Read more
source§

impl PartialEq<Vector4> for Vector4

source§

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

§

type Output = Vector4

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Vector4) -> Vector4

Performs the - operation. Read more
source§

impl Copy for Vector4

source§

impl StructuralPartialEq for Vector4

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