Join us on the livestream at Android Dev Summit on 7-8 November 2018, starting at 10AM PDT!

MathUtils

public final class MathUtils
extends Object

java.lang.Object
   ↳ com.google.android.material.math.MathUtils


A class that contains utility methods related to numbers.

Summary

Constants

float DEFAULT_EPSILON

Default epsilon value for fuzzy float comparisons.

Public methods

static float dist(float x1, float y1, float x2, float y2)

Returns the distance between two points.

static float distanceToFurthestCorner(float pointX, float pointY, float rectLeft, float rectTop, float rectRight, float rectBottom)

Returns the furthest distance from the point defined by pointX and pointY to the four corners of the rectangle defined by rectLeft, rectTop, rectRight, and rectBottom.

static boolean geq(float a, float b, float epsilon)

Fuzzy greater than or equal to for floats.

static float lerp(float start, float stop, float amount)

Returns the linear interpolation of between and .

Inherited methods

From class java.lang.Object

Constants

DEFAULT_EPSILON

float DEFAULT_EPSILON

Default epsilon value for fuzzy float comparisons.

Constant Value: 1.0E-4

Public methods

dist

float dist (float x1, 
                float y1, 
                float x2, 
                float y2)

Returns the distance between two points.

Parameters
x1 float

y1 float

x2 float

y2 float

Returns
float

distanceToFurthestCorner

float distanceToFurthestCorner (float pointX, 
                float pointY, 
                float rectLeft, 
                float rectTop, 
                float rectRight, 
                float rectBottom)

Returns the furthest distance from the point defined by pointX and pointY to the four corners of the rectangle defined by rectLeft, rectTop, rectRight, and rectBottom.

The caller should ensure that the point and rectangle share the same coordinate space.

Parameters
pointX float

pointY float

rectLeft float

rectTop float

rectRight float

rectBottom float

Returns
float

geq

boolean geq (float a, 
                float b, 
                float epsilon)

Fuzzy greater than or equal to for floats.

Returns true if a is greater than or equal to b, allowing for epsilon error due to limitations in floating point accuracy.

Does not handle overflow, underflow, infinity, or NaN.

Parameters
a float

b float

epsilon float

Returns
boolean

lerp

float lerp (float start, 
                float stop, 
                float amount)

Returns the linear interpolation of between and .

Returns
float