honeycomb_core::geometry

Struct Vector3

Source
pub struct Vector3<T: CoordsFloat>(pub T, pub T, pub T);
Expand description

3D vector representation

§Generics

  • T: CoordsFloat – Generic type for coordinates representation.

§Example

use honeycomb_core::geometry::Vector3;

let unit_x = Vector3::unit_x();
let unit_y = Vector3::unit_y();
let unit_z = Vector3::unit_z();

assert_eq!(unit_x.dot(&unit_y), 0.0);
assert_eq!(unit_x.cross(&unit_y), unit_z);

let three: f64 = 3.0;
let x_plus_y_plus_z: Vector3<f64> = unit_x + unit_y + unit_z;

assert_eq!(x_plus_y_plus_z.norm(), three.sqrt());
assert_eq!(x_plus_y_plus_z.unit_dir()?, Vector3(1.0 / three.sqrt(), 1.0 / three.sqrt(), 1.0 / three.sqrt()));

Tuple Fields§

§0: T§1: T§2: T

Implementations§

Source§

impl<T: CoordsFloat> Vector3<T>

Source

pub fn unit_x() -> Self

Base vector

§Return

Return a unit vector along the x axis.

Source

pub fn unit_y() -> Self

Base vector

§Return

Return a unit vector along the y axis.

Source

pub fn unit_z() -> Self

Base vector

§Return

Return a unit vector along the z axis.

Source

pub fn into_inner(self) -> (T, T, T)

Consume self to return inner value

§Return

Return coordinate values as a simple tuple.

Source

pub fn x(&self) -> T

Getter

§Return

Return the value of the x coordinate of the vector.

Source

pub fn y(&self) -> T

Getter

§Return

Return the value of the y coordinate of the vector.

Source

pub fn z(&self) -> T

Getter

§Return

Return the value of the z coordinate of the vector.

Source

pub fn norm(&self) -> T

Compute the norm of self.

§Return

Return the norm. Its type is the same as the one used for internal representation.

§Example

See Vector3 example.

Source

pub fn unit_dir(&self) -> Result<Self, CoordsError>

Compute the direction of self as a unit vector.

§Return

Return a Vector3 indicating the direction of self. The norm of the returned struct is equal to one.

§Errors

This method will return an error if called on a Vector3 with a norm equal to zero, i.e. a null Vector3.

§Example

See Vector3 example.

Source

pub fn dot(&self, other: &Vector3<T>) -> T

Compute the dot product between two vectors

§Arguments
  • other: &Vector3 – reference to the second vector.
§Return

Return the dot product between self and other.

§Example

See Vector3 example.

Source

pub fn cross(&self, other: &Vector3<T>) -> Self

Compute the cross product between two vectors

§Arguments
  • other: &Vector3 – reference to the second vector.
§Return

Return the cross product between self and other.

§Example

See Vector3 example.

Trait Implementations§

Source§

impl<T: CoordsFloat> Add<&Vector3<T>> for Vertex3<T>

Source§

type Output = Vertex3<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Vector3<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: CoordsFloat> Add<Vector3<T>> for Vertex3<T>

Source§

type Output = Vertex3<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector3<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: CoordsFloat> Add for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector3<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: CoordsFloat> AddAssign<&Vector3<T>> for Vertex3<T>

Source§

fn add_assign(&mut self, rhs: &Vector3<T>)

Performs the += operation. Read more
Source§

impl<T: CoordsFloat> AddAssign<Vector3<T>> for Vertex3<T>

Source§

fn add_assign(&mut self, rhs: Vector3<T>)

Performs the += operation. Read more
Source§

impl<T: CoordsFloat> AddAssign for Vector3<T>

Source§

fn add_assign(&mut self, rhs: Vector3<T>)

Performs the += operation. Read more
Source§

impl<T: Clone + CoordsFloat> Clone for Vector3<T>

Source§

fn clone(&self) -> Vector3<T>

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<T: Debug + CoordsFloat> Debug for Vector3<T>

Source§

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

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

impl<T: Default + CoordsFloat> Default for Vector3<T>

Source§

fn default() -> Vector3<T>

Returns the “default value” for a type. Read more
Source§

impl<T: CoordsFloat> Div<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: CoordsFloat> DivAssign<T> for Vector3<T>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T: CoordsFloat> From<(T, T, T)> for Vector3<T>

Source§

fn from((x, y, z): (T, T, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordsFloat> From<Vector2<T>> for Vector3<T>

Source§

fn from(v: Vector2<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CoordsFloat> Mul<T> for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: CoordsFloat> MulAssign<T> for Vector3<T>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T: CoordsFloat> Neg for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: PartialEq + CoordsFloat> PartialEq for Vector3<T>

Source§

fn eq(&self, other: &Vector3<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: CoordsFloat> Sub<&Vector3<T>> for Vertex3<T>

Source§

type Output = Vertex3<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Vector3<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: CoordsFloat> Sub<Vector3<T>> for Vertex3<T>

Source§

type Output = Vertex3<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector3<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: CoordsFloat> Sub for Vector3<T>

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector3<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: CoordsFloat> SubAssign<&Vector3<T>> for Vertex3<T>

Source§

fn sub_assign(&mut self, rhs: &Vector3<T>)

Performs the -= operation. Read more
Source§

impl<T: CoordsFloat> SubAssign<Vector3<T>> for Vertex3<T>

Source§

fn sub_assign(&mut self, rhs: Vector3<T>)

Performs the -= operation. Read more
Source§

impl<T: CoordsFloat> SubAssign for Vector3<T>

Source§

fn sub_assign(&mut self, rhs: Vector3<T>)

Performs the -= operation. Read more
Source§

impl<T: Copy + CoordsFloat> Copy for Vector3<T>

Source§

impl<T: CoordsFloat> Send for Vector3<T>

Source§

impl<T: CoordsFloat> StructuralPartialEq for Vector3<T>

Source§

impl<T: CoordsFloat> Sync for Vector3<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector3<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector3<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Vector3<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector3<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> ToOwned for T
where T: Clone,

Source§

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