From 0373b7e31207f81bc7f3812b585070acec4bbbd7 Mon Sep 17 00:00:00 2001 From: Tefek <493msi@gmail.com> Date: Thu, 20 Aug 2020 23:59:19 +0200 Subject: [PATCH] Moved some math utils to plutolib --- .../cz/tefek/pluto}/math/ClampedSineWave.java | 36 +++++++++---------- .../cz/tefek/pluto}/math/CubicBezier.java | 20 ++++++----- .../cz/tefek/pluto}/math/CubicBezierLT.java | 18 ++++++---- .../cz/tefek/pluto/math/package-info.java | 7 ++++ 4 files changed, 48 insertions(+), 33 deletions(-) rename {plutostatic/src/main/java/cz/tefek/pluto/engine => plutolib/src/main/java/cz/tefek/pluto}/math/ClampedSineWave.java (67%) rename {plutostatic/src/main/java/cz/tefek/pluto/engine => plutolib/src/main/java/cz/tefek/pluto}/math/CubicBezier.java (76%) rename {plutostatic/src/main/java/cz/tefek/pluto/engine => plutolib/src/main/java/cz/tefek/pluto}/math/CubicBezierLT.java (84%) create mode 100644 plutolib/src/main/java/cz/tefek/pluto/math/package-info.java diff --git a/plutostatic/src/main/java/cz/tefek/pluto/engine/math/ClampedSineWave.java b/plutolib/src/main/java/cz/tefek/pluto/math/ClampedSineWave.java similarity index 67% rename from plutostatic/src/main/java/cz/tefek/pluto/engine/math/ClampedSineWave.java rename to plutolib/src/main/java/cz/tefek/pluto/math/ClampedSineWave.java index 7a4a04c..c4b0d34 100644 --- a/plutostatic/src/main/java/cz/tefek/pluto/engine/math/ClampedSineWave.java +++ b/plutolib/src/main/java/cz/tefek/pluto/math/ClampedSineWave.java @@ -1,26 +1,26 @@ -package cz.tefek.pluto.engine.math; +package cz.tefek.pluto.math; /** * A clamped sine wave generator, for animations, mostly. * - * @since 0.2 + * @since 0.3 * @author 493msi */ public class ClampedSineWave { /** - * Gets a clamped value of the abs(sine) function from the given parameters as a - * {@link double}. + * Gets a clamped value of the abs(sine) function from the given parameters + * as a {@link double}. * * @param animationProgress The animation progress in frames. - * @param frameOffset The animation offset in frames. - * @param animationFrames The total amount of animation frames. - * @param bottomClamp The sine wave clamp, minimum value. - * @param topClamp The sine wave clamp, maximum value. + * @param frameOffset The animation offset in frames. + * @param animationFrames The total amount of animation frames. + * @param bottomClamp The sine wave clamp, minimum value. + * @param topClamp The sine wave clamp, maximum value. * * @return The resulting value * - * @since 0.2 + * @since 0.3 * @author 493msi */ public static double getAbsolute(double animationProgress, double frameOffset, double animationFrames, double bottomClamp, double topClamp) @@ -34,14 +34,14 @@ public class ClampedSineWave * {@link double}. * * @param animationProgress The animation progress in frames. - * @param frameOffset The animation offset in frames. - * @param animationFrames The total amount of animation frames. - * @param bottomClamp The sine wave clamp, minimum value. - * @param topClamp The sine wave clamp, maximum value. + * @param frameOffset The animation offset in frames. + * @param animationFrames The total amount of animation frames. + * @param bottomClamp The sine wave clamp, minimum value. + * @param topClamp The sine wave clamp, maximum value. * * @return The resulting value * - * @since 0.2 + * @since 0.3 * @author 493msi */ public static double get(double animationProgress, double frameOffset, double animationFrames, float bottomClamp, float topClamp) @@ -55,13 +55,13 @@ public class ClampedSineWave * {@link double}. * * @param animationProgress The animation progress in frames. - * @param animationFrames The total amount of animation frames. - * @param bottomClamp The sine wave clamp, minimum value. - * @param topClamp The sine wave clamp, maximum value. + * @param animationFrames The total amount of animation frames. + * @param bottomClamp The sine wave clamp, minimum value. + * @param topClamp The sine wave clamp, maximum value. * * @return The resulting value * - * @since 0.2 + * @since 0.3 * @author 493msi */ public static double get(double animationProgress, double animationFrames, float bottomClamp, float topClamp) diff --git a/plutostatic/src/main/java/cz/tefek/pluto/engine/math/CubicBezier.java b/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezier.java similarity index 76% rename from plutostatic/src/main/java/cz/tefek/pluto/engine/math/CubicBezier.java rename to plutolib/src/main/java/cz/tefek/pluto/math/CubicBezier.java index eccc8f2..4eacf6f 100644 --- a/plutostatic/src/main/java/cz/tefek/pluto/engine/math/CubicBezier.java +++ b/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezier.java @@ -1,4 +1,4 @@ -package cz.tefek.pluto.engine.math; +package cz.tefek.pluto.math; /** * A class to generate a cubic bezier interpolation function. Not very @@ -20,7 +20,7 @@ public class CubicBezier * @param cpx2 the X position of the direction the function "arrives from" * @param cpy2 the Y position of the direction the function "arrives from" * - * @since 0.2 + * @since 0.3 * @author 493msi */ public CubicBezier(double cpx1, double cpy1, double cpx2, double cpy2) @@ -44,29 +44,33 @@ public class CubicBezier * * @return the approximate Y position for the given X position * - * @since 0.2 + * @since 0.3 * @author 493msi */ public double forX(double xIn) { if (xIn < 0) - return forX(0); + { + return this.forX(0); + } if (xIn > 1) - return forX(1); + { + return this.forX(1); + } double t = 0.5; double x; - double y = 3 * (1 - t) * (1 - t) * t * b + 3 * (1 - t) * t * t * d + t * t * t; + double y = 3 * (1 - t) * (1 - t) * t * this.b + 3 * (1 - t) * t * t * this.d + t * t * t; double delta = 0.25; boolean uh; for (int i = 0; i < iterations; i++) { - x = 3 * (1 - t) * (1 - t) * t * a + 3 * (1 - t) * t * t * c + t * t * t; - y = 3 * (1 - t) * (1 - t) * t * b + 3 * (1 - t) * t * t * d + t * t * t; + x = 3 * (1 - t) * (1 - t) * t * this.a + 3 * (1 - t) * t * t * this.c + t * t * t; + y = 3 * (1 - t) * (1 - t) * t * this.b + 3 * (1 - t) * t * t * this.d + t * t * t; uh = x > xIn; diff --git a/plutostatic/src/main/java/cz/tefek/pluto/engine/math/CubicBezierLT.java b/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezierLT.java similarity index 84% rename from plutostatic/src/main/java/cz/tefek/pluto/engine/math/CubicBezierLT.java rename to plutolib/src/main/java/cz/tefek/pluto/math/CubicBezierLT.java index 3703dba..a7b44e2 100644 --- a/plutostatic/src/main/java/cz/tefek/pluto/engine/math/CubicBezierLT.java +++ b/plutolib/src/main/java/cz/tefek/pluto/math/CubicBezierLT.java @@ -1,4 +1,4 @@ -package cz.tefek.pluto.engine.math; +package cz.tefek.pluto.math; /** * A class to generate a cubic bezier interpolation function. This @@ -21,7 +21,7 @@ public class CubicBezierLT * @param cpx2 the X position of the direction the function "arrives from" * @param cpy2 the Y position of the direction the function "arrives from" * - * @since 0.2 + * @since 0.3 * @author 493msi */ public CubicBezierLT(double cpx1, double cpy1, double cpx2, double cpy2) @@ -37,7 +37,7 @@ public class CubicBezierLT for (int i = 0; i < tableSize; i++) { - values[i] = cubicBezier.forX(i / upperBound); + this.values[i] = cubicBezier.forX(i / this.upperBound); } } @@ -49,17 +49,21 @@ public class CubicBezierLT * * @return the approximate Y position for the given X position * - * @since 0.2 + * @since 0.3 * @author 493msi */ public double forX(double xIn) { if (xIn < 0) - return forX(0); + { + return this.forX(0); + } if (xIn > 1) - return forX(1); + { + return this.forX(1); + } - return values[(int) (xIn * upperBound)]; + return this.values[(int) (xIn * this.upperBound)]; } } diff --git a/plutolib/src/main/java/cz/tefek/pluto/math/package-info.java b/plutolib/src/main/java/cz/tefek/pluto/math/package-info.java new file mode 100644 index 0000000..b439110 --- /dev/null +++ b/plutolib/src/main/java/cz/tefek/pluto/math/package-info.java @@ -0,0 +1,7 @@ +/** + * Math utility classes. + * + * @author 493msi + * + */ +package cz.tefek.pluto.math;