Added easing functions
This commit is contained in:
parent
a27873bedd
commit
4955731abc
2 changed files with 674 additions and 0 deletions
357
src/zutil/math/Easing.java
Normal file
357
src/zutil/math/Easing.java
Normal file
|
|
@ -0,0 +1,357 @@
|
|||
package zutil.math;
|
||||
|
||||
/**
|
||||
* Class contains easing function mostly used in animations and other graphical things.
|
||||
*
|
||||
* @see <a href="https://easings.net/">Easing.net</a>
|
||||
*/
|
||||
public class Easing {
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Sin
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInSine(double x) {
|
||||
return 1 - Math.cos((x * Math.PI) / 2.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutSine(double x) {
|
||||
return Math.sin((x * Math.PI) / 2.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutSine(double x) {
|
||||
return -(Math.cos(x * Math.PI) - 1.0) / 2.0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Quad
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInQuad(double x) {
|
||||
return x * x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutQuad(double x) {
|
||||
return 1 - (1 - x) * (1 - x);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutQuad(double x) {
|
||||
return (x < 0.5 ?
|
||||
2 * x * x :
|
||||
1 - Math.pow(-2 * x + 2, 2) / 2);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Cubic
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInCubic(double x) {
|
||||
return x * x * x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutCubic(double x) {
|
||||
return 1 - Math.pow(1 - x, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutCubic(double x) {
|
||||
return (x < 0.5 ?
|
||||
4 * x * x * x :
|
||||
1 - Math.pow(-2 * x + 2, 3) / 2);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Cubic
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInQuart(double x) {
|
||||
return x * x * x * x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutQuart(double x) {
|
||||
return 1 - Math.pow(1 - x, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutQuart(double x) {
|
||||
return (x < 0.5 ?
|
||||
8 * x * x * x * x :
|
||||
1 - Math.pow(-2 * x + 2, 4) / 2);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Quint
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInQuint(double x) {
|
||||
return x * x * x * x * x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutQuint(double x) {
|
||||
return 1 - Math.pow(1 - x, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutQuint(double x) {
|
||||
return (x < 0.5 ?
|
||||
16 * x * x * x * x * x :
|
||||
1 - Math.pow(-2 * x + 2, 5) / 2);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Cubic
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInExpo(double x) {
|
||||
return (x == 0 ?
|
||||
0 :
|
||||
Math.pow(2, 10 * x - 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutExpo(double x) {
|
||||
return (x == 1 ?
|
||||
1 :
|
||||
1 - Math.pow(2, -10 * x));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutExpo(double x) {
|
||||
if (x == 0.0)
|
||||
return 0;
|
||||
else if (x == 1.0)
|
||||
return 1;
|
||||
else if (x < 0.5)
|
||||
return Math.pow(2, 20 * x - 10) / 2;
|
||||
else
|
||||
return (2 - Math.pow(2, -20 * x + 10)) / 2;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Circ
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInCirc(double x) {
|
||||
return 1 - Math.sqrt(1 - Math.pow(x, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutCirc(double x) {
|
||||
return Math.sqrt(1 - Math.pow(x - 1, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutCirc(double x) {
|
||||
return (x < 0.5
|
||||
? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2
|
||||
: (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Back
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInBack(double x) {
|
||||
double c1 = 1.70158;
|
||||
double c3 = c1 + 1;
|
||||
|
||||
return c3 * x * x * x - c1 * x * x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutBack(double x) {
|
||||
double c1 = 1.70158;
|
||||
double c3 = c1 + 1;
|
||||
|
||||
return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutBack(double x) {
|
||||
double c1 = 1.70158;
|
||||
double c2 = c1 * 1.525;
|
||||
|
||||
return x < 0.5
|
||||
? (Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
|
||||
: (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Elastic
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInElastic(double x) {
|
||||
double c4 = (2 * Math.PI) / 3;
|
||||
|
||||
if (x == 0.0)
|
||||
return 0;
|
||||
else if (x == 1.0)
|
||||
return 1;
|
||||
else
|
||||
return - Math.pow(2, 10 * x - 10) * Math.sin((x * 10 - 10.75) * c4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutElastic(double x) {
|
||||
double c4 = (2 * Math.PI) / 3;
|
||||
|
||||
if (x == 0.0)
|
||||
return 0;
|
||||
else if (x == 1.0)
|
||||
return 1;
|
||||
else
|
||||
return Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutElastic(double x) {
|
||||
double c5 = (2 * Math.PI) / 4.5;
|
||||
|
||||
if (x == 0.0)
|
||||
return 0;
|
||||
else if (x == 1.0)
|
||||
return 1;
|
||||
else if (x < 0.5)
|
||||
return -(Math.pow(2, 20 * x - 10) * Math.sin((20 * x - 11.125) * c5)) / 2;
|
||||
else
|
||||
return (Math.pow(2, -20 * x + 10) * Math.sin((20 * x - 11.125) * c5)) / 2 + 1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Bounce
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInBounce(double x) {
|
||||
return 1 - easeOutBounce(1 - x);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeOutBounce(double x) {
|
||||
double n1 = 7.5625;
|
||||
double d1 = 2.75;
|
||||
|
||||
if (x < 1 / d1) {
|
||||
return n1 * x * x;
|
||||
} else if (x < 2 / d1) {
|
||||
return n1 * (x -= 1.5 / d1) * x + 0.75;
|
||||
} else if (x < 2.5 / d1) {
|
||||
return n1 * (x -= 2.25 / d1) * x + 0.9375;
|
||||
} else {
|
||||
return n1 * (x -= 2.625 / d1) * x + 0.984375;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x represents the absolute progress of the animation in the bounds of 0 (beginning of the animation) and 1 (end of animation).
|
||||
* @return a double value between 0 and 1 based on the animation progress.
|
||||
*/
|
||||
public static double easeInOutBounce(double x) {
|
||||
return x < 0.5
|
||||
? (1 - easeOutBounce(1 - 2 * x)) / 2
|
||||
: (1 + easeOutBounce(2 * x - 1)) / 2;
|
||||
}
|
||||
}
|
||||
317
test/zutil/math/EasingTest.java
Normal file
317
test/zutil/math/EasingTest.java
Normal file
|
|
@ -0,0 +1,317 @@
|
|||
package zutil.math;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EasingTest {
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Sin
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInSine() {
|
||||
assertEquals(0.0, Easing.easeInSine(0), 0.01);
|
||||
assertEquals(0.07, Easing.easeInSine(0.25), 0.01);
|
||||
assertEquals(0.29, Easing.easeInSine(0.5), 0.01);
|
||||
assertEquals(0.62, Easing.easeInSine(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInSine(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutSine() {
|
||||
assertEquals(0.0, Easing.easeOutSine(0), 0.01);
|
||||
assertEquals(0.38, Easing.easeOutSine(0.25), 0.01);
|
||||
assertEquals(0.70, Easing.easeOutSine(0.5), 0.01);
|
||||
assertEquals(0.92, Easing.easeOutSine(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutSine(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutSine() {
|
||||
assertEquals(0.0, Easing.easeInOutSine(0), 0.01);
|
||||
assertEquals(0.14, Easing.easeInOutSine(0.25), 0.01);
|
||||
assertEquals(0.5, Easing.easeInOutSine(0.5), 0.01);
|
||||
assertEquals(0.85, Easing.easeInOutSine(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutSine(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Quad
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInQuad() {
|
||||
assertEquals(0.0, Easing.easeInQuad(0), 0.01);
|
||||
assertEquals(0.06, Easing.easeInQuad(0.25), 0.01);
|
||||
assertEquals(0.25, Easing.easeInQuad(0.5), 0.01);
|
||||
assertEquals(0.56, Easing.easeInQuad(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInQuad(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutQuad() {
|
||||
assertEquals(0.0, Easing.easeOutQuad(0), 0.01);
|
||||
assertEquals(0.43, Easing.easeOutQuad(0.25), 0.01);
|
||||
assertEquals(0.75, Easing.easeOutQuad(0.5), 0.01);
|
||||
assertEquals(0.93, Easing.easeOutQuad(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutQuad(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutQuad() {
|
||||
assertEquals(0.0, Easing.easeInOutQuad(0), 0.01);
|
||||
assertEquals(0.12, Easing.easeInOutQuad(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutQuad(0.5), 0.01);
|
||||
assertEquals(0.87, Easing.easeInOutQuad(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutQuad(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Cubic
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInCubic() {
|
||||
assertEquals(0.0, Easing.easeInCubic(0), 0.01);
|
||||
assertEquals(0.01, Easing.easeInCubic(0.25), 0.01);
|
||||
assertEquals(0.12, Easing.easeInCubic(0.5), 0.01);
|
||||
assertEquals(0.42, Easing.easeInCubic(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInCubic(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutCubic() {
|
||||
assertEquals(0.0, Easing.easeOutCubic(0), 0.01);
|
||||
assertEquals(0.57, Easing.easeOutCubic(0.25), 0.01);
|
||||
assertEquals(0.87, Easing.easeOutCubic(0.5), 0.01);
|
||||
assertEquals(0.98, Easing.easeOutCubic(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutCubic(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutCubic() {
|
||||
assertEquals(0.0, Easing.easeInOutCubic(0), 0.01);
|
||||
assertEquals(0.06, Easing.easeInOutCubic(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutCubic(0.5), 0.01);
|
||||
assertEquals(0.93, Easing.easeInOutCubic(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutCubic(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Cubic
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInQuart() {
|
||||
assertEquals(0.0, Easing.easeInQuart(0), 0.01);
|
||||
assertEquals(0.00, Easing.easeInQuart(0.25), 0.01);
|
||||
assertEquals(0.06, Easing.easeInQuart(0.5), 0.01);
|
||||
assertEquals(0.31, Easing.easeInQuart(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInQuart(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutQuart() {
|
||||
assertEquals(0.0, Easing.easeOutQuart(0), 0.01);
|
||||
assertEquals(0.68, Easing.easeOutQuart(0.25), 0.01);
|
||||
assertEquals(0.93, Easing.easeOutQuart(0.5), 0.01);
|
||||
assertEquals(0.99, Easing.easeOutQuart(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutQuart(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutQuart() {
|
||||
assertEquals(0.0, Easing.easeInOutQuart(0), 0.01);
|
||||
assertEquals(0.03, Easing.easeInOutQuart(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutQuart(0.5), 0.01);
|
||||
assertEquals(0.96, Easing.easeInOutQuart(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutQuart(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Quint
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInQuint() {
|
||||
assertEquals(0.0, Easing.easeInQuint(0), 0.01);
|
||||
assertEquals(0.00, Easing.easeInQuint(0.25), 0.01);
|
||||
assertEquals(0.03, Easing.easeInQuint(0.5), 0.01);
|
||||
assertEquals(0.23, Easing.easeInQuint(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInQuint(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutQuint() {
|
||||
assertEquals(0.0, Easing.easeOutQuint(0), 0.01);
|
||||
assertEquals(0.76, Easing.easeOutQuint(0.25), 0.01);
|
||||
assertEquals(0.96, Easing.easeOutQuint(0.5), 0.01);
|
||||
assertEquals(0.99, Easing.easeOutQuint(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutQuint(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutQuint() {
|
||||
assertEquals(0.0, Easing.easeInOutQuint(0), 0.01);
|
||||
assertEquals(0.01, Easing.easeInOutQuint(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutQuint(0.5), 0.01);
|
||||
assertEquals(0.98, Easing.easeInOutQuint(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutQuint(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Cubic
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInExpo() {
|
||||
assertEquals(0.0, Easing.easeInExpo(0), 0.01);
|
||||
assertEquals(0.00, Easing.easeInExpo(0.25), 0.01);
|
||||
assertEquals(0.03, Easing.easeInExpo(0.5), 0.01);
|
||||
assertEquals(0.17, Easing.easeInExpo(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInExpo(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutExpo() {
|
||||
assertEquals(0.0, Easing.easeOutExpo(0), 0.01);
|
||||
assertEquals(0.82, Easing.easeOutExpo(0.25), 0.01);
|
||||
assertEquals(0.97, Easing.easeOutExpo(0.5), 0.01);
|
||||
assertEquals(0.99, Easing.easeOutExpo(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutExpo(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutExpo() {
|
||||
assertEquals(0.0, Easing.easeInOutExpo(0), 0.01);
|
||||
assertEquals(0.01, Easing.easeInOutExpo(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutExpo(0.5), 0.01);
|
||||
assertEquals(0.98, Easing.easeInOutExpo(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutExpo(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Circ
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInCirc() {
|
||||
assertEquals(0.0, Easing.easeInCirc(0), 0.01);
|
||||
assertEquals(0.03, Easing.easeInCirc(0.25), 0.01);
|
||||
assertEquals(0.13, Easing.easeInCirc(0.5), 0.01);
|
||||
assertEquals(0.33, Easing.easeInCirc(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInCirc(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutCirc() {
|
||||
assertEquals(0.0, Easing.easeOutCirc(0), 0.01);
|
||||
assertEquals(0.66, Easing.easeOutCirc(0.25), 0.01);
|
||||
assertEquals(0.86, Easing.easeOutCirc(0.5), 0.01);
|
||||
assertEquals(0.96, Easing.easeOutCirc(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutCirc(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutCirc() {
|
||||
assertEquals(0.0, Easing.easeInOutCirc(0), 0.01);
|
||||
assertEquals(0.06, Easing.easeInOutCirc(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutCirc(0.5), 0.01);
|
||||
assertEquals(0.93, Easing.easeInOutCirc(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutCirc(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Back
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInBack() {
|
||||
assertEquals(0.0, Easing.easeInBack(0), 0.01);
|
||||
assertEquals(-0.06, Easing.easeInBack(0.25), 0.01);
|
||||
assertEquals(-0.09, Easing.easeInBack(0.5), 0.01);
|
||||
assertEquals(0.18, Easing.easeInBack(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInBack(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutBack() {
|
||||
assertEquals(0.0, Easing.easeOutBack(0), 0.01);
|
||||
assertEquals(0.81, Easing.easeOutBack(0.25), 0.01);
|
||||
assertEquals(1.08, Easing.easeOutBack(0.5), 0.01);
|
||||
assertEquals(1.06, Easing.easeOutBack(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutBack(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutBack() {
|
||||
assertEquals(0.0, Easing.easeInOutBack(0), 0.01);
|
||||
assertEquals(-0.09, Easing.easeInOutBack(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutBack(0.5), 0.01);
|
||||
assertEquals(1.09, Easing.easeInOutBack(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutBack(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Elastic
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInElastic() {
|
||||
assertEquals(0.0, Easing.easeInElastic(0), 0.01);
|
||||
assertEquals(0.00, Easing.easeInElastic(0.25), 0.01);
|
||||
assertEquals(-0.01, Easing.easeInElastic(0.5), 0.01);
|
||||
assertEquals(0.08, Easing.easeInElastic(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInElastic(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutElastic() {
|
||||
assertEquals(0.0, Easing.easeOutElastic(0), 0.01);
|
||||
assertEquals(0.91, Easing.easeOutElastic(0.25), 0.01);
|
||||
assertEquals(1.01, Easing.easeOutElastic(0.5), 0.01);
|
||||
assertEquals(1.00, Easing.easeOutElastic(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutElastic(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutElastic() {
|
||||
assertEquals(0.0, Easing.easeInOutElastic(0), 0.01);
|
||||
assertEquals(0.01, Easing.easeInOutElastic(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutElastic(0.5), 0.01);
|
||||
assertEquals(0.98, Easing.easeInOutElastic(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutElastic(1), 0.01);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Bounce
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void easeInBounce() {
|
||||
assertEquals(0.0, Easing.easeInBounce(0), 0.01);
|
||||
assertEquals(0.02, Easing.easeInBounce(0.25), 0.01);
|
||||
assertEquals(0.23, Easing.easeInBounce(0.5), 0.01);
|
||||
assertEquals(0.52, Easing.easeInBounce(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInBounce(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeOutBounce() {
|
||||
assertEquals(0.0, Easing.easeOutBounce(0), 0.01);
|
||||
assertEquals(0.47, Easing.easeOutBounce(0.25), 0.01);
|
||||
assertEquals(0.76, Easing.easeOutBounce(0.5), 0.01);
|
||||
assertEquals(0.97, Easing.easeOutBounce(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeOutBounce(1), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void easeInOutBounce() {
|
||||
assertEquals(0.0, Easing.easeInOutBounce(0), 0.01);
|
||||
assertEquals(0.11, Easing.easeInOutBounce(0.25), 0.01);
|
||||
assertEquals(0.50, Easing.easeInOutBounce(0.5), 0.01);
|
||||
assertEquals(0.88, Easing.easeInOutBounce(0.75), 0.01);
|
||||
assertEquals(1.0, Easing.easeInOutBounce(1), 0.01);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue