MCPcopy Index your code
hub / github.com/VolmitSoftware/Adapt / M

Class M

src/main/java/com/volmit/adapt/util/M.java:31–374  ·  view source on GitHub ↗

Math @author cyberpwn

Source from the content-addressed store, hash-verified

29 * @author cyberpwn
30 */
31public class M {
32 private static final int precision = 128;
33 private static final int modulus = 360 * precision;
34 private static final float[] sin = new float[modulus];
35 public static int tick = 0;
36
37 static {
38 for (int i = 0; i < sin.length; i++) {
39 sin[i] = (float) Math.sin((i * Math.PI) / (precision * 180));
40 }
41 }
42
43 /**
44 * Scales B by an external range change so that <br/>
45 * <br/>
46 * BMIN < B < BMAX <br/>
47 * AMIN < RESULT < AMAX <br/>
48 * <br/>
49 * So Given rangeScale(0, 20, 0, 10, 5) -> 10 <br/>
50 * 0 < 5 < 10 <br/>
51 * 0 < ? < 20 <br/>
52 * <br/>
53 * would return 10
54 *
55 * @param amin the resulting minimum
56 * @param amax the resulting maximum
57 * @param bmin the initial minimum
58 * @param bmax the initial maximum
59 * @param b the initial value
60 * @return the resulting value
61 */
62 public static double rangeScale(double amin, double amax, double bmin, double bmax, double b) {
63 return amin + ((amax - amin) * ((b - bmin) / (bmax - bmin)));
64 }
65
66 /**
67 * Get the percent (inverse lerp) from "from" to "to" where "at".
68 * <p>
69 * If from = 0 and to = 100 and at = 25 then it would return 0.25
70 *
71 * @param from the from
72 * @param to the to
73 * @param at the at
74 * @return the percent
75 */
76 public static double lerpInverse(double from, double to, double at) {
77 return M.rangeScale(0, 1, from, to, at);
78 }
79
80 /**
81 * Linear interpolation from a to b where f is the percent across
82 *
83 * @param a the first pos (0)
84 * @param b the second pos (1)
85 * @param f the percent
86 * @return the value
87 */
88 public static double lerp(double a, double b, double f) {

Callers

nothing calls this directly

Calls 1

sinMethod · 0.45

Tested by

no test coverage detected