Struct Vector4

Source
pub struct Vector4 { /* private fields */ }

Implementations§

Source§

impl Vector4

Source

pub fn from1(v: f32) -> Self

Creates Vector4 instance from one float value. x, y, z and w will be set to the same value.

use rmath_rs::Vector4;
let v = Vector4::from1(0.1);
assert_approx_eq!(v.x(), 0.1);
assert_approx_eq!(v.y(), 0.1);
assert_approx_eq!(v.z(), 0.1);
assert_approx_eq!(v.w(), 0.1);
Source

pub fn from4(x: f32, y: f32, z: f32, w: f32) -> Self

Creates Vector4 instance from four float values. x, y, z and w will be set to the value of appropriate parameter.

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
assert_approx_eq!(v.x(), 0.2);
assert_approx_eq!(v.y(), 1.1);
assert_approx_eq!(v.z(), -2.9);
assert_approx_eq!(v.w(), 99.9);
Source

pub fn x(&self) -> f32

Retrieves x component of Vector4.

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
assert_approx_eq!(v.x(), 0.2);
Source

pub fn y(&self) -> f32

Retrieves y component of Vector4.

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
assert_approx_eq!(v.y(), 1.1);
Source

pub fn z(&self) -> f32

Retrieves z component of Vector4.

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
assert_approx_eq!(v.z(), -2.9);
Source

pub fn w(&self) -> f32

Retrieves w component of Vector4.

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
assert_approx_eq!(v.w(), 99.9);
Source

pub fn floor(&self) -> Vector4

Finds the nearest integer less than or equal to the parameter

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
let v2 = v.floor();
assert_approx_eq!(v2.x(), 0.0);
assert_approx_eq!(v2.y(), 1.0);
assert_approx_eq!(v2.z(), -3.0);
assert_approx_eq!(v2.w(), 99.0);

See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/floor.xhtml

Source

pub fn abs(&self) -> Vector4

Finds absolute value of parameter

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
let v2 = v.abs();
assert_approx_eq!(v2.x(), 0.2);
assert_approx_eq!(v2.y(), 1.1);
assert_approx_eq!(v2.z(), 2.9);
assert_approx_eq!(v2.w(), 99.9);
Source

pub fn fract(&self) -> Vector4

Computes the fractional part of the argument

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
let v2 = v.fract();
assert_approx_eq!(v2.x(), 0.2);
assert_approx_eq!(v2.y(), 0.1);
assert_approx_eq!(v2.z(), 0.1);
assert_approx_eq!(v2.w(), 0.9, 1.0e-5); // this one becomes 0.9000015 with regular 1.0e-6 precision :/

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fract.xhtml

Source

pub fn modulo(&self, other: &Vector4) -> Vector4

Computes value of one parameter modulo another. Consistent with GLSL implementation

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
let v2 = Vector4::from1(-1.8);
let v3 = v.modulo(&v2);
assert_approx_eq!(v3.x(), -1.6);
assert_approx_eq!(v3.y(), -0.7);
assert_approx_eq!(v3.z(), -1.1);
assert_approx_eq!(v3.w(), -0.9, 1.0e-5);

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mod.xhtml

Source

pub fn modulo_euclidean(&self, other: &Vector4) -> Vector4

Computes value of one parameter modulo another. Consistent with Euclidean division algorithm.

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
let v2 = Vector4::from1(-1.8);
let v3 = v.modulo_euclidean(&v2);
assert_approx_eq!(v3.x(), 0.2);
assert_approx_eq!(v3.y(), 1.1);
assert_approx_eq!(v3.z(), 0.7);
assert_approx_eq!(v3.w(), 0.9, 1.0e-5);
Source

pub fn distance_sq(&self, other: &Vector4) -> f32

Computes value of distance squared between two vectors

use rmath_rs::Vector4;
let v1 = Vector4::from4(0.2, 1.1, -2.9, 99.9);
let v2 = Vector4::from4(0.9, 1.8, 2.9, -14.4);
let d = v1.distance_sq(&v2);
assert_approx_eq!(d, 13099.11);
Source

pub fn distance(&self, other: &Vector4) -> f32

Computes value of distance between two vectors

