#[repr(C)]
pub struct Vec2<T: Number>(_);

Implementations

Creates a new Vec2D with a unit value.

Tries to cast the values to different number type.

Examples
   use mathie::Vec2;
   assert_eq!(Vec2::<f32>::new(250.5, 250.5).cast(), Vec2::<u32>::new(250, 250));
   assert_eq!(Vec2::<f32>::new(0.5, 0.5).cast(), Vec2::<u32>::new(0, 0));

Same as Self::cast but returns None if the cast failed.

Checks if any of the values match a condition.

Examples
let v0 = mathie::Vec2::new(2.0, 1.0);
assert!(v0.any(|v| v == 1.0))

Checks if all of the values match a condition.

Examples
let v0 = mathie::Vec2::new(2.0, 1.0);
assert!(!v0.all(|v| v == 1.0))

Maps both of the values to the function result.

Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
assert_eq!(v0.map(|v| v + 2.0), mathie::Vec2::new(1.0 + 2.0, 1.0 + 2.0))

Maps the X value to the function result.

Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
assert_eq!(v0.map_x(|v| v + 2.0), mathie::Vec2::new(1.0 + 2.0, 1.0))

Maps the Y value to the function result.

Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
assert_eq!(v0.map_y(|v| v + 2.0), mathie::Vec2::new(1.0, 1.0 + 2.0))

Moves the x value from the other value and keeps its original y

Arguments
  • other: The vector to pull x from.

returns: Vec2D<N, U>

Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
let other = mathie::Vec2::new(0.0, 0.0);
assert_eq!(v0.move_x(other), mathie::Vec2::new(0.0, 1.0))

Moves the y value from the other value and keeps its original x

Arguments
  • other: The vector to pull y from.

returns: Vec2D<N, U>

Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
let other = mathie::Vec2::new(0.0, 0.0);
assert_eq!(v0.move_y(other), mathie::Vec2::new(1.0, 0.0))

Adds both of the values together.

Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
assert_eq!(v0.add_xy(), 2.0)

Subtracts both of the values together.

Examples
let v0 = mathie::Vec2::new(1.0, 2.0);
assert_eq!(v0.sub_xy(), -1.0)

Multiplies both of the values together.

Examples
let v0 = mathie::Vec2::new(2.0, 2.0);
assert_eq!(v0.mul_xy(), 4.0)

Divides x/y of the values together.

Examples
let v0 = mathie::Vec2::new(2.0, 4.0);
assert_eq!(v0.div_xy(), 0.5)

Divides y/x of the values together.

Examples
let v0 = mathie::Vec2::new(2.0, 4.0);
assert_eq!(v0.div_yx(), 2.0)

Returns the X value.

Returns the Y value.

Does nothing.

Returns X as Y and Y as X. (Basically inverts the values.)

Gets the smallest coordinate of the Vector.

Examples
let v0 = mathie::Vec2::new(1, 2);
assert_eq!(v0.min_val(), 1)

Gets the biggest coordinate of the Vector.

Examples
let v0 = mathie::Vec2::new(1, 2);
assert_eq!(v0.max_val(), 2)

Gets the smallest coordinates of both of the vectors.

Examples
let v0 = mathie::Vec2::new(1, 2);
let other = mathie::Vec2::new(5, 1);
assert_eq!(v0.min(other), mathie::Vec2::new(1, 1))

Gets the biggest coordinates of both of the vectors.

Examples
let v0 = mathie::Vec2::new(1, 2);
let other = mathie::Vec2::new(5, 1);
assert_eq!(v0.max(other), mathie::Vec2::new(5, 2))

Gets the normalized vector from this vector. Meaning a vector the length of 1

Examples
use mathie::Vec2;
let value = Vec2::new(4.0, 3.0);
assert_eq!(value.norm(), Vec2::new(4.0 / 5.0, 3.0 / 5.0));
assert_eq!(value.norm().hypot(), 1.0);

let value = Vec2::new(69.0, 420.0);
assert_eq!(value.norm().hypot(), 1.0);

Linearly interpolated the value of self and other by the value t where 0 is self and 1 is other.

Arguments
  • other: The target value.
  • t: A value which says where the value should be.

returns: Vec2D<N, U>

Examples
let v0 = mathie::Vec2::new(1.0, 1.0);
let other = mathie::Vec2::new(2.0, 2.0);
assert_eq!(v0.lerp(other, 0.0), v0);
assert_eq!(v0.lerp(other, 1.0), other);
assert_eq!(v0.lerp(other, 0.5), mathie::Vec2::new(1.5, 1.5));

The same as Self::min_val but for floating-point numbers.

The same as Self::max_val but for floating-point numbers.

The same as Self::min but for floating-point numbers.

The same as Self::max but for floating-point numbers.

Gets the hypotenuse of the vector. In other terms the length.

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
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
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
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.
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
Performs the *= operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. 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
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
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
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
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

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
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.