# MathUtilities

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/utilities/math_utilities/struct-mathutilities/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct MathUtilities
```

Provides math utilities not provided by the standard library.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L80)

## Members

- [`DOUBLE_EPSILON`](#assoc_const-double_epsilon)
- [`FLOAT_EPSILON`](#assoc_const-float_epsilon)
- [`are_close`](#function-are_close)
- [`are_close_eps`](#function-are_close_eps)
- [`are_close_f32`](#function-are_close_f32)
- [`less_than`](#function-less_than)
- [`less_than_f32`](#function-less_than_f32)
- [`greater_than`](#function-greater_than)
- [`greater_than_f32`](#function-greater_than_f32)
- [`less_than_or_close`](#function-less_than_or_close)
- [`less_than_or_close_f32`](#function-less_than_or_close_f32)
- [`greater_than_or_close`](#function-greater_than_or_close)
- [`greater_than_or_close_f32`](#function-greater_than_or_close_f32)
- [`is_one`](#function-is_one)
- [`is_one_f32`](#function-is_one_f32)
- [`is_zero`](#function-is_zero)
- [`is_zero_f32`](#function-is_zero_f32)
- [`clamp`](#function-clamp)
- [`clamp_f32`](#function-clamp_f32)
- [`clamp_i32`](#function-clamp_i32)
- [`clamp_decimal`](#function-clamp_decimal)
- [`deg2rad`](#function-deg2rad)
- [`grad2rad`](#function-grad2rad)
- [`turn2rad`](#function-turn2rad)
- [`get_ellipse_point`](#function-get_ellipse_point)
- [`get_min_max`](#function-get_min_max)
- [`get_min_max_from_delta`](#function-get_min_max_from_delta)
- [`is_negative_or_non_finite`](#function-is_negative_or_non_finite)
- [`is_finite`](#function-is_finite)
- [`which_polygon_side_intersects`](#function-which_polygon_side_intersects)
- [`do_polygons_intersect`](#function-do_polygons_intersect)
- [`is_entirely_contained`](#function-is_entirely_contained)

<a id="assoc_const-double_epsilon"></a>

### DOUBLE_EPSILON

```rust
const DOUBLE_EPSILON: f64
```

Smallest value such that `1.0 + DOUBLE_EPSILON != 1.0`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L84)

<a id="assoc_const-float_epsilon"></a>

### FLOAT_EPSILON

```rust
const FLOAT_EPSILON: f32
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L86)

<a id="function-are_close"></a>

### are_close

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L91)

<a id="function-are_close_eps"></a>

### are_close_eps

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L103)

<a id="function-are_close_f32"></a>

### are_close_f32

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

Returns whether or not two floats are "close".

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L114)

<a id="function-less_than"></a>

### less_than

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L126)

<a id="function-less_than_f32"></a>

### less_than_f32

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L132)

<a id="function-greater_than"></a>

### greater_than

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L138)

<a id="function-greater_than_f32"></a>

### greater_than_f32

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L144)

<a id="function-less_than_or_close"></a>

### less_than_or_close

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L150)

<a id="function-less_than_or_close_f32"></a>

### less_than_or_close_f32

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L156)

<a id="function-greater_than_or_close"></a>

### greater_than_or_close

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L162)

<a id="function-greater_than_or_close_f32"></a>

### greater_than_or_close_f32

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L168)

<a id="function-is_one"></a>

### is_one

```rust
fn is_one(value: f64) -> bool
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L174)

<a id="function-is_one_f32"></a>

### is_one_f32

```rust
fn is_one_f32(value: f32) -> bool
```

Returns whether the float is "close" to 1.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L180)

<a id="function-is_zero"></a>

### is_zero

```rust
fn is_zero(value: f64) -> bool
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L186)

<a id="function-is_zero_f32"></a>

### is_zero_f32

```rust
fn is_zero_f32(value: f32) -> bool
```

Returns whether the float is "close" to 0.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L192)

<a id="function-clamp"></a>

### clamp

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L201)

<a id="function-clamp_f32"></a>

### clamp_f32

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L218)

<a id="function-clamp_i32"></a>

### clamp_i32

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L229)

<a id="function-clamp_decimal"></a>

### clamp_decimal

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L248)

<a id="function-deg2rad"></a>

### deg2rad

```rust
fn deg2rad(angle: f64) -> f64
```

Converts an angle in degrees to radians.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L264)

<a id="function-grad2rad"></a>

### grad2rad

```rust
fn grad2rad(angle: f64) -> f64
```

Converts an angle in gradians to radians.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L270)

<a id="function-turn2rad"></a>

### turn2rad

```rust
fn turn2rad(angle: f64) -> f64
```

Converts an angle in turns to radians.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L276)

<a id="function-get_ellipse_point"></a>

### get_ellipse_point

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L282)

<a id="function-get_min_max"></a>

### get_min_max

```rust
fn get_min_max(a: f64, b: f64) -> (f64, f64)
```

Gets the minimum and maximum from the specified numbers.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L291)

<a id="function-get_min_max_from_delta"></a>

### get_min_max_from_delta

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L301)

<a id="function-is_negative_or_non_finite"></a>

### is_negative_or_non_finite

```rust
fn is_negative_or_non_finite(d: f64) -> bool
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L307)

<a id="function-is_finite"></a>

### is_finite

```rust
fn is_finite(d: f64) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L312)

<a id="function-which_polygon_side_intersects"></a>

### which_polygon_side_intersects

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L319)

<a id="function-do_polygons_intersect"></a>

### do_polygons_intersect

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L356)

<a id="function-is_entirely_contained"></a>

### is_entirely_contained

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/math_utilities.rs#L386)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
