MathUtilities
struct · ferroui-base · v0.5.0
struct MathUtilities
Provides math utilities not provided by the standard library.
Members
DOUBLE_EPSILONFLOAT_EPSILONare_closeare_close_epsare_close_f32less_thanless_than_f32greater_thangreater_than_f32less_than_or_closeless_than_or_close_f32greater_than_or_closegreater_than_or_close_f32is_oneis_one_f32is_zerois_zero_f32clampclamp_f32clamp_i32clamp_decimaldeg2radgrad2radturn2radget_ellipse_pointget_min_maxget_min_max_from_deltais_negative_or_non_finiteis_finitewhich_polygon_side_intersectsdo_polygons_intersectis_entirely_contained
DOUBLE_EPSILON
const DOUBLE_EPSILON: f64
Smallest value such that 1.0 + DOUBLE_EPSILON != 1.0.
FLOAT_EPSILON
const FLOAT_EPSILON: f32
are_close
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.
are_close_eps
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.
are_close_f32
fn are_close_f32(value1: f32, value2: f32) -> bool
Returns whether or not two floats are "close".
less_than
fn less_than(value1: f64, value2: f64) -> bool
Returns whether the first double is strictly less than and not close to the second.
less_than_f32
fn less_than_f32(value1: f32, value2: f32) -> bool
Returns whether the first float is strictly less than and not close to the second.
greater_than
fn greater_than(value1: f64, value2: f64) -> bool
Returns whether the first double is strictly greater than and not close to the second.
greater_than_f32
fn greater_than_f32(value1: f32, value2: f32) -> bool
Returns whether the first float is strictly greater than and not close to the second.
less_than_or_close
fn less_than_or_close(value1: f64, value2: f64) -> bool
Returns whether the first double is less than or close to the second.
less_than_or_close_f32
fn less_than_or_close_f32(value1: f32, value2: f32) -> bool
Returns whether the first float is less than or close to the second.
greater_than_or_close
fn greater_than_or_close(value1: f64, value2: f64) -> bool
Returns whether the first double is greater than or close to the second.
greater_than_or_close_f32
fn greater_than_or_close_f32(value1: f32, value2: f32) -> bool
Returns whether the first float is greater than or close to the second.
is_one
fn is_one(value: f64) -> bool
Returns whether the double is "close" to 1. Same as are_close(value, 1.0) but faster.
is_one_f32
fn is_one_f32(value: f32) -> bool
Returns whether the float is "close" to 1.
is_zero
fn is_zero(value: f64) -> bool
Returns whether the double is "close" to 0. Same as are_close(value, 0.0) but faster.
is_zero_f32
fn is_zero_f32(value: f32) -> bool
Returns whether the float is "close" to 0.
clamp
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).
clamp_f32
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.
clamp_i32
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).
clamp_decimal
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).
deg2rad
fn deg2rad(angle: f64) -> f64
Converts an angle in degrees to radians.
grad2rad
fn grad2rad(angle: f64) -> f64
Converts an angle in gradians to radians.
turn2rad
fn turn2rad(angle: f64) -> f64
Converts an angle in turns to radians.
get_ellipse_point
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.
get_min_max
fn get_min_max(a: f64, b: f64) -> (f64, f64)
Gets the minimum and maximum from the specified numbers.
get_min_max_from_delta
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.
is_negative_or_non_finite
fn is_negative_or_non_finite(d: f64) -> bool
True for negative values (including -0.0), infinities and NaN.
is_finite
fn is_finite(d: f64) -> bool
which_polygon_side_intersects
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.
do_polygons_intersect
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.
is_entirely_contained
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.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyErasedDestructorIntoEither
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.