Skip to content

Commit b82a0d4

Browse files
authored
Update FastMath: javadoc
1 parent 97ba999 commit b82a0d4

File tree

1 file changed

+42
-53
lines changed

1 file changed

+42
-53
lines changed

jme3-core/src/main/java/com/jme3/math/FastMath.java

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
* @author Various
4141
* @version $Id: FastMath.java,v 1.45 2007/08/26 08:44:20 irrisor Exp $
4242
*/
43-
final public class FastMath {
44-
private FastMath() {
45-
}
43+
public final class FastMath {
44+
45+
private FastMath() {}
46+
4647
/**
4748
* A "close to zero" double epsilon value for use
4849
*/
@@ -173,7 +174,7 @@ public static float interpolateLinear(float scale, float startValue, float endVa
173174
* @return The interpolated value between startValue and endValue.
174175
*/
175176
public static Vector3f interpolateLinear(float scale, Vector3f startValue,
176-
Vector3f endValue, Vector3f store) {
177+
Vector3f endValue, Vector3f store) {
177178
if (store == null) {
178179
store = new Vector3f();
179180
}
@@ -230,7 +231,7 @@ public static float extrapolateLinear(float scale, float startValue, float endVa
230231
* @return an extrapolation for the given parameters
231232
*/
232233
public static Vector3f extrapolateLinear(float scale, Vector3f startValue,
233-
Vector3f endValue, Vector3f store) {
234+
Vector3f endValue, Vector3f store) {
234235
if (store == null) {
235236
store = new Vector3f();
236237
}
@@ -306,7 +307,7 @@ public static float interpolateCatmullRom(float u, float T, float p0, float p1,
306307
* @return Catmull–Rom interpolation
307308
*/
308309
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0,
309-
Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) {
310+
Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) {
310311
if (store == null) {
311312
store = new Vector3f();
312313
}
@@ -335,7 +336,7 @@ public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0,
335336
* @return Catmull–Rom interpolation
336337
*/
337338
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0,
338-
Vector3f p1, Vector3f p2, Vector3f p3) {
339+
Vector3f p1, Vector3f p2, Vector3f p3) {
339340
return interpolateCatmullRom(u, T, p0, p1, p2, p3, null);
340341
}
341342

@@ -384,7 +385,7 @@ public static float interpolateBezier(float u, float p0, float p1, float p2, flo
384385
* @return Bezier interpolation
385386
*/
386387
public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1,
387-
Vector3f p2, Vector3f p3, Vector3f store) {
388+
Vector3f p2, Vector3f p3, Vector3f store) {
388389
if (store == null) {
389390
store = new Vector3f();
390391
}
@@ -428,7 +429,7 @@ public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vect
428429
* @return the length of the segment
429430
*/
430431
public static float getCatmullRomP1toP2Length(Vector3f p0, Vector3f p1,
431-
Vector3f p2, Vector3f p3, float startRange, float endRange, float curveTension) {
432+
Vector3f p2, Vector3f p3, float startRange, float endRange, float curveTension) {
432433

433434
float epsilon = 0.001f;
434435
float middleValue = (startRange + endRange) * 0.5f;
@@ -489,10 +490,8 @@ public static float acos(float fValue) {
489490
if (fValue < 1.0f) {
490491
return (float) Math.acos(fValue);
491492
}
492-
493493
return 0.0f;
494494
}
495-
496495
return PI;
497496
}
498497

@@ -511,10 +510,8 @@ public static float asin(float fValue) {
511510
if (fValue < 1.0f) {
512511
return (float) Math.asin(fValue);
513512
}
514-
515513
return HALF_PI;
516514
}
517-
518515
return -HALF_PI;
519516
}
520517

@@ -827,9 +824,9 @@ public static Vector3f computeNormal(Vector3f v1, Vector3f v2, Vector3f v3) {
827824
* @return the determinant
828825
*/
829826
public static float determinant(double m00, double m01, double m02,
830-
double m03, double m10, double m11, double m12, double m13,
831-
double m20, double m21, double m22, double m23, double m30,
832-
double m31, double m32, double m33) {
827+
double m03, double m10, double m11, double m12, double m13,
828+
double m20, double m21, double m22, double m23, double m30,
829+
double m31, double m32, double m33) {
833830

834831
double det01 = m20 * m31 - m21 * m30;
835832
double det02 = m20 * m32 - m22 * m30;
@@ -844,41 +841,40 @@ public static float determinant(double m00, double m01, double m02,
844841
}
845842

846843
/**
847-
* Returns a random float between 0 and 1.
844+
* Generates a pseudorandom {@code float} in the range [0.0, 1.0).
848845
*
849-
* @return a random float between 0 (inclusive) and 1 (exclusive)
846+
* @return A random {@code float} value.
850847
*/
851848
public static float nextRandomFloat() {
852849
return rand.nextFloat();
853850
}
854851

855852
/**
856-
* Returns a random float between min and max.
853+
* Generates a pseudorandom {@code float} in the range [min, max] (inclusive).
857854
*
858-
* @param min the desired minimum value
859-
* @param max the desired maximum value
860-
* @return a random float between min (inclusive) and max (inclusive)
855+
* @param min The lower bound (inclusive).
856+
* @param max The upper bound (inclusive).
857+
* @return A random {@code float} value within the specified range.
861858
*/
862859
public static float nextRandomFloat(float min, float max) {
863-
return min + (max - min) * rand.nextFloat();
860+
return min + (max - min) * nextRandomFloat();
864861
}
865862

866863
/**
867-
* Choose a pseudo-random, uniformly-distributed integer value from
868-
* the shared generator.
864+
* Generates a pseudorandom, uniformly-distributed {@code int} value.
869865
*
870-
* @return the next integer value
866+
* @return The next pseudorandom {@code int} value.
871867
*/
872868
public static int nextRandomInt() {
873869
return rand.nextInt();
874870
}
875871

876872
/**
877-
* Returns a random integer between min and max.
873+
* Generates a pseudorandom {@code int} in the range [min, max] (inclusive).
878874
*
879-
* @param min the desired minimum value
880-
* @param max the desired maximum value
881-
* @return a random int between min (inclusive) and max (inclusive)
875+
* @param min The lower bound (inclusive).
876+
* @param max The upper bound (inclusive).
877+
* @return A random {@code int} value within the specified range.
882878
*/
883879
public static int nextRandomInt(int min, int max) {
884880
return (int) (nextRandomFloat() * (max - min + 1)) + min;
@@ -891,12 +887,12 @@ public static int nextRandomInt(int min, int max) {
891887
*/
892888
public static Vector3f onUnitSphere() {
893889

894-
float u = FastMath.nextRandomFloat();
895-
float v = FastMath.nextRandomFloat();
890+
float u = nextRandomFloat();
891+
float v = nextRandomFloat();
896892

897-
// azimuthal angle: The angle between x-axis in radians [0, 2pi]
893+
// azimuthal angle: The angle between x-axis in radians [0, 2PI]
898894
float theta = FastMath.TWO_PI * u;
899-
// polar angle: The angle between z-axis in radians [0, pi]
895+
// polar angle: The angle between z-axis in radians [0, PI]
900896
float phi = (float) Math.acos(2f * v - 1f);
901897

902898
float cosPolar = FastMath.cos(phi);
@@ -914,11 +910,11 @@ public static Vector3f onUnitSphere() {
914910
* @return A new {@link Vector3f} representing a random point within the unit sphere.
915911
*/
916912
public static Vector3f insideUnitSphere() {
917-
float u = FastMath.nextRandomFloat();
913+
float u = nextRandomFloat();
918914
// Azimuthal angle [0, 2PI]
919-
float theta = FastMath.TWO_PI * FastMath.nextRandomFloat();
915+
float theta = FastMath.TWO_PI * nextRandomFloat();
920916
// Polar angle [0, PI] for uniform surface distribution
921-
float phi = FastMath.acos(2f * FastMath.nextRandomFloat() - 1f);
917+
float phi = FastMath.acos(2f * nextRandomFloat() - 1f);
922918

923919
// For uniform distribution within the volume, radius R should be such that R^3 is uniformly distributed.
924920
// So, R = cbrt(random_uniform_0_to_1)
@@ -940,9 +936,9 @@ public static Vector3f insideUnitSphere() {
940936
*/
941937
public static Vector2f insideUnitCircle() {
942938
// Angle [0, 2PI]
943-
float angle = FastMath.TWO_PI * FastMath.nextRandomFloat();
939+
float angle = FastMath.TWO_PI * nextRandomFloat();
944940
// For uniform distribution, R^2 is uniform
945-
float radius = FastMath.sqrt(FastMath.nextRandomFloat());
941+
float radius = FastMath.sqrt(nextRandomFloat());
946942

947943
float x = radius * FastMath.cos(angle);
948944
float y = radius * FastMath.sin(angle);
@@ -960,8 +956,7 @@ public static Vector2f insideUnitCircle() {
960956
* @param store storage for the result (modified if not null)
961957
* @return the Cartesian coordinates (either store or a new vector)
962958
*/
963-
public static Vector3f sphericalToCartesian(Vector3f sphereCoords,
964-
Vector3f store) {
959+
public static Vector3f sphericalToCartesian(Vector3f sphereCoords, Vector3f store) {
965960
if (store == null) {
966961
store = new Vector3f();
967962
}
@@ -983,8 +978,7 @@ public static Vector3f sphericalToCartesian(Vector3f sphereCoords,
983978
* @return the Cartesian coordinates: x=distance from origin, y=longitude in
984979
* radians, z=latitude in radians (either store or a new vector)
985980
*/
986-
public static Vector3f cartesianToSpherical(Vector3f cartCoords,
987-
Vector3f store) {
981+
public static Vector3f cartesianToSpherical(Vector3f cartCoords, Vector3f store) {
988982
if (store == null) {
989983
store = new Vector3f();
990984
}
@@ -1013,8 +1007,7 @@ public static Vector3f cartesianToSpherical(Vector3f cartCoords,
10131007
* @param store storage for the result (modified if not null)
10141008
* @return the Cartesian coordinates (either store or a new vector)
10151009
*/
1016-
public static Vector3f sphericalToCartesianZ(Vector3f sphereCoords,
1017-
Vector3f store) {
1010+
public static Vector3f sphericalToCartesianZ(Vector3f sphereCoords, Vector3f store) {
10181011
if (store == null) {
10191012
store = new Vector3f();
10201013
}
@@ -1036,8 +1029,7 @@ public static Vector3f sphericalToCartesianZ(Vector3f sphereCoords,
10361029
* @return the Cartesian coordinates: x=distance from origin, y=latitude in
10371030
* radians, z=longitude in radians (either store or a new vector)
10381031
*/
1039-
public static Vector3f cartesianZToSpherical(Vector3f cartCoords,
1040-
Vector3f store) {
1032+
public static Vector3f cartesianZToSpherical(Vector3f cartCoords, Vector3f store) {
10411033
if (store == null) {
10421034
store = new Vector3f();
10431035
}
@@ -1059,12 +1051,9 @@ public static Vector3f cartesianZToSpherical(Vector3f cartCoords,
10591051
/**
10601052
* Takes a value and expresses it in terms of min to max.
10611053
*
1062-
* @param val -
1063-
* the angle to normalize (in radians)
1064-
* @param min
1065-
* the lower limit of the range
1066-
* @param max
1067-
* the upper limit of the range
1054+
* @param val the angle to normalize (in radians)
1055+
* @param min the lower limit of the range
1056+
* @param max the upper limit of the range
10681057
* @return the normalized angle (also in radians)
10691058
*/
10701059
public static float normalize(float val, float min, float max) {

0 commit comments

Comments
 (0)