pub struct Vector4 { /* private fields */ }
Implementations§
Source§impl Vector4
impl Vector4
Sourcepub fn from1(v: f32) -> Self
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);
Sourcepub fn from4(x: f32, y: f32, z: f32, w: f32) -> Self
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);
Sourcepub fn x(&self) -> f32
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);
Sourcepub fn y(&self) -> f32
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);
Sourcepub fn z(&self) -> f32
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);
Sourcepub fn w(&self) -> f32
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);
Sourcepub fn floor(&self) -> Vector4
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
Sourcepub fn abs(&self) -> Vector4
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);
Sourcepub fn fract(&self) -> Vector4
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
Sourcepub fn modulo(&self, other: &Vector4) -> Vector4
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
Sourcepub fn modulo_euclidean(&self, other: &Vector4) -> Vector4
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);
Sourcepub fn distance_sq(&self, other: &Vector4) -> f32
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);
Trait Implementations§
Source§impl Add<&Vector4> for &Vector4
impl Add<&Vector4> for &Vector4
Source§fn add(self, other: &Vector4) -> Vector4
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);