@@ -108,6 +108,84 @@ public static int max(int... numbers) {
108
108
return max ;
109
109
}
110
110
111
+ /**
112
+ * Returns the smaller number of a and b.
113
+ * @param a value.
114
+ * @param b value.
115
+ * @return min
116
+ */
117
+ public static long min (long a , long b ) {
118
+ return a < b ? a : b ;
119
+ }
120
+
121
+ /**
122
+ * Returns the smaller number of a, b and c.
123
+ * @param a value.
124
+ * @param b value.
125
+ * @param c value.
126
+ * @return min
127
+ */
128
+ public static long min (long a , long b , long c ) {
129
+ return min (min (a , b ), c );
130
+ }
131
+
132
+ /**
133
+ * Returns the smallest number contained in the provided array.
134
+ * @param numbers Array of numbers
135
+ * @return min
136
+ */
137
+ public static long min (long ... numbers ) {
138
+ if (numbers .length < 1 ) {
139
+ throw new IllegalArgumentException ();
140
+ }
141
+ long min = numbers [0 ];
142
+ for (int i = 1 ; i < numbers .length ; i ++) {
143
+ if (numbers [i ] < min ) {
144
+ min = numbers [i ];
145
+ }
146
+ }
147
+ return min ;
148
+ }
149
+
150
+ /**
151
+ * Returns the bigger number of a and b.
152
+ * @param a value.
153
+ * @param b value.
154
+ * @return max
155
+ */
156
+ public static long max (long a , long b ) {
157
+ return a > b ? a : b ;
158
+ }
159
+
160
+ /**
161
+ * Returns the bigger number of a, b and c.
162
+ * @param a value.
163
+ * @param b value.
164
+ * @param c value.
165
+ * @return max
166
+ */
167
+ public static long max (long a , long b , long c ) {
168
+ return max (max (a , b ), c );
169
+ }
170
+
171
+ /**
172
+ * Returns the biggest number contained in the provided array.
173
+ * @param numbers Array of numbers
174
+ * @return max
175
+ */
176
+ public static long max (long ... numbers ) {
177
+ if (numbers .length < 1 ) {
178
+ throw new IllegalArgumentException ();
179
+ }
180
+ long max = numbers [0 ];
181
+ for (int i = 1 ; i < numbers .length ; i ++) {
182
+ if (numbers [i ] > max ) {
183
+ max = numbers [i ];
184
+ }
185
+ }
186
+ return max ;
187
+ }
188
+
111
189
/**
112
190
* Returns the smaller number of a and b.
113
191
* @param a value.
@@ -263,7 +341,7 @@ public static float max(float... numbers) {
263
341
}
264
342
return max ;
265
343
}
266
-
344
+
267
345
/**
268
346
* Clamps the given number so that {@code min <= a <= max}
269
347
* @param a value.
@@ -275,6 +353,17 @@ public static int clamp(int a, int min, int max) {
275
353
return min (max (a , min ), max );
276
354
}
277
355
356
+ /**
357
+ * Clamps the given number so that {@code min <= a <= max}
358
+ * @param a value.
359
+ * @param min lower limit
360
+ * @param max upper limit
361
+ * @return {@code min <= a <= max}
362
+ */
363
+ public static long clamp (long a , long min , long max ) {
364
+ return min (max (a , min ), max );
365
+ }
366
+
278
367
/**
279
368
* Clamps the given number so that {@code min <= a <= max}
280
369
* @param a value.
@@ -297,23 +386,57 @@ public static double lerp(double a, double b, double f) {
297
386
return a + f * (b - a );
298
387
}
299
388
389
+ /**
390
+ * Linear interpolates isBetween point a and point b
391
+ * @param a value.
392
+ * @param b value.
393
+ * @param f A percentage value isBetween 0 to 1
394
+ * @return The interpolated value
395
+ */
300
396
public static float lerp (float a , float b , float f ) {
301
397
return a + f * (b - a );
302
398
}
303
399
400
+ /**
401
+ * Linear interpolates isBetween point a and point b
402
+ * @param a value.
403
+ * @param b value.
404
+ * @param f A percentage value isBetween 0 to 1
405
+ * @return The interpolated value
406
+ */
304
407
public static Vector3D lerp (Vector3D a , Vector3D b , float f ) {
305
408
return a .add ((b .subtract (a )).scalarMultiply (f ));
306
409
}
307
410
308
411
/**
309
- * Clamps a value isBetween -bounds to +bounds
310
- * @return A value capped isBetween two bounds.
412
+ * Clamps a value between -bounds to +bounds
413
+ * @return A value capped between two bounds.
414
+ */
415
+ public static int absClamp (int value , int bounds ) {
416
+ return min (max (value , -bounds ), bounds );
417
+ }
418
+
419
+ /**
420
+ * Clamps a value between -bounds to +bounds
421
+ * @return A value capped between two bounds.
422
+ */
423
+ public static long absClamp (long value , long bounds ) {
424
+ return min (max (value , -bounds ), bounds );
425
+ }
426
+
427
+ /**
428
+ * Clamps a value between -bounds to +bounds
429
+ * @return A value capped between two bounds.
311
430
*/
312
431
public static double absClamp (double value , double bounds ) {
313
432
return min (max (value , -bounds ), bounds );
314
433
}
315
434
316
- public static float absClamp (int value , int bounds ) {
435
+ /**
436
+ * Clamps a value between -bounds to +bounds
437
+ * @return A value capped between two bounds.
438
+ */
439
+ public static float absClamp (float value , float bounds ) {
317
440
return min (max (value , -bounds ), bounds );
318
441
}
319
442
@@ -325,6 +448,10 @@ public static int log(int x, int base) {
325
448
return (int ) (Math .log (x ) / Math .log (base ));
326
449
}
327
450
451
+ public static long log (long x , long base ) {
452
+ return (long ) (Math .log (x ) / Math .log (base ));
453
+ }
454
+
328
455
public static double log (double x , double base ) {
329
456
return Math .log (x ) / Math .log (base );
330
457
}
@@ -339,4 +466,20 @@ public static boolean isBetween(double a, double x, double b) {
339
466
return a <= x && x <= b ;
340
467
}
341
468
469
+ /**
470
+ * Rounds a number to a specific number place places
471
+ *
472
+ * @param d - the number
473
+ * @return The rounded number
474
+ */
475
+ public static double roundDecimals (double d , int decimalPlaces ) {
476
+ long i = Math .round (d * Math .pow (10 , decimalPlaces ));
477
+ return i / Math .pow (10 , decimalPlaces );
478
+ }
479
+
480
+ public static String toString (double d , boolean removeTrailingZeroes ) {
481
+ if (removeTrailingZeroes && d % 1 == 0 )
482
+ return Long .toString ((long ) d );
483
+ return Double .toString (d );
484
+ }
342
485
}
0 commit comments