Vector
struct · ferroui-base · v0.5.0
struct Vector
Defines a vector.
Members
xyZEROONEUNIT_XUNIT_Ynewparselengthsquared_lengthequalsnearly_equalswith_xwith_ynormalizenegatedotcrossnormalize_vectordividedivide_scalarmultiplymultiply_scalaraddsubtractnegate_vectordeconstructabsclampmaxmindistancedistance_squared
x
x: f64
The X component.
y
y: f64
The Y component.
ZERO
const ZERO: Vector
The zero vector.
ONE
const ONE: Vector
The one vector.
UNIT_X
const UNIT_X: Vector
The X unit vector.
UNIT_Y
const UNIT_Y: Vector
The Y unit vector.
new
const fn new(x: f64, y: f64) -> Self
Initializes a new instance of the Vector structure.
parse
fn parse(s: &str) -> Result<Self, FormatError>
Parses a Vector string ("x, y" or "x y").
length
fn length(self: &Self) -> f64
Length of the vector.
squared_length
fn squared_length(self: &Self) -> f64
Squared length of the vector.
equals
fn equals(self: &Self, other: Vector) -> bool
Check if two vectors are equal (exact comparison of the components).
nearly_equals
fn nearly_equals(self: &Self, other: Vector) -> bool
Check if two vectors are nearly equal (numerically).
with_x
const fn with_x(self: &Self, x: f64) -> Vector
Returns a new vector with the specified X component.
with_y
const fn with_y(self: &Self, y: f64) -> Vector
Returns a new vector with the specified Y component.
normalize
fn normalize(self: &Self) -> Vector
Returns a normalized version of this vector. A zero-length vector yields NaN components.
negate
fn negate(self: &Self) -> Vector
Returns a negated version of this vector.
dot
fn dot(a: Vector, b: Vector) -> f64
Returns the dot product of two vectors.
cross
fn cross(a: Vector, b: Vector) -> f64
Returns the cross product of two vectors.
normalize_vector
fn normalize_vector(vector: Vector) -> Vector
Normalizes the given vector (static form of normalize).
divide
fn divide(a: Vector, b: Vector) -> Vector
Divides the first vector by the second, component-wise.
divide_scalar
fn divide_scalar(vector: Vector, scalar: f64) -> Vector
Divides the vector by the given scalar.
multiply
fn multiply(a: Vector, b: Vector) -> Vector
Multiplies the first vector by the second, component-wise.
multiply_scalar
fn multiply_scalar(vector: Vector, scalar: f64) -> Vector
Multiplies the vector by the given scalar.
add
fn add(a: Vector, b: Vector) -> Vector
Adds the second to the first vector.
subtract
fn subtract(a: Vector, b: Vector) -> Vector
Subtracts the second from the first vector.
negate_vector
fn negate_vector(vector: Vector) -> Vector
Negates the vector (static form of negate).
deconstruct
const fn deconstruct(self: &Self) -> (f64, f64)
Deconstructs the vector into its X and Y components.
abs
fn abs(self: &Self) -> Vector
Returns a vector whose elements are the absolute values of each of the specified vector's elements.
clamp
fn clamp(value: Vector, min: Vector, max: Vector) -> Vector
Restricts a vector between a minimum and a maximum value.
max
fn max(left: Vector, right: Vector) -> Vector
Returns a vector whose elements are the maximum of each of the pairs of elements in two specified vectors.
min
fn min(left: Vector, right: Vector) -> Vector
Returns a vector whose elements are the minimum of each of the pairs of elements in two specified vectors.
distance
fn distance(value1: Vector, value2: Vector) -> f64
Computes the Euclidean distance between the two given points.
distance_squared
fn distance_squared(value1: Vector, value2: Vector) -> f64
Returns the Euclidean distance squared between two specified points.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafePropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringErasedDestructorIntoEitherTransition<Vector>From<Vector>From<Vector2>IInterpolator<Vector>ExpressionVariantValueServerPropertyValueBatchValueMarkupTypedValueTypeRegistrationFrom<Point>Add<Vector>Sub<Vector>AddAssign<Vector>SubAssign<Vector>Mul<Vector>Div<Vector>MulAssign<Vector>DivAssign<Vector>CloneCopyDebugStructuralPartialEqPartialEqDefaultMulMul<f64>Div<f64>NegAddSubAddAssignSubAssignMulAssign<f64>DivAssign<f64>FromStrDisplay
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.