Struct primitives::Point[][src]

#[repr(C)]
pub struct Point<T> { pub x: T, pub y: T, }
Expand description

A 2d Vector tagged with a unit.

Fields

x: T

The x (traditionally, horizontal) coordinate.

y: T

The y (traditionally, vertical) coordinate.

Implementations

Constructor taking scalar values directly.

Constructor setting all components to the same value.

Computes the vector with absolute values of each component.

Example

enum U {}

assert_eq!(Vector2D::new(-1, 2).abs(), Vector2D::new(1, 2));

let vec = Vector2D::new(f32::NAN, -f32::MAX).abs();
assert!(vec.x.is_nan());
assert_eq!(vec.y, f32::MAX);

Panics

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

Dot product.

Returns the norm of the cross product [self.x, self.y, 0] x [other.x, other.y, 0].

Returns the component-wise multiplication of the two vectors.

Returns the component-wise division of the two vectors.

Swap x and y.

Drop the units, preserving only the numeric value.

Cast into an array with x and y.

Cast into a tuple with x and y.

Returns the vector’s length squared.

Returns this vector projected onto another one.

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

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 the normalized vector even if the length is larger than the max value of Float.

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.

Returns true if all members are finite.

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

Performs the += operation. 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

Performs the /= operation. Read more

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

Performs the conversion.

Performs the conversion.

The resulting type after applying the * operator.

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

Performs the -= operation. Read more

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

Performs the conversion.

Performs the conversion.

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)

recently added

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.