pub struct Vector4 { /* fields omitted */ }
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);
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);
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);
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);
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);
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);
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
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);
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);
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fract.xhtml
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
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);
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);
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);
Formats the value using the given formatter. Read more
The resulting type after applying the +
operator.
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);
The resulting type after applying the +
operator.
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);
The resulting type after applying the -
operator.
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);
The resulting type after applying the -
operator.
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);
The resulting type after applying the *
operator.
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);
The resulting type after applying the *
operator.
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);
The resulting type after applying the /
operator.
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);
The resulting type after applying the /
operator.
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);
The resulting type after applying the -
operator.
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);
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static