use rmath_rs::Vector4;
let v1 = Vector4::from4(0.2, 1.1, -2.9, 99.9);
let v2 = Vector4::from4(0.9, 1.8, 2.9, -14.4);
let d = v1.distance(&v2);
assert_approx_eq!(d, 114.45134, 1.0e-5);

Trait Implementations§

Source§

impl Add<&Vector4> for &Vector4

Source§

fn add(self, other: &Vector4) -> Vector4

Implements Add trait for Vector4. Operator +(Vector4, Vector4).

use rmath_rs::Vector4;
let v1 = Vector4::from1(0.1);
let v2 = Vector4::from1(1.8);
let v3 = &v1 + &v2;
assert_approx_eq!(v3.x(), 1.9);
assert_approx_eq!(v3.y(), 1.9);
assert_approx_eq!(v3.z(), 1.9);
assert_approx_eq!(v3.w(), 1.9);
Source§

type Output = Vector4

The resulting type after applying the + operator.
Source§

impl Add<f32> for &Vector4

Source§

fn add(self, other: f32) -> Vector4

Implements Add trait for Vector4. Operator +(Vector4, f32).

use rmath_rs::Vector4;
let v1 = Vector4::from1(0.1);
let v2 = &v1 + 1.8;
assert_approx_eq!(v2.x(), 1.9);
Source§

type Output = Vector4

The resulting type after applying the + operator.
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<f32> for &Vector4

Source§

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

Implements Div trait for Vector4. Operator /(Vector4, f32).

use rmath_rs::Vector4;
let v1 = Vector4::from1(0.1);
let v2 = &v1 / 1.8;
assert_approx_eq!(v2.x(), 0.055555556);
Source§

type Output = Vector4

The resulting type after applying the / operator.
Source§

impl Div for &Vector4

Source§

fn div(self, other: &Vector4) -> Vector4

Implements Div trait for Vector4. Operator /(Vector4, Vector4).

use rmath_rs::Vector4;
let v1 = Vector4::from1(0.1);
let v2 = Vector4::from1(1.8);
let v3 = &v1 / &v2;
assert_approx_eq!(v3.x(), 0.055555556);
Source§

type Output = Vector4

The resulting type after applying the / operator.
Source§

impl Mul<f32> for &Vector4

Source§

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

Implements Mul trait for Vector4. Operator *(Vector4, f32).

use rmath_rs::Vector4;
let v1 = Vector4::from1(0.1);
let v2 = &v1 * 1.8;
assert_approx_eq!(v2.x(), 0.18);
Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

impl Mul for &Vector4

Source§

fn mul(self, other: &Vector4) -> Vector4

Implements Mul trait for Vector4. Operator *(Vector4, Vector4).

use rmath_rs::Vector4;
let v1 = Vector4::from1(0.1);
let v2 = Vector4::from1(1.8);
let v3 = &v1 * &v2;
assert_approx_eq!(v3.x(), 0.18);
Source§

type Output = Vector4

The resulting type after applying the * operator.
Source§

impl Neg for &Vector4

Source§

fn neg(self) -> Vector4

Implements Neg trait for Vector4. Operator -(Vector4).

use rmath_rs::Vector4;
let v = Vector4::from4(0.2, 1.1, -2.9, 99.9);
let v2 = -&v;
assert_approx_eq!(v2.x(), -0.2);
assert_approx_eq!(v2.y(), -1.1);
assert_approx_eq!(v2.z(), 2.9);
assert_approx_eq!(v2.w(), -99.9);
Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

impl Sub<f32> for &Vector4

Source§

fn sub(self, other: f32) -> Vector4

Implements Sub trait for Vector4. Operator -(Vector4, f32).

use rmath_rs::Vector4;
let v1 = Vector4::from1(0.1);
let v2 = &v1 - 1.8;
assert_approx_eq!(v2.x(), -1.7);
Source§

type Output = Vector4

The resulting type after applying the - operator.
Source§

impl Sub for &Vector4

Source§

fn sub(self, other: &Vector4) -> Vector4

Implements Sub trait for Vector4. Operator -(Vector4, Vector4).

use rmath_rs::Vector4;
let v1 = Vector4::from1(0.1);
let v2 = Vector4::from1(1.8);
let v3 = &v1 - &v2;
assert_approx_eq!(v3.x(), -1.7);
Source§

type Output = Vector4

The resulting type after applying the - operator.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.