public class MathHelper extends Object
Modifier and Type | Field and Description |
---|---|
private static double[] |
ARCSINE_TABLE |
private static double[] |
COSINE_TABLE |
private static int[] |
MULTIPLY_DE_BRUIJN_BIT_POSITION |
private static Random |
RANDOM |
private static float[] |
SINE_TABLE |
private static double |
SMALLEST_FRACTION_FREE_DOUBLE |
static float |
SQUARE_ROOT_OF_TWO |
Constructor and Description |
---|
MathHelper() |
Modifier and Type | Method and Description |
---|---|
static float |
abs(float float2) |
static int |
abs(int int2) |
static double |
absMax(double double2,
double double3) |
static float |
angleBetween(float first,
float second) |
static boolean |
approximatelyEquals(double a,
double b) |
static boolean |
approximatelyEquals(float a,
float b) |
static double |
atan2(double y,
double x) |
static double |
average(long[] array) |
static int |
binarySearch(int start,
int end,
IntPredicate leftPredicate) |
static int |
ceil(double double2) |
static int |
ceil(float float2) |
static double |
clamp(double value,
double min,
double max) |
static float |
clamp(float value,
float min,
float max) |
static int |
clamp(int value,
int min,
int max) |
static long |
clamp(long value,
long min,
long max) |
static double |
clampedLerp(double start,
double end,
double delta) |
static float |
cos(float float2) |
static int |
fastFloor(double double2) |
static float |
fastInverseCbrt(float x) |
static double |
fastInverseSqrt(double x) |
static float |
fastInverseSqrt(float x) |
static int |
floor(double double2) |
static int |
floor(float float2) |
static int |
floorDiv(int int2,
int int3) |
static double |
floorMod(double double2,
double double3) |
static float |
floorMod(float float2,
float float3) |
static int |
floorMod(int int2,
int int3) |
static double |
fractionalPart(double value) |
static float |
fractionalPart(float value) |
static float |
fwrapDegrees(double degrees)
Deprecated.
|
static double |
getLerpProgress(double value,
double start,
double end)
Gets the fraction of the way that
value is between start and end . |
static long |
hashCode(int x,
int y,
int z) |
static long |
hashCode(Vec3i vec) |
static int |
hsvToRgb(float hue,
float saturation,
float value) |
static int |
idealHash(int int2) |
static boolean |
isPowerOfTwo(int int2) |
static double |
lerp(double delta,
double start,
double end) |
static float |
lerp(float delta,
float start,
float end) |
static double |
lerp2(double deltaX,
double deltaY,
double val00,
double val10,
double val01,
double val11)
A two-dimensional lerp between values on the 4 corners of the unit square.
|
static double |
lerp3(double deltaX,
double deltaY,
double deltaZ,
double val000,
double val100,
double val010,
double val110,
double val001,
double val101,
double val011,
double val111)
A three-dimensional lerp between values on the 8 corners of the unit cube.
|
static float |
lerpAngle(float start,
float end,
float delta)
Deprecated.
|
static float |
lerpAngleDegrees(float delta,
float start,
float end) |
static long |
lfloor(double double2) |
static int |
log2(int int2) |
static int |
log2DeBruijn(int int2) |
static float |
method_24504(float float2,
float float3) |
static double |
nextDouble(Random random,
double min,
double max) |
static float |
nextFloat(Random random,
float min,
float max) |
static int |
nextInt(Random random,
int min,
int max) |
static int |
packRgb(float r,
float g,
float b) |
static int |
packRgb(int r,
int g,
int b) |
static int |
parseInt(String string,
int fallback) |
static double |
perlinFade(double double2) |
static UUID |
randomUuid() |
static UUID |
randomUuid(Random random) |
static int |
roundUpToMultiple(int value,
int divisor)
Returns a value farther than or as far as
value from zero that
is a multiple of divisor . |
static int |
sign(double double2) |
static float |
sin(float float2) |
static int |
smallestEncompassingPowerOfTwo(int value) |
static float |
sqrt(double double2) |
static float |
sqrt(float float2) |
static float |
square(float n) |
static float |
stepAngleTowards(float from,
float to,
float step)
Steps from
from degrees towards to degrees, changing the value by at most step degrees. |
static float |
stepTowards(float from,
float to,
float step)
Steps from
from towards to , changing the value by at most step . |
static float |
stepUnwrappedAngleTowards(float from,
float to,
float step)
Steps from
from degrees towards to degrees, changing the value by at most step degrees. |
static float |
subtractAngles(float start,
float end) |
static double |
wrapDegrees(double double2) |
static float |
wrapDegrees(float float2) |
static int |
wrapDegrees(int int2) |
public static final float SQUARE_ROOT_OF_TWO
private static final float[] SINE_TABLE
private static final Random RANDOM
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION
private static final double SMALLEST_FRACTION_FREE_DOUBLE
private static final double[] ARCSINE_TABLE
private static final double[] COSINE_TABLE
public static float sin(float float2)
public static float cos(float float2)
public static float sqrt(float float2)
public static float sqrt(double double2)
public static int floor(float float2)
@Environment(value=CLIENT) public static int fastFloor(double double2)
public static int floor(double double2)
public static long lfloor(double double2)
public static float abs(float float2)
public static int abs(int int2)
public static int ceil(float float2)
public static int ceil(double double2)
public static int clamp(int value, int min, int max)
@Environment(value=CLIENT) public static long clamp(long value, long min, long max)
public static float clamp(float value, float min, float max)
public static double clamp(double value, double min, double max)
public static double clampedLerp(double start, double end, double delta)
public static double absMax(double double2, double double3)
public static int floorDiv(int int2, int int3)
public static int nextInt(Random random, int min, int max)
public static float nextFloat(Random random, float min, float max)
public static double nextDouble(Random random, double min, double max)
public static double average(long[] array)
@Environment(value=CLIENT) public static boolean approximatelyEquals(float a, float b)
public static boolean approximatelyEquals(double a, double b)
public static int floorMod(int int2, int int3)
@Environment(value=CLIENT) public static float floorMod(float float2, float float3)
@Environment(value=CLIENT) public static double floorMod(double double2, double double3)
@Environment(value=CLIENT) public static int wrapDegrees(int int2)
public static float wrapDegrees(float float2)
public static double wrapDegrees(double double2)
public static float subtractAngles(float start, float end)
public static float angleBetween(float first, float second)
public static float stepAngleTowards(float from, float to, float step)
from
degrees towards to
degrees, changing the value by at most step
degrees.public static float stepTowards(float from, float to, float step)
from
towards to
, changing the value by at most step
.public static float stepUnwrappedAngleTowards(float from, float to, float step)
from
degrees towards to
degrees, changing the value by at most step
degrees.
This method does not wrap the resulting angle, so stepAngleTowards(float, float, float)
should be used in preference.
@Environment(value=CLIENT) public static int parseInt(String string, int fallback)
public static int smallestEncompassingPowerOfTwo(int value)
public static boolean isPowerOfTwo(int int2)
public static int log2DeBruijn(int int2)
public static int log2(int int2)
public static int roundUpToMultiple(int value, int divisor)
value
from zero that
is a multiple of divisor
.@Environment(value=CLIENT) public static int packRgb(float r, float g, float b)
@Environment(value=CLIENT) public static int packRgb(int r, int g, int b)
public static float fractionalPart(float value)
public static double fractionalPart(double value)
public static long hashCode(Vec3i vec)
public static long hashCode(int x, int y, int z)
public static UUID randomUuid()
public static double getLerpProgress(double value, double start, double end)
value
is between start
and end
.
This is the delta value needed to lerp between start
and end
to get value
.
In other words, getLerpProgress(lerp(delta, start, end), start, end) == delta
.value
- The result of the lerp functionstart
- The value interpolated fromend
- The value interpolated topublic static double atan2(double y, double x)
@Environment(value=CLIENT) public static float fastInverseSqrt(float x)
public static double fastInverseSqrt(double x)
@Environment(value=CLIENT) public static float fastInverseCbrt(float x)
public static int hsvToRgb(float hue, float saturation, float value)
public static int idealHash(int int2)
public static int binarySearch(int start, int end, IntPredicate leftPredicate)
public static float lerp(float delta, float start, float end)
public static double lerp(double delta, double start, double end)
public static double lerp2(double deltaX, double deltaY, double val00, double val10, double val01, double val11)
deltaX
- The x-coordinate on the unit squaredeltaY
- The y-coordinate on the unit squareval00
- The output if deltaX
is 0 and deltaY
is 0val10
- The output if deltaX
is 1 and deltaY
is 0val01
- The output if deltaX
is 0 and deltaY
is 1val11
- The output if deltaX
is 1 and deltaY
is 1public static double lerp3(double deltaX, double deltaY, double deltaZ, double val000, double val100, double val010, double val110, double val001, double val101, double val011, double val111)
deltaX
- The x-coordinate on the unit cubedeltaY
- The y-coordinate on the unit cubedeltaZ
- The z-coordinate on the unit cubeval000
- The output if deltaX
is 0, deltaY
is 0 and deltaZ
is 0val100
- The output if deltaX
is 1, deltaY
is 0 and deltaZ
is 0val010
- The output if deltaX
is 0, deltaY
is 1 and deltaZ
is 0val110
- The output if deltaX
is 1, deltaY
is 1 and deltaZ
is 0val001
- The output if deltaX
is 0, deltaY
is 0 and deltaZ
is 1val101
- The output if deltaX
is 1, deltaY
is 0 and deltaZ
is 1val011
- The output if deltaX
is 0, deltaY
is 1 and deltaZ
is 1val111
- The output if deltaX
is 1, deltaY
is 1 and deltaZ
is 1public static double perlinFade(double double2)
public static int sign(double double2)
@Environment(value=CLIENT) public static float lerpAngleDegrees(float delta, float start, float end)
@Deprecated public static float lerpAngle(float start, float end, float delta)
@Environment(value=CLIENT) @Deprecated public static float fwrapDegrees(double degrees)
@Environment(value=CLIENT) public static float method_24504(float float2, float float3)
public static float square(float n)