pub struct MathUtilities;Expand description
Provides math utilities not provided by the standard library.
Implementations§
Source§impl MathUtilities
impl MathUtilities
Sourcepub const DOUBLE_EPSILON: f64 = f64::EPSILON
pub const DOUBLE_EPSILON: f64 = f64::EPSILON
Smallest value such that 1.0 + DOUBLE_EPSILON != 1.0.
pub const FLOAT_EPSILON: f32 = f32::EPSILON
Sourcepub fn are_close(value1: f64, value2: f64) -> bool
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.
Sourcepub fn are_close_eps(value1: f64, value2: f64, eps: f64) -> bool
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.
Sourcepub fn are_close_f32(value1: f32, value2: f32) -> bool
pub fn are_close_f32(value1: f32, value2: f32) -> bool
Returns whether or not two floats are “close”.
Sourcepub fn less_than(value1: f64, value2: f64) -> bool
pub fn less_than(value1: f64, value2: f64) -> bool
Returns whether the first double is strictly less than and not close to the second.
Sourcepub fn less_than_f32(value1: f32, value2: f32) -> bool
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.
Sourcepub fn greater_than(value1: f64, value2: f64) -> bool
pub fn greater_than(value1: f64, value2: f64) -> bool
Returns whether the first double is strictly greater than and not close to the second.
Sourcepub fn greater_than_f32(value1: f32, value2: f32) -> bool
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.
Sourcepub fn less_than_or_close(value1: f64, value2: f64) -> bool
pub fn less_than_or_close(value1: f64, value2: f64) -> bool
Returns whether the first double is less than or close to the second.
Sourcepub fn less_than_or_close_f32(value1: f32, value2: f32) -> bool
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.
Sourcepub fn greater_than_or_close(value1: f64, value2: f64) -> bool
pub fn greater_than_or_close(value1: f64, value2: f64) -> bool
Returns whether the first double is greater than or close to the second.
Sourcepub fn greater_than_or_close_f32(value1: f32, value2: f32) -> bool
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.
Sourcepub fn is_one(value: f64) -> bool
pub fn is_one(value: f64) -> bool
Returns whether the double is “close” to 1. Same as are_close(value, 1.0) but faster.
Sourcepub fn is_one_f32(value: f32) -> bool
pub fn is_one_f32(value: f32) -> bool
Returns whether the float is “close” to 1.
Sourcepub fn is_zero(value: f64) -> bool
pub fn is_zero(value: f64) -> bool
Returns whether the double is “close” to 0. Same as are_close(value, 0.0) but faster.
Sourcepub fn is_zero_f32(value: f32) -> bool
pub fn is_zero_f32(value: f32) -> bool
Returns whether the float is “close” to 0.
Sourcepub fn clamp(val: f64, min: f64, max: f64) -> f64
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).
Sourcepub fn clamp_f32(value: f32, min: f32, max: f32) -> f32
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.
Sourcepub fn clamp_i32(val: i32, min: i32, max: i32) -> i32
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).
Sourcepub fn clamp_decimal(val: Decimal, min: Decimal, max: Decimal) -> Decimal
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).
Sourcepub fn get_ellipse_point(
centre: Point,
radius_x: f64,
radius_y: f64,
angle: f64,
) -> Point
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.
Sourcepub fn get_min_max(a: f64, b: f64) -> (f64, f64)
pub fn get_min_max(a: f64, b: f64) -> (f64, f64)
Gets the minimum and maximum from the specified numbers.
Sourcepub fn get_min_max_from_delta(initial_value: f64, delta: f64) -> (f64, f64)
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.
Sourcepub fn is_negative_or_non_finite(d: f64) -> bool
pub fn is_negative_or_non_finite(d: f64) -> bool
True for negative values (including -0.0), infinities and NaN.
pub fn is_finite(d: f64) -> bool
Sourcepub fn which_polygon_side_intersects(
c_poly: u32,
p_pt_poly: &[Vector],
pt_current: Vector,
vec_edge: Vector,
) -> i32
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.
Auto Trait Implementations§
impl Freeze for MathUtilities
impl RefUnwindSafe for MathUtilities
impl Send for MathUtilities
impl Sync for MathUtilities
impl Unpin for MathUtilities
impl UnsafeUnpin for MathUtilities
impl UnwindSafe for MathUtilities
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more