#[repr(C)]
pub struct Vec2 { pub x: f32, pub y: f32, }
Expand description

A 2-dimensional vector.

Fields

x: f32y: f32

Implementations

Performs is_nan on each element of self, returning a Vec2Mask of the results.

In other words, this computes [x.is_nan(), y.is_nan()].

Returns a Vec2 with elements representing the sign of self.

  • 1.0 if the number is positive, +0.0 or INFINITY
  • -1.0 if the number is negative, -0.0 or NEG_INFINITY
  • NAN if the number is NAN

Returns a Vec2 containing the reciprocal 1.0/n of each element of self.

Performs a linear interpolation between self and other based on the value s.

When s is 0.0, the result will be equal to self. When s is 1.0, the result will be equal to other.

Returns whether self is length 1.0 or not.

Uses a precision threshold of 1e-6.

Returns true if the absolute difference of all elements between self and other is less than or equal to max_abs_diff.

This can be used to compare if two Vec2’s contain similar elements. It works best when comparing with a known value. The max_abs_diff that should be used used depends on the values being compared against.

For more on floating point comparisons see https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Creates a new Vec2.

Creates a Vec2 with all elements set to 0.0.

Creates a Vec2 with all elements set to 1.0.

Creates a Vec2 with values [x: 1.0, y: 0.0].

Creates a Vec2 with values [x: 0.0, y: 1.0].

Creates a Vec2 with all elements set to v.

Creates a Vec3 from self and the given z value.

👎Deprecated since 0.10.0:

please use .x instead

👎Deprecated since 0.10.0:

please use .y instead

👎Deprecated since 0.10.0:

please use .x instead

👎Deprecated since 0.10.0:

please use .y instead

👎Deprecated since 0.10.0:

please use .x instead

👎Deprecated since 0.10.0:

please use .y instead

Computes the dot product of self and other.

Computes the length of self.

Computes the squared length of self.

This is generally faster than Vec2::length() as it avoids a square root operation.

Computes 1.0 / Vec2::length().

For valid results, self must not be of length zero.

Computes the Euclidean distance between two points.

Compute the squared Euclidean distance between two points.

Returns self normalized to length 1.0.

For valid results, self must not be of length zero.

Returns the vertical minimum of self and other.

In other words, this computes [x: min(x1, x2), y: min(y1, y2)], taking the minimum of each element individually.

Returns the vertical maximum of self and other.

In other words, this computes [x: max(x1, x2), y: max(y1, y2)], taking the maximum of each element individually.

Returns the horizontal minimum of self’s elements.

In other words, this computes min(x, y).

Returns the horizontal maximum of self’s elements.

In other words, this computes max(x, y).

Performs a vertical == comparison between self and other, returning a Vec2Mask of the results.

In other words, this computes [x1 == x2, y1 == y2].

Performs a vertical != comparison between self and other, returning a Vec2Mask of the results.

In other words, this computes [x1 != x2, y1 != y2].

Performs a vertical >= comparison between self and other, returning a Vec2Mask of the results.

In other words, this computes [x1 >= x2, y1 >= y2].

Performs a vertical > comparison between self and other, returning a Vec2Mask of the results.

In other words, this computes [x1 > x2, y1 > y2].

Performs a vertical <= comparison between self and other, returning a Vec2Mask of the results.

In other words, this computes [x1 <= x2, y1 <= y2].

Performs a vertical < comparison between self and other, returning a Vec2Mask of the results.

In other words, this computes [x1 < x2, y1 < y2].

Creates a Vec2 from the first two values in slice.

Panics

Panics if slice is less than two elements long.

Writes the elements of self to the first two elements in slice.

Panics

Panics if slice is less than two elements long.

Returns a Vec2 containing the absolute value of each element of self.

Returns a Vec2 containing the nearest integer to a number for each element of self. Round half-way cases away from 0.0.

Returns a Vec2 containing the largest integer less than or equal to a number for each element of self.

Returns a Vec2 containing the smallest integer greater than or equal to a number for each element of self.

Returns a Vec2 that is equal to self rotated by 90 degrees.

The perpendicular dot product of the vector and other.

Returns the angle between two vectors, in radians.

The vectors do not need to be unit length, but this function does perform a sqrt.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

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

Formats the value using the given formatter. 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.

Creates a Vec2 from the x and y elements of the Vec3, discarding z.

Creates a Vec2 from the x and y elements of the Vec3A, discarding z.

Creates a Vec2 from the x and y elements of the Vec4, discarding z.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) 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

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 default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

The resulting type after applying the - operator.

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

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

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

Converts the given value to a String. 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.