Struct ludomath::vec2d::Vector
[−]
[src]
#[repr(C)]pub struct Vector { pub x: f32, pub y: f32, }
Represents a cartesian vector in the 2D euclidean plane.
Fields
x: f32
The X component of the vector.
y: f32
The Y component of the vector.
Methods
impl Vector
[src]
pub fn new(x: f32, y: f32) -> Vector
[src]
Constructs a new vector.
pub fn unit_from_radians(angle: f32) -> Vector
[src]
Constructs a unit-length vector with a certain angle in radians.
pub fn unit_from_degrees(angle: f32) -> Vector
[src]
Constructs a unit-length vector with a certain angle in degrees.
pub fn new_polar_rad(radius: f32, angle: f32) -> Vector
[src]
Constructs a vector of a certain magnitude and angle (in radians).
pub fn new_polar_deg(radius: f32, angle: f32) -> Vector
[src]
Constructs a vector of a certain magnitude and angle (in degrees).
pub fn magnitude(self) -> f32
[src]
Computes the magnitude/length of a vector.
pub fn dot(self, other: Vector) -> f32
[src]
Computes the dot product of two vectors.
pub fn scale(self, other: Vector) -> Vector
[src]
Computes the component-wise product of two vectors.
pub fn scale_mut(&mut self, other: Vector)
[src]
Computes the component-wise product of two vectors, assigning the result to the first one.
pub fn rotate(self, rotation: Rotation) -> Vector
[src]
Rotates a vector by a Rotation
struct.
pub fn rotate_mut(&mut self, rotation: Rotation)
[src]
Rotates a vector, mutating it.
pub fn rotate_rad(self, angle: f32) -> Vector
[src]
Rotates a vector by an angle in radians.
pub fn rotate_rad_mut(&mut self, angle: f32)
[src]
Rotates a vector by an angle in radians, mutating it.
pub fn rotate_deg(self, angle: f32) -> Vector
[src]
Rotates a vector by an angle in degrees.
pub fn rotate_deg_mut(&mut self, angle: f32)
[src]
Rotates a vector by an angle in degrees, mutating it.
pub fn normalize(self) -> Vector
[src]
Normalizes a vector to unit length.
If the vector is zero, returns (1, 0).
pub fn normalize_mut(&mut self)
[src]
Sets a vector to unit length.
If the vector is zero, sets to (1, 0).
pub fn dist(self, other: Vector) -> f32
[src]
Computes the euclidean distance between two vectors.
pub fn grid_dist(self, other: Vector) -> f32
[src]
Computes the grid-based distance between two vectors.
This is the length of the shortest path between the vectors, if the only movement allowed is parallel to the x- or y-axis.
pub fn angle_rad(self) -> f32
[src]
Computes the angle between a vector and the positive x-axis, in radians.
Return values are contained in (-τ/2, τ/2], aka. (-π, π].
pub fn angle_deg(self) -> f32
[src]
Computes the angle between a vector and the positive x-axis, in degrees.
Return values are approximately contained in (-180, 180].
pub fn angle_between_rad(self, other: Vector) -> f32
[src]
Computes the angle between two vectors, in radians.
Rotating the first vector by the resulting angle will give it the same angle as the second.
Return values are contained in (-τ/2, τ/2], aka (-π, π].
pub fn angle_between_deg(self, other: Vector) -> f32
[src]
Computes the angle between two vectors, in degrees.
Return values are approximately contained in (-180, 180].
pub fn map<F: Fn(f32) -> f32>(self, func: &F) -> Vector
[src]
Calls a function on each component of a vector, returning the result as a new vector.
pub fn map_mut<F: Fn(f32) -> f32>(&mut self, func: &F)
[src]
Sets each component to the result of calling a function on the component's value.
pub fn lerp(self, other: Vector, t: f32) -> Vector
[src]
Linearly interpolates from one vector to another by t
.
t
< 0 or t
> 1 gives results outside the
rectangular bounds of the vectors.
pub fn is_in_rect(self, vert1: Vector, vert2: Vector) -> bool
[src]
Returns true
if self
is within the (inclusive) bounds
of the rectangle defined by two vertices.
pub fn clamp_to_rect(self, vert1: Vector, vert2: Vector) -> Vector
[src]
Clamps a vector to within the (inclusive) bounds of the rectangle defined by two vertices.
pub fn as_point(self) -> Point
[src]
Reinterprets the x- and y-components of a vector as a point.
pub fn from_vec2(vec2: [f32; 2]) -> Vector
[src]
Converts a OpenGL-style vec2
to a Vector
.
Optimizes into a simple copy, since the types have the same layout.
pub fn to_vec2(self) -> [f32; 2]
[src]
Converts a Vector
to a OpenGL-style vec2
.
Optimizes into a simple copy, since the types have the same layout.
pub fn to_vec3(self) -> [f32; 3]
[src]
Converts a Vector
to a OpenGL-style vec3
.
The result is padded to [x, y, 0]
.
pub fn to_vec4(self) -> [f32; 4]
[src]
Converts a Vector
to a OpenGL-style vec4
.
The result is padded to [x, y, 0, 0]
.
pub fn arr_from_vec2s(arr: &[[f32; 2]]) -> &[Vector]
[src]
Reinterprets a slice of vec2
s as Vector
s.
Does not allocate a new array, only changes the type of the pointer.
pub fn arr_to_vec2s(arr: &[Vector]) -> &[[f32; 2]]
[src]
Reinterprets a slice of Vector
s as vec2
s.
Does not allocate a new array, only changes the type of the pointer.
Trait Implementations
impl Clone for Vector
[src]
fn clone(&self) -> Vector
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Vector
[src]
impl Default for Vector
[src]
impl PartialEq for Vector
[src]
fn eq(&self, __arg_0: &Vector) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Vector) -> bool
[src]
This method tests for !=
.
impl Debug for Vector
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Transformation<Vector> for Transform
[src]
fn transform(self, vec: Vector) -> Vector
[src]
Returns a transformed copy of an object. Read more
fn inverse_transform(self, vec: Vector) -> Vector
[src]
Transforms an object by the inverse of a transformation. Read more
fn transform_mut(self, operand: &mut T) where
T: Copy,
[src]
T: Copy,
Transforms an object, mutating it.
fn inverse_transform_checked(self, operand: T) -> Option<T>
[src]
Transforms an object by the inverse of a transformation. Read more
impl Add<Vector> for Vector
[src]
type Output = Vector
The resulting type after applying the +
operator.
fn add(self, other: Vector) -> Vector
[src]
Performs the +
operation.
impl Add<Vector> for Point
[src]
type Output = Point
The resulting type after applying the +
operator.
fn add(self, other: Vector) -> Point
[src]
Performs the +
operation.
impl Add<Point> for Vector
[src]
type Output = Point
The resulting type after applying the +
operator.
fn add(self, other: Point) -> Point
[src]
Performs the +
operation.
impl Sub<Vector> for Vector
[src]
type Output = Vector
The resulting type after applying the -
operator.
fn sub(self, other: Vector) -> Vector
[src]
Performs the -
operation.
impl Sub<Vector> for Point
[src]
type Output = Point
The resulting type after applying the -
operator.
fn sub(self, other: Vector) -> Point
[src]
Performs the -
operation.
impl AddAssign<Vector> for Vector
[src]
fn add_assign(&mut self, other: Vector)
[src]
Performs the +=
operation.
impl AddAssign<Vector> for Point
[src]
fn add_assign(&mut self, other: Vector)
[src]
Performs the +=
operation.
impl SubAssign<Vector> for Vector
[src]
fn sub_assign(&mut self, other: Vector)
[src]
Performs the -=
operation.
impl SubAssign<Vector> for Point
[src]
fn sub_assign(&mut self, other: Vector)
[src]
Performs the -=
operation.
impl Mul<f32> for Vector
[src]
type Output = Vector
The resulting type after applying the *
operator.
fn mul(self, scalar: f32) -> Vector
[src]
Performs the *
operation.
impl Mul<Vector> for f32
[src]
type Output = Vector
The resulting type after applying the *
operator.
fn mul(self, vec: Vector) -> Vector
[src]
Performs the *
operation.
impl MulAssign<f32> for Vector
[src]
fn mul_assign(&mut self, scalar: f32)
[src]
Performs the *=
operation.
impl Div<f32> for Vector
[src]
type Output = Vector
The resulting type after applying the /
operator.
fn div(self, scalar: f32) -> Vector
[src]
Performs the /
operation.
impl DivAssign<f32> for Vector
[src]
fn div_assign(&mut self, scalar: f32)
[src]
Performs the /=
operation.