|
@@ -34,6 +34,7 @@ package com.jme3.math;
|
|
import com.jme3.asset.AssetManager;
|
|
import com.jme3.asset.AssetManager;
|
|
import com.jme3.asset.DesktopAssetManager;
|
|
import com.jme3.asset.DesktopAssetManager;
|
|
import com.jme3.export.binary.BinaryExporter;
|
|
import com.jme3.export.binary.BinaryExporter;
|
|
|
|
+import com.jme3.util.clone.Cloner;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
@@ -52,6 +53,47 @@ public class SplineTest {
|
|
// *************************************************************************
|
|
// *************************************************************************
|
|
// tests
|
|
// tests
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Verifies that spline cloning works correctly.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void cloneSplines() {
|
|
|
|
+ // Clone a Bézier spline:
|
|
|
|
+ {
|
|
|
|
+ Spline test1 = createBezier();
|
|
|
|
+ Spline copy1 = Cloner.deepClone(test1);
|
|
|
|
+ assertSplineEquals(test1, copy1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Clone a NURB spline:
|
|
|
|
+ {
|
|
|
|
+ Spline test2 = createNurb();
|
|
|
|
+ Spline copy2 = Cloner.deepClone(test2);
|
|
|
|
+ assertSplineEquals(test2, copy2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Clone a Catmull-Rom spline:
|
|
|
|
+ {
|
|
|
|
+ Spline test3 = createCatmullRom();
|
|
|
|
+ Spline copy3 = Cloner.deepClone(test3);
|
|
|
|
+ assertSplineEquals(test3, copy3);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Clone a linear spline:
|
|
|
|
+ {
|
|
|
|
+ Spline test4 = createLinear();
|
|
|
|
+ Spline copy4 = Cloner.deepClone(test4);
|
|
|
|
+ assertSplineEquals(test4, copy4);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Clone a default spline:
|
|
|
|
+ {
|
|
|
|
+ Spline test5 = new Spline();
|
|
|
|
+ Spline copy5 = Cloner.deepClone(test5);
|
|
|
|
+ assertSplineEquals(test5, copy5);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Verifies that spline serialization/deserialization works correctly.
|
|
* Verifies that spline serialization/deserialization works correctly.
|
|
*/
|
|
*/
|
|
@@ -59,63 +101,28 @@ public class SplineTest {
|
|
public void saveAndLoadSplines() {
|
|
public void saveAndLoadSplines() {
|
|
// Serialize and deserialize a Bezier spline:
|
|
// Serialize and deserialize a Bezier spline:
|
|
{
|
|
{
|
|
- Vector3f[] controlPoints1 = {
|
|
|
|
- new Vector3f(0f, 1f, 0f), new Vector3f(1f, 2f, 1f),
|
|
|
|
- new Vector3f(1.5f, 1.5f, 1.5f), new Vector3f(2f, 0f, 1f)
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- Spline test1 = new Spline(
|
|
|
|
- Spline.SplineType.Bezier, controlPoints1, 0.1f, true);
|
|
|
|
|
|
+ Spline test1 = createBezier();
|
|
Spline copy1 = BinaryExporter.saveAndLoad(assetManager, test1);
|
|
Spline copy1 = BinaryExporter.saveAndLoad(assetManager, test1);
|
|
assertSplineEquals(test1, copy1);
|
|
assertSplineEquals(test1, copy1);
|
|
}
|
|
}
|
|
|
|
|
|
// Serialize and deserialize a NURB spline:
|
|
// Serialize and deserialize a NURB spline:
|
|
{
|
|
{
|
|
- List<Vector4f> controlPoints2 = new ArrayList<>(5);
|
|
|
|
- controlPoints2.add(new Vector4f(0f, 1f, 2f, 3f));
|
|
|
|
- controlPoints2.add(new Vector4f(3f, 1f, 4f, 0f));
|
|
|
|
- controlPoints2.add(new Vector4f(2f, 5f, 3f, 0f));
|
|
|
|
- controlPoints2.add(new Vector4f(3f, 2f, 3f, 1f));
|
|
|
|
- controlPoints2.add(new Vector4f(0.5f, 1f, 0.6f, 5f));
|
|
|
|
- List<Float> nurbKnots = new ArrayList<>(6);
|
|
|
|
- nurbKnots.add(0.2f);
|
|
|
|
- nurbKnots.add(0.3f);
|
|
|
|
- nurbKnots.add(0.4f);
|
|
|
|
- nurbKnots.add(0.43f);
|
|
|
|
- nurbKnots.add(0.51f);
|
|
|
|
- nurbKnots.add(0.52f);
|
|
|
|
-
|
|
|
|
- Spline test2 = new Spline(controlPoints2, nurbKnots);
|
|
|
|
|
|
+ Spline test2 = createNurb();
|
|
Spline copy2 = BinaryExporter.saveAndLoad(assetManager, test2);
|
|
Spline copy2 = BinaryExporter.saveAndLoad(assetManager, test2);
|
|
assertSplineEquals(test2, copy2);
|
|
assertSplineEquals(test2, copy2);
|
|
}
|
|
}
|
|
|
|
|
|
// Serialize and deserialize a Catmull-Rom spline:
|
|
// Serialize and deserialize a Catmull-Rom spline:
|
|
{
|
|
{
|
|
- List<Vector3f> controlPoints3 = new ArrayList<>(6);
|
|
|
|
- controlPoints3.add(new Vector3f(0f, 1f, 2f));
|
|
|
|
- controlPoints3.add(new Vector3f(3f, -1f, 4f));
|
|
|
|
- controlPoints3.add(new Vector3f(2f, 5f, 3f));
|
|
|
|
- controlPoints3.add(new Vector3f(3f, -2f, 3f));
|
|
|
|
- controlPoints3.add(new Vector3f(0.5f, 1f, 0.6f));
|
|
|
|
- controlPoints3.add(new Vector3f(-0.5f, 4f, 0.2f));
|
|
|
|
-
|
|
|
|
- Spline test3 = new Spline(
|
|
|
|
- Spline.SplineType.CatmullRom, controlPoints3, 0.01f, false);
|
|
|
|
|
|
+ Spline test3 = createCatmullRom();
|
|
Spline copy3 = BinaryExporter.saveAndLoad(assetManager, test3);
|
|
Spline copy3 = BinaryExporter.saveAndLoad(assetManager, test3);
|
|
assertSplineEquals(test3, copy3);
|
|
assertSplineEquals(test3, copy3);
|
|
}
|
|
}
|
|
|
|
|
|
// Serialize and deserialize a linear spline:
|
|
// Serialize and deserialize a linear spline:
|
|
{
|
|
{
|
|
- List<Vector3f> controlPoints4 = new ArrayList<>(3);
|
|
|
|
- controlPoints4.add(new Vector3f(3f, -1f, 4f));
|
|
|
|
- controlPoints4.add(new Vector3f(2f, 0f, 3f));
|
|
|
|
- controlPoints4.add(new Vector3f(3f, -2f, 3f));
|
|
|
|
-
|
|
|
|
- Spline test4 = new Spline(
|
|
|
|
- Spline.SplineType.Linear, controlPoints4, 0f, true);
|
|
|
|
|
|
+ Spline test4 = createLinear();
|
|
Spline copy4 = BinaryExporter.saveAndLoad(assetManager, test4);
|
|
Spline copy4 = BinaryExporter.saveAndLoad(assetManager, test4);
|
|
assertSplineEquals(test4, copy4);
|
|
assertSplineEquals(test4, copy4);
|
|
}
|
|
}
|
|
@@ -131,14 +138,22 @@ public class SplineTest {
|
|
// private helper methods
|
|
// private helper methods
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Verify that the specified lists are equivalent.
|
|
|
|
|
|
+ * Verifies that the specified lists are equivalent but distinct.
|
|
*
|
|
*
|
|
* @param s1 the first list to compare (may be null, unaffected)
|
|
* @param s1 the first list to compare (may be null, unaffected)
|
|
* @param s2 the 2nd list to compare (may be null, unaffected)
|
|
* @param s2 the 2nd list to compare (may be null, unaffected)
|
|
*/
|
|
*/
|
|
private static void assertListEquals(List<?> a1, List<?> a2) {
|
|
private static void assertListEquals(List<?> a1, List<?> a2) {
|
|
- if (a1 != a2) {
|
|
|
|
|
|
+ if (a1 == null || a2 == null) {
|
|
|
|
+ // If either list is null, verify that both are null:
|
|
|
|
+ Assert.assertNull(a1);
|
|
|
|
+ Assert.assertNull(a2);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ // Verify that the lists are distinct and and of equal length:
|
|
|
|
+ Assert.assertTrue(a1 != a2);
|
|
Assert.assertEquals(a1.size(), a2.size());
|
|
Assert.assertEquals(a1.size(), a2.size());
|
|
|
|
+
|
|
for (int i = 0; i < a1.size(); ++i) {
|
|
for (int i = 0; i < a1.size(); ++i) {
|
|
Assert.assertEquals(a1.get(i), a2.get(i));
|
|
Assert.assertEquals(a1.get(i), a2.get(i));
|
|
}
|
|
}
|
|
@@ -172,4 +187,80 @@ public class SplineTest {
|
|
s1.getTotalLength(), s2.getTotalLength(), 0f);
|
|
s1.getTotalLength(), s2.getTotalLength(), 0f);
|
|
Assert.assertArrayEquals(s1.getWeights(), s2.getWeights(), 0f);
|
|
Assert.assertArrayEquals(s1.getWeights(), s2.getWeights(), 0f);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Generates a simple cyclic Bézier spline for testing.
|
|
|
|
+ *
|
|
|
|
+ * @return a new Spline
|
|
|
|
+ */
|
|
|
|
+ private static Spline createBezier() {
|
|
|
|
+ Vector3f[] controlPoints1 = {
|
|
|
|
+ new Vector3f(0f, 1f, 0f), new Vector3f(1f, 2f, 1f),
|
|
|
|
+ new Vector3f(1.5f, 1.5f, 1.5f), new Vector3f(2f, 0f, 1f)
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ Spline result = new Spline(
|
|
|
|
+ Spline.SplineType.Bezier, controlPoints1, 0.1f, true);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Generates a simple acyclic Catmull-Rom spline for testing.
|
|
|
|
+ *
|
|
|
|
+ * @return a new Spline
|
|
|
|
+ */
|
|
|
|
+ private static Spline createCatmullRom() {
|
|
|
|
+ List<Vector3f> controlPoints3 = new ArrayList<>(6);
|
|
|
|
+ controlPoints3.add(new Vector3f(0f, 1f, 2f));
|
|
|
|
+ controlPoints3.add(new Vector3f(3f, -1f, 4f));
|
|
|
|
+ controlPoints3.add(new Vector3f(2f, 5f, 3f));
|
|
|
|
+ controlPoints3.add(new Vector3f(3f, -2f, 3f));
|
|
|
|
+ controlPoints3.add(new Vector3f(0.5f, 1f, 0.6f));
|
|
|
|
+ controlPoints3.add(new Vector3f(-0.5f, 4f, 0.2f));
|
|
|
|
+
|
|
|
|
+ Spline result = new Spline(
|
|
|
|
+ Spline.SplineType.CatmullRom, controlPoints3, 0.01f, false);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Generates a simple cyclic linear spline for testing.
|
|
|
|
+ *
|
|
|
|
+ * @return a new Spline
|
|
|
|
+ */
|
|
|
|
+ private static Spline createLinear() {
|
|
|
|
+ List<Vector3f> controlPoints4 = new ArrayList<>(3);
|
|
|
|
+ controlPoints4.add(new Vector3f(3f, -1f, 4f));
|
|
|
|
+ controlPoints4.add(new Vector3f(2f, 0f, 3f));
|
|
|
|
+ controlPoints4.add(new Vector3f(3f, -2f, 3f));
|
|
|
|
+
|
|
|
|
+ Spline result = new Spline(
|
|
|
|
+ Spline.SplineType.Linear, controlPoints4, 0f, true);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Generates a simple NURB spline for testing.
|
|
|
|
+ *
|
|
|
|
+ * @return a new Spline
|
|
|
|
+ */
|
|
|
|
+ private static Spline createNurb() {
|
|
|
|
+ List<Vector4f> controlPoints2 = new ArrayList<>(5);
|
|
|
|
+ controlPoints2.add(new Vector4f(0f, 1f, 2f, 3f));
|
|
|
|
+ controlPoints2.add(new Vector4f(3f, 1f, 4f, 0f));
|
|
|
|
+ controlPoints2.add(new Vector4f(2f, 5f, 3f, 0f));
|
|
|
|
+ controlPoints2.add(new Vector4f(3f, 2f, 3f, 1f));
|
|
|
|
+ controlPoints2.add(new Vector4f(0.5f, 1f, 0.6f, 5f));
|
|
|
|
+
|
|
|
|
+ List<Float> nurbKnots = new ArrayList<>(6);
|
|
|
|
+ nurbKnots.add(0.2f);
|
|
|
|
+ nurbKnots.add(0.3f);
|
|
|
|
+ nurbKnots.add(0.4f);
|
|
|
|
+ nurbKnots.add(0.43f);
|
|
|
|
+ nurbKnots.add(0.51f);
|
|
|
|
+ nurbKnots.add(0.52f);
|
|
|
|
+
|
|
|
|
+ Spline result = new Spline(controlPoints2, nurbKnots);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|