#[repr(C)]
pub struct Vector3D<T, U> { pub x: T, pub y: T, pub z: T, /* private fields */ }
Expand description

A 3d Vector tagged with a unit.

Fields

x: T

The x (traditionally, horizontal) coordinate.

y: T

The y (traditionally, vertical) coordinate.

z: T

The z (traditionally, depth) coordinate.

Implementations

Constructor, setting all components to zero.

Constructor, setting all components to one.

Constructor taking scalar values directly.

Constructor setting all components to the same value.

Constructor taking properly Lengths instead of scalar values.

Tag a unitless value with units.

Computes the vector with absolute values of each component.

Example
enum U {}

assert_eq!(vec3::<_, U>(-1, 0, 2).abs(), vec3(1, 0, 2));

let vec = vec3::<_, U>(f32::NAN, 0.0, -f32::MAX).abs();
assert!(vec.x.is_nan());
assert_eq!(vec.y, 0.0);
assert_eq!(vec.z, f32::MAX);
Panics

The behavior for each component follows the scalar type’s implementation of num_traits::Signed::abs.

Dot product.

Cross product.

Returns the component-wise multiplication of the two vectors.

Returns the component-wise division of the two vectors.

Cast this vector into a point.

Equivalent to adding this vector to the origin.

Returns a 2d vector using this vector’s x and y coordinates

Returns a 2d vector using this vector’s x and z coordinates

Returns a 2d vector using this vector’s x and z coordinates

Cast into an array with x, y and z.

Cast into an array with x, y, z and 0.

Cast into a tuple with x, y and z.

Cast into a tuple with x, y, z and 0.

Drop the units, preserving only the numeric value.

Cast the unit.

Convert into a 2d vector.

Rounds each component to the nearest integer value.

This behavior is preserved for negative values (unlike the basic cast).

enum Mm {}

assert_eq!(vec3::<_, Mm>(-0.1, -0.8, 0.4).round(), vec3::<_, Mm>(0.0, -1.0, 0.0))

Rounds each component to the smallest integer equal or greater than the original value.

This behavior is preserved for negative values (unlike the basic cast).

enum Mm {}

assert_eq!(vec3::<_, Mm>(-0.1, -0.8, 0.4).ceil(), vec3::<_, Mm>(0.0, 0.0, 1.0))

Rounds each component to the biggest integer equal or lower than the original value.

This behavior is preserved for negative values (unlike the basic cast).

enum Mm {}

assert_eq!(vec3::<_, Mm>(-0.1, -0.8, 0.4).floor(), vec3::<_, Mm>(-1.0, -1.0, 0.0))

Creates translation by this vector in vector units

Returns the vector’s length squared.

Returns this vector projected onto another one.

Projecting onto a nil vector will cause a division by zero.

Return the normalized vector even if the length is larger than the max value of Float.

Returns true if all members are finite.

Returns the positive angle between this vector and another vector.

The returned angle is between 0 and PI.

Returns the vector length.

Returns the vector with length of one unit

Returns the vector with length of one unit.

Unlike Vector2D::normalize, this returns None in the case that the length of the vector is zero.

Return this vector capped to a maximum length.

Return this vector with a minimum length applied.

Return this vector with minimum and maximum lengths applied.

Linearly interpolate each component between this vector and another vector.

Example
use euclid::vec3;
use euclid::default::Vector3D;

let from: Vector3D<_> = vec3(0.0, 10.0, -1.0);
let to:  Vector3D<_> = vec3(8.0, -4.0,  0.0);

assert_eq!(from.lerp(to, -1.0), vec3(-8.0,  24.0, -2.0));
assert_eq!(from.lerp(to,  0.0), vec3( 0.0,  10.0, -1.0));
assert_eq!(from.lerp(to,  0.5), vec3( 4.0,   3.0, -0.5));
assert_eq!(from.lerp(to,  1.0), vec3( 8.0,  -4.0,  0.0));
assert_eq!(from.lerp(to,  2.0), vec3(16.0, -18.0,  1.0));

Returns a reflection vector using an incident ray and a surface normal.

Returns the vector each component of which are minimum of this vector and another.

Returns the vector each component of which are maximum of this vector and another.

Returns the vector each component of which is clamped by corresponding components of start and end.

Shortcut for self.max(start).min(end).

Returns vector with results of “greater than” operation on each component.

Returns vector with results of “lower than” operation on each component.

Returns vector with results of “equal” operation on each component.

Returns vector with results of “not equal” operation on each component.

Cast from one numeric representation to another, preserving the units.

When casting from floating vector to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using round(), ceil() or floor() before casting.

Fallible cast from one numeric representation to another, preserving the units.

When casting from floating vector to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using round(), ceil() or floor() before casting.

Cast into an f32 vector.

Cast into an f64 vector.

Cast into an usize vector, truncating decimals if any.

When casting from floating vector vectors, it is worth considering whether to round(), ceil() or floor() before the cast in order to obtain the desired conversion behavior.

Cast into an u32 vector, truncating decimals if any.

When casting from floating vector vectors, it is worth considering whether to round(), ceil() or floor() before the cast in order to obtain the desired conversion behavior.

Cast into an i32 vector, truncating decimals if any.

When casting from floating vector vectors, it is worth considering whether to round(), ceil() or floor() before the cast in order to obtain the desired conversion behavior.

Cast into an i64 vector, truncating decimals if any.

When casting from floating vector vectors, it is worth considering whether to round(), ceil() or floor() before the cast in order to obtain the desired conversion behavior.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Default epsilon value

Returns true is this object is approximately equal to the other one, using a provided epsilon value. Read more

Returns true is this object is approximately equal to the other one, using the approx_epsilon() epsilon value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Converts this type into the (usually inferred) input type.

Converts this type into the (usually inferred) input type.

Converts this type into the (usually inferred) input type.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Constructor, setting all components to zero.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.