diff --git a/src/main/java/engine/components/FlyByCameraControl.java b/src/main/java/engine/components/FlyByCameraControl.java
new file mode 100644
index 00000000..d96751bd
--- /dev/null
+++ b/src/main/java/engine/components/FlyByCameraControl.java
@@ -0,0 +1,183 @@
+package engine.components;
+
+import engine.input.Input;
+import engine.input.Key;
+import engine.scene.camera.Camera;
+import engine.scene.camera.PerspectiveCamera;
+import math.Mathf;
+import math.Vector3f;
+
+/**
+ * The {@code FlyByCameraControl} class provides first-person camera control functionality, allowing
+ * the user to move the camera in all directions and adjust its orientation using mouse and keyboard
+ * input. This control simulates a "fly-by" movement, typically used in 3D games or applications
+ * that require free-form camera navigation.
+ *
+ *
The movement is controlled by the following keys:
+ *
+ *
+ * - W: Move forward
+ *
- S: Move backward
+ *
- A: Move left (strafe)
+ *
- D: Move right (strafe)
+ *
- SPACE: Move up
+ *
- SHIFT: Move down
+ *
+ *
+ * The mouse controls the camera's yaw (left-right) and pitch (up-down) based on the mouse
+ * movement, with vertical angle limits set for pitch to prevent excessive rotations.
+ */
+public class FlyByCameraControl extends AbstractComponent {
+
+ private static final float DEFAULT_MOUSE_SENSITIVITY = 10f;
+
+ private static final float DEFAULT_MOVE_SPEED = 30f;
+
+ private static final float MAX_VERTICAL_ANGLE = 80f;
+
+ private static final float MIN_VERTICAL_ANGLE = -80f;
+
+ private final Vector3f forward = new Vector3f();
+
+ private final Vector3f target = new Vector3f();
+
+ private float mouseSensitivity = DEFAULT_MOUSE_SENSITIVITY;
+
+ private float moveSpeed = DEFAULT_MOVE_SPEED;
+
+ private Input input;
+
+ private Camera camera;
+
+ /**
+ * Constructs a new {@code FlyByCameraControl} with the specified input and camera.
+ *
+ * @param input The {@link Input} instance to capture user input.
+ * @param camera The {@link PerspectiveCamera} to control.
+ * @throws IllegalArgumentException if either {@code input} or {@code camera} is {@code null}.
+ */
+ public FlyByCameraControl(Input input, PerspectiveCamera camera) {
+ if (input == null || camera == null) {
+ throw new IllegalArgumentException("Input and Camera cannot be null.");
+ }
+ this.input = input;
+ this.camera = camera;
+ }
+
+ /**
+ * Updates the camera control state, handling mouse input for camera rotation and keyboard input
+ * for movement.
+ *
+ *
This method is typically called once per frame.
+ *
+ * @param tpf The time per frame (delta time) used for movement scaling.
+ */
+ @Override
+ public void update(float tpf) {
+ float mouseX = input.getMouseDeltaX() * mouseSensitivity * tpf;
+ float mouseY = input.getMouseDeltaY() * mouseSensitivity * tpf;
+
+ handleRotation(mouseX, mouseY);
+ updateTarget();
+
+ Vector3f velocity = calculateVelocity();
+ if (velocity.length() > 0) {
+ applyMovement(velocity, tpf);
+ }
+
+ input.center();
+ }
+
+ /**
+ * Handles camera rotation based on mouse input, applying yaw and pitch to the camera's transform.
+ * The vertical rotation (pitch) is clamped within defined limits to prevent excessive rotation.
+ *
+ * @param mouseX The mouse movement on the X-axis (horizontal movement).
+ * @param mouseY The mouse movement on the Y-axis (vertical movement).
+ */
+ private void handleRotation(float mouseX, float mouseY) {
+ // Handle yaw (left-right rotation)
+ float yaw = mouseX;
+ yaw = Mathf.clamp(yaw, -180f, 180f);
+ camera.getTransform().rotate(0, Mathf.toRadians(yaw), 0);
+
+ // Handle pitch (up-down rotation)
+ Vector3f rotation = camera.getTransform().getRotation();
+ float currentPitch = rotation.x;
+ currentPitch += Mathf.toRadians(mouseY);
+ currentPitch =
+ Mathf.clamp(
+ currentPitch, Mathf.toRadians(MIN_VERTICAL_ANGLE), Mathf.toRadians(MAX_VERTICAL_ANGLE));
+
+ rotation.x = currentPitch;
+ camera.getTransform().setRotation(rotation);
+ }
+
+ /**
+ * Calculates the movement velocity vector based on the current keyboard input. The velocity is a
+ * vector that indicates the desired direction of movement.
+ *
+ * @return A {@link Vector3f} representing the movement velocity.
+ */
+ private Vector3f calculateVelocity() {
+ Vector3f velocity = new Vector3f();
+ Vector3f forward = camera.getTransform().getForward();
+ Vector3f right = camera.getTransform().getRight();
+
+ // Movement controls (WASD, Space, Shift)
+ if (input.isKeyPressed(Key.W)) velocity.addLocal(forward);
+ if (input.isKeyPressed(Key.S)) velocity.addLocal(forward.negate());
+ if (input.isKeyPressed(Key.A)) velocity.addLocal(right.negate());
+ if (input.isKeyPressed(Key.D)) velocity.addLocal(right);
+ if (input.isKeyPressed(Key.SPACE)) velocity.addLocal(0, -1, 0);
+ if (input.isKeyPressed(Key.SHIFT)) velocity.addLocal(0, 1, 0);
+
+ return velocity;
+ }
+
+ /**
+ * Applies the calculated velocity to the camera's position, updating the camera's location based
+ * on user movement input.
+ *
+ * @param velocity The movement velocity to apply.
+ * @param tpf The time per frame (delta time) to scale the movement.
+ */
+ private void applyMovement(Vector3f velocity, float tpf) {
+ velocity.normalizeLocal();
+ Vector3f position = camera.getTransform().getPosition();
+ position.addLocal(velocity.mult(moveSpeed * tpf));
+ camera.getTransform().setPosition(position);
+ updateTarget();
+ }
+
+ /**
+ * Updates the target position for the camera. The target is a point in the scene that the camera
+ * looks at, and it is updated based on the camera's current position and rotation.
+ */
+ private void updateTarget() {
+ Vector3f position = camera.getTransform().getPosition();
+ Vector3f rotation = camera.getTransform().getRotation();
+
+ forward
+ .set(
+ Mathf.cos(rotation.y) * Mathf.cos(rotation.x),
+ Mathf.sin(rotation.x),
+ Mathf.sin(rotation.y) * Mathf.cos(rotation.x))
+ .normalizeLocal();
+
+ target.set(position).addLocal(forward);
+ camera.setTarget(target);
+ }
+
+ /** This method is called when the component is attached to an entity. Currently not used. */
+ @Override
+ public void onAttach() {
+ // Not used yet
+ }
+
+ /** This method is called when the component is detached from an entity. Currently not used. */
+ @Override
+ public void onDetach() {
+ // Not used yet
+ }
+}
diff --git a/src/main/java/engine/debug/DebugInfoUpdater.java b/src/main/java/engine/debug/DebugInfoUpdater.java
index ecfca957..abdcd2c1 100644
--- a/src/main/java/engine/debug/DebugInfoUpdater.java
+++ b/src/main/java/engine/debug/DebugInfoUpdater.java
@@ -11,6 +11,7 @@
import engine.scene.Scene;
import engine.scene.camera.Camera;
import math.Mathf;
+import workspace.GraphicsPImpl;
/**
* The {@code DebugInfoUpdater} class is responsible for updating debug information displayed by a
@@ -101,8 +102,8 @@ private void updateCameraInfo(Camera camera) {
if (camera == null) return;
setInfo(CATEGORY_CAMERA, "Aspect", camera.getAspectRatio());
setInfo(CATEGORY_CAMERA, "FOV", Mathf.toDegrees(camera.getFieldOfView()));
- setInfo(CATEGORY_CAMERA, "Near", Mathf.toDegrees(camera.getNearPlane()));
- setInfo(CATEGORY_CAMERA, "Far", Mathf.toDegrees(camera.getFarPlane()));
+ setInfo(CATEGORY_CAMERA, "Near", camera.getNearPlane());
+ setInfo(CATEGORY_CAMERA, "Far", camera.getFarPlane());
}
private void updateOsMetrics() {
@@ -122,6 +123,8 @@ private void updateSceneMetrics(Scene activeScene) {
setInfo(CATEGORY_SCENE, "Root count", activeScene.getRootCount());
setInfo(CATEGORY_SCENE, "Lights count", activeScene.getLightCount());
setInfo(CATEGORY_SCENE, "Wireframe mode", activeScene.isWireframeMode());
+ setInfo(CATEGORY_SCENE, "Faces", GraphicsPImpl.faceCount);
+ setInfo(CATEGORY_SCENE, "Vertices", GraphicsPImpl.vertexCount);
}
private void updateTimeMetrics(Timer timer) {
diff --git a/src/main/java/engine/input/MouseInput.java b/src/main/java/engine/input/MouseInput.java
index 435874dd..bd16f008 100644
--- a/src/main/java/engine/input/MouseInput.java
+++ b/src/main/java/engine/input/MouseInput.java
@@ -25,4 +25,6 @@ public interface MouseInput {
float getMouseDeltaY();
void updateMouseState(); // To track mouse-specific states
+
+ void center();
}
diff --git a/src/main/java/engine/processing/ProcessingApplication.java b/src/main/java/engine/processing/ProcessingApplication.java
index d855b5a5..8ba85e30 100644
--- a/src/main/java/engine/processing/ProcessingApplication.java
+++ b/src/main/java/engine/processing/ProcessingApplication.java
@@ -5,6 +5,7 @@
import engine.input.Input;
import engine.input.KeyInput;
import engine.input.MouseInput;
+import engine.resources.ResourceManager;
import processing.core.PApplet;
import workspace.GraphicsPImpl;
import workspace.ui.Graphics;
@@ -29,6 +30,7 @@ public void settings() {
@Override
public void setup() {
Graphics g = new GraphicsPImpl(this);
+ ResourceManager.getInstance().setImageLoader(new ProcessingImageLoader(this));
container.setGraphics(g);
getSurface().setTitle(settings.getTitle());
setupInput();
diff --git a/src/main/java/engine/processing/ProcessingInput.java b/src/main/java/engine/processing/ProcessingInput.java
index 4133e63a..3b17f6a9 100644
--- a/src/main/java/engine/processing/ProcessingInput.java
+++ b/src/main/java/engine/processing/ProcessingInput.java
@@ -93,6 +93,11 @@ public void updateMouseState() {
mouseInput.updateMouseState();
}
+ @Override
+ public void center() {
+ mouseInput.center();
+ }
+
@Override
public void update() {
updateKeyState();
diff --git a/src/main/java/engine/processing/ProcessingMouseInput.java b/src/main/java/engine/processing/ProcessingMouseInput.java
index f7e1659a..4799451a 100644
--- a/src/main/java/engine/processing/ProcessingMouseInput.java
+++ b/src/main/java/engine/processing/ProcessingMouseInput.java
@@ -1,5 +1,7 @@
package engine.processing;
+import java.awt.Robot;
+
import engine.input.MouseInput;
import processing.core.PApplet;
@@ -9,9 +11,15 @@ public class ProcessingMouseInput implements MouseInput {
private float mouseWheelDelta = 0;
+ private Robot robot;
+
public ProcessingMouseInput(PApplet applet) {
this.applet = applet;
applet.registerMethod("mouseEvent", this);
+ try {
+ robot = new Robot();
+ } catch (Throwable e) {
+ }
}
public void mouseEvent(processing.event.MouseEvent event) {
@@ -79,7 +87,14 @@ public float getMouseWheelDelta() {
}
@Override
- public void updateMouseState() {
- // Handle frame-specific mouse state updates if necessary
+ public void updateMouseState() {}
+
+ @Override
+ public void center() {
+ applet.mouseX = applet.width / 2;
+ applet.mouseY = applet.height / 2;
+ applet.pmouseX = applet.width / 2;
+ applet.pmouseY = applet.height / 2;
+ robot.mouseMove((int) getScreenWidth() / 2, (int) getScreenHeight() / 2);
}
}
diff --git a/src/test/java/mesh/modifier/test/NoiseModifierTest.java b/src/test/java/mesh/modifier/test/NoiseModifierTest.java
index 2a68bd0d..67d9e2d4 100644
--- a/src/test/java/mesh/modifier/test/NoiseModifierTest.java
+++ b/src/test/java/mesh/modifier/test/NoiseModifierTest.java
@@ -19,276 +19,272 @@
import mesh.modifier.NoiseModifier;
public class NoiseModifierTest {
-
- private NoiseModifier modifier;
-
- @BeforeEach
- public void setUp() {
- modifier = new NoiseModifier();
- }
-
- @Test
- public void testImplementsMeshModifierInterface() {
- assertTrue(modifier instanceof IMeshModifier);
- }
-
- @Test
- public void testReturnsNonNullReference() {
- Mesh3D mesh = new CubeCreator().create();
- assertNotNull(modifier.modify(mesh));
- }
-
- @Test
- public void testReturnsReferenceToTheModifiedMesh() {
- Mesh3D expected = new CubeCreator().create();
- Mesh3D actual = modifier.modify(expected);
- assertSame(expected, actual);
- }
-
- @Test
- public void testDefaultMinimum() {
- assertEquals(0, modifier.getMinimum());
- }
-
- @Test
- public void testDefaultMaximum() {
- assertEquals(1.0f, modifier.getMaximum());
- }
-
- @ParameterizedTest
- @ValueSource(floats = {
- 0.1f,
- 0.322f,
- 0.123f,
- 0.022f,
- 0.245f,
- 0.751f,
- 0.965f,
- Float.MIN_VALUE,
- Float.MAX_VALUE,
- })
- public void testGetSetMinumum(float minimum) {
- modifier.setMinimum(minimum);
- assertEquals(minimum, modifier.getMinimum());
- }
-
- @ParameterizedTest
- @ValueSource(floats = {
- 0.123f,
- 0.422f,
- 0.1553f,
- 0.2f,
- 1.245f,
- 3.751f,
- 100.965f,
- Float.MIN_VALUE,
- Float.MAX_VALUE,
- })
- public void testGetSetMaximum(float maximum) {
- modifier.setMaximum(maximum);
- assertEquals(maximum, modifier.getMaximum());
- }
-
- @Test
- public void testDefaultSeed() {
- assertEquals(0, modifier.getSeed());
+
+ private NoiseModifier modifier;
+
+ @BeforeEach
+ public void setUp() {
+ modifier = new NoiseModifier();
+ }
+
+ @Test
+ public void testImplementsMeshModifierInterface() {
+ assertTrue(modifier instanceof IMeshModifier);
+ }
+
+ @Test
+ public void testReturnsNonNullReference() {
+ Mesh3D mesh = new CubeCreator().create();
+ assertNotNull(modifier.modify(mesh));
+ }
+
+ @Test
+ public void testReturnsReferenceToTheModifiedMesh() {
+ Mesh3D expected = new CubeCreator().create();
+ Mesh3D actual = modifier.modify(expected);
+ assertSame(expected, actual);
+ }
+
+ @Test
+ public void testDefaultMinimum() {
+ assertEquals(0, modifier.getMinimum());
+ }
+
+ @Test
+ public void testDefaultMaximum() {
+ assertEquals(1.0f, modifier.getMaximum());
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ floats = {
+ 0.1f,
+ 0.322f,
+ 0.123f,
+ 0.022f,
+ 0.245f,
+ 0.751f,
+ 0.965f,
+ Float.MIN_VALUE,
+ Float.MAX_VALUE,
+ })
+ public void testGetSetMinumum(float minimum) {
+ modifier.setMinimum(minimum);
+ assertEquals(minimum, modifier.getMinimum());
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ floats = {
+ 0.123f,
+ 0.422f,
+ 0.1553f,
+ 0.2f,
+ 1.245f,
+ 3.751f,
+ 100.965f,
+ Float.MIN_VALUE,
+ Float.MAX_VALUE,
+ })
+ public void testGetSetMaximum(float maximum) {
+ modifier.setMaximum(maximum);
+ assertEquals(maximum, modifier.getMaximum());
+ }
+
+ @Test
+ public void testDefaultSeed() {
+ assertEquals(0, modifier.getSeed());
+ }
+
+ @ParameterizedTest
+ @ValueSource(longs = {-1000, -234, 0, 10000, 22344, Long.MIN_VALUE, Long.MAX_VALUE})
+ public void testGetSetSeed(long seed) {
+ modifier.setSeed(seed);
+ assertEquals(seed, modifier.getSeed());
+ }
+
+ @Test
+ public void testModifyEmptyMesh() {
+ Mesh3D mesh = new Mesh3D();
+ modifier.modify(mesh);
+ assertEquals(0, mesh.getFaceCount());
+ assertEquals(0, mesh.getVertexCount());
+ }
+
+ @Test
+ public void testVertexCountStaysConsistent() {
+ Mesh3D mesh = new IcoSphereCreator().create();
+ int expected = mesh.getVertexCount();
+ assertEquals(expected, modifier.modify(mesh).getVertexCount());
+ }
+
+ @Test
+ public void testFaceCountStaysConsistent() {
+ Mesh3D mesh = new IcoSphereCreator().create();
+ int expected = mesh.getFaceCount();
+ assertEquals(expected, modifier.modify(mesh).getFaceCount());
+ }
+
+ @Test
+ public void testDoesNotModifyFaceIndices() {
+ Mesh3D expected = new IcoSphereCreator().create();
+ Mesh3D actual = new IcoSphereCreator().create();
+ modifier.modify(actual);
+ for (int i = 0; i < actual.getFaceCount(); i++) {
+ int[] expectedIndices = expected.getFaceAt(i).indices;
+ int[] actualIndices = actual.getFaceAt(i).indices;
+ assertArrayEquals(expectedIndices, actualIndices);
}
-
- @ParameterizedTest
- @ValueSource(longs = {
- -1000,
- -234,
- 0,
- 10000,
- 22344,
- Long.MIN_VALUE,
- Long.MAX_VALUE
- })
- public void testGetSetSeed(long seed) {
- modifier.setSeed(seed);
- assertEquals(seed, modifier.getSeed());
+ }
+
+ @Test
+ public void testCubeVerticesDefaultSeed() {
+ Vector3f[] expectedVertices =
+ new Vector3f[] {
+ new Vector3f(1.4220245f, -1.4220245f, -1.4220245f),
+ new Vector3f(1.4800327f, -1.4800327f, 1.4800327f),
+ new Vector3f(-1.1388737f, -1.1388737f, 1.1388737f),
+ new Vector3f(-1.3500736f, -1.3500736f, -1.3500736f),
+ new Vector3f(1.3680131f, 1.3680131f, -1.3680131f),
+ new Vector3f(1.1784304f, 1.1784304f, 1.1784304f),
+ new Vector3f(-1.3177949f, 1.3177949f, 1.3177949f),
+ new Vector3f(-1.0675538f, 1.0675538f, -1.0675538f),
+ };
+
+ Mesh3D cube = new CubeCreator().create();
+ modifier.modify(cube);
+ for (int i = 0; i < cube.getFaceCount(); i++) {
+ Vector3f expectedVertex = expectedVertices[i];
+ Vector3f actualVertex = cube.getVertexAt(i);
+ assertEquals(expectedVertex, actualVertex);
}
-
- @Test
- public void testModifyEmptyMesh() {
- Mesh3D mesh = new Mesh3D();
- modifier.modify(mesh);
- assertEquals(0, mesh.getFaceCount());
- assertEquals(0, mesh.getVertexCount());
+ }
+
+ @Test
+ public void testCubeVerticesPositiveSeed() {
+ Vector3f[] expectedVertices =
+ new Vector3f[] {
+ new Vector3f(1.4390444f, -1.4390444f, -1.4390444f),
+ new Vector3f(1.4232731f, -1.4232731f, 1.4232731f),
+ new Vector3f(-1.4091227f, -1.4091227f, 1.4091227f),
+ new Vector3f(-1.1638807f, -1.1638807f, -1.1638807f),
+ new Vector3f(1.2712379f, 1.2712379f, -1.2712379f),
+ new Vector3f(1.111674f, 1.111674f, 1.111674f),
+ new Vector3f(-1.210412f, 1.210412f, 1.210412f),
+ new Vector3f(-1.2455546f, 1.2455546f, -1.2455546f),
+ };
+
+ Mesh3D cube = new CubeCreator().create();
+ modifier.setSeed(30445);
+ modifier.modify(cube);
+
+ for (int i = 0; i < cube.getFaceCount(); i++) {
+ Vector3f expectedVertex = expectedVertices[i];
+ Vector3f actualVertex = cube.getVertexAt(i);
+ assertEquals(expectedVertex, actualVertex);
}
-
- @Test
- public void testVertexCountStaysConsistent() {
- Mesh3D mesh = new IcoSphereCreator().create();
- int expected = mesh.getVertexCount();
- assertEquals(expected, modifier.modify(mesh).getVertexCount());
- }
-
- @Test
- public void testFaceCountStaysConsistent() {
- Mesh3D mesh = new IcoSphereCreator().create();
- int expected = mesh.getFaceCount();
- assertEquals(expected, modifier.modify(mesh).getFaceCount());
- }
-
- @Test
- public void testDoesNotModifyFaceIndices() {
- Mesh3D expected = new IcoSphereCreator().create();
- Mesh3D actual = new IcoSphereCreator().create();
- modifier.modify(actual);
- for (int i = 0; i < actual.getFaceCount(); i++) {
- int[] expectedIndices = expected.getFaceAt(i).indices;
- int[] actualIndices = actual.getFaceAt(i).indices;
- assertArrayEquals(expectedIndices, actualIndices);
- }
- }
-
- @Test
- public void testCubeVerticesDefaultSeed() {
- Vector3f[] expectedVertices = new Vector3f[] {
- new Vector3f(1.4220245f, -1.4220245f, -1.4220245f),
- new Vector3f(1.4800327f, -1.4800327f, 1.4800327f),
- new Vector3f(-1.1388737f, -1.1388737f, 1.1388737f),
- new Vector3f(-1.3500736f, -1.3500736f, -1.3500736f),
- new Vector3f(1.3680131f, 1.3680131f, -1.3680131f),
- new Vector3f(1.1784304f, 1.1784304f, 1.1784304f),
- new Vector3f(-1.3177949f, 1.3177949f, 1.3177949f),
- new Vector3f(-1.0675538f, 1.0675538f, -1.0675538f),
- };
-
- Mesh3D cube = new CubeCreator().create();
- modifier.modify(cube);
- for (int i = 0; i < cube.getFaceCount(); i++) {
- Vector3f expectedVertex = expectedVertices[i];
- Vector3f actualVertex = cube.getVertexAt(i);
- assertEquals(expectedVertex, actualVertex);
- }
- }
-
- @Test
- public void testCubeVerticesPositiveSeed() {
- Vector3f[] expectedVertices = new Vector3f[] {
- new Vector3f(1.4390444f, -1.4390444f, -1.4390444f),
- new Vector3f(1.4232731f, -1.4232731f, 1.4232731f),
- new Vector3f(-1.4091227f, -1.4091227f, 1.4091227f),
- new Vector3f(-1.1638807f, -1.1638807f, -1.1638807f),
- new Vector3f(1.2712379f, 1.2712379f, -1.2712379f),
- new Vector3f(1.111674f, 1.111674f, 1.111674f),
- new Vector3f(-1.210412f, 1.210412f, 1.210412f),
- new Vector3f(-1.2455546f, 1.2455546f, -1.2455546f),
- };
-
- Mesh3D cube = new CubeCreator().create();
- modifier.setSeed(30445);
- modifier.modify(cube);
-
- for (int i = 0; i < cube.getFaceCount(); i++) {
- Vector3f expectedVertex = expectedVertices[i];
- Vector3f actualVertex = cube.getVertexAt(i);
- assertEquals(expectedVertex, actualVertex);
- }
- }
-
- @Test
- public void testCubeVerticesNegativeSeed() {
- Vector3f[] expectedVertices = new Vector3f[] {
- new Vector3f(1.0861642f, -1.0861642f, -1.0861642f),
- new Vector3f(1.1106155f, -1.1106155f, 1.1106155f),
- new Vector3f(-1.0040842f, -1.0040842f, 1.0040842f),
- new Vector3f(-1.4769852f, -1.4769852f, -1.4769852f),
- new Vector3f(1.5054972f, 1.5054972f, -1.5054972f),
- new Vector3f(1.5229388f, 1.5229388f, 1.5229388f),
- new Vector3f(-1.2344728f, 1.2344728f, 1.2344728f),
- new Vector3f(-1.1652328f, 1.1652328f, -1.1652328f),
-
- };
-
- Mesh3D cube = new CubeCreator().create();
- modifier.setSeed(-738739);
- modifier.modify(cube);
-
- for (int i = 0; i < cube.getFaceCount(); i++) {
- Vector3f expectedVertex = expectedVertices[i];
- Vector3f actualVertex = cube.getVertexAt(i);
- assertEquals(expectedVertex, actualVertex);
- }
- }
-
- @Test
- public void testDefaulDisplacement() {
- Mesh3D originalMesh = new IcoSphereCreator(1, 3).create();
- Mesh3D modifiedMesh = new IcoSphereCreator(1, 3).create();
-
- modifier.modify(modifiedMesh);
-
- float totalDistance = 0;
-
- for (int i = 0; i < originalMesh.getVertexCount(); i++) {
- Vector3f originalVertex = originalMesh.getVertexAt(i);
- Vector3f modifiedVertex = modifiedMesh.getVertexAt(i);
- float distance = originalVertex.distance(modifiedVertex);
- totalDistance += distance;
- }
-
- float averageDisplacement = totalDistance / originalMesh.getVertexCount();
-
- assertTrue(averageDisplacement <= 1 && averageDisplacement >= 0);
- }
-
- @Test
- public void testDisplacementWithPositiveSeed() {
- Mesh3D originalMesh = new IcoSphereCreator(1, 3).create();
- Mesh3D modifiedMesh = new IcoSphereCreator(1, 3).create();
-
- modifier.setSeed(23445453);
- modifier.modify(modifiedMesh);
-
- float totalDistance = 0;
-
- for (int i = 0; i < originalMesh.getVertexCount(); i++) {
- Vector3f originalVertex = originalMesh.getVertexAt(i);
- Vector3f modifiedVertex = modifiedMesh.getVertexAt(i);
- float distance = originalVertex.distance(modifiedVertex);
- totalDistance += distance;
- }
-
- float averageDisplacement = totalDistance / originalMesh.getVertexCount();
-
- assertTrue(averageDisplacement <= 1 && averageDisplacement >= 0);
- }
-
- @ParameterizedTest
- @ValueSource(floats = {
- 0.1f,
- 0.322f,
- 0.123f,
- 0.022f,
- 0.245f,
- 0.751f,
- 0.965f,
- 10.98f,
- 11.44521f,
- Float.MIN_VALUE,
- })
- public void testDislacementAverageWithPositiveMaximumValues(float maximum) {
- Mesh3D originalMesh = new IcoSphereCreator(1, 3).create();
- Mesh3D modifiedMesh = new IcoSphereCreator(1, 3).create();
-
- modifier.setMaximum(maximum);
- modifier.modify(modifiedMesh);
-
- float totalDistance = 0;
-
- for (int i = 0; i < originalMesh.getVertexCount(); i++) {
- Vector3f originalVertex = originalMesh.getVertexAt(i);
- Vector3f modifiedVertex = modifiedMesh.getVertexAt(i);
- float distance = originalVertex.distance(modifiedVertex);
- totalDistance += distance;
- }
-
- float averageDisplacement = totalDistance / originalMesh.getVertexCount();
-
- assertTrue(averageDisplacement <= maximum);
- }
-
+ }
+
+ @Test
+ public void testCubeVerticesNegativeSeed() {
+ Vector3f[] expectedVertices =
+ new Vector3f[] {
+ new Vector3f(1.0861642f, -1.0861642f, -1.0861642f),
+ new Vector3f(1.1106155f, -1.1106155f, 1.1106155f),
+ new Vector3f(-1.0040842f, -1.0040842f, 1.0040842f),
+ new Vector3f(-1.4769852f, -1.4769852f, -1.4769852f),
+ new Vector3f(1.5054972f, 1.5054972f, -1.5054972f),
+ new Vector3f(1.5229388f, 1.5229388f, 1.5229388f),
+ new Vector3f(-1.2344728f, 1.2344728f, 1.2344728f),
+ new Vector3f(-1.1652328f, 1.1652328f, -1.1652328f),
+ };
+
+ Mesh3D cube = new CubeCreator().create();
+ modifier.setSeed(-738739);
+ modifier.modify(cube);
+
+ for (int i = 0; i < cube.getFaceCount(); i++) {
+ Vector3f expectedVertex = expectedVertices[i];
+ Vector3f actualVertex = cube.getVertexAt(i);
+ assertEquals(expectedVertex, actualVertex);
+ }
+ }
+
+ @Test
+ public void testDefaulDisplacement() {
+ Mesh3D originalMesh = new IcoSphereCreator(1, 3).create();
+ Mesh3D modifiedMesh = new IcoSphereCreator(1, 3).create();
+
+ modifier.modify(modifiedMesh);
+
+ float totalDistance = 0;
+
+ for (int i = 0; i < originalMesh.getVertexCount(); i++) {
+ Vector3f originalVertex = originalMesh.getVertexAt(i);
+ Vector3f modifiedVertex = modifiedMesh.getVertexAt(i);
+ float distance = originalVertex.distance(modifiedVertex);
+ totalDistance += distance;
+ }
+
+ float averageDisplacement = totalDistance / originalMesh.getVertexCount();
+
+ assertTrue(averageDisplacement <= 1 && averageDisplacement >= 0);
+ }
+
+ @Test
+ public void testDisplacementWithPositiveSeed() {
+ Mesh3D originalMesh = new IcoSphereCreator(1, 3).create();
+ Mesh3D modifiedMesh = new IcoSphereCreator(1, 3).create();
+
+ modifier.setSeed(23445453);
+ modifier.modify(modifiedMesh);
+
+ float totalDistance = 0;
+
+ for (int i = 0; i < originalMesh.getVertexCount(); i++) {
+ Vector3f originalVertex = originalMesh.getVertexAt(i);
+ Vector3f modifiedVertex = modifiedMesh.getVertexAt(i);
+ float distance = originalVertex.distance(modifiedVertex);
+ totalDistance += distance;
+ }
+
+ float averageDisplacement = totalDistance / originalMesh.getVertexCount();
+
+ assertTrue(averageDisplacement <= 1 && averageDisplacement >= 0);
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ floats = {
+ 0.1f,
+ 0.322f,
+ 0.123f,
+ 0.022f,
+ 0.245f,
+ 0.751f,
+ 0.965f,
+ 10.98f,
+ 11.44521f,
+ Float.MIN_VALUE,
+ })
+ public void testDislacementAverageWithPositiveMaximumValues(float maximum) {
+ Mesh3D originalMesh = new IcoSphereCreator(1, 3).create();
+ Mesh3D modifiedMesh = new IcoSphereCreator(1, 3).create();
+
+ modifier.setMaximum(maximum);
+ modifier.modify(modifiedMesh);
+
+ float totalDistance = 0;
+
+ for (int i = 0; i < originalMesh.getVertexCount(); i++) {
+ Vector3f originalVertex = originalMesh.getVertexAt(i);
+ Vector3f modifiedVertex = modifiedMesh.getVertexAt(i);
+ float distance = originalVertex.distance(modifiedVertex);
+ totalDistance += distance;
+ }
+
+ float averageDisplacement = totalDistance / originalMesh.getVertexCount();
+
+ assertTrue(averageDisplacement <= maximum);
+ }
}
diff --git a/src/test/java/mesh/modifier/test/RandomHolesModifierFaceCollectionOperationTest.java b/src/test/java/mesh/modifier/test/RandomHolesModifierFaceCollectionOperationTest.java
index c3946d9f..eaaf8870 100644
--- a/src/test/java/mesh/modifier/test/RandomHolesModifierFaceCollectionOperationTest.java
+++ b/src/test/java/mesh/modifier/test/RandomHolesModifierFaceCollectionOperationTest.java
@@ -22,212 +22,254 @@
public class RandomHolesModifierFaceCollectionOperationTest {
- private RandomHolesModifier modifier;
-
- @BeforeEach
- public void setUp() {
- modifier = new RandomHolesModifier();
- }
-
- @Test
- public void returnsNonNullMesh() {
- Mesh3D mesh = new CubeCreator().create();
- assertNotNull(modifier.modify(mesh, new ArrayList()));
- }
-
- @Test
- public void nullMeshThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> {
- modifier.modify(null, new ArrayList());
- });
- }
-
- @Test
- public void nullCollcetionThrowsException() {
- ArrayList faces = null;
- assertThrows(IllegalArgumentException.class, () -> {
- modifier.modify(new Mesh3D(), faces);
- });
- }
-
- @Test
- public void testFaceCountModifyAllCubeFaces() {
- Mesh3D cube = new CubeCreator().create();
- ArrayList faces = new ArrayList(cube.getFaces());
- modifier.modify(cube, faces);
- assertEquals(24, cube.getFaceCount());
- }
-
- @Test
- public void testFaceCountModifyTwoCubeFaces() {
- Mesh3D cube = new CubeCreator().create();
- ArrayList faces = new ArrayList();
- faces.add(cube.getFaceAt(0));
- faces.add(cube.getFaceAt(5));
- modifier.modify(cube, faces);
- assertEquals(12, cube.getFaceCount());
- }
-
- @Test
- public void testVertexCountModifyAllCubeFaces() {
- Mesh3D cube = new CubeCreator().create();
- ArrayList faces = new ArrayList(cube.getFaces());
- modifier.modify(cube, faces);
- assertEquals(32, cube.getVertexCount());
- }
-
- @Test
- public void testVertexCountModifyTwoCubeFaces() {
- Mesh3D cube = new CubeCreator().create();
- ArrayList faces = new ArrayList();
- faces.add(cube.getFaceAt(3));
- faces.add(cube.getFaceAt(4));
- modifier.modify(cube, faces);
- assertEquals(16, cube.getVertexCount());
- }
-
- @ParameterizedTest
- @ValueSource(longs = { 0, 4432, 245, -14332, -13423293, 4324243,
- Long.MAX_VALUE, Long.MIN_VALUE })
- public void testFacesWithDifferentSeeds(long seed) {
- int[][] expected = new int[][] { { 3, 0, 9, 8 }, { 0, 1, 10, 9 },
- { 1, 2, 11, 10 }, { 2, 3, 8, 11 }, { 6, 5, 13, 12 }, { 5, 4, 14, 13 },
- { 4, 7, 15, 14 }, { 7, 6, 12, 15 }, { 1, 0, 17, 16 }, { 0, 4, 18, 17 },
- { 4, 5, 19, 18 }, { 5, 1, 16, 19 }, { 1, 5, 21, 20 }, { 5, 6, 22, 21 },
- { 6, 2, 23, 22 }, { 2, 1, 20, 23 }, { 6, 7, 25, 24 }, { 7, 3, 26, 25 },
- { 3, 2, 27, 26 }, { 2, 6, 24, 27 }, { 3, 7, 29, 28 }, { 7, 4, 30, 29 },
- { 4, 0, 31, 30 }, { 0, 3, 28, 31 } };
- Mesh3D mesh = new CubeCreator().create();
- modifier.setSeed(seed);
- modifier.modify(mesh, mesh.getFaces());
- for (int i = 0; i < expected.length; i++) {
- int[] actual = mesh.getFaceAt(i).indices;
- assertArrayEquals(expected[i], actual);
- }
- }
-
- @Test
- public void testPlaneVerticesWithZeroSeeed() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.6847742f, 0.0f, -0.6847742f),
- new Vector3f(0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, -0.6847742f) };
- ArrayList faces = new ArrayList();
- Mesh3D plane = new PlaneCreator().create();
- faces.add(plane.getFaceAt(0));
- modifier.modify(plane, faces);
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void testPlaneVerticesWithPositiveSeeed() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.31211585f, 0.0f, -0.31211585f),
- new Vector3f(0.31211585f, 0.0f, 0.31211585f),
- new Vector3f(-0.31211585f, 0.0f, 0.31211585f),
- new Vector3f(-0.31211585f, 0.0f, -0.31211585f), };
- ArrayList faces = new ArrayList();
- Mesh3D plane = new PlaneCreator().create();
- faces.add(plane.getFaceAt(0));
- modifier.setSeed(13424);
- modifier.modify(plane, faces);
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void testPlaneVerticesWithNegativeSeeed() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.2969781f, 0.0f, -0.2969781f),
- new Vector3f(0.2969781f, 0.0f, 0.2969781f),
- new Vector3f(-0.2969781f, 0.0f, 0.2969781f),
- new Vector3f(-0.2969781f, 0.0f, -0.2969781f), };
- ArrayList faces = new ArrayList();
- Mesh3D plane = new PlaneCreator().create();
- faces.add(plane.getFaceAt(0));
- modifier.setSeed(-3244324);
- modifier.modify(plane, faces);
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void testPlaneVerticesWithSeedMaxLong() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.31515408f, 0.0f, -0.31515408f),
- new Vector3f(0.31515408f, 0.0f, 0.31515408f),
- new Vector3f(-0.31515408f, 0.0f, 0.31515408f),
- new Vector3f(-0.31515408f, 0.0f, -0.31515408f), };
- ArrayList faces = new ArrayList();
- Mesh3D plane = new PlaneCreator().create();
- faces.add(plane.getFaceAt(0));
- modifier.setSeed(Long.MAX_VALUE);
- modifier.modify(plane, faces);
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void testPlaneVerticesWithSeedMinLong() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.6847742f, 0.0f, -0.6847742f),
- new Vector3f(0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, -0.6847742f), };
- ArrayList faces = new ArrayList();
- Mesh3D plane = new PlaneCreator().create();
- faces.add(plane.getFaceAt(0));
- modifier.setSeed(Long.MIN_VALUE);
- modifier.modify(plane, faces);
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void tesCubeVerticesWithPositiveSeed() {
- Vector3f[] expected = new Vector3f[] { new Vector3f(1.0f, -1.0f, -1.0f),
- new Vector3f(1.0f, -1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, 1.0f),
- new Vector3f(-1.0f, -1.0f, -1.0f), new Vector3f(1.0f, 1.0f, -1.0f),
- new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, 1.0f, 1.0f),
- new Vector3f(-1.0f, 1.0f, -1.0f),
- new Vector3f(-1.0f, 0.2517369f, 0.2517369f),
- new Vector3f(-1.0f, 0.2517369f, -0.2517369f),
- new Vector3f(-1.0f, -0.2517369f, -0.2517369f),
- new Vector3f(-1.0f, -0.2517369f, 0.2517369f), };
- Mesh3D mesh = new CubeCreator().create();
- ArrayList faces = new ArrayList();
- faces.add(mesh.getFaceAt(4));
- modifier = new RandomHolesModifier(0.1f, 0.3f);
- modifier.setSeed(234453);
- modifier.modify(mesh, faces);
- assertArrayEquals(expected, mesh.vertices.toArray());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 0.1f, 0.322f, 0.123f, 0.022f, 0.245f, 0.751f,
- 0.965f })
- public void testMinMaxAmountPositiveValuesAndSeed(float amount) {
- Mesh3D expected = new PlaneCreator().create();
- ExtrudeModifier extrudeModifier = new ExtrudeModifier();
- extrudeModifier.setRemoveFaces(true);
- extrudeModifier.setScale(amount);
- extrudeModifier.setAmount(0);
- expected.apply(extrudeModifier);
-
- Mesh3D actual = new PlaneCreator().create();
- ArrayList faces = new ArrayList();
- faces.add(actual.getFaceAt(0));
- modifier = new RandomHolesModifier(amount, amount);
- modifier.setSeed(234);
- modifier.modify(actual, faces);
- assertArrayEquals(expected.vertices.toArray(), actual.vertices.toArray());
- }
+ private RandomHolesModifier modifier;
+ @BeforeEach
+ public void setUp() {
+ modifier = new RandomHolesModifier();
+ }
+
+ @Test
+ public void returnsNonNullMesh() {
+ Mesh3D mesh = new CubeCreator().create();
+ assertNotNull(modifier.modify(mesh, new ArrayList()));
+ }
+
+ @Test
+ public void nullMeshThrowsException() {
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ modifier.modify(null, new ArrayList());
+ });
+ }
+
+ @Test
+ public void nullCollcetionThrowsException() {
+ ArrayList faces = null;
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ modifier.modify(new Mesh3D(), faces);
+ });
+ }
+
+ @Test
+ public void testFaceCountModifyAllCubeFaces() {
+ Mesh3D cube = new CubeCreator().create();
+ ArrayList faces = new ArrayList(cube.getFaces());
+ modifier.modify(cube, faces);
+ assertEquals(24, cube.getFaceCount());
+ }
+
+ @Test
+ public void testFaceCountModifyTwoCubeFaces() {
+ Mesh3D cube = new CubeCreator().create();
+ ArrayList faces = new ArrayList();
+ faces.add(cube.getFaceAt(0));
+ faces.add(cube.getFaceAt(5));
+ modifier.modify(cube, faces);
+ assertEquals(12, cube.getFaceCount());
+ }
+
+ @Test
+ public void testVertexCountModifyAllCubeFaces() {
+ Mesh3D cube = new CubeCreator().create();
+ ArrayList faces = new ArrayList(cube.getFaces());
+ modifier.modify(cube, faces);
+ assertEquals(32, cube.getVertexCount());
+ }
+
+ @Test
+ public void testVertexCountModifyTwoCubeFaces() {
+ Mesh3D cube = new CubeCreator().create();
+ ArrayList faces = new ArrayList();
+ faces.add(cube.getFaceAt(3));
+ faces.add(cube.getFaceAt(4));
+ modifier.modify(cube, faces);
+ assertEquals(16, cube.getVertexCount());
+ }
+
+ @ParameterizedTest
+ @ValueSource(longs = {0, 4432, 245, -14332, -13423293, 4324243, Long.MAX_VALUE, Long.MIN_VALUE})
+ public void testFacesWithDifferentSeeds(long seed) {
+ int[][] expected =
+ new int[][] {
+ {3, 0, 9, 8},
+ {0, 1, 10, 9},
+ {1, 2, 11, 10},
+ {2, 3, 8, 11},
+ {6, 5, 13, 12},
+ {5, 4, 14, 13},
+ {4, 7, 15, 14},
+ {7, 6, 12, 15},
+ {1, 0, 17, 16},
+ {0, 4, 18, 17},
+ {4, 5, 19, 18},
+ {5, 1, 16, 19},
+ {1, 5, 21, 20},
+ {5, 6, 22, 21},
+ {6, 2, 23, 22},
+ {2, 1, 20, 23},
+ {6, 7, 25, 24},
+ {7, 3, 26, 25},
+ {3, 2, 27, 26},
+ {2, 6, 24, 27},
+ {3, 7, 29, 28},
+ {7, 4, 30, 29},
+ {4, 0, 31, 30},
+ {0, 3, 28, 31}
+ };
+ Mesh3D mesh = new CubeCreator().create();
+ modifier.setSeed(seed);
+ modifier.modify(mesh, mesh.getFaces());
+ for (int i = 0; i < expected.length; i++) {
+ int[] actual = mesh.getFaceAt(i).indices;
+ assertArrayEquals(expected[i], actual);
+ }
+ }
+
+ @Test
+ public void testPlaneVerticesWithZeroSeeed() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.6847742f, 0.0f, -0.6847742f),
+ new Vector3f(0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, -0.6847742f)
+ };
+ ArrayList faces = new ArrayList();
+ Mesh3D plane = new PlaneCreator().create();
+ faces.add(plane.getFaceAt(0));
+ modifier.modify(plane, faces);
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneVerticesWithPositiveSeeed() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.31211585f, 0.0f, -0.31211585f),
+ new Vector3f(0.31211585f, 0.0f, 0.31211585f),
+ new Vector3f(-0.31211585f, 0.0f, 0.31211585f),
+ new Vector3f(-0.31211585f, 0.0f, -0.31211585f),
+ };
+ ArrayList faces = new ArrayList();
+ Mesh3D plane = new PlaneCreator().create();
+ faces.add(plane.getFaceAt(0));
+ modifier.setSeed(13424);
+ modifier.modify(plane, faces);
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneVerticesWithNegativeSeeed() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.2969781f, 0.0f, -0.2969781f),
+ new Vector3f(0.2969781f, 0.0f, 0.2969781f),
+ new Vector3f(-0.2969781f, 0.0f, 0.2969781f),
+ new Vector3f(-0.2969781f, 0.0f, -0.2969781f),
+ };
+ ArrayList faces = new ArrayList();
+ Mesh3D plane = new PlaneCreator().create();
+ faces.add(plane.getFaceAt(0));
+ modifier.setSeed(-3244324);
+ modifier.modify(plane, faces);
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneVerticesWithSeedMaxLong() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.31515408f, 0.0f, -0.31515408f),
+ new Vector3f(0.31515408f, 0.0f, 0.31515408f),
+ new Vector3f(-0.31515408f, 0.0f, 0.31515408f),
+ new Vector3f(-0.31515408f, 0.0f, -0.31515408f),
+ };
+ ArrayList faces = new ArrayList();
+ Mesh3D plane = new PlaneCreator().create();
+ faces.add(plane.getFaceAt(0));
+ modifier.setSeed(Long.MAX_VALUE);
+ modifier.modify(plane, faces);
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneVerticesWithSeedMinLong() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.6847742f, 0.0f, -0.6847742f),
+ new Vector3f(0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, -0.6847742f),
+ };
+ ArrayList faces = new ArrayList();
+ Mesh3D plane = new PlaneCreator().create();
+ faces.add(plane.getFaceAt(0));
+ modifier.setSeed(Long.MIN_VALUE);
+ modifier.modify(plane, faces);
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void tesCubeVerticesWithPositiveSeed() {
+ Vector3f[] expected =
+ new Vector3f[] {
+ new Vector3f(1.0f, -1.0f, -1.0f),
+ new Vector3f(1.0f, -1.0f, 1.0f),
+ new Vector3f(-1.0f, -1.0f, 1.0f),
+ new Vector3f(-1.0f, -1.0f, -1.0f),
+ new Vector3f(1.0f, 1.0f, -1.0f),
+ new Vector3f(1.0f, 1.0f, 1.0f),
+ new Vector3f(-1.0f, 1.0f, 1.0f),
+ new Vector3f(-1.0f, 1.0f, -1.0f),
+ new Vector3f(-1.0f, 0.2517369f, 0.2517369f),
+ new Vector3f(-1.0f, 0.2517369f, -0.2517369f),
+ new Vector3f(-1.0f, -0.2517369f, -0.2517369f),
+ new Vector3f(-1.0f, -0.2517369f, 0.2517369f),
+ };
+ Mesh3D mesh = new CubeCreator().create();
+ ArrayList faces = new ArrayList();
+ faces.add(mesh.getFaceAt(4));
+ modifier = new RandomHolesModifier(0.1f, 0.3f);
+ modifier.setSeed(234453);
+ modifier.modify(mesh, faces);
+ assertArrayEquals(expected, mesh.vertices.toArray());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {0.1f, 0.322f, 0.123f, 0.022f, 0.245f, 0.751f, 0.965f})
+ public void testMinMaxAmountPositiveValuesAndSeed(float amount) {
+ Mesh3D expected = new PlaneCreator().create();
+ ExtrudeModifier extrudeModifier = new ExtrudeModifier();
+ extrudeModifier.setRemoveFaces(true);
+ extrudeModifier.setScale(amount);
+ extrudeModifier.setAmount(0);
+ expected.apply(extrudeModifier);
+
+ Mesh3D actual = new PlaneCreator().create();
+ ArrayList faces = new ArrayList();
+ faces.add(actual.getFaceAt(0));
+ modifier = new RandomHolesModifier(amount, amount);
+ modifier.setSeed(234);
+ modifier.modify(actual, faces);
+ assertArrayEquals(expected.vertices.toArray(), actual.vertices.toArray());
+ }
}
diff --git a/src/test/java/mesh/modifier/test/RandomHolesModifierSingleFaceOperationTest.java b/src/test/java/mesh/modifier/test/RandomHolesModifierSingleFaceOperationTest.java
index 8dfad498..38891723 100644
--- a/src/test/java/mesh/modifier/test/RandomHolesModifierSingleFaceOperationTest.java
+++ b/src/test/java/mesh/modifier/test/RandomHolesModifierSingleFaceOperationTest.java
@@ -23,223 +23,262 @@
public class RandomHolesModifierSingleFaceOperationTest {
- private RandomHolesModifier modifier;
-
- @BeforeEach
- public void setUp() {
- modifier = new RandomHolesModifier();
- }
-
- @Test
- public void implementsFaceModifierInterface() {
- assertTrue(modifier instanceof FaceModifier);
- }
-
- @Test
- public void returnsNonNullMesh() {
- Mesh3D mesh = new CubeCreator().create();
- assertNotNull(modifier.modify(mesh, mesh.getFaceAt(4)));
- }
-
- @Test
- public void returnsReferenceOfModifiedMesh() {
- Mesh3D mesh = new CubeCreator().create();
- assertSame(mesh, modifier.modify(mesh, mesh.getFaceAt(0)));
- }
-
- @Test
- public void nullMeshThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> {
- modifier.modify(null, new Face3D());
- });
- }
-
- @Test
- public void nullFaceThrowsException() {
- Face3D face = null;
- assertThrows(IllegalArgumentException.class, () -> {
- modifier.modify(new Mesh3D(), face);
- });
- }
-
- @Test
- public void nullMeshAndNullFaceThrowsException() {
- Mesh3D mesh = null;
- Face3D face = null;
- assertThrows(IllegalArgumentException.class, () -> {
- modifier.modify(mesh, face);
- });
- }
-
- @Test
- public void testFaceCountPlane() {
- Mesh3D plane = new PlaneCreator().create();
- modifier.modify(plane, plane.getFaceAt(0));
- assertEquals(4, plane.getFaceCount());
- }
-
- @Test
- public void testVertexCountPlane() {
- Mesh3D plane = new PlaneCreator().create();
- modifier.modify(plane, plane.getFaceAt(0));
- assertEquals(8, plane.getVertexCount());
- }
-
- @ParameterizedTest
- @ValueSource(ints = { 0, 1, 2, 3, 4, 5 })
- public void testFaceCountCube(int faceIndex) {
- Mesh3D cube = new CubeCreator().create();
- modifier.modify(cube, cube.getFaceAt(faceIndex));
- assertEquals(9, cube.getFaceCount());
- }
-
- @ParameterizedTest
- @ValueSource(ints = { 0, 1, 2, 3, 4, 5 })
- public void testVertexCountCube(int faceIndex) {
- Mesh3D cube = new CubeCreator().create();
- modifier.modify(cube, cube.getFaceAt(faceIndex));
- assertEquals(12, cube.getVertexCount());
- }
-
- @Test
- public void testPlaneVerticesWithZeroSeeed() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.6847742f, 0.0f, -0.6847742f),
- new Vector3f(0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, -0.6847742f) };
- Mesh3D plane = new PlaneCreator().create();
- modifier.modify(plane, plane.getFaceAt(0));
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void testPlaneVerticesWithPositiveSeeed() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.31211585f, 0.0f, -0.31211585f),
- new Vector3f(0.31211585f, 0.0f, 0.31211585f),
- new Vector3f(-0.31211585f, 0.0f, 0.31211585f),
- new Vector3f(-0.31211585f, 0.0f, -0.31211585f), };
- Mesh3D plane = new PlaneCreator().create();
- modifier.setSeed(13424);
- modifier.modify(plane, plane.getFaceAt(0));
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void testPlaneVerticesWithNegativeSeeed() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.2969781f, 0.0f, -0.2969781f),
- new Vector3f(0.2969781f, 0.0f, 0.2969781f),
- new Vector3f(-0.2969781f, 0.0f, 0.2969781f),
- new Vector3f(-0.2969781f, 0.0f, -0.2969781f), };
- Mesh3D plane = new PlaneCreator().create();
- modifier.setSeed(-3244324);
- modifier.modify(plane, plane.getFaceAt(0));
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void testPlaneVerticesWithSeedMaxLong() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.31515408f, 0.0f, -0.31515408f),
- new Vector3f(0.31515408f, 0.0f, 0.31515408f),
- new Vector3f(-0.31515408f, 0.0f, 0.31515408f),
- new Vector3f(-0.31515408f, 0.0f, -0.31515408f), };
- Mesh3D plane = new PlaneCreator().create();
- modifier.setSeed(Long.MAX_VALUE);
- modifier.modify(plane, plane.getFaceAt(0));
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void testPlaneVerticesWithSeedMinLong() {
- Vector3f[] expected = { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.6847742f, 0.0f, -0.6847742f),
- new Vector3f(0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, -0.6847742f), };
- Mesh3D plane = new PlaneCreator().create();
- modifier.setSeed(Long.MIN_VALUE);
- modifier.modify(plane, plane.getFaceAt(0));
- assertArrayEquals(expected, plane.vertices.toArray());
- }
-
- @Test
- public void tesCubeVerticesWithPositiveSeed() {
- Vector3f[] expected = new Vector3f[] { new Vector3f(1.0f, -1.0f, -1.0f),
- new Vector3f(1.0f, -1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, 1.0f),
- new Vector3f(-1.0f, -1.0f, -1.0f), new Vector3f(1.0f, 1.0f, -1.0f),
- new Vector3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, 1.0f, 1.0f),
- new Vector3f(-1.0f, 1.0f, -1.0f),
- new Vector3f(-1.0f, 0.2517369f, 0.2517369f),
- new Vector3f(-1.0f, 0.2517369f, -0.2517369f),
- new Vector3f(-1.0f, -0.2517369f, -0.2517369f),
- new Vector3f(-1.0f, -0.2517369f, 0.2517369f), };
- Mesh3D mesh = new CubeCreator().create();
-
- modifier = new RandomHolesModifier(0.1f, 0.3f);
- modifier.setSeed(234453);
- modifier.modify(mesh, mesh.getFaceAt(4));
- assertArrayEquals(expected, mesh.vertices.toArray());
- }
-
- @Test
- public void testCubeFacesWithPositiveSeed() {
- int[][] expected = new int[][] { { 3, 0, 1, 2 }, { 6, 5, 4, 7 },
- { 1, 0, 4, 5 }, { 1, 5, 6, 2 }, { 3, 7, 4, 0 }, { 6, 7, 9, 8 },
- { 7, 3, 10, 9 }, { 3, 2, 11, 10 }, { 2, 6, 8, 11 }, };
- Mesh3D mesh = new CubeCreator().create();
- modifier = new RandomHolesModifier(0.1f, 0.3f);
- modifier.setSeed(234453);
- modifier.modify(mesh, mesh.getFaceAt(4));
- for (int i = 0; i < mesh.getFaceCount(); i++) {
- int[] actual = mesh.getFaceAt(i).indices;
- assertArrayEquals(expected[i], actual);
- }
- }
-
- @ParameterizedTest
- @ValueSource(longs = { 0, 13424, -3244324, Long.MAX_VALUE, Long.MIN_VALUE })
- public void testPlaneFaceIndicesWithSeeds(long seed) {
- int[][] expected = new int[][] { { 0, 1, 5, 4 }, { 1, 2, 6, 5 },
- { 2, 3, 7, 6 }, { 3, 0, 4, 7 }, };
- Mesh3D mesh = new PlaneCreator().create();
- modifier.setSeed(seed);
- modifier.modify(mesh);
- for (int i = 0; i < mesh.getFaceCount(); i++) {
- int[] actual = mesh.getFaceAt(i).indices;
- assertArrayEquals(expected[i], actual);
- }
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 0.1f, 0.322f, 0.123f, 0.022f, 0.245f, 0.751f,
- 0.965f, })
- public void testMinMaxAmountPositiveValuesAndSeed(float amount) {
- Mesh3D expected = new PlaneCreator().create();
- ExtrudeModifier extrudeModifier = new ExtrudeModifier();
- extrudeModifier.setRemoveFaces(true);
- extrudeModifier.setScale(amount);
- extrudeModifier.setAmount(0);
- expected.apply(extrudeModifier);
-
- Mesh3D actual = new PlaneCreator().create();
- modifier = new RandomHolesModifier(amount, amount);
- modifier.setSeed(234);
- modifier.modify(actual, actual.getFaceAt(0));
-
- assertArrayEquals(expected.vertices.toArray(), actual.vertices.toArray());
- }
+ private RandomHolesModifier modifier;
+ @BeforeEach
+ public void setUp() {
+ modifier = new RandomHolesModifier();
+ }
+
+ @Test
+ public void implementsFaceModifierInterface() {
+ assertTrue(modifier instanceof FaceModifier);
+ }
+
+ @Test
+ public void returnsNonNullMesh() {
+ Mesh3D mesh = new CubeCreator().create();
+ assertNotNull(modifier.modify(mesh, mesh.getFaceAt(4)));
+ }
+
+ @Test
+ public void returnsReferenceOfModifiedMesh() {
+ Mesh3D mesh = new CubeCreator().create();
+ assertSame(mesh, modifier.modify(mesh, mesh.getFaceAt(0)));
+ }
+
+ @Test
+ public void nullMeshThrowsException() {
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ modifier.modify(null, new Face3D());
+ });
+ }
+
+ @Test
+ public void nullFaceThrowsException() {
+ Face3D face = null;
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ modifier.modify(new Mesh3D(), face);
+ });
+ }
+
+ @Test
+ public void nullMeshAndNullFaceThrowsException() {
+ Mesh3D mesh = null;
+ Face3D face = null;
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> {
+ modifier.modify(mesh, face);
+ });
+ }
+
+ @Test
+ public void testFaceCountPlane() {
+ Mesh3D plane = new PlaneCreator().create();
+ modifier.modify(plane, plane.getFaceAt(0));
+ assertEquals(4, plane.getFaceCount());
+ }
+
+ @Test
+ public void testVertexCountPlane() {
+ Mesh3D plane = new PlaneCreator().create();
+ modifier.modify(plane, plane.getFaceAt(0));
+ assertEquals(8, plane.getVertexCount());
+ }
+
+ @ParameterizedTest
+ @ValueSource(ints = {0, 1, 2, 3, 4, 5})
+ public void testFaceCountCube(int faceIndex) {
+ Mesh3D cube = new CubeCreator().create();
+ modifier.modify(cube, cube.getFaceAt(faceIndex));
+ assertEquals(9, cube.getFaceCount());
+ }
+
+ @ParameterizedTest
+ @ValueSource(ints = {0, 1, 2, 3, 4, 5})
+ public void testVertexCountCube(int faceIndex) {
+ Mesh3D cube = new CubeCreator().create();
+ modifier.modify(cube, cube.getFaceAt(faceIndex));
+ assertEquals(12, cube.getVertexCount());
+ }
+
+ @Test
+ public void testPlaneVerticesWithZeroSeeed() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.6847742f, 0.0f, -0.6847742f),
+ new Vector3f(0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, -0.6847742f)
+ };
+ Mesh3D plane = new PlaneCreator().create();
+ modifier.modify(plane, plane.getFaceAt(0));
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneVerticesWithPositiveSeeed() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.31211585f, 0.0f, -0.31211585f),
+ new Vector3f(0.31211585f, 0.0f, 0.31211585f),
+ new Vector3f(-0.31211585f, 0.0f, 0.31211585f),
+ new Vector3f(-0.31211585f, 0.0f, -0.31211585f),
+ };
+ Mesh3D plane = new PlaneCreator().create();
+ modifier.setSeed(13424);
+ modifier.modify(plane, plane.getFaceAt(0));
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneVerticesWithNegativeSeeed() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.2969781f, 0.0f, -0.2969781f),
+ new Vector3f(0.2969781f, 0.0f, 0.2969781f),
+ new Vector3f(-0.2969781f, 0.0f, 0.2969781f),
+ new Vector3f(-0.2969781f, 0.0f, -0.2969781f),
+ };
+ Mesh3D plane = new PlaneCreator().create();
+ modifier.setSeed(-3244324);
+ modifier.modify(plane, plane.getFaceAt(0));
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneVerticesWithSeedMaxLong() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.31515408f, 0.0f, -0.31515408f),
+ new Vector3f(0.31515408f, 0.0f, 0.31515408f),
+ new Vector3f(-0.31515408f, 0.0f, 0.31515408f),
+ new Vector3f(-0.31515408f, 0.0f, -0.31515408f),
+ };
+ Mesh3D plane = new PlaneCreator().create();
+ modifier.setSeed(Long.MAX_VALUE);
+ modifier.modify(plane, plane.getFaceAt(0));
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneVerticesWithSeedMinLong() {
+ Vector3f[] expected = {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.6847742f, 0.0f, -0.6847742f),
+ new Vector3f(0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, -0.6847742f),
+ };
+ Mesh3D plane = new PlaneCreator().create();
+ modifier.setSeed(Long.MIN_VALUE);
+ modifier.modify(plane, plane.getFaceAt(0));
+ assertArrayEquals(expected, plane.vertices.toArray());
+ }
+
+ @Test
+ public void tesCubeVerticesWithPositiveSeed() {
+ Vector3f[] expected =
+ new Vector3f[] {
+ new Vector3f(1.0f, -1.0f, -1.0f),
+ new Vector3f(1.0f, -1.0f, 1.0f),
+ new Vector3f(-1.0f, -1.0f, 1.0f),
+ new Vector3f(-1.0f, -1.0f, -1.0f),
+ new Vector3f(1.0f, 1.0f, -1.0f),
+ new Vector3f(1.0f, 1.0f, 1.0f),
+ new Vector3f(-1.0f, 1.0f, 1.0f),
+ new Vector3f(-1.0f, 1.0f, -1.0f),
+ new Vector3f(-1.0f, 0.2517369f, 0.2517369f),
+ new Vector3f(-1.0f, 0.2517369f, -0.2517369f),
+ new Vector3f(-1.0f, -0.2517369f, -0.2517369f),
+ new Vector3f(-1.0f, -0.2517369f, 0.2517369f),
+ };
+ Mesh3D mesh = new CubeCreator().create();
+
+ modifier = new RandomHolesModifier(0.1f, 0.3f);
+ modifier.setSeed(234453);
+ modifier.modify(mesh, mesh.getFaceAt(4));
+ assertArrayEquals(expected, mesh.vertices.toArray());
+ }
+
+ @Test
+ public void testCubeFacesWithPositiveSeed() {
+ int[][] expected =
+ new int[][] {
+ {3, 0, 1, 2},
+ {6, 5, 4, 7},
+ {1, 0, 4, 5},
+ {1, 5, 6, 2},
+ {3, 7, 4, 0},
+ {6, 7, 9, 8},
+ {7, 3, 10, 9},
+ {3, 2, 11, 10},
+ {2, 6, 8, 11},
+ };
+ Mesh3D mesh = new CubeCreator().create();
+ modifier = new RandomHolesModifier(0.1f, 0.3f);
+ modifier.setSeed(234453);
+ modifier.modify(mesh, mesh.getFaceAt(4));
+ for (int i = 0; i < mesh.getFaceCount(); i++) {
+ int[] actual = mesh.getFaceAt(i).indices;
+ assertArrayEquals(expected[i], actual);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(longs = {0, 13424, -3244324, Long.MAX_VALUE, Long.MIN_VALUE})
+ public void testPlaneFaceIndicesWithSeeds(long seed) {
+ int[][] expected =
+ new int[][] {
+ {0, 1, 5, 4}, {1, 2, 6, 5}, {2, 3, 7, 6}, {3, 0, 4, 7},
+ };
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier.setSeed(seed);
+ modifier.modify(mesh);
+ for (int i = 0; i < mesh.getFaceCount(); i++) {
+ int[] actual = mesh.getFaceAt(i).indices;
+ assertArrayEquals(expected[i], actual);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ floats = {
+ 0.1f, 0.322f, 0.123f, 0.022f, 0.245f, 0.751f, 0.965f,
+ })
+ public void testMinMaxAmountPositiveValuesAndSeed(float amount) {
+ Mesh3D expected = new PlaneCreator().create();
+ ExtrudeModifier extrudeModifier = new ExtrudeModifier();
+ extrudeModifier.setRemoveFaces(true);
+ extrudeModifier.setScale(amount);
+ extrudeModifier.setAmount(0);
+ expected.apply(extrudeModifier);
+
+ Mesh3D actual = new PlaneCreator().create();
+ modifier = new RandomHolesModifier(amount, amount);
+ modifier.setSeed(234);
+ modifier.modify(actual, actual.getFaceAt(0));
+
+ assertArrayEquals(expected.vertices.toArray(), actual.vertices.toArray());
+ }
}
diff --git a/src/test/java/mesh/modifier/test/RandomHolesModifierTest.java b/src/test/java/mesh/modifier/test/RandomHolesModifierTest.java
index b8eb49ff..54eeb790 100644
--- a/src/test/java/mesh/modifier/test/RandomHolesModifierTest.java
+++ b/src/test/java/mesh/modifier/test/RandomHolesModifierTest.java
@@ -21,228 +21,268 @@
public class RandomHolesModifierTest {
- private RandomHolesModifier modifier;
-
- @BeforeEach
- public void setUp() {
- modifier = new RandomHolesModifier();
- }
-
- @Test
- public void modifierImplementsIMeshModifierInterface() {
- assertTrue(modifier instanceof IMeshModifier);
- }
-
- @Test
- public void modifyMeshReturnsNonNullMesh() {
- Mesh3D mesh = modifier.modify(new CubeCreator().create());
- assertNotNull(mesh);
- }
-
- @Test
- public void modifyFaceReturnsNonNullMesh() {
- Mesh3D mesh = new CubeCreator().create();
- assertNotNull(modifier.modify(mesh, mesh.getFaceAt(0)));
- }
-
- @Test
- public void modifyMeshreturnsReferenceToModifiedMesh() {
- Mesh3D expected = new CubeCreator().create();
- Mesh3D actual = modifier.modify(expected);
- assertSame(expected, actual);
- }
-
- @Test
- public void testDefaultSeed() {
- assertEquals(0, modifier.getSeed());
- }
-
- @ParameterizedTest
- @ValueSource(longs = { 0, 1, 20032, -130, Long.MIN_VALUE, Long.MAX_VALUE })
- public void testGetSetSeed(long expectedSeed) {
- modifier.setSeed(expectedSeed);
- assertEquals(expectedSeed, modifier.getSeed());
- }
-
- @Test
- public void testDefaultMinAmount() {
- float expected = 0.1f;
- assertEquals(expected, modifier.getMinAmount());
- }
-
- @Test
- public void testDefaultMaxAmount() {
- float expected = 0.9f;
- assertEquals(expected, modifier.getMaxAmount());
- }
-
- @Test
- public void faceCountPlane() {
- Mesh3D mesh = new PlaneCreator().create();
- mesh.apply(modifier);
- assertEquals(4, mesh.getFaceCount());
- }
-
- @Test
- public void testVerticesPlaneWithZeroSeed() {
- Vector3f[] expected = new Vector3f[] { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.6847742f, 0.0f, -0.6847742f),
- new Vector3f(0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
- new Vector3f(-0.6847742f, 0.0f, -0.6847742f) };
- Mesh3D mesh = new PlaneCreator().create();
- modifier.modify(mesh);
- assertArrayEquals(expected, mesh.vertices.toArray());
- }
-
- @Test
- public void testVerticesPlaneWithPositiveSeed() {
- Vector3f[] expected = new Vector3f[] { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.62473404f, 0.0f, -0.62473404f),
- new Vector3f(0.62473404f, 0.0f, 0.62473404f),
- new Vector3f(-0.62473404f, 0.0f, 0.62473404f),
- new Vector3f(-0.62473404f, 0.0f, -0.62473404f) };
-
- Mesh3D mesh = new PlaneCreator().create();
- modifier.setSeed(1321441);
- modifier.modify(mesh);
- assertArrayEquals(expected, mesh.vertices.toArray());
- }
-
- @Test
- public void testVerticesPlaneWithNegativeSeed() {
- Vector3f[] expected = new Vector3f[] { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.3719052f, 0.0f, -0.3719052f),
- new Vector3f(0.3719052f, 0.0f, 0.3719052f),
- new Vector3f(-0.3719052f, 0.0f, 0.3719052f),
- new Vector3f(-0.3719052f, 0.0f, -0.3719052f), };
-
- Mesh3D mesh = new PlaneCreator().create();
- modifier.setSeed(-133221441);
- modifier.modify(mesh);
- assertArrayEquals(expected, mesh.vertices.toArray());
- }
-
- @Test
- public void testVerticesWithMinMaxAndPositiveSeed() {
- Vector3f[] expected = new Vector3f[] { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.7055122f, 0.0f, -0.7055122f),
- new Vector3f(0.7055122f, 0.0f, 0.7055122f),
- new Vector3f(-0.7055122f, 0.0f, 0.7055122f),
- new Vector3f(-0.7055122f, 0.0f, -0.7055122f) };
- Mesh3D mesh = new PlaneCreator().create();
- modifier = new RandomHolesModifier(0.24f, 0.9872f);
- modifier.setSeed(2323424);
- modifier.modify(mesh);
- assertArrayEquals(expected, mesh.vertices.toArray());
- }
-
- @Test
- public void testVerticesWithMinMaxAndNegativeSeed() {
- Vector3f[] expected = new Vector3f[] { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.63038445f, 0.0f, -0.63038445f),
- new Vector3f(0.63038445f, 0.0f, 0.63038445f),
- new Vector3f(-0.63038445f, 0.0f, 0.63038445f),
- new Vector3f(-0.63038445f, 0.0f, -0.63038445f), };
- Mesh3D mesh = new PlaneCreator().create();
- modifier = new RandomHolesModifier(0.2344f, 0.87f);
- modifier.setSeed(2323424);
- modifier.modify(mesh);
- assertArrayEquals(expected, mesh.vertices.toArray());
- }
-
- @Test
- public void testVerticesWithMinMaxContstuctorAndPositiveSeed() {
- Vector3f[] expected = new Vector3f[] { new Vector3f(1.0f, 0.0f, -1.0f),
- new Vector3f(1.0f, 0.0f, 1.0f), new Vector3f(-1.0f, 0.0f, 1.0f),
- new Vector3f(-1.0f, 0.0f, -1.0f),
- new Vector3f(0.7055122f, 0.0f, -0.7055122f),
- new Vector3f(0.7055122f, 0.0f, 0.7055122f),
- new Vector3f(-0.7055122f, 0.0f, 0.7055122f),
- new Vector3f(-0.7055122f, 0.0f, -0.7055122f) };
- float minAmount = 0.24f;
- float maxAmount = 0.9872f;
- Mesh3D mesh = new PlaneCreator().create();
- modifier = new RandomHolesModifier(minAmount, maxAmount);
- modifier.setSeed(2323424);
- modifier.modify(mesh);
- assertArrayEquals(expected, mesh.vertices.toArray());
- }
-
- @Test
- public void testPlaneFacesWithZeroSeed() {
- int[][] expected = new int[][] { { 0, 1, 5, 4 }, { 1, 2, 6, 5 },
- { 2, 3, 7, 6 }, { 3, 0, 4, 7 } };
- Mesh3D mesh = new PlaneCreator().create();
- modifier.modify(mesh);
- for (int i = 0; i < mesh.getFaceCount(); i++) {
- int[] actual = mesh.getFaceAt(i).indices;
- assertArrayEquals(expected[i], actual);
- }
- }
-
- @ParameterizedTest
- @ValueSource(longs = { 0, 1000, 134424, -14, -1342424293, 432424229,
- Long.MAX_VALUE, Long.MIN_VALUE })
- public void testPlaneFacesWithDifferentSeeds(long seed) {
- int[][] expected = new int[][] { { 0, 1, 5, 4 }, { 1, 2, 6, 5 },
- { 2, 3, 7, 6 }, { 3, 0, 4, 7 } };
- Mesh3D mesh = new PlaneCreator().create();
- modifier.setSeed(seed);
- modifier.modify(mesh);
- for (int i = 0; i < mesh.getFaceCount(); i++) {
- int[] actual = mesh.getFaceAt(i).indices;
- assertArrayEquals(expected[i], actual);
- }
- }
-
- @ParameterizedTest
- @ValueSource(longs = { 0, 1000, 134424, -14, -1342424293, 432424229,
- Long.MAX_VALUE, Long.MIN_VALUE })
- public void testFacesWithDifferentSeeds(long seed) {
- int[][] expected = new int[][] { { 3, 0, 9, 8 }, { 0, 1, 10, 9 },
- { 1, 2, 11, 10 }, { 2, 3, 8, 11 }, { 6, 5, 13, 12 }, { 5, 4, 14, 13 },
- { 4, 7, 15, 14 }, { 7, 6, 12, 15 }, { 1, 0, 17, 16 }, { 0, 4, 18, 17 },
- { 4, 5, 19, 18 }, { 5, 1, 16, 19 }, { 1, 5, 21, 20 }, { 5, 6, 22, 21 },
- { 6, 2, 23, 22 }, { 2, 1, 20, 23 }, { 6, 7, 25, 24 }, { 7, 3, 26, 25 },
- { 3, 2, 27, 26 }, { 2, 6, 24, 27 }, { 3, 7, 29, 28 }, { 7, 4, 30, 29 },
- { 4, 0, 31, 30 }, { 0, 3, 28, 31 } };
- Mesh3D mesh = new CubeCreator().create();
- modifier.setSeed(seed);
- modifier.modify(mesh);
- for (int i = 0; i < expected.length; i++) {
- int[] actual = mesh.getFaceAt(i).indices;
- assertArrayEquals(expected[i], actual);
- }
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 0.1f, 0.135f, 0.13f, 0.2f, 0.23555f, 0.721f, 0.9654f,
- Float.MIN_VALUE })
- public void testMinMaxAmountPositiveValuesAndSeed(float amount) {
- Mesh3D expected = new PlaneCreator().create();
- ExtrudeModifier extrudeModifier = new ExtrudeModifier();
- extrudeModifier.setRemoveFaces(true);
- extrudeModifier.setScale(amount);
- extrudeModifier.setAmount(0);
- expected.apply(extrudeModifier);
-
- Mesh3D actual = new PlaneCreator().create();
- modifier = new RandomHolesModifier(amount, amount);
- modifier.setSeed(234);
- modifier.modify(actual);
-
- assertArrayEquals(expected.vertices.toArray(), actual.vertices.toArray());
- }
+ private RandomHolesModifier modifier;
+ @BeforeEach
+ public void setUp() {
+ modifier = new RandomHolesModifier();
+ }
+
+ @Test
+ public void modifierImplementsIMeshModifierInterface() {
+ assertTrue(modifier instanceof IMeshModifier);
+ }
+
+ @Test
+ public void modifyMeshReturnsNonNullMesh() {
+ Mesh3D mesh = modifier.modify(new CubeCreator().create());
+ assertNotNull(mesh);
+ }
+
+ @Test
+ public void modifyFaceReturnsNonNullMesh() {
+ Mesh3D mesh = new CubeCreator().create();
+ assertNotNull(modifier.modify(mesh, mesh.getFaceAt(0)));
+ }
+
+ @Test
+ public void modifyMeshreturnsReferenceToModifiedMesh() {
+ Mesh3D expected = new CubeCreator().create();
+ Mesh3D actual = modifier.modify(expected);
+ assertSame(expected, actual);
+ }
+
+ @Test
+ public void testDefaultSeed() {
+ assertEquals(0, modifier.getSeed());
+ }
+
+ @ParameterizedTest
+ @ValueSource(longs = {0, 1, 20032, -130, Long.MIN_VALUE, Long.MAX_VALUE})
+ public void testGetSetSeed(long expectedSeed) {
+ modifier.setSeed(expectedSeed);
+ assertEquals(expectedSeed, modifier.getSeed());
+ }
+
+ @Test
+ public void testDefaultMinAmount() {
+ float expected = 0.1f;
+ assertEquals(expected, modifier.getMinAmount());
+ }
+
+ @Test
+ public void testDefaultMaxAmount() {
+ float expected = 0.9f;
+ assertEquals(expected, modifier.getMaxAmount());
+ }
+
+ @Test
+ public void faceCountPlane() {
+ Mesh3D mesh = new PlaneCreator().create();
+ mesh.apply(modifier);
+ assertEquals(4, mesh.getFaceCount());
+ }
+
+ @Test
+ public void testVerticesPlaneWithZeroSeed() {
+ Vector3f[] expected =
+ new Vector3f[] {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.6847742f, 0.0f, -0.6847742f),
+ new Vector3f(0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, 0.6847742f),
+ new Vector3f(-0.6847742f, 0.0f, -0.6847742f)
+ };
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier.modify(mesh);
+ assertArrayEquals(expected, mesh.vertices.toArray());
+ }
+
+ @Test
+ public void testVerticesPlaneWithPositiveSeed() {
+ Vector3f[] expected =
+ new Vector3f[] {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.62473404f, 0.0f, -0.62473404f),
+ new Vector3f(0.62473404f, 0.0f, 0.62473404f),
+ new Vector3f(-0.62473404f, 0.0f, 0.62473404f),
+ new Vector3f(-0.62473404f, 0.0f, -0.62473404f)
+ };
+
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier.setSeed(1321441);
+ modifier.modify(mesh);
+ assertArrayEquals(expected, mesh.vertices.toArray());
+ }
+
+ @Test
+ public void testVerticesPlaneWithNegativeSeed() {
+ Vector3f[] expected =
+ new Vector3f[] {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.3719052f, 0.0f, -0.3719052f),
+ new Vector3f(0.3719052f, 0.0f, 0.3719052f),
+ new Vector3f(-0.3719052f, 0.0f, 0.3719052f),
+ new Vector3f(-0.3719052f, 0.0f, -0.3719052f),
+ };
+
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier.setSeed(-133221441);
+ modifier.modify(mesh);
+ assertArrayEquals(expected, mesh.vertices.toArray());
+ }
+
+ @Test
+ public void testVerticesWithMinMaxAndPositiveSeed() {
+ Vector3f[] expected =
+ new Vector3f[] {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.7055122f, 0.0f, -0.7055122f),
+ new Vector3f(0.7055122f, 0.0f, 0.7055122f),
+ new Vector3f(-0.7055122f, 0.0f, 0.7055122f),
+ new Vector3f(-0.7055122f, 0.0f, -0.7055122f)
+ };
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier = new RandomHolesModifier(0.24f, 0.9872f);
+ modifier.setSeed(2323424);
+ modifier.modify(mesh);
+ assertArrayEquals(expected, mesh.vertices.toArray());
+ }
+
+ @Test
+ public void testVerticesWithMinMaxAndNegativeSeed() {
+ Vector3f[] expected =
+ new Vector3f[] {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.63038445f, 0.0f, -0.63038445f),
+ new Vector3f(0.63038445f, 0.0f, 0.63038445f),
+ new Vector3f(-0.63038445f, 0.0f, 0.63038445f),
+ new Vector3f(-0.63038445f, 0.0f, -0.63038445f),
+ };
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier = new RandomHolesModifier(0.2344f, 0.87f);
+ modifier.setSeed(2323424);
+ modifier.modify(mesh);
+ assertArrayEquals(expected, mesh.vertices.toArray());
+ }
+
+ @Test
+ public void testVerticesWithMinMaxContstuctorAndPositiveSeed() {
+ Vector3f[] expected =
+ new Vector3f[] {
+ new Vector3f(1.0f, 0.0f, -1.0f),
+ new Vector3f(1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, 1.0f),
+ new Vector3f(-1.0f, 0.0f, -1.0f),
+ new Vector3f(0.7055122f, 0.0f, -0.7055122f),
+ new Vector3f(0.7055122f, 0.0f, 0.7055122f),
+ new Vector3f(-0.7055122f, 0.0f, 0.7055122f),
+ new Vector3f(-0.7055122f, 0.0f, -0.7055122f)
+ };
+ float minAmount = 0.24f;
+ float maxAmount = 0.9872f;
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier = new RandomHolesModifier(minAmount, maxAmount);
+ modifier.setSeed(2323424);
+ modifier.modify(mesh);
+ assertArrayEquals(expected, mesh.vertices.toArray());
+ }
+
+ @Test
+ public void testPlaneFacesWithZeroSeed() {
+ int[][] expected = new int[][] {{0, 1, 5, 4}, {1, 2, 6, 5}, {2, 3, 7, 6}, {3, 0, 4, 7}};
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier.modify(mesh);
+ for (int i = 0; i < mesh.getFaceCount(); i++) {
+ int[] actual = mesh.getFaceAt(i).indices;
+ assertArrayEquals(expected[i], actual);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ longs = {0, 1000, 134424, -14, -1342424293, 432424229, Long.MAX_VALUE, Long.MIN_VALUE})
+ public void testPlaneFacesWithDifferentSeeds(long seed) {
+ int[][] expected = new int[][] {{0, 1, 5, 4}, {1, 2, 6, 5}, {2, 3, 7, 6}, {3, 0, 4, 7}};
+ Mesh3D mesh = new PlaneCreator().create();
+ modifier.setSeed(seed);
+ modifier.modify(mesh);
+ for (int i = 0; i < mesh.getFaceCount(); i++) {
+ int[] actual = mesh.getFaceAt(i).indices;
+ assertArrayEquals(expected[i], actual);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ longs = {0, 1000, 134424, -14, -1342424293, 432424229, Long.MAX_VALUE, Long.MIN_VALUE})
+ public void testFacesWithDifferentSeeds(long seed) {
+ int[][] expected =
+ new int[][] {
+ {3, 0, 9, 8},
+ {0, 1, 10, 9},
+ {1, 2, 11, 10},
+ {2, 3, 8, 11},
+ {6, 5, 13, 12},
+ {5, 4, 14, 13},
+ {4, 7, 15, 14},
+ {7, 6, 12, 15},
+ {1, 0, 17, 16},
+ {0, 4, 18, 17},
+ {4, 5, 19, 18},
+ {5, 1, 16, 19},
+ {1, 5, 21, 20},
+ {5, 6, 22, 21},
+ {6, 2, 23, 22},
+ {2, 1, 20, 23},
+ {6, 7, 25, 24},
+ {7, 3, 26, 25},
+ {3, 2, 27, 26},
+ {2, 6, 24, 27},
+ {3, 7, 29, 28},
+ {7, 4, 30, 29},
+ {4, 0, 31, 30},
+ {0, 3, 28, 31}
+ };
+ Mesh3D mesh = new CubeCreator().create();
+ modifier.setSeed(seed);
+ modifier.modify(mesh);
+ for (int i = 0; i < expected.length; i++) {
+ int[] actual = mesh.getFaceAt(i).indices;
+ assertArrayEquals(expected[i], actual);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {0.1f, 0.135f, 0.13f, 0.2f, 0.23555f, 0.721f, 0.9654f, Float.MIN_VALUE})
+ public void testMinMaxAmountPositiveValuesAndSeed(float amount) {
+ Mesh3D expected = new PlaneCreator().create();
+ ExtrudeModifier extrudeModifier = new ExtrudeModifier();
+ extrudeModifier.setRemoveFaces(true);
+ extrudeModifier.setScale(amount);
+ extrudeModifier.setAmount(0);
+ expected.apply(extrudeModifier);
+
+ Mesh3D actual = new PlaneCreator().create();
+ modifier = new RandomHolesModifier(amount, amount);
+ modifier.setSeed(234);
+ modifier.modify(actual);
+
+ assertArrayEquals(expected.vertices.toArray(), actual.vertices.toArray());
+ }
}
diff --git a/src/test/java/mesh/modifier/test/RippleModifierTest.java b/src/test/java/mesh/modifier/test/RippleModifierTest.java
index 8d63c030..44f38452 100644
--- a/src/test/java/mesh/modifier/test/RippleModifierTest.java
+++ b/src/test/java/mesh/modifier/test/RippleModifierTest.java
@@ -21,222 +21,222 @@
public class RippleModifierTest {
- private RippleModifier modifier;
-
- @BeforeEach
- public void setUp() {
- modifier = new RippleModifier();
- }
-
- @Test
- public void testModifierImplementsModifierInterface() {
- assertTrue(modifier instanceof IMeshModifier);
- }
-
- @Test
- public void testModifiedMeshIsNotNull() {
- Mesh3D mesh = new Mesh3D();
- assertNotNull(modifier.modify(mesh));
- }
-
- @Test
- public void testReturnsReferenceToTheModifiedMesh() {
- Mesh3D mesh0 = new CubeCreator().create();
- Mesh3D mesh1 = modifier.modify(mesh0);
- assertSame(mesh0, mesh1);
- }
-
- @Test
- public void testDefaultValues() {
- assertAll("Default Values",
- () -> assertEquals(0, modifier.getTime()),
- () -> assertEquals(1.0f, modifier.getAmplitude1()),
- () -> assertEquals(0.5f, modifier.getAmplitude2()),
- () -> assertEquals(5.0f, modifier.getWaveLength()),
- () -> assertEquals(0.1f, modifier.getDecayFactor())
- );
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 1.0f, 15.002f, 20.245f })
- public void testGetSetAmplitude1(float amplitude1) {
- modifier.setAmplitude1(amplitude1);
- assertEquals(amplitude1, modifier.getAmplitude1());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 1.12f, 11.0352f, 56.245f, 120.23f })
- public void testGetSetAmplitude2(float amplitude2) {
- modifier.setAmplitude2(amplitude2);
- assertEquals(amplitude2, modifier.getAmplitude2());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 10.0f, 51.44f, 60.245f })
- public void testGetSetWaveLength(float waveLength) {
- modifier.setWaveLength(waveLength);
- assertEquals(waveLength, modifier.getWaveLength());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 155.0f, 20.44f, -100.245f })
- public void testGetSetDecayFactor(float decayFactor) {
- modifier.setDecayFactor(decayFactor);
- assertEquals(decayFactor, modifier.getDecayFactor());
- }
-
- @Test
- public void testCenterIsNotNullByDefault() {
- assertNotNull(modifier.getCenter());
- }
-
- @Test
- public void testCenterIsAtOriginByDefault() {
- assertEquals(Vector3f.ZERO, modifier.getCenter());
- }
-
- @Test
- public void testGetSetCenter() {
- Vector3f[] centers = new Vector3f[] {
- new Vector3f(-0.134f, 1, 10.4f),
- new Vector3f(102.34f, 332.431f, -0.4f),
- new Vector3f(46.34f, -32.432f, 0.134f),
- new Vector3f(0.001f, 0.32f, -2.34f)
+ private RippleModifier modifier;
+
+ @BeforeEach
+ public void setUp() {
+ modifier = new RippleModifier();
+ }
+
+ @Test
+ public void testModifierImplementsModifierInterface() {
+ assertTrue(modifier instanceof IMeshModifier);
+ }
+
+ @Test
+ public void testModifiedMeshIsNotNull() {
+ Mesh3D mesh = new Mesh3D();
+ assertNotNull(modifier.modify(mesh));
+ }
+
+ @Test
+ public void testReturnsReferenceToTheModifiedMesh() {
+ Mesh3D mesh0 = new CubeCreator().create();
+ Mesh3D mesh1 = modifier.modify(mesh0);
+ assertSame(mesh0, mesh1);
+ }
+
+ @Test
+ public void testDefaultValues() {
+ assertAll(
+ "Default Values",
+ () -> assertEquals(0, modifier.getTime()),
+ () -> assertEquals(1.0f, modifier.getAmplitude1()),
+ () -> assertEquals(0.5f, modifier.getAmplitude2()),
+ () -> assertEquals(5.0f, modifier.getWaveLength()),
+ () -> assertEquals(0.1f, modifier.getDecayFactor()));
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {1.0f, 15.002f, 20.245f})
+ public void testGetSetAmplitude1(float amplitude1) {
+ modifier.setAmplitude1(amplitude1);
+ assertEquals(amplitude1, modifier.getAmplitude1());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {1.12f, 11.0352f, 56.245f, 120.23f})
+ public void testGetSetAmplitude2(float amplitude2) {
+ modifier.setAmplitude2(amplitude2);
+ assertEquals(amplitude2, modifier.getAmplitude2());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {10.0f, 51.44f, 60.245f})
+ public void testGetSetWaveLength(float waveLength) {
+ modifier.setWaveLength(waveLength);
+ assertEquals(waveLength, modifier.getWaveLength());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {155.0f, 20.44f, -100.245f})
+ public void testGetSetDecayFactor(float decayFactor) {
+ modifier.setDecayFactor(decayFactor);
+ assertEquals(decayFactor, modifier.getDecayFactor());
+ }
+
+ @Test
+ public void testCenterIsNotNullByDefault() {
+ assertNotNull(modifier.getCenter());
+ }
+
+ @Test
+ public void testCenterIsAtOriginByDefault() {
+ assertEquals(Vector3f.ZERO, modifier.getCenter());
+ }
+
+ @Test
+ public void testGetSetCenter() {
+ Vector3f[] centers =
+ new Vector3f[] {
+ new Vector3f(-0.134f, 1, 10.4f),
+ new Vector3f(102.34f, 332.431f, -0.4f),
+ new Vector3f(46.34f, -32.432f, 0.134f),
+ new Vector3f(0.001f, 0.32f, -2.34f)
};
- for (int i = 0; i < centers.length; i++) {
- modifier.setCenter(centers[i]);
- assertEquals(centers[i], modifier.getCenter());
- }
- }
-
- @Test
- public void testSetCenterToNullThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> modifier.setCenter(null));
- }
-
- @Test
- public void testSetWaveLengthToZeroThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> modifier.setWaveLength(0));
- }
-
- @ParameterizedTest
- @ValueSource(floats = { -1.0f, -15.002f, -20.245f, -100.23f })
- public void testSetWaveLengthLessThanZeroThrowsException(float waveLength) {
- assertThrows(IllegalArgumentException.class, () -> modifier.setWaveLength(waveLength));
- }
-
- @Test
- public void testModifyNullMeshThrowsIllegalArgumentException() {
- assertThrows(IllegalArgumentException.class, () -> modifier.modify(null));
- }
-
- @Test
- public void testNegativeAmplitude1ThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> modifier.setAmplitude1(-1));
- }
-
- @Test
- public void testNegativeAmplitude2ThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> modifier.setAmplitude2(-1));
- }
-
- @Test
- public void testDefaultDirection() {
- Vector3f expected = new Vector3f(0, -1, 0);
- assertEquals(expected, modifier.getDirection());
- }
-
- @Test
- public void testSetNullDirectionThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> modifier.setDirection(null));
- }
-
- @Test
- public void testDirectionIsNormalizedByDefault() {
- float length = modifier.getDirection().length();
- assertEquals(1, length);
- }
-
- @Test
- public void testSetDirectionNormalizesDirection() {
- Vector3f direction = new Vector3f(5, 43.45f, 1);
- modifier.setDirection(direction);
- float length = modifier.getDirection().length();
- assertEquals(1, length, 0.0001f);
- }
-
- @Test
- public void testDirectionIsNormalizedInternally() {
- Vector3f expected = new Vector3f(1, 3.556f, 2.345f);
- Vector3f direction = new Vector3f(expected);
- modifier.setDirection(direction);
- assertEquals(expected, direction);
- }
-
- @Test
- public void testDefaultPhaseShift() {
- assertEquals(0, modifier.getPhaseShift());
- }
-
- @Test
- public void testPhaseShiftMultiplesOfTwoPi() {
- float expected = Mathf.TWO_PI;
- modifier.setPhaseShift(expected * 4);
- assertEquals(0, modifier.getPhaseShift());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 0, Mathf.HALF_PI, Mathf.QUARTER_PI })
- public void testGetSetPhaseShift(float phaseShift) {
- modifier.setPhaseShift(phaseShift);
- assertEquals(phaseShift, modifier.getPhaseShift());
- }
-
- @Test
- public void testSetPhaseShiftPositive() {
- RippleModifier modifier = new RippleModifier();
- modifier.setPhaseShift(1.5f);
- assertEquals(1.5f, modifier.getPhaseShift(), 0.001);
- }
-
- @Test
- public void testSetPhaseShiftNegative() {
- RippleModifier modifier = new RippleModifier();
- modifier.setPhaseShift(-2.0f);
- assertEquals(Math.PI * 2 - 2.0f, modifier.getPhaseShift(), 0.001);
- }
-
- @Test
- public void testSetPhaseShiftZero() {
- RippleModifier modifier = new RippleModifier();
- modifier.setPhaseShift(0.0f);
- assertEquals(0.0f, modifier.getPhaseShift(), 0.001);
- }
-
- @Test
- public void testSetPhaseShiftLargePositive() {
- RippleModifier modifier = new RippleModifier();
- modifier.setPhaseShift(Mathf.PI * 10);
- assertEquals(0.0f, modifier.getPhaseShift(), 0.001);
- }
-
- @Test
- public void testSetPhaseShiftLargeNegative() {
- RippleModifier modifier = new RippleModifier();
- modifier.setPhaseShift(-Mathf.PI * 10);
- assertEquals(0.0f, modifier.getPhaseShift(), 0.001);
- }
-
- @Test
- public void testSetPhaseShiftExactlyTwoPi() {
- modifier.setPhaseShift(Mathf.TWO_PI);
- assertEquals(0.0f, modifier.getPhaseShift(), 0.001);
- }
-
- @Test
- public void testSetPhaseShiftVerySmallPositive() {
- modifier.setPhaseShift(0.0001f);
- assertEquals(0.0001f, modifier.getPhaseShift(), 0.001);
- }
-
-}
\ No newline at end of file
+ for (int i = 0; i < centers.length; i++) {
+ modifier.setCenter(centers[i]);
+ assertEquals(centers[i], modifier.getCenter());
+ }
+ }
+
+ @Test
+ public void testSetCenterToNullThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> modifier.setCenter(null));
+ }
+
+ @Test
+ public void testSetWaveLengthToZeroThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> modifier.setWaveLength(0));
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {-1.0f, -15.002f, -20.245f, -100.23f})
+ public void testSetWaveLengthLessThanZeroThrowsException(float waveLength) {
+ assertThrows(IllegalArgumentException.class, () -> modifier.setWaveLength(waveLength));
+ }
+
+ @Test
+ public void testModifyNullMeshThrowsIllegalArgumentException() {
+ assertThrows(IllegalArgumentException.class, () -> modifier.modify(null));
+ }
+
+ @Test
+ public void testNegativeAmplitude1ThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> modifier.setAmplitude1(-1));
+ }
+
+ @Test
+ public void testNegativeAmplitude2ThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> modifier.setAmplitude2(-1));
+ }
+
+ @Test
+ public void testDefaultDirection() {
+ Vector3f expected = new Vector3f(0, -1, 0);
+ assertEquals(expected, modifier.getDirection());
+ }
+
+ @Test
+ public void testSetNullDirectionThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> modifier.setDirection(null));
+ }
+
+ @Test
+ public void testDirectionIsNormalizedByDefault() {
+ float length = modifier.getDirection().length();
+ assertEquals(1, length);
+ }
+
+ @Test
+ public void testSetDirectionNormalizesDirection() {
+ Vector3f direction = new Vector3f(5, 43.45f, 1);
+ modifier.setDirection(direction);
+ float length = modifier.getDirection().length();
+ assertEquals(1, length, 0.0001f);
+ }
+
+ @Test
+ public void testDirectionIsNormalizedInternally() {
+ Vector3f expected = new Vector3f(1, 3.556f, 2.345f);
+ Vector3f direction = new Vector3f(expected);
+ modifier.setDirection(direction);
+ assertEquals(expected, direction);
+ }
+
+ @Test
+ public void testDefaultPhaseShift() {
+ assertEquals(0, modifier.getPhaseShift());
+ }
+
+ @Test
+ public void testPhaseShiftMultiplesOfTwoPi() {
+ float expected = Mathf.TWO_PI;
+ modifier.setPhaseShift(expected * 4);
+ assertEquals(0, modifier.getPhaseShift());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {0, Mathf.HALF_PI, Mathf.QUARTER_PI})
+ public void testGetSetPhaseShift(float phaseShift) {
+ modifier.setPhaseShift(phaseShift);
+ assertEquals(phaseShift, modifier.getPhaseShift());
+ }
+
+ @Test
+ public void testSetPhaseShiftPositive() {
+ RippleModifier modifier = new RippleModifier();
+ modifier.setPhaseShift(1.5f);
+ assertEquals(1.5f, modifier.getPhaseShift(), 0.001);
+ }
+
+ @Test
+ public void testSetPhaseShiftNegative() {
+ RippleModifier modifier = new RippleModifier();
+ modifier.setPhaseShift(-2.0f);
+ assertEquals(Math.PI * 2 - 2.0f, modifier.getPhaseShift(), 0.001);
+ }
+
+ @Test
+ public void testSetPhaseShiftZero() {
+ RippleModifier modifier = new RippleModifier();
+ modifier.setPhaseShift(0.0f);
+ assertEquals(0.0f, modifier.getPhaseShift(), 0.001);
+ }
+
+ @Test
+ public void testSetPhaseShiftLargePositive() {
+ RippleModifier modifier = new RippleModifier();
+ modifier.setPhaseShift(Mathf.PI * 10);
+ assertEquals(0.0f, modifier.getPhaseShift(), 0.001);
+ }
+
+ @Test
+ public void testSetPhaseShiftLargeNegative() {
+ RippleModifier modifier = new RippleModifier();
+ modifier.setPhaseShift(-Mathf.PI * 10);
+ assertEquals(0.0f, modifier.getPhaseShift(), 0.001);
+ }
+
+ @Test
+ public void testSetPhaseShiftExactlyTwoPi() {
+ modifier.setPhaseShift(Mathf.TWO_PI);
+ assertEquals(0.0f, modifier.getPhaseShift(), 0.001);
+ }
+
+ @Test
+ public void testSetPhaseShiftVerySmallPositive() {
+ modifier.setPhaseShift(0.0001f);
+ assertEquals(0.0001f, modifier.getPhaseShift(), 0.001);
+ }
+}
diff --git a/src/test/java/mesh/modifier/test/ScaleModifierTest.java b/src/test/java/mesh/modifier/test/ScaleModifierTest.java
index ad22ddd6..cf69e16b 100644
--- a/src/test/java/mesh/modifier/test/ScaleModifierTest.java
+++ b/src/test/java/mesh/modifier/test/ScaleModifierTest.java
@@ -19,170 +19,169 @@
public class ScaleModifierTest {
- @Test
- public void testImplementsModifierInterface() {
- ScaleModifier modifier = new ScaleModifier();
- assertTrue(modifier instanceof IMeshModifier);
+ @Test
+ public void testImplementsModifierInterface() {
+ ScaleModifier modifier = new ScaleModifier();
+ assertTrue(modifier instanceof IMeshModifier);
+ }
+
+ @Test
+ public void returnedReferenceIsNotNull() {
+ assertNotNull(new ScaleModifier().modify(new Mesh3D()));
+ }
+
+ @Test
+ public void testReturnsReference() {
+ Mesh3D mesh0 = new CubeCreator().create();
+ Mesh3D mesh1 = new ScaleModifier().modify(mesh0);
+ assertTrue(mesh0 == mesh1);
+ }
+
+ @Test
+ public void testDefaultScale() {
+ ScaleModifier modifier = new ScaleModifier();
+ assertEquals(1, modifier.getScaleX());
+ assertEquals(1, modifier.getScaleY());
+ assertEquals(1, modifier.getScaleZ());
+ }
+
+ @Test
+ public void testScaleConstructor() {
+ float expectedScale = 12.45f;
+ ScaleModifier modifier = new ScaleModifier(expectedScale);
+ assertEquals(expectedScale, modifier.getScaleX());
+ assertEquals(expectedScale, modifier.getScaleY());
+ assertEquals(expectedScale, modifier.getScaleZ());
+ }
+
+ @Test
+ public void testGetSetScaleX() {
+ float expectedScale = 123.4f;
+ ScaleModifier modifier = new ScaleModifier();
+ modifier.setScaleX(expectedScale);
+ assertEquals(expectedScale, modifier.getScaleX());
+ }
+
+ @Test
+ public void testGetSetScaleY() {
+ float expectedScale = 24.5f;
+ ScaleModifier modifier = new ScaleModifier();
+ modifier.setScaleY(expectedScale);
+ assertEquals(expectedScale, modifier.getScaleY());
+ }
+
+ @Test
+ public void testGetSetScaleZ() {
+ float expectedScale = 24.1223f;
+ ScaleModifier modifier = new ScaleModifier();
+ modifier.setScaleZ(expectedScale);
+ assertEquals(expectedScale, modifier.getScaleZ());
+ }
+
+ @Test
+ public void testScalesOriginalVertices() {
+ Mesh3D mesh = new IcosahedronCreator().create();
+ List vertices = new ArrayList(mesh.vertices);
+ mesh.apply(new ScaleModifier(2.3f));
+ for (int i = 0; i < vertices.size(); i++) {
+ Vector3f expected = vertices.get(i);
+ Vector3f actual = mesh.vertices.get(i);
+ assertTrue(expected == actual);
}
-
- @Test
- public void returnedReferenceIsNotNull() {
- assertNotNull(new ScaleModifier().modify(new Mesh3D()));
+ }
+
+ @Test
+ public void testScaleQuadSphereScalar() {
+ float scale = 134.3f;
+ Mesh3D mesh = new QuadSphereCreator().create();
+ List unscaledVertices = new ArrayList();
+ for (Vector3f v : mesh.vertices) {
+ unscaledVertices.add(new Vector3f(v));
}
-
- @Test
- public void testReturnsReference() {
- Mesh3D mesh0 = new CubeCreator().create();
- Mesh3D mesh1 = new ScaleModifier().modify(mesh0);
- assertTrue(mesh0 == mesh1);
+ ScaleModifier modifier = new ScaleModifier(scale);
+ modifier.modify(mesh);
+ for (int i = 0; i < unscaledVertices.size(); i++) {
+ Vector3f unscaled = unscaledVertices.get(i);
+ Vector3f expected = unscaled.mult(scale);
+ Vector3f actual = mesh.vertices.get(i);
+ assertEquals(expected, actual);
}
-
- @Test
- public void testDefaultScale() {
- ScaleModifier modifier = new ScaleModifier();
- assertEquals(1, modifier.getScaleX());
- assertEquals(1, modifier.getScaleY());
- assertEquals(1, modifier.getScaleZ());
+ }
+
+ @Test
+ public void testScaleQuadSphereXYZ() {
+ float scaleX = 134.3f;
+ float scaleY = 12.3f;
+ float scaleZ = 1234.3f;
+ Mesh3D mesh = new QuadSphereCreator().create();
+ List unscaledVertices = new ArrayList();
+ for (Vector3f v : mesh.vertices) {
+ unscaledVertices.add(new Vector3f(v));
}
-
- @Test
- public void testScaleConstructor() {
- float expectedScale = 12.45f;
- ScaleModifier modifier = new ScaleModifier(expectedScale);
- assertEquals(expectedScale, modifier.getScaleX());
- assertEquals(expectedScale, modifier.getScaleY());
- assertEquals(expectedScale, modifier.getScaleZ());
+ ScaleModifier modifier = new ScaleModifier(scaleX, scaleY, scaleZ);
+ modifier.modify(mesh);
+ for (int i = 0; i < unscaledVertices.size(); i++) {
+ Vector3f unscaled = unscaledVertices.get(i);
+ Vector3f expected = unscaled.mult(scaleX, scaleY, scaleZ);
+ Vector3f actual = mesh.vertices.get(i);
+ assertEquals(expected, actual);
}
-
- @Test
- public void testGetSetScaleX() {
- float expectedScale = 123.4f;
- ScaleModifier modifier = new ScaleModifier();
- modifier.setScaleX(expectedScale);
- assertEquals(expectedScale, modifier.getScaleX());
+ }
+
+ @Test
+ public void testScaleQuadSphereSetX() {
+ float scaleX = 234.3f;
+ Mesh3D mesh = new QuadSphereCreator().create();
+ List unscaledVertices = new ArrayList();
+ for (Vector3f v : mesh.vertices) {
+ unscaledVertices.add(new Vector3f(v));
}
-
- @Test
- public void testGetSetScaleY() {
- float expectedScale = 24.5f;
- ScaleModifier modifier = new ScaleModifier();
- modifier.setScaleY(expectedScale);
- assertEquals(expectedScale, modifier.getScaleY());
+ ScaleModifier modifier = new ScaleModifier();
+ modifier.setScaleX(scaleX);
+ modifier.modify(mesh);
+ for (int i = 0; i < unscaledVertices.size(); i++) {
+ Vector3f unscaled = unscaledVertices.get(i);
+ Vector3f expected = unscaled.mult(scaleX, 1, 1);
+ Vector3f actual = mesh.vertices.get(i);
+ assertEquals(expected, actual);
}
-
- @Test
- public void testGetSetScaleZ() {
- float expectedScale = 24.1223f;
- ScaleModifier modifier = new ScaleModifier();
- modifier.setScaleZ(expectedScale);
- assertEquals(expectedScale, modifier.getScaleZ());
+ }
+
+ @Test
+ public void testScaleQuadSphereSetY() {
+ float scaleY = 234.323f;
+ Mesh3D mesh = new QuadSphereCreator().create();
+ List unscaledVertices = new ArrayList();
+ for (Vector3f v : mesh.vertices) {
+ unscaledVertices.add(new Vector3f(v));
}
-
- @Test
- public void testScalesOriginalVertices() {
- Mesh3D mesh = new IcosahedronCreator().create();
- List vertices = new ArrayList(mesh.vertices);
- mesh.apply(new ScaleModifier(2.3f));
- for (int i = 0; i < vertices.size(); i++) {
- Vector3f expected = vertices.get(i);
- Vector3f actual = mesh.vertices.get(i);
- assertTrue(expected == actual);
- }
+ ScaleModifier modifier = new ScaleModifier();
+ modifier.setScaleY(scaleY);
+ modifier.modify(mesh);
+ for (int i = 0; i < unscaledVertices.size(); i++) {
+ Vector3f unscaled = unscaledVertices.get(i);
+ Vector3f expected = unscaled.mult(1, scaleY, 1);
+ Vector3f actual = mesh.vertices.get(i);
+ assertEquals(expected, actual);
}
-
- @Test
- public void testScaleQuadSphereScalar() {
- float scale = 134.3f;
- Mesh3D mesh = new QuadSphereCreator().create();
- List unscaledVertices = new ArrayList();
- for (Vector3f v : mesh.vertices) {
- unscaledVertices.add(new Vector3f(v));
- }
- ScaleModifier modifier = new ScaleModifier(scale);
- modifier.modify(mesh);
- for (int i = 0; i < unscaledVertices.size(); i++) {
- Vector3f unscaled = unscaledVertices.get(i);
- Vector3f expected = unscaled.mult(scale);
- Vector3f actual = mesh.vertices.get(i);
- assertEquals(expected, actual);
- }
+ }
+
+ @Test
+ public void testScaleQuadSphereSetZ() {
+ float scaleZ = 21.34f;
+ Mesh3D mesh = new QuadSphereCreator().create();
+ List unscaledVertices = new ArrayList();
+ for (Vector3f v : mesh.vertices) {
+ unscaledVertices.add(new Vector3f(v));
}
-
- @Test
- public void testScaleQuadSphereXYZ() {
- float scaleX = 134.3f;
- float scaleY = 12.3f;
- float scaleZ = 1234.3f;
- Mesh3D mesh = new QuadSphereCreator().create();
- List unscaledVertices = new ArrayList();
- for (Vector3f v : mesh.vertices) {
- unscaledVertices.add(new Vector3f(v));
- }
- ScaleModifier modifier = new ScaleModifier(scaleX, scaleY, scaleZ);
- modifier.modify(mesh);
- for (int i = 0; i < unscaledVertices.size(); i++) {
- Vector3f unscaled = unscaledVertices.get(i);
- Vector3f expected = unscaled.mult(scaleX, scaleY, scaleZ);
- Vector3f actual = mesh.vertices.get(i);
- assertEquals(expected, actual);
- }
+ ScaleModifier modifier = new ScaleModifier();
+ modifier.setScaleZ(scaleZ);
+ modifier.modify(mesh);
+ for (int i = 0; i < unscaledVertices.size(); i++) {
+ Vector3f unscaled = unscaledVertices.get(i);
+ Vector3f expected = unscaled.mult(1, 1, scaleZ);
+ Vector3f actual = mesh.vertices.get(i);
+ assertEquals(expected, actual);
}
-
- @Test
- public void testScaleQuadSphereSetX() {
- float scaleX = 234.3f;
- Mesh3D mesh = new QuadSphereCreator().create();
- List unscaledVertices = new ArrayList();
- for (Vector3f v : mesh.vertices) {
- unscaledVertices.add(new Vector3f(v));
- }
- ScaleModifier modifier = new ScaleModifier();
- modifier.setScaleX(scaleX);
- modifier.modify(mesh);
- for (int i = 0; i < unscaledVertices.size(); i++) {
- Vector3f unscaled = unscaledVertices.get(i);
- Vector3f expected = unscaled.mult(scaleX, 1, 1);
- Vector3f actual = mesh.vertices.get(i);
- assertEquals(expected, actual);
- }
- }
-
- @Test
- public void testScaleQuadSphereSetY() {
- float scaleY = 234.323f;
- Mesh3D mesh = new QuadSphereCreator().create();
- List unscaledVertices = new ArrayList();
- for (Vector3f v : mesh.vertices) {
- unscaledVertices.add(new Vector3f(v));
- }
- ScaleModifier modifier = new ScaleModifier();
- modifier.setScaleY(scaleY);
- modifier.modify(mesh);
- for (int i = 0; i < unscaledVertices.size(); i++) {
- Vector3f unscaled = unscaledVertices.get(i);
- Vector3f expected = unscaled.mult(1, scaleY, 1);
- Vector3f actual = mesh.vertices.get(i);
- assertEquals(expected, actual);
- }
- }
-
- @Test
- public void testScaleQuadSphereSetZ() {
- float scaleZ = 21.34f;
- Mesh3D mesh = new QuadSphereCreator().create();
- List unscaledVertices = new ArrayList();
- for (Vector3f v : mesh.vertices) {
- unscaledVertices.add(new Vector3f(v));
- }
- ScaleModifier modifier = new ScaleModifier();
- modifier.setScaleZ(scaleZ);
- modifier.modify(mesh);
- for (int i = 0; i < unscaledVertices.size(); i++) {
- Vector3f unscaled = unscaledVertices.get(i);
- Vector3f expected = unscaled.mult(1, 1, scaleZ);
- Vector3f actual = mesh.vertices.get(i);
- assertEquals(expected, actual);
- }
- }
-
+ }
}
diff --git a/src/test/java/mesh/modifier/test/SnapToGroundModifierTest.java b/src/test/java/mesh/modifier/test/SnapToGroundModifierTest.java
index 53b67046..70cc4246 100644
--- a/src/test/java/mesh/modifier/test/SnapToGroundModifierTest.java
+++ b/src/test/java/mesh/modifier/test/SnapToGroundModifierTest.java
@@ -22,174 +22,173 @@
public class SnapToGroundModifierTest {
- private SnapToGroundModifier modifier;
-
- @BeforeEach
- public void setUp() {
- modifier = new SnapToGroundModifier();
- }
-
- @Test
- public void implementsModifierInterface() {
- assertTrue(modifier instanceof IMeshModifier);
- }
-
- @Test
- public void modifiedMeshIsNotNull() {
- Mesh3D mesh = new Mesh3D();
- assertNotNull(modifier.modify(mesh));
- }
-
- @Test
- public void returnsReferenceToModifiedMesh() {
- Mesh3D expected = new Mesh3D();
- Mesh3D actual = modifier.modify(expected);
- assertSame(expected, actual);
- }
-
- @Test
- public void defaultGroundLevel() {
- assertEquals(0, modifier.getGroundLevel());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 0, -1, 2.024f, 3.235f, Float.MIN_VALUE, Float.MAX_VALUE })
- public void testGetSetGroundLevel(float groundLevel) {
- modifier.setGroundLevel(groundLevel);
- assertEquals(groundLevel, modifier.getGroundLevel());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 0, -1, 66.024f, -240.235f, Float.MIN_VALUE, Float.MAX_VALUE })
- public void testConstructor(float groundLevel) {
- modifier = new SnapToGroundModifier(groundLevel);
- assertEquals(groundLevel, modifier.getGroundLevel());
- }
-
- @Test
- public void testConsistentVertexCount() {
- QuadSphereCreator creator = new QuadSphereCreator();
- Mesh3D mesh = creator.create();
- int expectedVertexCount = mesh.getVertexCount();
- modifier.modify(mesh);
- assertEquals(expectedVertexCount, mesh.getVertexCount());
- }
-
- @Test
- public void testConsistentFaceCount() {
- QuadSphereCreator creator = new QuadSphereCreator();
- Mesh3D mesh = creator.create();
- int expectedFaceCount = mesh.getFaceCount();
- modifier.modify(mesh);
- assertEquals(expectedFaceCount, mesh.getFaceCount());
- }
-
- @Test
- public void doesOnlyModifiyY() {
- IcoSphereCreator creator = new IcoSphereCreator(1, 3);
- Mesh3D expected = creator.create();
- Mesh3D actual = creator.create();
- modifier.modify(actual);
- for (int i = 0; i < actual.getVertexCount(); i++) {
- Vector3f expectedVertex = expected.getVertexAt(i);
- Vector3f actualVertex = actual.getVertexAt(i);
- assertEquals(expectedVertex.x, actualVertex.x);
- assertEquals(expectedVertex.z, actualVertex.z);
- }
- }
-
- @Test
- public void testPlaneNegativeY() {
- Mesh3D plane = new PlaneCreator().create();
- plane.apply(new TranslateModifier(0, -10.23f, 0));
- modifier.modify(plane);
- for (int i = 0; i < plane.getVertexCount(); i++) {
- Vector3f vertex = plane.getVertexAt(i);
- assertEquals(0, vertex.y);
- }
- }
-
- @Test
- public void testPlanePositiveY() {
- Mesh3D plane = new PlaneCreator().create();
- plane.apply(new TranslateModifier(0, 10.23f, 0));
- modifier.modify(plane);
- for (int i = 0; i < plane.getVertexCount(); i++) {
- Vector3f vertex = plane.getVertexAt(i);
- assertEquals(0, vertex.y);
- }
- }
-
- @ParameterizedTest
- @ValueSource(floats = { -5.02f, -7.24f, -100, -2000.3f })
- public void testCubeAboveGround(float translateY) {
- Mesh3D expeted = new CubeCreator().create();
- Mesh3D actual = new CubeCreator().create();
- expeted.apply(new TranslateModifier(0, -1, 0));
- actual.apply(new TranslateModifier(0, translateY, 0));
- modifier.modify(actual);
- for (int i = 0; i < actual.getVertexCount(); i++) {
- Vector3f expectedVertex = expeted.getVertexAt(i);
- Vector3f actualVertex = actual.getVertexAt(i);
- assertEquals(expectedVertex, actualVertex);
- }
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 8.02f, 20.24f, 100.234f, 2030.321f })
- public void testCubeBelowGround(float translateY) {
- Mesh3D expeted = new CubeCreator().create();
- Mesh3D actual = new CubeCreator().create();
- expeted.apply(new TranslateModifier(0, -1, 0));
- actual.apply(new TranslateModifier(0, translateY, 0));
- modifier.modify(actual);
- for (int i = 0; i < actual.getVertexCount(); i++) {
- Vector3f expectedVertex = expeted.getVertexAt(i);
- Vector3f actualVertex = actual.getVertexAt(i);
- assertEquals(expectedVertex, actualVertex);
- }
- }
-
- @Test
- public void testCubeCenteredAtOrigin() {
- Mesh3D expeted = new CubeCreator().create();
- Mesh3D actual = new CubeCreator().create();
- expeted.apply(new TranslateModifier(0, -1, 0));
- modifier.modify(actual);
- for (int i = 0; i < actual.getVertexCount(); i++) {
- Vector3f expectedVertex = expeted.getVertexAt(i);
- Vector3f actualVertex = actual.getVertexAt(i);
- assertEquals(expectedVertex, actualVertex);
- }
- }
-
- @ParameterizedTest
- @ValueSource(floats = { -5.02f, -7.24f, -100, -2000.3f, 0, 10, 20, 100 })
- public void testDifferentGroundLevelsPlane(float groundLevel) {
- Mesh3D plane = new PlaneCreator().create();
- modifier.setGroundLevel(groundLevel);
- modifier.modify(plane);
- for (Vector3f vertex : plane.getVertices()) {
- assertEquals(groundLevel, vertex.y, 0.001);
- }
- }
-
- @ParameterizedTest
- @ValueSource(floats = { -3.122f, -8.2454f, -100, -2024.3f, 0, 10.34f, 20.33f, 100.32f })
- public void testDifferentGroundLevelsCube(float groundLevel) {
- Mesh3D cube = new CubeCreator().create();
- modifier.setGroundLevel(groundLevel);
- modifier.modify(cube);
-
- for (int i = 0; i < 4; i++) {
- Vector3f vertex = cube.getVertexAt(i);
- assertEquals((groundLevel - 2), vertex.y, 0.001);
- }
-
- for (int i = 4; i < 8; i++) {
- Vector3f vertex = cube.getVertexAt(i);
- assertEquals(groundLevel, vertex.y, 0.001);
- }
- }
-
+ private SnapToGroundModifier modifier;
+
+ @BeforeEach
+ public void setUp() {
+ modifier = new SnapToGroundModifier();
+ }
+
+ @Test
+ public void implementsModifierInterface() {
+ assertTrue(modifier instanceof IMeshModifier);
+ }
+
+ @Test
+ public void modifiedMeshIsNotNull() {
+ Mesh3D mesh = new Mesh3D();
+ assertNotNull(modifier.modify(mesh));
+ }
+
+ @Test
+ public void returnsReferenceToModifiedMesh() {
+ Mesh3D expected = new Mesh3D();
+ Mesh3D actual = modifier.modify(expected);
+ assertSame(expected, actual);
+ }
+
+ @Test
+ public void defaultGroundLevel() {
+ assertEquals(0, modifier.getGroundLevel());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {0, -1, 2.024f, 3.235f, Float.MIN_VALUE, Float.MAX_VALUE})
+ public void testGetSetGroundLevel(float groundLevel) {
+ modifier.setGroundLevel(groundLevel);
+ assertEquals(groundLevel, modifier.getGroundLevel());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {0, -1, 66.024f, -240.235f, Float.MIN_VALUE, Float.MAX_VALUE})
+ public void testConstructor(float groundLevel) {
+ modifier = new SnapToGroundModifier(groundLevel);
+ assertEquals(groundLevel, modifier.getGroundLevel());
+ }
+
+ @Test
+ public void testConsistentVertexCount() {
+ QuadSphereCreator creator = new QuadSphereCreator();
+ Mesh3D mesh = creator.create();
+ int expectedVertexCount = mesh.getVertexCount();
+ modifier.modify(mesh);
+ assertEquals(expectedVertexCount, mesh.getVertexCount());
+ }
+
+ @Test
+ public void testConsistentFaceCount() {
+ QuadSphereCreator creator = new QuadSphereCreator();
+ Mesh3D mesh = creator.create();
+ int expectedFaceCount = mesh.getFaceCount();
+ modifier.modify(mesh);
+ assertEquals(expectedFaceCount, mesh.getFaceCount());
+ }
+
+ @Test
+ public void doesOnlyModifiyY() {
+ IcoSphereCreator creator = new IcoSphereCreator(1, 3);
+ Mesh3D expected = creator.create();
+ Mesh3D actual = creator.create();
+ modifier.modify(actual);
+ for (int i = 0; i < actual.getVertexCount(); i++) {
+ Vector3f expectedVertex = expected.getVertexAt(i);
+ Vector3f actualVertex = actual.getVertexAt(i);
+ assertEquals(expectedVertex.x, actualVertex.x);
+ assertEquals(expectedVertex.z, actualVertex.z);
+ }
+ }
+
+ @Test
+ public void testPlaneNegativeY() {
+ Mesh3D plane = new PlaneCreator().create();
+ plane.apply(new TranslateModifier(0, -10.23f, 0));
+ modifier.modify(plane);
+ for (int i = 0; i < plane.getVertexCount(); i++) {
+ Vector3f vertex = plane.getVertexAt(i);
+ assertEquals(0, vertex.y);
+ }
+ }
+
+ @Test
+ public void testPlanePositiveY() {
+ Mesh3D plane = new PlaneCreator().create();
+ plane.apply(new TranslateModifier(0, 10.23f, 0));
+ modifier.modify(plane);
+ for (int i = 0; i < plane.getVertexCount(); i++) {
+ Vector3f vertex = plane.getVertexAt(i);
+ assertEquals(0, vertex.y);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {-5.02f, -7.24f, -100, -2000.3f})
+ public void testCubeAboveGround(float translateY) {
+ Mesh3D expeted = new CubeCreator().create();
+ Mesh3D actual = new CubeCreator().create();
+ expeted.apply(new TranslateModifier(0, -1, 0));
+ actual.apply(new TranslateModifier(0, translateY, 0));
+ modifier.modify(actual);
+ for (int i = 0; i < actual.getVertexCount(); i++) {
+ Vector3f expectedVertex = expeted.getVertexAt(i);
+ Vector3f actualVertex = actual.getVertexAt(i);
+ assertEquals(expectedVertex, actualVertex);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {8.02f, 20.24f, 100.234f, 2030.321f})
+ public void testCubeBelowGround(float translateY) {
+ Mesh3D expeted = new CubeCreator().create();
+ Mesh3D actual = new CubeCreator().create();
+ expeted.apply(new TranslateModifier(0, -1, 0));
+ actual.apply(new TranslateModifier(0, translateY, 0));
+ modifier.modify(actual);
+ for (int i = 0; i < actual.getVertexCount(); i++) {
+ Vector3f expectedVertex = expeted.getVertexAt(i);
+ Vector3f actualVertex = actual.getVertexAt(i);
+ assertEquals(expectedVertex, actualVertex);
+ }
+ }
+
+ @Test
+ public void testCubeCenteredAtOrigin() {
+ Mesh3D expeted = new CubeCreator().create();
+ Mesh3D actual = new CubeCreator().create();
+ expeted.apply(new TranslateModifier(0, -1, 0));
+ modifier.modify(actual);
+ for (int i = 0; i < actual.getVertexCount(); i++) {
+ Vector3f expectedVertex = expeted.getVertexAt(i);
+ Vector3f actualVertex = actual.getVertexAt(i);
+ assertEquals(expectedVertex, actualVertex);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {-5.02f, -7.24f, -100, -2000.3f, 0, 10, 20, 100})
+ public void testDifferentGroundLevelsPlane(float groundLevel) {
+ Mesh3D plane = new PlaneCreator().create();
+ modifier.setGroundLevel(groundLevel);
+ modifier.modify(plane);
+ for (Vector3f vertex : plane.getVertices()) {
+ assertEquals(groundLevel, vertex.y, 0.001);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {-3.122f, -8.2454f, -100, -2024.3f, 0, 10.34f, 20.33f, 100.32f})
+ public void testDifferentGroundLevelsCube(float groundLevel) {
+ Mesh3D cube = new CubeCreator().create();
+ modifier.setGroundLevel(groundLevel);
+ modifier.modify(cube);
+
+ for (int i = 0; i < 4; i++) {
+ Vector3f vertex = cube.getVertexAt(i);
+ assertEquals((groundLevel - 2), vertex.y, 0.001);
+ }
+
+ for (int i = 4; i < 8; i++) {
+ Vector3f vertex = cube.getVertexAt(i);
+ assertEquals(groundLevel, vertex.y, 0.001);
+ }
+ }
}
diff --git a/src/test/java/mesh/modifier/test/SpherifyModifierTest.java b/src/test/java/mesh/modifier/test/SpherifyModifierTest.java
index caabdd17..57b9d896 100644
--- a/src/test/java/mesh/modifier/test/SpherifyModifierTest.java
+++ b/src/test/java/mesh/modifier/test/SpherifyModifierTest.java
@@ -23,184 +23,183 @@
public class SpherifyModifierTest {
- private SpherifyModifier modifier;
-
- @BeforeEach
- public void setUp() {
- modifier = new SpherifyModifier();
- }
-
- @Test
- public void testModifierImplementsMeshModifierInterface() {
- assertTrue(modifier instanceof IMeshModifier);
- }
-
- @Test
- public void testReturnsReferenceToModifedMesh() {
- Mesh3D epected = new CubeCreator().create();
- Mesh3D actual = modifier.modify(epected);
- assertSame(epected, actual);
- }
-
- @Test
- public void testDefaultConstructor() {
- SpherifyModifier modifier = new SpherifyModifier();
- assertEquals(1, modifier.getFactor());
- assertEquals(1, modifier.getRadius());
- assertEquals(Vector3f.ZERO, modifier.getCenter());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 2.45f, 0.2f, 100.345f, Float.MIN_VALUE, Float.MAX_VALUE })
- public void testConstructorWithRadiusParameter() {
- float expectedRadius = 2.55f;
- SpherifyModifier modifier = new SpherifyModifier(expectedRadius);
- assertEquals(1, modifier.getFactor());
- assertEquals(expectedRadius, modifier.getRadius());
- assertEquals(Vector3f.ZERO, modifier.getCenter());
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 0, -0.1f, -100.3f, -Mathf.FLT_EPSILON })
- public void testConstructorWithRadiusLessOrEqualsToZero(float radius) {
- assertThrows(IllegalArgumentException.class, () -> new SpherifyModifier(radius));
- }
-
- @Test
- public void testDefaultCenter() {
- assertEquals(Vector3f.ZERO, modifier.getCenter());
- }
-
- @Test
- public void testGetSetCenterViaParameters() {
- float expectedX = 10.345f;
- float expectedY = 345.553f;
- float expectedZ = -1345.345f;
- modifier.setCenter(expectedX, expectedY, expectedZ);
- assertEquals(expectedX, modifier.getCenter().x);
- assertEquals(expectedY, modifier.getCenter().y);
- assertEquals(expectedZ, modifier.getCenter().z);
- }
-
- @Test
- public void testGetSetCenterViaVector3f() {
- Vector3f center = new Vector3f(0.134f, -23.443f, 100.0f);
- modifier.setCenter(center);
- assertEquals(center, modifier.getCenter());
- }
-
- @Test
- public void testGetCenterReturnsImutable() {
- Vector3f center = new Vector3f();
- modifier.setCenter(center);
- assertNotSame(center, modifier.getCenter());
- }
-
- @Test
- public void testDefaultFactor() {
- assertEquals(1.0f, modifier.getFactor());
- }
-
- @Test
- public void testDefaultRadius() {
- assertEquals(1, modifier.getRadius());
- }
-
- @Test
- public void testModifyReturnsNonNullMesh() {
- assertNotNull(modifier.modify(new CubeCreator().create()));
- }
-
- @Test
- public void testModifyReturnsReferenceToModifiedMesh() {
- Mesh3D expected = new CubeCreator().create();
- Mesh3D actual = modifier.modify(expected);
- assertSame(expected, actual);
- }
-
- @ParameterizedTest
- @ValueSource(floats = { -Float.MIN_VALUE, 0f, -1f, -Mathf.FLT_EPSILON })
- public void testSetRadiusToLessOrEqualToZeroThrowsException(float radius) {
- assertThrows(IllegalArgumentException.class, () -> modifier.setRadius(radius));
- }
-
- @Test
- public void testSetNullCenterThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> modifier.setCenter(null));
- }
-
- @Test
- public void testModifyNullMeshThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> modifier.modify(null));
- }
-
- @Test
- public void testSetFactorAboveBoundsThrowsException() {
- float factor = 1.0f + Mathf.FLT_EPSILON;
- assertThrows(IllegalArgumentException.class, () -> modifier.setFactor(factor));
- }
-
- @Test
- public void testSetFactorBelowBoundsThrowsException() {
- float factor = -Mathf.FLT_EPSILON;
- assertThrows(IllegalArgumentException.class, () -> modifier.setFactor(factor));
- }
-
- @Test
- public void testGetSetFactorWithinBouns() {
- float expectedFactor = 0.126f;
- modifier.setFactor(expectedFactor);
- assertEquals(expectedFactor, modifier.getFactor());
- }
-
- @ParameterizedTest
- @ValueSource(ints = { 2, 4, 10, 20 })
- public void testMultipleIteractionsHaveSameEffectAsOne(int n) {
- Mesh3D expected = new CubeCreator().create();
- Mesh3D actual = new CubeCreator().create();
- modifier.modify(expected);
- for (int i = 0; i < n; i++) {
- modifier.modify(actual);
- }
- for (int i = 0; i < expected.getVertexCount(); i++) {
- Vector3f expectedVertex = expected.getVertexAt(i);
- Vector3f actualVertex = actual.getVertexAt(i);
- assertEquals(expectedVertex.x, actualVertex.x, 0.001f);
- assertEquals(expectedVertex.y, actualVertex.y, 0.001f);
- assertEquals(expectedVertex.z, actualVertex.z, 0.001f);
- }
- }
-
- @ParameterizedTest
- @ValueSource(floats = { 2.134f, 4.234f, Float.MIN_VALUE })
- public void testMultipleRadiiWithFactorOne(float expectedRadius) {
- int segments = 30;
- float size = 1.0f;
- SegmentedCubeCreator creator = new SegmentedCubeCreator(segments, size);
- Mesh3D mesh = creator.create();
- modifier.setRadius(expectedRadius);
- modifier.modify(mesh);
- for (Vector3f vertex : mesh.vertices) {
- float distance = vertex.distance(Vector3f.ZERO);
- assertEquals(expectedRadius, distance, 0.001f);
- }
- }
-
- @Test
- public void testZeroFactorLeavesTheMeshUnchanged() {
- IcoSphereCreator creator = new IcoSphereCreator(1, 3);
- Mesh3D expected = creator.create();
- Mesh3D actual = creator.create();
- modifier.setFactor(0);
- modifier.setRadius(3);
- modifier.modify(actual);
- for (int i = 0; i < expected.getVertexCount(); i++) {
- Vector3f expectedVertex = expected.getVertexAt(i);
- Vector3f actualVertex = actual.getVertexAt(i);
- assertEquals(expectedVertex.x, actualVertex.x, 0.001f);
- assertEquals(expectedVertex.y, actualVertex.y, 0.001f);
- assertEquals(expectedVertex.z, actualVertex.z, 0.001f);
- }
- }
-
-}
\ No newline at end of file
+ private SpherifyModifier modifier;
+
+ @BeforeEach
+ public void setUp() {
+ modifier = new SpherifyModifier();
+ }
+
+ @Test
+ public void testModifierImplementsMeshModifierInterface() {
+ assertTrue(modifier instanceof IMeshModifier);
+ }
+
+ @Test
+ public void testReturnsReferenceToModifedMesh() {
+ Mesh3D epected = new CubeCreator().create();
+ Mesh3D actual = modifier.modify(epected);
+ assertSame(epected, actual);
+ }
+
+ @Test
+ public void testDefaultConstructor() {
+ SpherifyModifier modifier = new SpherifyModifier();
+ assertEquals(1, modifier.getFactor());
+ assertEquals(1, modifier.getRadius());
+ assertEquals(Vector3f.ZERO, modifier.getCenter());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {2.45f, 0.2f, 100.345f, Float.MIN_VALUE, Float.MAX_VALUE})
+ public void testConstructorWithRadiusParameter() {
+ float expectedRadius = 2.55f;
+ SpherifyModifier modifier = new SpherifyModifier(expectedRadius);
+ assertEquals(1, modifier.getFactor());
+ assertEquals(expectedRadius, modifier.getRadius());
+ assertEquals(Vector3f.ZERO, modifier.getCenter());
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {0, -0.1f, -100.3f, -Mathf.FLT_EPSILON})
+ public void testConstructorWithRadiusLessOrEqualsToZero(float radius) {
+ assertThrows(IllegalArgumentException.class, () -> new SpherifyModifier(radius));
+ }
+
+ @Test
+ public void testDefaultCenter() {
+ assertEquals(Vector3f.ZERO, modifier.getCenter());
+ }
+
+ @Test
+ public void testGetSetCenterViaParameters() {
+ float expectedX = 10.345f;
+ float expectedY = 345.553f;
+ float expectedZ = -1345.345f;
+ modifier.setCenter(expectedX, expectedY, expectedZ);
+ assertEquals(expectedX, modifier.getCenter().x);
+ assertEquals(expectedY, modifier.getCenter().y);
+ assertEquals(expectedZ, modifier.getCenter().z);
+ }
+
+ @Test
+ public void testGetSetCenterViaVector3f() {
+ Vector3f center = new Vector3f(0.134f, -23.443f, 100.0f);
+ modifier.setCenter(center);
+ assertEquals(center, modifier.getCenter());
+ }
+
+ @Test
+ public void testGetCenterReturnsImutable() {
+ Vector3f center = new Vector3f();
+ modifier.setCenter(center);
+ assertNotSame(center, modifier.getCenter());
+ }
+
+ @Test
+ public void testDefaultFactor() {
+ assertEquals(1.0f, modifier.getFactor());
+ }
+
+ @Test
+ public void testDefaultRadius() {
+ assertEquals(1, modifier.getRadius());
+ }
+
+ @Test
+ public void testModifyReturnsNonNullMesh() {
+ assertNotNull(modifier.modify(new CubeCreator().create()));
+ }
+
+ @Test
+ public void testModifyReturnsReferenceToModifiedMesh() {
+ Mesh3D expected = new CubeCreator().create();
+ Mesh3D actual = modifier.modify(expected);
+ assertSame(expected, actual);
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {-Float.MIN_VALUE, 0f, -1f, -Mathf.FLT_EPSILON})
+ public void testSetRadiusToLessOrEqualToZeroThrowsException(float radius) {
+ assertThrows(IllegalArgumentException.class, () -> modifier.setRadius(radius));
+ }
+
+ @Test
+ public void testSetNullCenterThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> modifier.setCenter(null));
+ }
+
+ @Test
+ public void testModifyNullMeshThrowsException() {
+ assertThrows(IllegalArgumentException.class, () -> modifier.modify(null));
+ }
+
+ @Test
+ public void testSetFactorAboveBoundsThrowsException() {
+ float factor = 1.0f + Mathf.FLT_EPSILON;
+ assertThrows(IllegalArgumentException.class, () -> modifier.setFactor(factor));
+ }
+
+ @Test
+ public void testSetFactorBelowBoundsThrowsException() {
+ float factor = -Mathf.FLT_EPSILON;
+ assertThrows(IllegalArgumentException.class, () -> modifier.setFactor(factor));
+ }
+
+ @Test
+ public void testGetSetFactorWithinBouns() {
+ float expectedFactor = 0.126f;
+ modifier.setFactor(expectedFactor);
+ assertEquals(expectedFactor, modifier.getFactor());
+ }
+
+ @ParameterizedTest
+ @ValueSource(ints = {2, 4, 10, 20})
+ public void testMultipleIteractionsHaveSameEffectAsOne(int n) {
+ Mesh3D expected = new CubeCreator().create();
+ Mesh3D actual = new CubeCreator().create();
+ modifier.modify(expected);
+ for (int i = 0; i < n; i++) {
+ modifier.modify(actual);
+ }
+ for (int i = 0; i < expected.getVertexCount(); i++) {
+ Vector3f expectedVertex = expected.getVertexAt(i);
+ Vector3f actualVertex = actual.getVertexAt(i);
+ assertEquals(expectedVertex.x, actualVertex.x, 0.001f);
+ assertEquals(expectedVertex.y, actualVertex.y, 0.001f);
+ assertEquals(expectedVertex.z, actualVertex.z, 0.001f);
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(floats = {2.134f, 4.234f, Float.MIN_VALUE})
+ public void testMultipleRadiiWithFactorOne(float expectedRadius) {
+ int segments = 30;
+ float size = 1.0f;
+ SegmentedCubeCreator creator = new SegmentedCubeCreator(segments, size);
+ Mesh3D mesh = creator.create();
+ modifier.setRadius(expectedRadius);
+ modifier.modify(mesh);
+ for (Vector3f vertex : mesh.vertices) {
+ float distance = vertex.distance(Vector3f.ZERO);
+ assertEquals(expectedRadius, distance, 0.001f);
+ }
+ }
+
+ @Test
+ public void testZeroFactorLeavesTheMeshUnchanged() {
+ IcoSphereCreator creator = new IcoSphereCreator(1, 3);
+ Mesh3D expected = creator.create();
+ Mesh3D actual = creator.create();
+ modifier.setFactor(0);
+ modifier.setRadius(3);
+ modifier.modify(actual);
+ for (int i = 0; i < expected.getVertexCount(); i++) {
+ Vector3f expectedVertex = expected.getVertexAt(i);
+ Vector3f actualVertex = actual.getVertexAt(i);
+ assertEquals(expectedVertex.x, actualVertex.x, 0.001f);
+ assertEquals(expectedVertex.y, actualVertex.y, 0.001f);
+ assertEquals(expectedVertex.z, actualVertex.z, 0.001f);
+ }
+ }
+}