#[repr(C)]
pub struct Vec2D<T: Number, U: Unit = ()> { /* private fields */ }

Implementations

Creates a new Vec2D with an unknown unit.

Creates a new Vec2D with the default unit value.

Creates a new Vec2D with a unit value.

Tries to cast the values to different number type.

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

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

Same as Self::try_convert but panics if the conversion failed.

Converts the value to a different unit type by using UnitCompatibility::convert_pos2. This is Self::convert_u but it uses the target unit default value for easier usage.

Arguments

returns: Option<Vec2D<N, UO>>

Examples
   use mathie::unit::metric::Centimeter;

   let v0 = mathie::Vec2D::<f32, Centimeter>::new(250.0, 250.0);
   let v1 = v0.try_convert_u(()).unwrap();
   assert_eq!(v1, mathie::Vec2D::new(2.5, 2.5));
See also

Self::convert

Same as Self::try_convert_u but panics if the conversion failed.

Converts the value to a different unit type by using UnitCompatibility::convert_pos2

Arguments
  • to: The target unit to convert to.

returns: Option<Vec2D<N, UO>>

Examples
   use mathie::unit::metric::Centimeter;

   let v0 = mathie::Vec2D::<f32, Centimeter>::new(250.0, 250.0);
   let v1 = v0.try_convert_u(()).unwrap();
   assert_eq!(v1, mathie::Vec2D::new(2.5, 2.5));
See also

Self::convert

Clears the unit value and converts this to an un-united vector.

Checks if any of the values match a condition.

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

Checks if all of the values match a condition.

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

Maps both of the values to the function result.

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

Maps the X value to the function result.

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

Maps the Y value to the function result.

Examples
let v0 = mathie::Vec2D::new_any(1.0, 1.0);
assert_eq!(v0.map_y(|v| v + 2.0), mathie::Vec2D::new_any(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::Vec2D::new_any(1.0, 1.0);
let other = mathie::Vec2D::new_any(0.0, 0.0);
assert_eq!(v0.move_x(other), mathie::Vec2D::new_any(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::Vec2D::new_any(1.0, 1.0);
let other = mathie::Vec2D::new_any(0.0, 0.0);
assert_eq!(v0.move_y(other), mathie::Vec2D::new_any(1.0, 0.0))

Adds both of the values together.

Examples
let v0 = mathie::Vec2D::new_any(1.0, 1.0);
assert_eq!(v0.add_vals(), 2.0)

Subtracts both of the values together.

Examples
let v0 = mathie::Vec2D::new_any(1.0, 2.0);
assert_eq!(v0.sub_vals(), -1.0)

Multiplies both of the values together.

Examples
let v0 = mathie::Vec2D::new_any(2.0, 2.0);
assert_eq!(v0.mul_vals(), 4.0)

Divides both of the values together.

Examples
let v0 = mathie::Vec2D::new_any(2.0, 4.0);
assert_eq!(v0.div_vals(), 0.5)

Returns the unit of this vector.

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 value of the Vector.

Examples
let v0 = mathie::Vec2D::new_any(1, 2);
assert_eq!(v0.min(), 1)

Gets the biggest value of the Vector.

Examples
let v0 = mathie::Vec2D::new_any(1, 2);
assert_eq!(v0.max(), 2)

Gets the normalized vector from this vector.

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::Vec2D::new_any(1.0, 1.0);
let other = mathie::Vec2D::new_any(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::Vec2D::new_any(1.5, 1.5));

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 this type into the (usually inferred) input type.

Converts this type into the (usually inferred) 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 !=.

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.