Moved some math utils to plutolib

This commit is contained in:
Tefek 2020-08-20 23:59:19 +02:00
parent 6897977d26
commit 0373b7e312
4 changed files with 48 additions and 33 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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)];
}
}

View File

@ -0,0 +1,7 @@
/**
* Math utility classes.
*
* @author 493msi
*
*/
package cz.tefek.pluto.math;