Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

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 float floorMod(float x, int y)

This returns as similar as floorMod(int, int).

static int floorMod(int x, int y)

This is same as floorMod(int, int).

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

floorMod

float floorMod (float x, 
                int y)

This returns as similar as floorMod(int, int). Instead it works for float type values. And the re-implementation makes it back compatible to API<24.

Parameters
x float

y int

Returns
float

floorMod

int floorMod (int x, 
                int y)

This is same as floorMod(int, int). Re-implementation makes it back compatible to API<24.

Parameters
x int

y int

Returns
int

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