public final class FXGLMath extends Object
Modifier and Type | Field and Description |
---|---|
static double |
E |
static double |
EPSILON
A "close to zero" double epsilon value for use.
|
static double |
HALF_PI |
static double |
PI |
static double |
PI2 |
Modifier and Type | Method and Description |
---|---|
static double |
abs(double value) |
static float |
abs(float value) |
static double |
atan2(double y,
double x)
Average error of 0.00231 radians (0.1323 degrees),
largest error of 0.00488 radians (0.2796 degrees).
|
static double |
atan2Deg(double y,
double x)
Average error of 0.00231 radians (0.1323 degrees),
largest error of 0.00488 radians (0.2796 degrees).
|
static javafx.geometry.Point2D |
bezier(javafx.geometry.Point2D p1,
javafx.geometry.Point2D p2,
javafx.geometry.Point2D p3,
double t) |
static javafx.geometry.Point2D |
bezier(javafx.geometry.Point2D p1,
javafx.geometry.Point2D p2,
javafx.geometry.Point2D p3,
javafx.geometry.Point2D p4,
double t) |
static int |
ceil(double value) |
static int |
ceilPositive(double value) |
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 short |
clamp(short value,
short min,
short max) |
static BezierSpline |
closedBezierSpline(Vec2[] points) |
static double |
cos(double radians) |
static double |
cosDeg(double degrees) |
static int |
floor(double value) |
static int |
floorPositive(double value)
Note: this method simply casts the double to int.
|
static Random |
getRandom() |
static Random |
getRandom(long seed) |
static double |
interpolate(double fromValue,
double toValue,
double progress,
javafx.animation.Interpolator interpolator) |
static javafx.geometry.Point2D |
interpolate(javafx.geometry.Point2D fromValue,
javafx.geometry.Point2D toValue,
double progress,
javafx.animation.Interpolator interpolator) |
static boolean |
isClose(double a,
double b,
double tolerance)
Note: prone to floating point errors if the arguments are not doubles.
|
static boolean |
isCloseToZero(double value,
double tolerance)
Note: prone to floating point errors if the arguments are not doubles.
|
static boolean |
isPowerOfTwo(int value) |
static double |
lerp(double fromValue,
double toValue,
double progress) |
static javafx.geometry.Point2D |
lerp(double fromX,
double fromY,
double toX,
double toY,
double progress) |
static double |
lerpAngle(double fromRadians,
double toRadians,
double progress)
Linearly interpolates between two angles in radians.
|
static double |
lerpAngleDeg(double fromDegrees,
double toDegrees,
double progress)
Linearly interpolates between two angles in degrees.
|
static double |
log(double base,
double value) |
static double |
log2(double value) |
static double |
map(double value,
double currentRangeStart,
double currentRangeStop,
double targetRangeStart,
double targetRangeStop)
Map value of a given range to a target range.
|
static double |
max(double a,
double b) |
static double |
min(double a,
double b) |
static int |
nextPowerOfTwo(int value) |
static double |
noise1D(double t) |
static double |
noise2D(double x,
double y)
A typical usage would be to pass 2d coordinates multiplied by a frequency (lower frequency -> smoother output) value, like:
double noise = noise2D(x * freq, y * freq)
|
static double |
pow(double a,
double b) |
static double |
random() |
static double |
random(double range) |
static double |
random(double start,
double end) |
static int |
random(int range) |
static int |
random(int start,
int end) |
static <T> Optional<T> |
random(List<T> list) |
static long |
random(long range) |
static long |
random(long start,
long end) |
static <T> Optional<T> |
random(T[] array) |
static boolean |
randomBoolean() |
static boolean |
randomBoolean(double chance) |
static javafx.scene.paint.Color |
randomColor() |
static float |
randomFloat() |
static javafx.geometry.Point2D |
randomPoint(javafx.geometry.Rectangle2D bounds) |
static javafx.geometry.Point2D |
randomPoint2D() |
static int |
randomSign() |
static double |
randomTriangular()
This is an optimized version of
randomTriangular(-1, 1, 0) . |
static double |
randomTriangular(double max)
This is an optimized version of
randomTriangular(-max, max, 0) . |
static double |
randomTriangular(double min,
double max)
This method is equivalent of
randomTriangular(min, max, (min + max) * .5f) . |
static double |
randomTriangular(double min,
double max,
double mode) |
static Vec2 |
randomVec2() |
static int |
round(double value) |
static int |
roundPositive(double value) |
static double |
sin(double radians) |
static double |
sinDeg(double degrees) |
static double |
sqrt(double x) |
static double |
toDegrees(double radians) |
static double |
toRadians(double degrees) |
public static final double EPSILON
public static final double PI
public static final double PI2
public static final double HALF_PI
public static final double E
public static double sin(double radians)
radians
- angle in radianspublic static double cos(double radians)
radians
- angle in radianspublic static double sinDeg(double degrees)
degrees
- angle in degreespublic static double cosDeg(double degrees)
degrees
- angle in degreespublic static double toDegrees(double radians)
public static double toRadians(double degrees)
public static double atan2(double y, double x)
y
- y componentx
- x componentpublic static double atan2Deg(double y, double x)
y
- y componentx
- x componentpublic static Random getRandom()
public static Random getRandom(long seed)
public static int random(int range)
range
- the end inclusive valuepublic static int random(int start, int end)
start
- start valueend
- end valuepublic static long random(long range)
range
- the end inclusive valuepublic static long random(long start, long end)
start
- start valueend
- end valuepublic static boolean randomBoolean()
public static boolean randomBoolean(double chance)
chance
- chance to checkpublic static double random()
public static float randomFloat()
public static double random(double range)
range
- end exclusive valuepublic static double random(double start, double end)
start
- start inclusive valueend
- end exclusive valuepublic static int randomSign()
public static double randomTriangular()
randomTriangular(-1, 1, 0)
.public static double randomTriangular(double max)
randomTriangular(-max, max, 0)
.max
- the upper limit-max
(exclusive) and max
(exclusive),
where values around zero are more likelypublic static double randomTriangular(double min, double max)
randomTriangular(min, max, (min + max) * .5f)
.min
- the lower limitmax
- the upper limitmin
(inclusive) and max
(exclusive),
where the mode
argument defaults to the midpoint between the bounds, giving a symmetric distributionpublic static double randomTriangular(double min, double max, double mode)
min
- the lower limitmax
- the upper limitmode
- the point around which the values are more likelymin
(inclusive) and max
(exclusive),
where values around mode
are more likelypublic static javafx.geometry.Point2D randomPoint(javafx.geometry.Rectangle2D bounds)
public static Vec2 randomVec2()
public static javafx.geometry.Point2D randomPoint2D()
public static javafx.scene.paint.Color randomColor()
public static <T> Optional<T> random(T[] array)
public static <T> Optional<T> random(List<T> list)
public static double sqrt(double x)
public static int nextPowerOfTwo(int value)
value
- the valuepublic static boolean isPowerOfTwo(int value)
value
- the value to checkpublic static short clamp(short value, short min, short max)
public static int clamp(int value, int min, int max)
public static long clamp(long value, long min, long max)
public static double clamp(double value, double min, double max)
public static float clamp(float value, float min, float max)
public static double map(double value, double currentRangeStart, double currentRangeStop, double targetRangeStart, double targetRangeStop)
value
- the value to mappublic static double lerp(double fromValue, double toValue, double progress)
fromValue
- start valuetoValue
- end valueprogress
- the interpolation progress [0..1]public static javafx.geometry.Point2D lerp(double fromX, double fromY, double toX, double toY, double progress)
public static double interpolate(double fromValue, double toValue, double progress, javafx.animation.Interpolator interpolator)
public static javafx.geometry.Point2D interpolate(javafx.geometry.Point2D fromValue, javafx.geometry.Point2D toValue, double progress, javafx.animation.Interpolator interpolator)
public static double lerpAngle(double fromRadians, double toRadians, double progress)
fromRadians
- start angle in radianstoRadians
- target angle in radiansprogress
- interpolation value in the range [0, 1]public static double lerpAngleDeg(double fromDegrees, double toDegrees, double progress)
fromDegrees
- start angle in degreestoDegrees
- target angle in degreesprogress
- interpolation value in the range [0, 1]public static float abs(float value)
public static double abs(double value)
public static double min(double a, double b)
public static double max(double a, double b)
public static int floor(double value)
value
- from -(2^14) to (double.MAX_VALUE - 2^14)public static int floorPositive(double value)
value
- a positive valuepublic static int ceil(double value)
value
- from -(2^14) to (double.MAX_VALUE - 2^14)public static int ceilPositive(double value)
value
- a positive doublepublic static int round(double value)
value
- from -(2^14) to (double.MAX_VALUE - 2^14)public static int roundPositive(double value)
value
- a positive doublepublic static boolean isCloseToZero(double value, double tolerance)
value
- the value to checktolerance
- represent an upper bound below which the value is considered zeropublic static boolean isClose(double a, double b, double tolerance)
a
- the first valueb
- the second valuetolerance
- represent an upper bound below which the two values are considered equalpublic static double pow(double a, double b)
public static double log(double base, double value)
base
- the basevalue
- the valuepublic static double log2(double value)
value
- the valuepublic static javafx.geometry.Point2D bezier(javafx.geometry.Point2D p1, javafx.geometry.Point2D p2, javafx.geometry.Point2D p3, double t)
public static javafx.geometry.Point2D bezier(javafx.geometry.Point2D p1, javafx.geometry.Point2D p2, javafx.geometry.Point2D p3, javafx.geometry.Point2D p4, double t)
public static BezierSpline closedBezierSpline(Vec2[] points)
points
- the spline passes through these pointspublic static double noise1D(double t)
t
- current time * frequency (lower frequency -> smoother output)public static double noise2D(double x, double y)
Copyright © 2018. All rights reserved.