Struct Vector4D

Source
pub struct Vector4D {
    pub x: f64,
    pub y: f64,
    pub z: f64,
    pub t: f64,
}

Fields§

§x: f64§y: f64§z: f64§t: f64

Implementations§

Source§

impl Vector4D

Source

pub fn new(x: f64, y: f64, z: f64, t: f64) -> Vector4D

This creates a new 4d vector with the four given entries.

Source

pub fn length_l1(&self) -> f64

This gives back the l1 length of a 4d vector, i.e. the maximum of absolute values of its components.

§Example:
use bb_geometry::vector4d::Vector4D;
let length = Vector4D::new(-5.0, 4.3, -2.2, 0.0).length_l1();
assert_eq!(length, 5.0);
Source

pub fn is_close_to_zero(self: &Vector4D) -> bool

This checks whether a 4d vector is close to the zero vector, up to crate::ALMOST_ZERO

§Example:
use bb_geometry::ALMOST_ZERO;
use bb_geometry::vector4d::Vector4D;
let a = Vector4D::new(ALMOST_ZERO, ALMOST_ZERO, ALMOST_ZERO, ALMOST_ZERO);
let b = Vector4D::new(0.99 * ALMOST_ZERO, 0.99 * ALMOST_ZERO, 0.99 * ALMOST_ZERO, 0.99 * ALMOST_ZERO);
assert_eq!(a.is_close_to_zero(), false);
assert_eq!(b.is_close_to_zero(), true);
Source

pub fn plus(self: &Vector4D, a: &Vector4D) -> Vector4D

This adds two 4d vectors

§Example:
use bb_geometry::vector4d::Vector4D;
let a = Vector4D::new(1.0, 2.0, 3.0, 4.0);
let b = Vector4D::new(-1.0, 4.0, 2.5, -3.1);
let c = Vector4D::new(0.0, 6.0, 5.5, 0.9);
assert!(a.plus(&b).almost_equals(&c));
Source

pub fn minus(self: &Vector4D, a: &Vector4D) -> Vector4D

This subtracts two 4d vectors

§Example:
use bb_geometry::vector4d::Vector4D;
let a = Vector4D::new(1.0, 2.0, 3.0, 4.0);
let b = Vector4D::new(-1.0, 4.0, 2.5, -3.1);
let c = Vector4D::new(2.0, -2.0, 0.5, 7.1);
assert!(a.minus(&b).almost_equals(&c));
Source

pub fn almost_equals(self: &Vector4D, a: &Vector4D) -> bool

This compares two 4d vectors up to crate::ALMOST_ZERO.

§Example:
use bb_geometry::vector4d::Vector4D;
let a = Vector4D::new(1.0, 2.0, 3.0, 4.0);
let b = Vector4D::new(1.00001, 2.0, 3.0, 4.0);
let c = Vector4D::new(1.0000000001, 2.0, 3.0, 4.0);
assert_eq!(a.almost_equals(&b), false);
assert_eq!(a.almost_equals(&c), true);
Source

pub fn revert(&self) -> Vector4D

This replaces a 4d vector with its negative

§Examples
use bb_geometry::vector4d::Vector4D;
let a = Vector4D::new(1.0, 2.0, 3.0, 4.0);
let b = Vector4D::new(-1.0, -2.0, -3.0, -4.0);
assert!(a.revert().almost_equals(&b));
Source

pub fn generate_random_vectors(n: usize) -> Vec<Vector4D>

This generates a 4d vector of length n containing randomly generated 4d vectors.

§Example:
use bb_geometry::vector4d::Vector4D;
let n = 10;
let list = Vector4D::generate_random_vectors(n);
assert_eq!(list.len(), n);
Source

pub fn random_vector() -> Vector4D

This generates a random 4d vector with entire between -1.0 and 1.0.

§Example:
use bb_geometry::vector4d::Vector4D;
let a = Vector4D::random_vector();
assert!(a.length_l1() <= 1.0);

Trait Implementations§

Source§

impl Debug for Vector4D

Source§

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

Formats the value using the given formatter. Read more

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V