Skip to main content

MathUtilities

Struct MathUtilities 

Source
pub struct MathUtilities;
Expand description

Provides math utilities not provided by the standard library.

Implementations§

Source§

impl MathUtilities

Source

pub const DOUBLE_EPSILON: f64 = f64::EPSILON

Smallest value such that 1.0 + DOUBLE_EPSILON != 1.0.

Source

pub const FLOAT_EPSILON: f32 = f32::EPSILON

Source

pub fn are_close(value1: f64, value2: f64) -> bool

Returns whether or not two doubles are “close”, i.e. within a relative epsilon of each other.

Source

pub fn are_close_eps(value1: f64, value2: f64, eps: f64) -> bool

Returns whether or not two doubles are within the fixed epsilon eps of each other.

Source

pub fn are_close_f32(value1: f32, value2: f32) -> bool

Returns whether or not two floats are “close”.

Source

pub fn less_than(value1: f64, value2: f64) -> bool

Returns whether the first double is strictly less than and not close to the second.

Source

pub fn less_than_f32(value1: f32, value2: f32) -> bool

Returns whether the first float is strictly less than and not close to the second.

Source

pub fn greater_than(value1: f64, value2: f64) -> bool

Returns whether the first double is strictly greater than and not close to the second.

Source

pub fn greater_than_f32(value1: f32, value2: f32) -> bool

Returns whether the first float is strictly greater than and not close to the second.

Source

pub fn less_than_or_close(value1: f64, value2: f64) -> bool

Returns whether the first double is less than or close to the second.

Source

pub fn less_than_or_close_f32(value1: f32, value2: f32) -> bool

Returns whether the first float is less than or close to the second.

Source

pub fn greater_than_or_close(value1: f64, value2: f64) -> bool

Returns whether the first double is greater than or close to the second.

Source

pub fn greater_than_or_close_f32(value1: f32, value2: f32) -> bool

Returns whether the first float is greater than or close to the second.

Source

pub fn is_one(value: f64) -> bool

Returns whether the double is “close” to 1. Same as are_close(value, 1.0) but faster.

Source

pub fn is_one_f32(value: f32) -> bool

Returns whether the float is “close” to 1.

Source

pub fn is_zero(value: f64) -> bool

Returns whether the double is “close” to 0. Same as are_close(value, 0.0) but faster.

Source

pub fn is_zero_f32(value: f32) -> bool

Returns whether the float is “close” to 0.

Source

pub fn clamp(val: f64, min: f64, max: f64) -> f64

Clamps a value between a minimum and maximum value. NaN is returned unchanged.

§Panics

Panics if min > max (a programmer error).

Source

pub fn clamp_f32(value: f32, min: f32, max: f32) -> f32

Clamps a value between a minimum and maximum value. The bounds may be given in either order.

Source

pub fn clamp_i32(val: i32, min: i32, max: i32) -> i32

Clamps a value between a minimum and maximum value.

§Panics

Panics if min > max (a programmer error).

Source

pub fn clamp_decimal(val: Decimal, min: Decimal, max: Decimal) -> Decimal

Clamps a value between a minimum and maximum value.

§Panics

Panics if min > max (a programmer error).

Source

pub fn deg2rad(angle: f64) -> f64

Converts an angle in degrees to radians.

Source

pub fn grad2rad(angle: f64) -> f64

Converts an angle in gradians to radians.

Source

pub fn turn2rad(angle: f64) -> f64

Converts an angle in turns to radians.

Source

pub fn get_ellipse_point( centre: Point, radius_x: f64, radius_y: f64, angle: f64, ) -> Point

Calculates the point of an angle (in radians) on an ellipse.

Source

pub fn get_min_max(a: f64, b: f64) -> (f64, f64)

Gets the minimum and maximum from the specified numbers.

Source

pub fn get_min_max_from_delta(initial_value: f64, delta: f64) -> (f64, f64)

Gets the minimum and maximum from the specified number and the difference with that number.

Source

pub fn is_negative_or_non_finite(d: f64) -> bool

True for negative values (including -0.0), infinities and NaN.

Source

pub fn is_finite(d: f64) -> bool

Source

pub fn which_polygon_side_intersects( c_poly: u32, p_pt_poly: &[Vector], pt_current: Vector, vec_edge: Vector, ) -> i32

Classifies on which side of an edge a polygon lies: 1 when all of its first c_poly points are on the positive side, -1 when all are on the negative side, 0 when it straddles (or touches) the edge.

Source

pub fn do_polygons_intersect( c_poly_a: u32, p_pt_poly_a: &[Vector], c_poly_b: u32, p_pt_poly_b: &[Vector], ) -> bool

Separating-axis test for two convex polygons.

Source

pub fn is_entirely_contained( c_poly_a: u32, p_pt_poly_a: &[Vector], c_poly_b: u32, p_pt_poly_b: &[Vector], ) -> bool

Returns whether polygon A lies entirely inside convex polygon B.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.