From 9502d5c5609d50492b7505638d67cde8455d0e14 Mon Sep 17 00:00:00 2001 From: jannetty Date: Wed, 2 Oct 2024 10:42:22 -0700 Subject: [PATCH 01/30] changed docstrung for getDirection to specify that it gets direction with shortest diameter through location --- src/arcade/potts/env/location/PottsLocation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index c61f84ac..57b0a5ee 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -569,7 +569,8 @@ void updateCenter(int x, int y, int z, int change) { abstract ArrayList getSelected(Voxel focus, double n); /** - * Gets the direction of the slice. + * Gets the direction of the slice through the location that + * has the smallest diameter. * * @param random the seeded random number generator * @return the direction of the slice From baeff5ae76ac82f0d5aabb50d464b1d1929bdce8 Mon Sep 17 00:00:00 2001 From: jannetty Date: Wed, 2 Oct 2024 14:06:14 -0700 Subject: [PATCH 02/30] adding initial Plane, Point, Vector classes and associated tests --- src/arcade/core/util/Plane.java | 38 ++++++++++ src/arcade/core/util/Point3D.java | 33 +++++++++ src/arcade/core/util/Vector3D.java | 26 +++++++ test/arcade/core/util/PlaneTest.java | 95 +++++++++++++++++++++++++ test/arcade/core/util/Point3DTest.java | 54 ++++++++++++++ test/arcade/core/util/Vector3DTest.java | 42 +++++++++++ 6 files changed, 288 insertions(+) create mode 100644 src/arcade/core/util/Plane.java create mode 100644 src/arcade/core/util/Point3D.java create mode 100644 src/arcade/core/util/Vector3D.java create mode 100644 test/arcade/core/util/PlaneTest.java create mode 100644 test/arcade/core/util/Point3DTest.java create mode 100644 test/arcade/core/util/Vector3DTest.java diff --git a/src/arcade/core/util/Plane.java b/src/arcade/core/util/Plane.java new file mode 100644 index 00000000..fd95530b --- /dev/null +++ b/src/arcade/core/util/Plane.java @@ -0,0 +1,38 @@ +package arcade.core.util; + +/** + * A plane in 3D space. + */ + +public class Plane { + /** A point on the plane */ + public final Point3D point; + + /** The normal to the plane */ + public final Vector3D normalVector; + + /** + * Creates a plane from a point and a vector. + * + * @param point a point on the plane + * @param normalVector the normal vector to the plane + */ + public Plane(Point3D point, Vector3D normalVector) { + this.point = point; + this.normalVector = normalVector; + } + + /** + * Determines whether a point is on one side of the plane. + * + * @param p the point to test + * @return {@code true} if the point is on the side of the plane + * where the normal vector points + * {@code false} otherwise + */ + public boolean isOnSide(Point3D p) { + return (p.getX() - point.getX()) * normalVector.getA() + + (p.getY() - point.getY()) * normalVector.getB() + + (p.getZ() - point.getZ()) * normalVector.getC() > 0; + } +} \ No newline at end of file diff --git a/src/arcade/core/util/Point3D.java b/src/arcade/core/util/Point3D.java new file mode 100644 index 00000000..47f57cc4 --- /dev/null +++ b/src/arcade/core/util/Point3D.java @@ -0,0 +1,33 @@ +package arcade.core.util; + +import arcade.potts.env.location.Voxel; + + +/** + * A point in 3D space. + */ +public class Point3D { + + private final int x, y, z; + + public Point3D(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Creates a point in the same location as a voxel. + * + * @param v the voxel + */ + public Point3D(Voxel v) { + this.x = v.x; + this.y = v.y; + this.z = v.z; + } + + public int getX() { return x; } + public int getY() { return y; } + public int getZ() { return z; } +} diff --git a/src/arcade/core/util/Vector3D.java b/src/arcade/core/util/Vector3D.java new file mode 100644 index 00000000..30f40257 --- /dev/null +++ b/src/arcade/core/util/Vector3D.java @@ -0,0 +1,26 @@ +package arcade.core.util; + +/** + * A 3D vector. + */ +public class Vector3D { + + private final int a,b,c; + + /** + * Creates a 3D vector. + * + * @param a the x component + * @param b the y component + * @param c the z component + */ + public Vector3D(int a, int b, int c) { + this.a = a; + this.b = b; + this.c = c; + } + + public int getA() { return a; } + public int getB() { return b; } + public int getC() { return c; } +} \ No newline at end of file diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java new file mode 100644 index 00000000..ae129ff0 --- /dev/null +++ b/test/arcade/core/util/PlaneTest.java @@ -0,0 +1,95 @@ +package arcade.core.util; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class PlaneTest { + + @Test + public void constructor_givenPointAndVector_returnsCorrectPlane() { + Point3D point = new Point3D(1, 2, 3); + Vector3D normalVector = new Vector3D(4, 5, 6); + + Plane plane = new Plane(point, normalVector); + + assertEquals(point, plane.point); + assertEquals(normalVector, plane.normalVector); + } + + @Test + public void isOnSide_givenPointOnSameSide_returnsTrue() { + Point3D pointOnPlane = new Point3D(0, 0, 0); + Vector3D normalVector = new Vector3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Point3D pointToTest = new Point3D(1, 0, 0); // Point is on the side where normal vector points + + assertTrue(plane.isOnSide(pointToTest)); + } + + @Test + public void isOnSide_givenPointOnOppositeSide_returnsFalse() { + Point3D pointOnPlane = new Point3D(0, 0, 0); + Vector3D normalVector = new Vector3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Point3D pointToTest = new Point3D(-1, 0, 0); // Point is on the opposite side + + assertFalse(plane.isOnSide(pointToTest)); + } + + @Test + public void isOnSide_givenPointOnPlane_returnsFalse() { + Point3D pointOnPlane = new Point3D(0, 0, 0); + Vector3D normalVector = new Vector3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Point3D pointToTest = new Point3D(0, 0, 0); // Point is on the plane + + assertFalse(plane.isOnSide(pointToTest)); + } + + @Test + public void isOnPlane_givenPointOnPlane_returnsTrue() { + Point3D pointOnPlane = new Point3D(0, 0, 0); + Vector3D normalVector = new Vector3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Point3D pointToTest = new Point3D(0, 0, 0); // Point is exactly on the plane + + assertTrue(plane.isOnPlane(pointToTest)); + } + + @Test + public void isOnPlane_givenPointOffPlane_returnsFalse() { + Point3D pointOnPlane = new Point3D(0, 0, 0); + Vector3D normalVector = new Vector3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Point3D pointToTest = new Point3D(1, 1, 1); // Point is not on the plane + + assertFalse(plane.isOnPlane(pointToTest)); + } + + @Test + public void isOnPlane_givenPointFarAwayOnPlane_returnsTrue() { + Point3D pointOnPlane = new Point3D(1, 1, 1); + Vector3D normalVector = new Vector3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Point3D pointToTest = new Point3D(1, 100, 200); // Same x-coordinate, lies on the plane + + assertTrue(plane.isOnPlane(pointToTest)); + } + + @Test + public void isOnPlane_givenPointCloseToPlaneButNotOnIt_returnsFalse() { + Point3D pointOnPlane = new Point3D(0, 0, 0); + Vector3D normalVector = new Vector3D(1, 1, 1); + Plane plane = new Plane(pointOnPlane, normalVector); + + Point3D pointToTest = new Point3D(1, 1, 2); // Close, but not on the plane + + assertFalse(plane.isOnPlane(pointToTest)); + } +} \ No newline at end of file diff --git a/test/arcade/core/util/Point3DTest.java b/test/arcade/core/util/Point3DTest.java new file mode 100644 index 00000000..d26f7404 --- /dev/null +++ b/test/arcade/core/util/Point3DTest.java @@ -0,0 +1,54 @@ +package arcade.core.util; + +import arcade.potts.env.location.Voxel; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Unit tests for the Point3D class. + */ +public class Point3DTest { + + @Test + public void constructor_givenInts_returnsCorrectPoint() { + int x = 1, y = 2, z = 3; + + Point3D point = new Point3D(x, y, z); + + assertEquals(x, point.getX()); + assertEquals(y, point.getY()); + assertEquals(z, point.getZ()); + } + + @Test + public void constructor_givenVoxel_returnsCorrectPoint() { + Voxel voxel = new Voxel(4, 5, 6); + + Point3D point = new Point3D(voxel); + + assertEquals(voxel.x, point.getX()); + assertEquals(voxel.y, point.getY()); + assertEquals(voxel.z, point.getZ()); + } + + @Test + public void getX_called_returnsX() { + Point3D point = new Point3D(7, 8, 9); + + assertEquals(7, point.getX()); + } + + @Test + public void getY_called_returnsY() { + Point3D point = new Point3D(7, 8, 9); + + assertEquals(8, point.getY()); + } + + @Test + public void getZ_called_returnsZ() { + Point3D point = new Point3D(7, 8, 9); + + assertEquals(9, point.getZ()); + } +} \ No newline at end of file diff --git a/test/arcade/core/util/Vector3DTest.java b/test/arcade/core/util/Vector3DTest.java new file mode 100644 index 00000000..9c3fb6cc --- /dev/null +++ b/test/arcade/core/util/Vector3DTest.java @@ -0,0 +1,42 @@ +package arcade.core.util; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Unit tests for the Vector3D class. + */ +public class Vector3DTest { + + @Test + public void constructor_givenInts_returnsCorrectVector() { + int a = 1, b = 2, c = 3; + + Vector3D vector = new Vector3D(a, b, c); + + assertEquals(a, vector.getA()); + assertEquals(b, vector.getB()); + assertEquals(c, vector.getC()); + } + + @Test + public void getA_called_returnsA() { + Vector3D vector = new Vector3D(4, 5, 6); + + assertEquals(4, vector.getA()); + } + + @Test + public void getB_called_returnsB() { + Vector3D vector = new Vector3D(4, 5, 6); + + assertEquals(5, vector.getB()); + } + + @Test + public void getC_called_returnsC() { + Vector3D vector = new Vector3D(4, 5, 6); + + assertEquals(6, vector.getC()); + } +} \ No newline at end of file From 4439952ae803a0f763d767ac77458d3e76d136d7 Mon Sep 17 00:00:00 2001 From: jannetty Date: Wed, 2 Oct 2024 14:09:21 -0700 Subject: [PATCH 03/30] adding last file --- src/arcade/core/util/Plane.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/arcade/core/util/Plane.java b/src/arcade/core/util/Plane.java index fd95530b..8511b5b6 100644 --- a/src/arcade/core/util/Plane.java +++ b/src/arcade/core/util/Plane.java @@ -35,4 +35,17 @@ public boolean isOnSide(Point3D p) { + (p.getY() - point.getY()) * normalVector.getB() + (p.getZ() - point.getZ()) * normalVector.getC() > 0; } + + /** + * Determines whether a point is on the plane. + * + * @param p the point to test + * @return {@code true} if the point is on the plane + * {@code false} otherwise + */ + public boolean isOnPlane(Point3D p) { + return (p.getX() - point.getX()) * normalVector.getA() + + (p.getY() - point.getY()) * normalVector.getB() + + (p.getZ() - point.getZ()) * normalVector.getC() == 0; + } } \ No newline at end of file From 8009e3990e0973ed5602f088aee22f4ad0e3af76 Mon Sep 17 00:00:00 2001 From: jannetty Date: Wed, 2 Oct 2024 14:48:55 -0700 Subject: [PATCH 04/30] adding Plane container and Plane factory to make planes from potts enums --- src/arcade/core/util/Plane.java | 15 +++ src/arcade/core/util/PlaneContainer.java | 26 +++++ src/arcade/core/util/Point3D.java | 15 +++ src/arcade/core/util/Vector3D.java | 15 +++ src/arcade/potts/util/PottsPlaneFactory.java | 44 +++++++ test/arcade/core/util/PlaneContainerTest.java | 48 ++++++++ test/arcade/core/util/PlaneTest.java | 16 +++ test/arcade/core/util/Point3DTest.java | 16 +++ test/arcade/core/util/Vector3DTest.java | 16 +++ .../potts/util/PottsPlaneFactoryTest.java | 108 ++++++++++++++++++ 10 files changed, 319 insertions(+) create mode 100644 src/arcade/core/util/PlaneContainer.java create mode 100644 src/arcade/potts/util/PottsPlaneFactory.java create mode 100644 test/arcade/core/util/PlaneContainerTest.java create mode 100644 test/arcade/potts/util/PottsPlaneFactoryTest.java diff --git a/src/arcade/core/util/Plane.java b/src/arcade/core/util/Plane.java index 8511b5b6..2ef9522f 100644 --- a/src/arcade/core/util/Plane.java +++ b/src/arcade/core/util/Plane.java @@ -48,4 +48,19 @@ public boolean isOnPlane(Point3D p) { + (p.getY() - point.getY()) * normalVector.getB() + (p.getZ() - point.getZ()) * normalVector.getC() == 0; } + + /** + * Determines if two planes are equal. + * + * @param obj the plane to compare + * @return {@code true} if the planes are equal, {@code false} otherwise + */ + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + Plane other = (Plane) obj; + return point.equals(other.point) && normalVector.equals(other.normalVector); + } } \ No newline at end of file diff --git a/src/arcade/core/util/PlaneContainer.java b/src/arcade/core/util/PlaneContainer.java new file mode 100644 index 00000000..76179782 --- /dev/null +++ b/src/arcade/core/util/PlaneContainer.java @@ -0,0 +1,26 @@ +package arcade.core.util; + +/** + * Container class for a plane. + */ +public class PlaneContainer { + private final Point3D point; + private final Vector3D normalVector; + + public PlaneContainer(Point3D point, Vector3D normalVector) { + this.point = point; + this.normalVector = normalVector; + } + + public Point3D getPoint() { + return point; + } + + public Vector3D getNormalVector() { + return normalVector; + } + + public Plane toPlane() { + return new Plane(point, normalVector); + } +} diff --git a/src/arcade/core/util/Point3D.java b/src/arcade/core/util/Point3D.java index 47f57cc4..de3076c9 100644 --- a/src/arcade/core/util/Point3D.java +++ b/src/arcade/core/util/Point3D.java @@ -30,4 +30,19 @@ public Point3D(Voxel v) { public int getX() { return x; } public int getY() { return y; } public int getZ() { return z; } + + /** + * Checks if two points have the same (x, y, z) coordinates. + * + * @param obj the point to compare + * @return {@code true} if coordinates are the same, {@code false} otherwise + */ + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + Point3D other = (Point3D) obj; + return x == other.x && y == other.y && z == other.z; + } } diff --git a/src/arcade/core/util/Vector3D.java b/src/arcade/core/util/Vector3D.java index 30f40257..85db92d7 100644 --- a/src/arcade/core/util/Vector3D.java +++ b/src/arcade/core/util/Vector3D.java @@ -23,4 +23,19 @@ public Vector3D(int a, int b, int c) { public int getA() { return a; } public int getB() { return b; } public int getC() { return c; } + + /** + * Determines if two vectors have the same (a, b, c) components. + * + * @param obj the vector to compare + * @return {@code true} if the vectors are equal, {@code false} otherwise + */ + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + Vector3D other = (Vector3D) obj; + return a == other.a && b == other.b && c == other.c; + } } \ No newline at end of file diff --git a/src/arcade/potts/util/PottsPlaneFactory.java b/src/arcade/potts/util/PottsPlaneFactory.java new file mode 100644 index 00000000..f8e1f976 --- /dev/null +++ b/src/arcade/potts/util/PottsPlaneFactory.java @@ -0,0 +1,44 @@ +package arcade.potts.util; + +import java.util.EnumMap; +import java.util.Map; +import arcade.core.util.Plane; +import arcade.core.util.Point3D; +import arcade.core.util.Vector3D; +import arcade.core.util.PlaneContainer; +import static arcade.potts.util.PottsEnums.Direction; + +/** + * Factory class for creating Potts Planes based on a Direction. + */ +public class PottsPlaneFactory { + + // Mapping between Direction Enum and Plane parameters + private static final Map planeParametersMap = new EnumMap<>(Direction.class); + + static { + planeParametersMap.put(Direction.YZ_PLANE, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(1, 0, 0))); + planeParametersMap.put(Direction.ZX_PLANE, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(0, 1, 0))); + planeParametersMap.put(Direction.XY_PLANE, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(0, 0, 1))); + planeParametersMap.put(Direction.POSITIVE_XY, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(1, 1, 0))); + planeParametersMap.put(Direction.NEGATIVE_XY, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(-1, 1, 0))); + planeParametersMap.put(Direction.POSITIVE_YZ, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(0, 1, 1))); + planeParametersMap.put(Direction.NEGATIVE_YZ, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(0, -1, 1))); + planeParametersMap.put(Direction.POSITIVE_ZX, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(1, 0, 1))); + planeParametersMap.put(Direction.NEGATIVE_ZX, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(-1, 0, 1))); + } + + /** + * Creates a Plane based on a Direction. + * + * @param direction the Direction + * @return a Plane + */ + public static Plane createPlane(Direction direction) { + PlaneContainer params = planeParametersMap.get(direction); + if (params == null) { + throw new IllegalArgumentException("No plane associated with this direction"); + } + return new Plane(params.getPoint(), params.getNormalVector()); + } +} diff --git a/test/arcade/core/util/PlaneContainerTest.java b/test/arcade/core/util/PlaneContainerTest.java new file mode 100644 index 00000000..507c7104 --- /dev/null +++ b/test/arcade/core/util/PlaneContainerTest.java @@ -0,0 +1,48 @@ +package arcade.core.util; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class PlaneContainerTest { + + @Test + public void constructor_givenPointAndNormalVector_returnsCorrectContainer() { + Point3D point = new Point3D(1, 2, 3); + Vector3D normalVector = new Vector3D(4, 5, 6); + + PlaneContainer container = new PlaneContainer(point, normalVector); + + assertEquals(point, container.getPoint()); + assertEquals(normalVector, container.getNormalVector()); + } + + @Test + public void getPoint_called_returnsCorrectPoint() { + Point3D point = new Point3D(1, 2, 3); + Vector3D normalVector = new Vector3D(4, 5, 6); + PlaneContainer container = new PlaneContainer(point, normalVector); + + assertEquals(point, container.getPoint()); + } + + @Test + public void getNormalVector_called_returnsCorrectNormalVector() { + Point3D point = new Point3D(1, 2, 3); + Vector3D normalVector = new Vector3D(4, 5, 6); + PlaneContainer container = new PlaneContainer(point, normalVector); + + assertEquals(normalVector, container.getNormalVector()); + } + + @Test + public void toPlane_called_returnsCorrectPlane() { + Point3D point = new Point3D(1, 2, 3); + Vector3D normalVector = new Vector3D(4, 5, 6); + PlaneContainer container = new PlaneContainer(point, normalVector); + + Plane plane = container.toPlane(); + + assertEquals(point, plane.point); + assertEquals(normalVector, plane.normalVector); + } +} diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java index ae129ff0..bafe4fc5 100644 --- a/test/arcade/core/util/PlaneTest.java +++ b/test/arcade/core/util/PlaneTest.java @@ -92,4 +92,20 @@ public void isOnPlane_givenPointCloseToPlaneButNotOnIt_returnsFalse() { assertFalse(plane.isOnPlane(pointToTest)); } + + @Test + public void equals_givenDifferentPlane_returnsFalse() { + Plane plane1 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); + Plane plane2 = new Plane(new Point3D(4, 5, 6), new Vector3D(7, 8, 9)); + + assertFalse(plane1.equals(plane2)); + } + + @Test + public void equals_givenSamePlane_returnsTrue() { + Plane plane1 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); + Plane plane2 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); + + assertTrue(plane1.equals(plane2)); + } } \ No newline at end of file diff --git a/test/arcade/core/util/Point3DTest.java b/test/arcade/core/util/Point3DTest.java index d26f7404..067dc542 100644 --- a/test/arcade/core/util/Point3DTest.java +++ b/test/arcade/core/util/Point3DTest.java @@ -51,4 +51,20 @@ public void getZ_called_returnsZ() { assertEquals(9, point.getZ()); } + + @Test + public void equals_givenDifferentPoint_returnsFalse() { + Point3D point1 = new Point3D(1, 2, 3); + Point3D point2 = new Point3D(4, 5, 6); + + assertFalse(point1.equals(point2)); + } + + @Test + public void equals_givenSamePoint_returnsTrue() { + Point3D point1 = new Point3D(1, 2, 3); + Point3D point2 = new Point3D(1, 2, 3); + + assertTrue(point1.equals(point2)); + } } \ No newline at end of file diff --git a/test/arcade/core/util/Vector3DTest.java b/test/arcade/core/util/Vector3DTest.java index 9c3fb6cc..eabb1b87 100644 --- a/test/arcade/core/util/Vector3DTest.java +++ b/test/arcade/core/util/Vector3DTest.java @@ -39,4 +39,20 @@ public void getC_called_returnsC() { assertEquals(6, vector.getC()); } + + @Test + public void equals_givenDifferentVector_returnsFalse() { + Vector3D vector1 = new Vector3D(1, 2, 3); + Vector3D vector2 = new Vector3D(4, 5, 6); + + assertFalse(vector1.equals(vector2)); + } + + @Test + public void equals_givenSameVector_returnsTrue() { + Vector3D vector1 = new Vector3D(1, 2, 3); + Vector3D vector2 = new Vector3D(1, 2, 3); + + assertTrue(vector1.equals(vector2)); + } } \ No newline at end of file diff --git a/test/arcade/potts/util/PottsPlaneFactoryTest.java b/test/arcade/potts/util/PottsPlaneFactoryTest.java new file mode 100644 index 00000000..6102ca9a --- /dev/null +++ b/test/arcade/potts/util/PottsPlaneFactoryTest.java @@ -0,0 +1,108 @@ +package arcade.potts.util; + +import arcade.core.util.Plane; +import arcade.core.util.Point3D; +import arcade.core.util.Vector3D; +import arcade.potts.util.PottsEnums.Direction; +import org.junit.Test; +import static org.junit.Assert.*; + +public class PottsPlaneFactoryTest { + + @Test + public void createPlane_givenYZPlaneDirection_returnsCorrectPlane() { + Direction direction = Direction.YZ_PLANE; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(1, 0, 0), plane.normalVector); + } + + @Test + public void createPlane_givenZXPlaneDirection_returnsCorrectPlane() { + Direction direction = Direction.ZX_PLANE; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(0, 1, 0), plane.normalVector); + } + + @Test + public void createPlane_givenXYPlaneDirection_returnsCorrectPlane() { + Direction direction = Direction.XY_PLANE; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(0, 0, 1), plane.normalVector); + } + + @Test + public void createPlane_givenPositiveXYDirection_returnsCorrectPlane() { + Direction direction = Direction.POSITIVE_XY; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(1, 1, 0), plane.normalVector); + } + + @Test + public void createPlane_givenNegativeXYDirection_returnsCorrectPlane() { + Direction direction = Direction.NEGATIVE_XY; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(-1, 1, 0), plane.normalVector); + } + + @Test + public void createPlane_givenPositiveYZDirection_returnsCorrectPlane() { + Direction direction = Direction.POSITIVE_YZ; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(0, 1, 1), plane.normalVector); + } + + @Test + public void createPlane_givenNegativeYZDirection_returnsCorrectPlane() { + Direction direction = Direction.NEGATIVE_YZ; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(0, -1, 1), plane.normalVector); + } + + @Test + public void createPlane_givenPositiveZXDirection_returnsCorrectPlane() { + Direction direction = Direction.POSITIVE_ZX; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(1, 0, 1), plane.normalVector); + } + + @Test + public void createPlane_givenNegativeZXDirection_returnsCorrectPlane() { + Direction direction = Direction.NEGATIVE_ZX; + + Plane plane = PottsPlaneFactory.createPlane(direction); + + assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(new Vector3D(-1, 0, 1), plane.normalVector); + } + + @Test(expected = IllegalArgumentException.class) + public void createPlane_givenUndefinedDirection_throwsIllegalArgumentException() { + Direction direction = Direction.UNDEFINED; + + PottsPlaneFactory.createPlane(direction); + } +} From 114f69db92c147f7b8b007c310c9f58a74b0ff20 Mon Sep 17 00:00:00 2001 From: jannetty Date: Wed, 2 Oct 2024 16:22:40 -0700 Subject: [PATCH 05/30] wip many tests failing, fixing PottsLocationTest.java --- src/arcade/core/util/Plane.java | 31 +-- .../potts/env/location/PottsLocation.java | 187 ++++-------------- src/arcade/potts/util/PottsPlaneFactory.java | 50 +++-- test/arcade/core/util/PlaneTest.java | 76 ++----- .../potts/env/location/PottsLocationTest.java | 94 ++++++--- .../potts/util/PottsPlaneFactoryTest.java | 48 +++-- 6 files changed, 194 insertions(+), 292 deletions(-) diff --git a/src/arcade/core/util/Plane.java b/src/arcade/core/util/Plane.java index 2ef9522f..dc1fa828 100644 --- a/src/arcade/core/util/Plane.java +++ b/src/arcade/core/util/Plane.java @@ -23,35 +23,36 @@ public Plane(Point3D point, Vector3D normalVector) { } /** - * Determines whether a point is on one side of the plane. - * + * Determines whether a point is on the plane. + * * @param p the point to test - * @return {@code true} if the point is on the side of the plane - * where the normal vector points + * @return {@code true} if the point is on the plane * {@code false} otherwise */ - public boolean isOnSide(Point3D p) { + public boolean isOnPlane(Point3D p) { return (p.getX() - point.getX()) * normalVector.getA() + (p.getY() - point.getY()) * normalVector.getB() - + (p.getZ() - point.getZ()) * normalVector.getC() > 0; + + (p.getZ() - point.getZ()) * normalVector.getC() == 0; } /** - * Determines whether a point is on the plane. - * - * @param p the point to test - * @return {@code true} if the point is on the plane - * {@code false} otherwise + * Determines distance from a point to the plane. + * + * @param p the point + * @return the distance from the point to the plane. + * The distance is positive if the point is on + * the same side of the plane as the normal vector + * and negative if it is on the opposite side. */ - public boolean isOnPlane(Point3D p) { + public double distanceToPlane(Point3D p) { return (p.getX() - point.getX()) * normalVector.getA() + (p.getY() - point.getY()) * normalVector.getB() - + (p.getZ() - point.getZ()) * normalVector.getC() == 0; + + (p.getZ() - point.getZ()) * normalVector.getC(); } - /** + /** * Determines if two planes are equal. - * + * * @param obj the plane to compare * @return {@code true} if the planes are equal, {@code false} otherwise */ diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index 57b0a5ee..a79d088f 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -8,6 +8,11 @@ import arcade.core.env.location.Location; import arcade.core.env.location.LocationContainer; import arcade.core.util.Utilities; +import arcade.potts.util.PottsEnums.Direction; +import arcade.potts.util.PottsEnums.Region; +import arcade.core.util.Plane; +import arcade.potts.util.PottsPlaneFactory; +import arcade.core.util.Point3D; import static arcade.potts.util.PottsEnums.Direction; import static arcade.potts.util.PottsEnums.Region; @@ -271,7 +276,8 @@ public void update(int id, int[][][] ids, int[][][] regions) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random) { - return split(random, null, null, DEFAULT_SPLIT_SELECTION_PROBABILITY); + Plane divisionPlane = PottsPlaneFactory.createPlane(getDirection(random), new Point3D(getCenter())); + return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } /** @@ -287,7 +293,8 @@ public Location split(MersenneTwisterFast random) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random, ArrayList offsets) { - return split(random, offsets, null, DEFAULT_SPLIT_SELECTION_PROBABILITY); + Plane divisionPlane = PottsPlaneFactory.createPlane(getDirection(random), new Point3D(getOffset(offsets))); + return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } /** @@ -305,7 +312,8 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { */ public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction) { - return split(random, offsets, direction, DEFAULT_SPLIT_SELECTION_PROBABILITY); + Plane divisionPlane = PottsPlaneFactory.createPlane(direction, new Point3D(getOffset(offsets))); + return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } /** @@ -326,24 +334,16 @@ public Location split(MersenneTwisterFast random, ArrayList offsets, * @param probability the probability to decide which split to return * @return a location with the split voxels */ - public Location split(MersenneTwisterFast random, ArrayList offsets, - Direction direction, Double probability) { + public Location split(MersenneTwisterFast random, + Plane plane, Double probability) { // Initialize lists of split voxels ArrayList voxelsA = new ArrayList<>(); ArrayList voxelsB = new ArrayList<>(); - // Calculate split point. - Voxel splitpoint = offsets == null ? getCenter() : getOffset(offsets); - - // Perform the split along the specified direction - if (direction == null) { - direction = getDirection(random); - } - - splitVoxels(direction, voxels, voxelsA, voxelsB, splitpoint, random); + splitVoxels(plane, voxels, voxelsA, voxelsB, random); connectVoxels(voxelsA, voxelsB, this, random); - if (offsets == null) { + if (plane.point == new Point3D(getCenter())) { balanceVoxels(voxelsA, voxelsB, this, random); } @@ -628,141 +628,34 @@ Location separateVoxels(ArrayList voxelsA, ArrayList voxelsB, calculateCenter(); return makeLocation(voxelsB); } - + /** - * Splits the voxels in the location along a given direction. - * - * @param direction the direction of the slice - * @param voxels the list of voxels - * @param voxelsA the container list for the first half of the split - * @param voxelsB the container list for the second half of the split - * @param center the center voxel - * @param random the seeded random number generator - */ - static void splitVoxels(Direction direction, ArrayList voxels, + * Divides the voxels in the location into two lists along a given plane. + *

+ * The voxels are split into two lists based on their position relative to + * the plane. Voxels on the plane are randomly assigned to one of the lists. + * @param plane the plane to split the voxels along + * @param voxels the list of voxels to split + * @param voxelsA the container list for the first half of the split. + * These voxels are on the side of the plane opposite the normal. + * @param voxelsB the container list for the second half of the split. + * These voxels are on the side of the plane the normal points to. + * @param random the seeded random number generator + */ + static void splitVoxels(Plane plane, ArrayList voxels, ArrayList voxelsA, ArrayList voxelsB, - Voxel center, MersenneTwisterFast random) { + MersenneTwisterFast random) { for (Voxel voxel : voxels) { - switch (direction) { - case ZX_PLANE: - if (voxel.y < center.y) { - voxelsA.add(voxel); - } else if (voxel.y > center.y) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - case YZ_PLANE: - if (voxel.x < center.x) { - voxelsA.add(voxel); - } else if (voxel.x > center.x) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - case XY_PLANE: - if (voxel.z < center.z) { - voxelsA.add(voxel); - } else if (voxel.z > center.z) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - case NEGATIVE_XY: - if (voxel.x - center.x > center.y - voxel.y) { - voxelsA.add(voxel); - } else if (voxel.x - center.x < center.y - voxel.y) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - case POSITIVE_XY: - if (voxel.x - center.x > voxel.y - center.y) { - voxelsA.add(voxel); - } else if (voxel.x - center.x < voxel.y - center.y) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - case NEGATIVE_YZ: - if (voxel.y - center.y > center.z - voxel.z) { - voxelsA.add(voxel); - } else if (voxel.y - center.y < center.z - voxel.z) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - case POSITIVE_YZ: - if (voxel.y - center.y > voxel.z - center.z) { - voxelsA.add(voxel); - } else if (voxel.y - center.y < voxel.z - center.z) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - case NEGATIVE_ZX: - if (voxel.z - center.z > center.x - voxel.x) { - voxelsA.add(voxel); - } else if (voxel.z - center.z < center.x - voxel.x) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - case POSITIVE_ZX: - if (voxel.z - center.z > voxel.x - center.x) { - voxelsA.add(voxel); - } else if (voxel.z - center.z < voxel.x - center.x) { - voxelsB.add(voxel); - } else { - if (random.nextDouble() > 0.5) { - voxelsA.add(voxel); - } else { - voxelsB.add(voxel); - } - } - break; - default: - break; + if (plane.distanceToPlane(new Point3D(voxel)) < 0) { + voxelsA.add(voxel); + } else if (plane.distanceToPlane(new Point3D(voxel)) > 0) { + voxelsB.add(voxel); + } else { + if (random.nextDouble() > 0.5) { + voxelsA.add(voxel); + } else { + voxelsB.add(voxel); + } } } } diff --git a/src/arcade/potts/util/PottsPlaneFactory.java b/src/arcade/potts/util/PottsPlaneFactory.java index f8e1f976..a25fc2c9 100644 --- a/src/arcade/potts/util/PottsPlaneFactory.java +++ b/src/arcade/potts/util/PottsPlaneFactory.java @@ -5,40 +5,50 @@ import arcade.core.util.Plane; import arcade.core.util.Point3D; import arcade.core.util.Vector3D; -import arcade.core.util.PlaneContainer; import static arcade.potts.util.PottsEnums.Direction; /** - * Factory class for creating Potts Planes based on a Direction. + * Factory class for creating Potts Planes based on a Direction and a given point. */ public class PottsPlaneFactory { - // Mapping between Direction Enum and Plane parameters - private static final Map planeParametersMap = new EnumMap<>(Direction.class); + // Mapping between Direction Enum and normal vectors + private static final Map normalVectorMap = new EnumMap<>(Direction.class); static { - planeParametersMap.put(Direction.YZ_PLANE, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(1, 0, 0))); - planeParametersMap.put(Direction.ZX_PLANE, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(0, 1, 0))); - planeParametersMap.put(Direction.XY_PLANE, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(0, 0, 1))); - planeParametersMap.put(Direction.POSITIVE_XY, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(1, 1, 0))); - planeParametersMap.put(Direction.NEGATIVE_XY, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(-1, 1, 0))); - planeParametersMap.put(Direction.POSITIVE_YZ, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(0, 1, 1))); - planeParametersMap.put(Direction.NEGATIVE_YZ, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(0, -1, 1))); - planeParametersMap.put(Direction.POSITIVE_ZX, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(1, 0, 1))); - planeParametersMap.put(Direction.NEGATIVE_ZX, new PlaneContainer(new Point3D(0, 0, 0), new Vector3D(-1, 0, 1))); + normalVectorMap.put(Direction.YZ_PLANE, new Vector3D(1, 0, 0)); + normalVectorMap.put(Direction.ZX_PLANE, new Vector3D(0, 1, 0)); + normalVectorMap.put(Direction.XY_PLANE, new Vector3D(0, 0, 1)); + normalVectorMap.put(Direction.POSITIVE_XY, new Vector3D(1, 1, 0)); + normalVectorMap.put(Direction.NEGATIVE_XY, new Vector3D(-1, 1, 0)); + normalVectorMap.put(Direction.POSITIVE_YZ, new Vector3D(0, 1, 1)); + normalVectorMap.put(Direction.NEGATIVE_YZ, new Vector3D(0, -1, 1)); + normalVectorMap.put(Direction.POSITIVE_ZX, new Vector3D(1, 0, 1)); + normalVectorMap.put(Direction.NEGATIVE_ZX, new Vector3D(-1, 0, 1)); } /** - * Creates a Plane based on a Direction. + * Creates a Plane based on a Direction and a specified point. * * @param direction the Direction + * @param point the point on the plane * @return a Plane */ - public static Plane createPlane(Direction direction) { - PlaneContainer params = planeParametersMap.get(direction); - if (params == null) { - throw new IllegalArgumentException("No plane associated with this direction"); + public static Plane createPlane(Direction direction, Point3D point) { + Vector3D normalVector = normalVectorMap.get(direction); + if (normalVector == null) { + throw new IllegalArgumentException("No normal vector associated with this direction"); } - return new Plane(params.getPoint(), params.getNormalVector()); + return new Plane(point, normalVector); } -} + + /** + * Retrieves the normal vector associated with a Direction. + * + * @param direction the Direction + * @return the normal vector + */ + public static Vector3D getNormalVector(Direction direction) { + return normalVectorMap.get(direction); + } +} \ No newline at end of file diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java index bafe4fc5..cd3dd207 100644 --- a/test/arcade/core/util/PlaneTest.java +++ b/test/arcade/core/util/PlaneTest.java @@ -17,95 +17,51 @@ public void constructor_givenPointAndVector_returnsCorrectPlane() { } @Test - public void isOnSide_givenPointOnSameSide_returnsTrue() { - Point3D pointOnPlane = new Point3D(0, 0, 0); - Vector3D normalVector = new Vector3D(1, 0, 0); - Plane plane = new Plane(pointOnPlane, normalVector); - - Point3D pointToTest = new Point3D(1, 0, 0); // Point is on the side where normal vector points + public void equals_givenDifferentPlane_returnsFalse() { + Plane plane1 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); + Plane plane2 = new Plane(new Point3D(4, 5, 6), new Vector3D(7, 8, 9)); - assertTrue(plane.isOnSide(pointToTest)); + assertFalse(plane1.equals(plane2)); } @Test - public void isOnSide_givenPointOnOppositeSide_returnsFalse() { - Point3D pointOnPlane = new Point3D(0, 0, 0); - Vector3D normalVector = new Vector3D(1, 0, 0); - Plane plane = new Plane(pointOnPlane, normalVector); - - Point3D pointToTest = new Point3D(-1, 0, 0); // Point is on the opposite side + public void equals_givenSamePlane_returnsTrue() { + Plane plane1 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); + Plane plane2 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); - assertFalse(plane.isOnSide(pointToTest)); + assertTrue(plane1.equals(plane2)); } @Test - public void isOnSide_givenPointOnPlane_returnsFalse() { + public void distanceToPlane_givenPointOnPlane_returnsZero() { Point3D pointOnPlane = new Point3D(0, 0, 0); Vector3D normalVector = new Vector3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); Point3D pointToTest = new Point3D(0, 0, 0); // Point is on the plane - assertFalse(plane.isOnSide(pointToTest)); - } - - @Test - public void isOnPlane_givenPointOnPlane_returnsTrue() { - Point3D pointOnPlane = new Point3D(0, 0, 0); - Vector3D normalVector = new Vector3D(1, 0, 0); - Plane plane = new Plane(pointOnPlane, normalVector); - - Point3D pointToTest = new Point3D(0, 0, 0); // Point is exactly on the plane - - assertTrue(plane.isOnPlane(pointToTest)); + assertEquals(0, plane.distanceToPlane(pointToTest), 0.0001); } @Test - public void isOnPlane_givenPointOffPlane_returnsFalse() { + public void distanceToPlane_givenPointOnNormalSideOfPlane_returnsCorrectPositiveDistance() { Point3D pointOnPlane = new Point3D(0, 0, 0); Vector3D normalVector = new Vector3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); Point3D pointToTest = new Point3D(1, 1, 1); // Point is not on the plane - assertFalse(plane.isOnPlane(pointToTest)); + assertEquals(1, plane.distanceToPlane(pointToTest), 0.0001); } @Test - public void isOnPlane_givenPointFarAwayOnPlane_returnsTrue() { - Point3D pointOnPlane = new Point3D(1, 1, 1); - Vector3D normalVector = new Vector3D(1, 0, 0); - Plane plane = new Plane(pointOnPlane, normalVector); - - Point3D pointToTest = new Point3D(1, 100, 200); // Same x-coordinate, lies on the plane - - assertTrue(plane.isOnPlane(pointToTest)); - } - - @Test - public void isOnPlane_givenPointCloseToPlaneButNotOnIt_returnsFalse() { + public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegativeDistance() { Point3D pointOnPlane = new Point3D(0, 0, 0); - Vector3D normalVector = new Vector3D(1, 1, 1); + Vector3D normalVector = new Vector3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - Point3D pointToTest = new Point3D(1, 1, 2); // Close, but not on the plane - - assertFalse(plane.isOnPlane(pointToTest)); - } - - @Test - public void equals_givenDifferentPlane_returnsFalse() { - Plane plane1 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); - Plane plane2 = new Plane(new Point3D(4, 5, 6), new Vector3D(7, 8, 9)); - - assertFalse(plane1.equals(plane2)); - } - - @Test - public void equals_givenSamePlane_returnsTrue() { - Plane plane1 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); - Plane plane2 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); + Point3D pointToTest = new Point3D(-1, -1, -1); // Point is not on the plane - assertTrue(plane1.equals(plane2)); + assertEquals(-1, plane.distanceToPlane(pointToTest), 0.0001); } } \ No newline at end of file diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 595b6423..cb34072c 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -6,7 +6,14 @@ import org.junit.BeforeClass; import org.junit.Test; import ec.util.MersenneTwisterFast; +import arcade.core.util.Plane; +import arcade.core.util.Point3D; +import arcade.core.util.Vector3D; +import arcade.potts.util.PottsEnums.Direction; +import arcade.potts.util.PottsEnums.Region; +import arcade.potts.util.PottsPlaneFactory; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; import static arcade.core.ARCADETestUtilities.*; import static arcade.potts.env.location.Voxel.VOXEL_COMPARATOR; @@ -811,18 +818,6 @@ private ArrayList prepSplit() { return voxels; } - @Test - public void splitVoxels_invalidDirection_doesNothing() { - ArrayList voxels = prepSplit(); - PottsLocationMock loc = new PottsLocationMock(voxels); - ArrayList voxelsA = new ArrayList<>(); - ArrayList voxelsB = new ArrayList<>(); - - PottsLocation.splitVoxels(Direction.UNDEFINED, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); - assertEquals(0, voxelsA.size()); - assertEquals(0, voxelsB.size()); - } - @Test public void splitVoxels_YZPlaneDirectionRandomZero_updatesLists() { ArrayList voxels = prepSplit(); @@ -836,12 +831,15 @@ public void splitVoxels_YZPlaneDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(0, 0, 0)); voxelsASplit.add(new Voxel(0, 1, 1)); voxelsASplit.add(new Voxel(0, 2, 1)); + voxelsBSplit.add(new Voxel(1, 0, 2)); voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane yzPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,0,0)); - PottsLocation.splitVoxels(Direction.YZ_PLANE, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); @@ -868,8 +866,10 @@ public void splitVoxels_ZXPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane zxPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,1,0)); - PottsLocation.splitVoxels(Direction.ZX_PLANE, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -891,8 +891,10 @@ public void splitVoxels_XYPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane xyPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,0,1)); - PottsLocation.splitVoxels(Direction.XY_PLANE, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -914,8 +916,10 @@ public void splitVoxels_negativeXYDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane negativeXYPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(-1,-1,0)); - PottsLocation.splitVoxels(Direction.NEGATIVE_XY, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -937,8 +941,10 @@ public void splitVoxels_positiveXYDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane positiveXYPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,1,0)); - PottsLocation.splitVoxels(Direction.POSITIVE_XY, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -960,8 +966,10 @@ public void splitVoxels_negativeYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane negativeYZPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,-1,-1)); - PottsLocation.splitVoxels(Direction.NEGATIVE_YZ, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -983,8 +991,10 @@ public void splitVoxels_positiveYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane positiveYZPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,1,1)); - PottsLocation.splitVoxels(Direction.POSITIVE_YZ, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1006,8 +1016,10 @@ public void splitVoxels_negativeZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane negativeZXPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(-1,0,-1)); - PottsLocation.splitVoxels(Direction.NEGATIVE_ZX, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1029,8 +1041,10 @@ public void splitVoxels_positiveZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane positiveZXPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,0,1)); - PottsLocation.splitVoxels(Direction.POSITIVE_ZX, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleZero); + PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1052,8 +1066,10 @@ public void splitVoxels_YZPlaneDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane yzPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,0,0)); - PottsLocation.splitVoxels(Direction.YZ_PLANE, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1075,8 +1091,10 @@ public void splitVoxels_ZXPlaneDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane zxPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,1,0)); - PottsLocation.splitVoxels(Direction.ZX_PLANE, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1098,8 +1116,10 @@ public void splitVoxels_XYPlaneDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane xyPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,0,1)); - PottsLocation.splitVoxels(Direction.XY_PLANE, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1121,8 +1141,10 @@ public void splitVoxels_negativeXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane negativeXYPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(-1,-1,0)); - PottsLocation.splitVoxels(Direction.NEGATIVE_XY, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1144,8 +1166,10 @@ public void splitVoxels_positiveXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane positiveXYPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,1,0)); - PottsLocation.splitVoxels(Direction.POSITIVE_XY, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1167,8 +1191,10 @@ public void splitVoxels_negativeYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane negativeYZPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,-1,-1)); - PottsLocation.splitVoxels(Direction.NEGATIVE_YZ, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1190,8 +1216,10 @@ public void splitVoxels_positiveYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane positiveYZPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,1,1)); - PottsLocation.splitVoxels(Direction.POSITIVE_YZ, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1213,8 +1241,10 @@ public void splitVoxels_negativeZXDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); + + Plane negativeZXPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(-1,0,-1)); - PottsLocation.splitVoxels(Direction.NEGATIVE_ZX, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1236,8 +1266,10 @@ public void splitVoxels_positiveZXDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); + + Plane positiveZXPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,0,1)); - PottsLocation.splitVoxels(Direction.POSITIVE_ZX, voxels, voxelsA, voxelsB, loc.getCenter(), randomDoubleOne); + PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); } @@ -1299,7 +1331,7 @@ public void separateVoxels_validLists_updatesCenter() { public void split_noOffsetsNoDirection_callsMethods() { PottsLocation spy = spy(new PottsLocationMock(voxelListAB)); spy.split(RANDOM); - verify(spy).split(eq(RANDOM), eq(null), eq(null), eq(0.5)); + verify(spy).split(eq(RANDOM), eq(null), eq(0.5)); } @Test diff --git a/test/arcade/potts/util/PottsPlaneFactoryTest.java b/test/arcade/potts/util/PottsPlaneFactoryTest.java index 6102ca9a..9b1fe089 100644 --- a/test/arcade/potts/util/PottsPlaneFactoryTest.java +++ b/test/arcade/potts/util/PottsPlaneFactoryTest.java @@ -12,97 +12,107 @@ public class PottsPlaneFactoryTest { @Test public void createPlane_givenYZPlaneDirection_returnsCorrectPlane() { Direction direction = Direction.YZ_PLANE; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(1, 0, 0), plane.normalVector); } @Test public void createPlane_givenZXPlaneDirection_returnsCorrectPlane() { Direction direction = Direction.ZX_PLANE; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(0, 1, 0), plane.normalVector); } @Test public void createPlane_givenXYPlaneDirection_returnsCorrectPlane() { Direction direction = Direction.XY_PLANE; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(0, 0, 1), plane.normalVector); } @Test public void createPlane_givenPositiveXYDirection_returnsCorrectPlane() { Direction direction = Direction.POSITIVE_XY; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(1, 1, 0), plane.normalVector); } @Test public void createPlane_givenNegativeXYDirection_returnsCorrectPlane() { Direction direction = Direction.NEGATIVE_XY; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(-1, 1, 0), plane.normalVector); } @Test public void createPlane_givenPositiveYZDirection_returnsCorrectPlane() { Direction direction = Direction.POSITIVE_YZ; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(0, 1, 1), plane.normalVector); } @Test public void createPlane_givenNegativeYZDirection_returnsCorrectPlane() { Direction direction = Direction.NEGATIVE_YZ; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(0, -1, 1), plane.normalVector); } @Test public void createPlane_givenPositiveZXDirection_returnsCorrectPlane() { Direction direction = Direction.POSITIVE_ZX; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(1, 0, 1), plane.normalVector); } @Test public void createPlane_givenNegativeZXDirection_returnsCorrectPlane() { Direction direction = Direction.NEGATIVE_ZX; + Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction); + Plane plane = PottsPlaneFactory.createPlane(direction, point); - assertEquals(new Point3D(0, 0, 0), plane.point); + assertEquals(point, plane.point); assertEquals(new Vector3D(-1, 0, 1), plane.normalVector); } @Test(expected = IllegalArgumentException.class) public void createPlane_givenUndefinedDirection_throwsIllegalArgumentException() { Direction direction = Direction.UNDEFINED; + Point3D point = new Point3D(1, 2, 3); - PottsPlaneFactory.createPlane(direction); + PottsPlaneFactory.createPlane(direction, point); } } From bcde1bd1827717b645aef26e3ce746c07d8c76bc Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 3 Oct 2024 17:46:11 -0700 Subject: [PATCH 06/30] corrected normal vectors in PottsPlaneFactory. Updated tests. Added tests. --- .../potts/env/location/PottsLocation.java | 31 ++- src/arcade/potts/util/PottsPlaneFactory.java | 14 +- .../potts/env/location/PottsLocationTest.java | 251 +++++++++++++++--- .../potts/util/PottsPlaneFactoryTest.java | 42 ++- 4 files changed, 264 insertions(+), 74 deletions(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index a79d088f..6b854f81 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -276,7 +276,7 @@ public void update(int id, int[][][] ids, int[][][] regions) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random) { - Plane divisionPlane = PottsPlaneFactory.createPlane(getDirection(random), new Point3D(getCenter())); + Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getCenter()), getDirection(random)); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -293,7 +293,7 @@ public Location split(MersenneTwisterFast random) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random, ArrayList offsets) { - Plane divisionPlane = PottsPlaneFactory.createPlane(getDirection(random), new Point3D(getOffset(offsets))); + Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), getDirection(random)); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -312,9 +312,30 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { */ public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction) { - Plane divisionPlane = PottsPlaneFactory.createPlane(direction, new Point3D(getOffset(offsets))); + Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), direction); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } + + /** + * Splits location voxels into two lists with given offset, direction, and probability. + *

+ * The location is split at the point specified by offsets along the given + * direction. The lists of locations are guaranteed to be connected. One of + * the splits is assigned to the current location and the other is + * returned. One of the splits is assigned to the current location and the + * other returned with the given probability + * + * @param random the seeded random number generator + * @param offsets the percentage offset in each direction for split point + * @param direction the direction of the split + * @param probability the probability to decide which split to return + * @return a location with the split voxels + */ + public Location split(MersenneTwisterFast random, ArrayList offsets, + Direction direction, Double probability) { + Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), direction); + return split(random, divisionPlane, probability); + } /** * Splits location voxels into two lists. @@ -342,8 +363,8 @@ public Location split(MersenneTwisterFast random, splitVoxels(plane, voxels, voxelsA, voxelsB, random); connectVoxels(voxelsA, voxelsB, this, random); - - if (plane.point == new Point3D(getCenter())) { + + if (plane.point.equals(new Point3D(getCenter()))) { balanceVoxels(voxelsA, voxelsB, this, random); } diff --git a/src/arcade/potts/util/PottsPlaneFactory.java b/src/arcade/potts/util/PottsPlaneFactory.java index a25fc2c9..d62db962 100644 --- a/src/arcade/potts/util/PottsPlaneFactory.java +++ b/src/arcade/potts/util/PottsPlaneFactory.java @@ -19,12 +19,12 @@ public class PottsPlaneFactory { normalVectorMap.put(Direction.YZ_PLANE, new Vector3D(1, 0, 0)); normalVectorMap.put(Direction.ZX_PLANE, new Vector3D(0, 1, 0)); normalVectorMap.put(Direction.XY_PLANE, new Vector3D(0, 0, 1)); - normalVectorMap.put(Direction.POSITIVE_XY, new Vector3D(1, 1, 0)); - normalVectorMap.put(Direction.NEGATIVE_XY, new Vector3D(-1, 1, 0)); - normalVectorMap.put(Direction.POSITIVE_YZ, new Vector3D(0, 1, 1)); - normalVectorMap.put(Direction.NEGATIVE_YZ, new Vector3D(0, -1, 1)); - normalVectorMap.put(Direction.POSITIVE_ZX, new Vector3D(1, 0, 1)); - normalVectorMap.put(Direction.NEGATIVE_ZX, new Vector3D(-1, 0, 1)); + normalVectorMap.put(Direction.POSITIVE_XY, new Vector3D(-1, 1, 0)); + normalVectorMap.put(Direction.NEGATIVE_XY, new Vector3D(-1, -1, 0)); + normalVectorMap.put(Direction.POSITIVE_YZ, new Vector3D(0, -1, 1)); + normalVectorMap.put(Direction.NEGATIVE_YZ, new Vector3D(0, -1, -1)); + normalVectorMap.put(Direction.POSITIVE_ZX, new Vector3D(1, 0, -1)); + normalVectorMap.put(Direction.NEGATIVE_ZX, new Vector3D(-1, 0, -1)); } /** @@ -34,7 +34,7 @@ public class PottsPlaneFactory { * @param point the point on the plane * @return a Plane */ - public static Plane createPlane(Direction direction, Point3D point) { + public static Plane createPlane(Point3D point, Direction direction) { Vector3D normalVector = normalVectorMap.get(direction); if (normalVector == null) { throw new IllegalArgumentException("No normal vector associated with this direction"); diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index cb34072c..5c4fdeee 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -1,8 +1,12 @@ package arcade.potts.env.location; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; import org.junit.BeforeClass; import org.junit.Test; import ec.util.MersenneTwisterFast; @@ -11,6 +15,7 @@ import arcade.core.util.Vector3D; import arcade.potts.util.PottsEnums.Direction; import arcade.potts.util.PottsEnums.Region; +import arcade.potts.sim.Potts; import arcade.potts.util.PottsPlaneFactory; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.eq; @@ -837,7 +842,7 @@ public void splitVoxels_YZPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane yzPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,0,0)); + Plane yzPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.YZ_PLANE); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -867,7 +872,7 @@ public void splitVoxels_ZXPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane zxPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,1,0)); + Plane zxPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.ZX_PLANE); PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -892,7 +897,7 @@ public void splitVoxels_XYPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane xyPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,0,1)); + Plane xyPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.XY_PLANE); PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -917,7 +922,7 @@ public void splitVoxels_negativeXYDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane negativeXYPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(-1,-1,0)); + Plane negativeXYPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_XY); PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -942,7 +947,7 @@ public void splitVoxels_positiveXYDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane positiveXYPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,1,0)); + Plane positiveXYPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_XY); PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -967,7 +972,7 @@ public void splitVoxels_negativeYZDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane negativeYZPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,-1,-1)); + Plane negativeYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_YZ);; PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -992,7 +997,7 @@ public void splitVoxels_positiveYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane positiveYZPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,1,1)); + Plane positiveYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_YZ);; PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1017,7 +1022,7 @@ public void splitVoxels_negativeZXDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane negativeZXPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(-1,0,-1)); + Plane negativeZXPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_ZX); PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1042,7 +1047,7 @@ public void splitVoxels_positiveZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane positiveZXPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,0,1)); + Plane positiveZXPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_ZX); PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1067,7 +1072,7 @@ public void splitVoxels_YZPlaneDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane yzPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,0,0)); + Plane yzPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.YZ_PLANE); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1092,7 +1097,7 @@ public void splitVoxels_ZXPlaneDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane zxPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,1,0)); + Plane zxPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.ZX_PLANE); PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1117,7 +1122,7 @@ public void splitVoxels_XYPlaneDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane xyPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,0,1)); + Plane xyPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.XY_PLANE); PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1142,7 +1147,7 @@ public void splitVoxels_negativeXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane negativeXYPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(-1,-1,0)); + Plane negativeXYPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_XY); PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1167,7 +1172,7 @@ public void splitVoxels_positiveXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane positiveXYPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,1,0)); + Plane positiveXYPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_XY); PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1192,7 +1197,7 @@ public void splitVoxels_negativeYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane negativeYZPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,-1,-1)); + Plane negativeYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_YZ); PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1217,7 +1222,7 @@ public void splitVoxels_positiveYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane positiveYZPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(0,1,1)); + Plane positiveYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_YZ); PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1242,7 +1247,7 @@ public void splitVoxels_negativeZXDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane negativeZXPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(-1,0,-1)); + Plane negativeZXPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_ZX); PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1267,7 +1272,7 @@ public void splitVoxels_positiveZXDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane positiveZXPlane = new Plane(new Point3D(loc.getCenter()), new Vector3D(1,0,1)); + Plane positiveZXPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_ZX); PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1326,31 +1331,153 @@ public void separateVoxels_validLists_updatesCenter() { assertEquals(1. / 3, split.cy, EPSILON); assertEquals(3. / 3, split.cz, EPSILON); } - + @Test - public void split_noOffsetsNoDirection_callsMethods() { - PottsLocation spy = spy(new PottsLocationMock(voxelListAB)); - spy.split(RANDOM); - verify(spy).split(eq(RANDOM), eq(null), eq(0.5)); + public void split_noOffsetsNoDirectionRandomDoubleZero_splitsVoxelsCorrectly() { + ArrayList voxels = new ArrayList<>(); + + // Create a 2x2x2 cuboid of voxels + for (int x = 0; x < 2; x++) { + for (int y = 0; y < 2; y++) { + for (int z = 0; z < 2; z++) { + voxels.add(new Voxel(x, y, z)); + } + } + } + // Only diameter in mock is YZ plane, so plane of division will be ZX plane + // Expected voxels in splitVoxels: y >= 1, including the plane where y = 1 + // (because of randomDoubleZero as RNG) + // Expected voxels in locVoxels: y < 1 + ArrayList splitVoxels = new ArrayList<>(); + ArrayList locVoxels = new ArrayList<>(); + for (Voxel voxel : voxels) { + if (voxel.y >= 1) { + splitVoxels.add(voxel); + } else { + locVoxels.add(voxel); + } + } + + PottsLocation loc = new PottsLocationMock(voxels); + PottsLocation split = (PottsLocation) loc.split(randomDoubleZero); + + // Verify that the total number of voxels remains the same + int totalVoxels = loc.voxels.size() + split.voxels.size(); + assertEquals(totalVoxels, voxels.size()); + + locVoxels.sort(VOXEL_COMPARATOR); + loc.voxels.sort(VOXEL_COMPARATOR); + splitVoxels.sort(VOXEL_COMPARATOR); + split.voxels.sort(VOXEL_COMPARATOR); + + // Verify that the voxels were split correctly + assertEquals(locVoxels, loc.voxels); + assertEquals(splitVoxels, split.voxels); } @Test - public void split_withOffsetsNoDirection_callsMethods() { - ArrayList offsets = new ArrayList<>(0); - offsets.add(0); - PottsLocation spy = spy(new PottsLocationMock(voxelListAB)); - spy.split(RANDOM, offsets); - verify(spy).split(eq(RANDOM), eq(offsets), eq(null), eq(0.5)); + public void split_withOffsetsNoDirection_splitsVoxelsCorrectly() { + ArrayList voxels = new ArrayList<>(); + ArrayList locVoxels = new ArrayList<>(); + ArrayList splitVoxels = new ArrayList<>(); + + + // Create a 5x5x5 cuboid of voxels + for (int x = 0; x < 5; x++) { + for (int y = 0; y < 5; y++) { + for (int z = 0; z < 5; z++) { + voxels.add(new Voxel(x, y, z)); + } + } + } + + // Only diameter in mock is YZ plane, so plane of division will be ZX plane + ArrayList offsets = new ArrayList<>(); + offsets.add(20); // split centered at x = 1 + offsets.add(20); // split centered at y = 1 + offsets.add(20); // split centered at x = 1 + + // expected locVoxels: y >= 1 + // expected splitVoxels: y < 1 + for (Voxel voxel : voxels) { + if (voxel.y >= 1) { + splitVoxels.add(voxel); + } else { + locVoxels.add(voxel); + } + } + + PottsLocation location = new PottsLocationMock(voxels); + + // Call split + PottsLocation splitLocation = (PottsLocation) location.split(randomDoubleZero, offsets); + + // Verify the split occurred as expected + int totalVoxels = location.voxels.size() + splitLocation.voxels.size(); + assertEquals(totalVoxels, voxels.size()); + + locVoxels.sort(VOXEL_COMPARATOR); + location.voxels.sort(VOXEL_COMPARATOR); + splitVoxels.sort(VOXEL_COMPARATOR); + splitLocation.voxels.sort(VOXEL_COMPARATOR); + + // Verify that the voxels were split correctly + assertEquals(locVoxels, location.voxels); + assertEquals(splitVoxels, splitLocation.voxels); } @Test - public void split_withOffsetsWithDirection_callsMethods() { - ArrayList offsets = new ArrayList<>(0); - offsets.add(0); - Direction direction = Direction.random(RANDOM); - PottsLocation spy = spy(new PottsLocationMock(voxelListAB)); - spy.split(RANDOM, offsets, direction); - verify(spy).split(eq(RANDOM), eq(offsets), eq(direction), eq(0.5)); + public void split_withOffsetsWithDirection_splitsVoxelsCorrectly() { + ArrayList voxels = new ArrayList<>(); + ArrayList locVoxels = new ArrayList<>(); + ArrayList splitVoxels = new ArrayList<>(); + + + // Create a 5x5x5 cuboid of voxels + for (int x = 0; x < 5; x++) { + for (int y = 0; y < 5; y++) { + for (int z = 0; z < 5; z++) { + voxels.add(new Voxel(x, y, z)); + } + } + } + + ArrayList offsets = new ArrayList<>(); + offsets.add(50); // split centered at x = 2 + offsets.add(75); // split centered at y = 3 + offsets.add(100); // split centered at z = 1 + + // expected locVoxels: x - y + 1 >= 0 + // expected splitVoxels: x - y + 1 < 0 + for (Voxel voxel : voxels) { + if (voxel.x - voxel.y + 1 > 0) { + locVoxels.add(voxel); + } else if (voxel.x - voxel.y + 1 < 0) { + splitVoxels.add(voxel); + } else { + // distance == 0 + // Since randomDoubleZero.nextDouble() == 0.0, and 0.0 > 0.5 is false + splitVoxels.add(voxel); + } + } + + PottsLocation location = new PottsLocationMock(voxels); + + // Call split + PottsLocation splitLocation = (PottsLocation) location.split(randomDoubleZero, offsets, Direction.POSITIVE_XY); + + // Verify the split occurred as expected + int totalVoxels = location.voxels.size() + splitLocation.voxels.size(); + assertEquals(totalVoxels, voxels.size()); + + locVoxels.sort(VOXEL_COMPARATOR); + location.voxels.sort(VOXEL_COMPARATOR); + splitVoxels.sort(VOXEL_COMPARATOR); + splitLocation.voxels.sort(VOXEL_COMPARATOR); + + // Verify that the voxels were split correctly + //assertEquals(locVoxels, location.voxels); + assertEquals(splitVoxels, splitLocation.voxels); } @Test @@ -1422,4 +1549,56 @@ public void split_withOffsetsWithZXDirectionWithProbability_splitsVoxelsCorrectl assertEquals(locVoxels, loc.voxels); assertEquals(splitVoxels, split.voxels); } + + @Test + public void split_withOddAnglePlaneThroughPointAndProbabilityOne_splitsVoxelsCorrectly() { + ArrayList voxels = new ArrayList<>(); + ArrayList locVoxels = new ArrayList<>(); + ArrayList splitVoxels = new ArrayList<>(); + + // Create a 3x3x3 grid of voxels (total of 27 voxels) + for (int x = 0; x < 3; x++) { + for (int y = 0; y < 3; y++) { + for (int z = 0; z < 3; z++) { + voxels.add(new Voxel(x, y, z)); + } + } + } + + // Plane with normal vector (1, 2, 3) passing through point (1, 2, 1) + // Plane equation: x + 2y + 3z = 8 + Point3D planePoint = new Point3D(1, 2, 1); + Vector3D normalVector = new Vector3D(1, 2, 3); + Plane plane = new Plane(planePoint, normalVector); + + // Expected locVoxels: x + 2y + 3z < 8 + // Expected splitVoxels: x + 2y + 3z >= 8 + for (Voxel voxel : voxels) { + int value = voxel.x + 2 * voxel.y + 3 * voxel.z; + if (value < 8) { + locVoxels.add(voxel); // Voxels opposite the normal vector + } else { + splitVoxels.add(voxel); // Voxels on the normal vector side and on the plane + } + } + + PottsLocation loc = new PottsLocationMock(voxels); + double probability = 1.0; + + // Call split + PottsLocation split = (PottsLocation) loc.split(randomDoubleZero, plane, probability); + + // Verify that the total number of voxels remains the same + int totalVoxels = loc.voxels.size() + split.voxels.size(); + assertEquals(voxels.size(), totalVoxels); + + locVoxels.sort(VOXEL_COMPARATOR); + loc.voxels.sort(VOXEL_COMPARATOR); + splitVoxels.sort(VOXEL_COMPARATOR); + split.voxels.sort(VOXEL_COMPARATOR); + + // Verify that the voxels were split correctly + assertEquals(locVoxels, loc.voxels); + assertEquals(splitVoxels, split.voxels); + } } diff --git a/test/arcade/potts/util/PottsPlaneFactoryTest.java b/test/arcade/potts/util/PottsPlaneFactoryTest.java index 9b1fe089..7b3c2499 100644 --- a/test/arcade/potts/util/PottsPlaneFactoryTest.java +++ b/test/arcade/potts/util/PottsPlaneFactoryTest.java @@ -11,10 +11,9 @@ public class PottsPlaneFactoryTest { @Test public void createPlane_givenYZPlaneDirection_returnsCorrectPlane() { - Direction direction = Direction.YZ_PLANE; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.YZ_PLANE); assertEquals(point, plane.point); assertEquals(new Vector3D(1, 0, 0), plane.normalVector); @@ -22,10 +21,9 @@ public void createPlane_givenYZPlaneDirection_returnsCorrectPlane() { @Test public void createPlane_givenZXPlaneDirection_returnsCorrectPlane() { - Direction direction = Direction.ZX_PLANE; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.ZX_PLANE); assertEquals(point, plane.point); assertEquals(new Vector3D(0, 1, 0), plane.normalVector); @@ -33,10 +31,9 @@ public void createPlane_givenZXPlaneDirection_returnsCorrectPlane() { @Test public void createPlane_givenXYPlaneDirection_returnsCorrectPlane() { - Direction direction = Direction.XY_PLANE; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.XY_PLANE); assertEquals(point, plane.point); assertEquals(new Vector3D(0, 0, 1), plane.normalVector); @@ -44,75 +41,68 @@ public void createPlane_givenXYPlaneDirection_returnsCorrectPlane() { @Test public void createPlane_givenPositiveXYDirection_returnsCorrectPlane() { - Direction direction = Direction.POSITIVE_XY; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.POSITIVE_XY); assertEquals(point, plane.point); - assertEquals(new Vector3D(1, 1, 0), plane.normalVector); + assertEquals(new Vector3D(-1, 1, 0), plane.normalVector); } @Test public void createPlane_givenNegativeXYDirection_returnsCorrectPlane() { - Direction direction = Direction.NEGATIVE_XY; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.NEGATIVE_XY); assertEquals(point, plane.point); - assertEquals(new Vector3D(-1, 1, 0), plane.normalVector); + assertEquals(new Vector3D(-1, -1, 0), plane.normalVector); } @Test public void createPlane_givenPositiveYZDirection_returnsCorrectPlane() { - Direction direction = Direction.POSITIVE_YZ; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.POSITIVE_YZ); assertEquals(point, plane.point); - assertEquals(new Vector3D(0, 1, 1), plane.normalVector); + assertEquals(new Vector3D(0, -1, 1), plane.normalVector); } @Test public void createPlane_givenNegativeYZDirection_returnsCorrectPlane() { - Direction direction = Direction.NEGATIVE_YZ; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.NEGATIVE_YZ); assertEquals(point, plane.point); - assertEquals(new Vector3D(0, -1, 1), plane.normalVector); + assertEquals(new Vector3D(0, -1, -1), plane.normalVector); } @Test public void createPlane_givenPositiveZXDirection_returnsCorrectPlane() { - Direction direction = Direction.POSITIVE_ZX; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.POSITIVE_ZX); assertEquals(point, plane.point); - assertEquals(new Vector3D(1, 0, 1), plane.normalVector); + assertEquals(new Vector3D(1, 0, -1), plane.normalVector); } @Test public void createPlane_givenNegativeZXDirection_returnsCorrectPlane() { - Direction direction = Direction.NEGATIVE_ZX; Point3D point = new Point3D(1, 2, 3); - Plane plane = PottsPlaneFactory.createPlane(direction, point); + Plane plane = PottsPlaneFactory.createPlane(point, Direction.NEGATIVE_ZX); assertEquals(point, plane.point); - assertEquals(new Vector3D(-1, 0, 1), plane.normalVector); + assertEquals(new Vector3D(-1, 0, -1), plane.normalVector); } @Test(expected = IllegalArgumentException.class) public void createPlane_givenUndefinedDirection_throwsIllegalArgumentException() { - Direction direction = Direction.UNDEFINED; Point3D point = new Point3D(1, 2, 3); - PottsPlaneFactory.createPlane(direction, point); + PottsPlaneFactory.createPlane(point, Direction.UNDEFINED); } } From ab94aa6b543ce631a1138f3a24bce3a3368fe8aa Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 3 Oct 2024 19:27:45 -0700 Subject: [PATCH 07/30] formatting fixes --- src/arcade/core/util/Plane.java | 19 ++++++-- src/arcade/core/util/PlaneContainer.java | 26 +++++++++-- src/arcade/core/util/Point3D.java | 43 +++++++++++++++++-- src/arcade/core/util/Vector3D.java | 39 +++++++++++++++-- .../potts/env/location/PottsLocation.java | 18 ++++---- src/arcade/potts/util/PottsPlaneFactory.java | 4 +- test/arcade/core/util/PlaneTest.java | 2 +- test/arcade/core/util/Point3DTest.java | 8 ++-- test/arcade/core/util/Vector3DTest.java | 6 ++- .../potts/util/PottsPlaneFactoryTest.java | 2 +- 10 files changed, 137 insertions(+), 30 deletions(-) diff --git a/src/arcade/core/util/Plane.java b/src/arcade/core/util/Plane.java index dc1fa828..4ec80687 100644 --- a/src/arcade/core/util/Plane.java +++ b/src/arcade/core/util/Plane.java @@ -5,10 +5,10 @@ */ public class Plane { - /** A point on the plane */ + /** A point on the plane. */ public final Point3D point; - /** The normal to the plane */ + /** The normal to the plane. */ public final Vector3D normalVector; /** @@ -64,4 +64,17 @@ public boolean equals(Object obj) { Plane other = (Plane) obj; return point.equals(other.point) && normalVector.equals(other.normalVector); } -} \ No newline at end of file + + /** + * Returns a hash code for the plane. + * + * @return a hash code for the plane + */ + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + (this.point != null ? this.point.hashCode() : 0); + hash = 97 * hash + (this.normalVector != null ? this.normalVector.hashCode() : 0); + return hash; + } +} diff --git a/src/arcade/core/util/PlaneContainer.java b/src/arcade/core/util/PlaneContainer.java index 76179782..03e50351 100644 --- a/src/arcade/core/util/PlaneContainer.java +++ b/src/arcade/core/util/PlaneContainer.java @@ -6,20 +6,38 @@ public class PlaneContainer { private final Point3D point; private final Vector3D normalVector; - + + /** + * Creates a PlaneContainer from a point and a vector. + * + * @param point a point on the plane + * @param normalVector the normal vector to the plane + */ public PlaneContainer(Point3D point, Vector3D normalVector) { this.point = point; this.normalVector = normalVector; } - + + /** + * Retrieves the point on the plane. + * @return the point + */ public Point3D getPoint() { return point; } - + + /** + * Retrieves the normal vector to the plane. + * @return the normal vector + */ public Vector3D getNormalVector() { return normalVector; } - + + /** + * Converts the PlaneContainer to a Plane. + * @return the Plane + */ public Plane toPlane() { return new Plane(point, normalVector); } diff --git a/src/arcade/core/util/Point3D.java b/src/arcade/core/util/Point3D.java index de3076c9..4d671129 100644 --- a/src/arcade/core/util/Point3D.java +++ b/src/arcade/core/util/Point3D.java @@ -2,14 +2,22 @@ import arcade.potts.env.location.Voxel; - /** * A point in 3D space. */ public class Point3D { - private final int x, y, z; + private final int x; + private final int y; + private final int z; + /** + * Creates a point in 3D space. + * + * @param x the x coordinate + * @param y the y coordinate + * @param z the z coordinate + */ public Point3D(int x, int y, int z) { this.x = x; this.y = y; @@ -27,13 +35,29 @@ public Point3D(Voxel v) { this.z = v.z; } + /** + * Retrieves the x coordinate of the point. + * + * @return the x coordinate + */ public int getX() { return x; } + + /** + * Retrieves the y coordinate of the point. + * + * @return the y coordinate + */ public int getY() { return y; } + + /** + * Retrieves the z coordinate of the point. + * @return the z coordinate + */ public int getZ() { return z; } /** * Checks if two points have the same (x, y, z) coordinates. - * + * * @param obj the point to compare * @return {@code true} if coordinates are the same, {@code false} otherwise */ @@ -45,4 +69,17 @@ public boolean equals(Object obj) { Point3D other = (Point3D) obj; return x == other.x && y == other.y && z == other.z; } + + /** + * Retrieves the hash code of the point. + * @return the hash code + */ + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + x; + hash = 31 * hash + y; + hash = 31 * hash + z; + return hash; + } } diff --git a/src/arcade/core/util/Vector3D.java b/src/arcade/core/util/Vector3D.java index 85db92d7..cca41503 100644 --- a/src/arcade/core/util/Vector3D.java +++ b/src/arcade/core/util/Vector3D.java @@ -5,7 +5,9 @@ */ public class Vector3D { - private final int a,b,c; + private final int a; + private final int b; + private final int c; /** * Creates a 3D vector. @@ -20,13 +22,30 @@ public Vector3D(int a, int b, int c) { this.c = c; } + /** + * Retrieves the x component of the vector. + * + * @return the x component + */ public int getA() { return a; } + + /** + * Retrieves the y component of the vector. + * + * @return the y component + */ public int getB() { return b; } + + /** + * Retrieves the z component of the vector. + * + * @return the z component + */ public int getC() { return c; } /** * Determines if two vectors have the same (a, b, c) components. - * + * * @param obj the vector to compare * @return {@code true} if the vectors are equal, {@code false} otherwise */ @@ -38,4 +57,18 @@ public boolean equals(Object obj) { Vector3D other = (Vector3D) obj; return a == other.a && b == other.b && c == other.c; } -} \ No newline at end of file + + /** + * Generates a hash code for the vector. + * + * @return the hash code + */ + @Override + public int hashCode() { + int hash = 7; + hash = 53 * hash + this.a; + hash = 53 * hash + this.b; + hash = 53 * hash + this.c; + return hash; + } +} diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index 6b854f81..682ad74f 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -8,8 +8,6 @@ import arcade.core.env.location.Location; import arcade.core.env.location.LocationContainer; import arcade.core.util.Utilities; -import arcade.potts.util.PottsEnums.Direction; -import arcade.potts.util.PottsEnums.Region; import arcade.core.util.Plane; import arcade.potts.util.PottsPlaneFactory; import arcade.core.util.Point3D; @@ -276,7 +274,8 @@ public void update(int id, int[][][] ids, int[][][] regions) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random) { - Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getCenter()), getDirection(random)); + Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getCenter()), + getDirection(random)); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -293,7 +292,8 @@ public Location split(MersenneTwisterFast random) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random, ArrayList offsets) { - Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), getDirection(random)); + Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), + getDirection(random)); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -312,7 +312,8 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { */ public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction) { - Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), direction); + Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), + direction); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -333,7 +334,8 @@ public Location split(MersenneTwisterFast random, ArrayList offsets, */ public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction, Double probability) { - Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), direction); + Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), + direction); return split(random, divisionPlane, probability); } @@ -350,8 +352,7 @@ public Location split(MersenneTwisterFast random, ArrayList offsets, * necessarily be balanced in size. * * @param random the seeded random number generator - * @param offsets the percentage offset in each direction for split point - * @param direction the direction of the split + * @param plane the plane of the split * @param probability the probability to decide which split to return * @return a location with the split voxels */ @@ -655,6 +656,7 @@ Location separateVoxels(ArrayList voxelsA, ArrayList voxelsB, *

* The voxels are split into two lists based on their position relative to * the plane. Voxels on the plane are randomly assigned to one of the lists. + * * @param plane the plane to split the voxels along * @param voxels the list of voxels to split * @param voxelsA the container list for the first half of the split. diff --git a/src/arcade/potts/util/PottsPlaneFactory.java b/src/arcade/potts/util/PottsPlaneFactory.java index d62db962..aa3df24b 100644 --- a/src/arcade/potts/util/PottsPlaneFactory.java +++ b/src/arcade/potts/util/PottsPlaneFactory.java @@ -10,7 +10,7 @@ /** * Factory class for creating Potts Planes based on a Direction and a given point. */ -public class PottsPlaneFactory { +public final class PottsPlaneFactory { // Mapping between Direction Enum and normal vectors private static final Map normalVectorMap = new EnumMap<>(Direction.class); @@ -51,4 +51,4 @@ public static Plane createPlane(Point3D point, Direction direction) { public static Vector3D getNormalVector(Direction direction) { return normalVectorMap.get(direction); } -} \ No newline at end of file +} diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java index cd3dd207..90c526cd 100644 --- a/test/arcade/core/util/PlaneTest.java +++ b/test/arcade/core/util/PlaneTest.java @@ -64,4 +64,4 @@ public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegati assertEquals(-1, plane.distanceToPlane(pointToTest), 0.0001); } -} \ No newline at end of file +} diff --git a/test/arcade/core/util/Point3DTest.java b/test/arcade/core/util/Point3DTest.java index 067dc542..e344cd76 100644 --- a/test/arcade/core/util/Point3DTest.java +++ b/test/arcade/core/util/Point3DTest.java @@ -1,8 +1,8 @@ package arcade.core.util; -import arcade.potts.env.location.Voxel; import org.junit.Test; import static org.junit.Assert.*; +import arcade.potts.env.location.Voxel; /** * Unit tests for the Point3D class. @@ -11,7 +11,9 @@ public class Point3DTest { @Test public void constructor_givenInts_returnsCorrectPoint() { - int x = 1, y = 2, z = 3; + int x = 1; + int y = 2; + int z = 3; Point3D point = new Point3D(x, y, z); @@ -67,4 +69,4 @@ public void equals_givenSamePoint_returnsTrue() { assertTrue(point1.equals(point2)); } -} \ No newline at end of file +} diff --git a/test/arcade/core/util/Vector3DTest.java b/test/arcade/core/util/Vector3DTest.java index eabb1b87..6270f614 100644 --- a/test/arcade/core/util/Vector3DTest.java +++ b/test/arcade/core/util/Vector3DTest.java @@ -10,7 +10,9 @@ public class Vector3DTest { @Test public void constructor_givenInts_returnsCorrectVector() { - int a = 1, b = 2, c = 3; + int a = 1; + int b = 2; + int c = 3; Vector3D vector = new Vector3D(a, b, c); @@ -55,4 +57,4 @@ public void equals_givenSameVector_returnsTrue() { assertTrue(vector1.equals(vector2)); } -} \ No newline at end of file +} diff --git a/test/arcade/potts/util/PottsPlaneFactoryTest.java b/test/arcade/potts/util/PottsPlaneFactoryTest.java index 7b3c2499..062bc3da 100644 --- a/test/arcade/potts/util/PottsPlaneFactoryTest.java +++ b/test/arcade/potts/util/PottsPlaneFactoryTest.java @@ -1,10 +1,10 @@ package arcade.potts.util; +import org.junit.Test; import arcade.core.util.Plane; import arcade.core.util.Point3D; import arcade.core.util.Vector3D; import arcade.potts.util.PottsEnums.Direction; -import org.junit.Test; import static org.junit.Assert.*; public class PottsPlaneFactoryTest { From 3bdd12794d856490aa63ecb244a6a5b4764cdc53 Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 3 Oct 2024 19:40:45 -0700 Subject: [PATCH 08/30] formatting fixes. Added private constructor to PottsPlaneFactory --- src/arcade/core/util/Plane.java | 6 ++-- src/arcade/core/util/PlaneContainer.java | 6 ++++ src/arcade/core/util/Point3D.java | 6 +++- src/arcade/core/util/Vector3D.java | 4 ++- .../potts/env/location/PottsLocation.java | 2 +- src/arcade/potts/util/PottsPlaneFactory.java | 31 +++++++++++-------- 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/arcade/core/util/Plane.java b/src/arcade/core/util/Plane.java index 4ec80687..45bef947 100644 --- a/src/arcade/core/util/Plane.java +++ b/src/arcade/core/util/Plane.java @@ -4,11 +4,11 @@ * A plane in 3D space. */ -public class Plane { +public final class Plane { /** A point on the plane. */ public final Point3D point; - /** The normal to the plane. */ + /** The normal vector to the plane. */ public final Vector3D normalVector; /** @@ -64,7 +64,7 @@ public boolean equals(Object obj) { Plane other = (Plane) obj; return point.equals(other.point) && normalVector.equals(other.normalVector); } - + /** * Returns a hash code for the plane. * diff --git a/src/arcade/core/util/PlaneContainer.java b/src/arcade/core/util/PlaneContainer.java index 03e50351..1c95d3a7 100644 --- a/src/arcade/core/util/PlaneContainer.java +++ b/src/arcade/core/util/PlaneContainer.java @@ -4,7 +4,10 @@ * Container class for a plane. */ public class PlaneContainer { + /** A point on the plane */ private final Point3D point; + + /** The normal vector to the plane */ private final Vector3D normalVector; /** @@ -20,6 +23,7 @@ public PlaneContainer(Point3D point, Vector3D normalVector) { /** * Retrieves the point on the plane. + * * @return the point */ public Point3D getPoint() { @@ -28,6 +32,7 @@ public Point3D getPoint() { /** * Retrieves the normal vector to the plane. + * * @return the normal vector */ public Vector3D getNormalVector() { @@ -36,6 +41,7 @@ public Vector3D getNormalVector() { /** * Converts the PlaneContainer to a Plane. + * * @return the Plane */ public Plane toPlane() { diff --git a/src/arcade/core/util/Point3D.java b/src/arcade/core/util/Point3D.java index 4d671129..0046d996 100644 --- a/src/arcade/core/util/Point3D.java +++ b/src/arcade/core/util/Point3D.java @@ -6,9 +6,11 @@ * A point in 3D space. */ public class Point3D { - + /** The x coordinate of the point */ private final int x; + /** The y coordinate of the point */ private final int y; + /** The z coordinate of the point */ private final int z; /** @@ -51,6 +53,7 @@ public Point3D(Voxel v) { /** * Retrieves the z coordinate of the point. + * * @return the z coordinate */ public int getZ() { return z; } @@ -72,6 +75,7 @@ public boolean equals(Object obj) { /** * Retrieves the hash code of the point. + * * @return the hash code */ @Override diff --git a/src/arcade/core/util/Vector3D.java b/src/arcade/core/util/Vector3D.java index cca41503..b03e2b50 100644 --- a/src/arcade/core/util/Vector3D.java +++ b/src/arcade/core/util/Vector3D.java @@ -4,9 +4,11 @@ * A 3D vector. */ public class Vector3D { - + /** The x component of the vector */ private final int a; + /** The y component of the vector */ private final int b; + /** The z component of the vector */ private final int c; /** diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index 682ad74f..9f67881a 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -9,8 +9,8 @@ import arcade.core.env.location.LocationContainer; import arcade.core.util.Utilities; import arcade.core.util.Plane; -import arcade.potts.util.PottsPlaneFactory; import arcade.core.util.Point3D; +import arcade.potts.util.PottsPlaneFactory; import static arcade.potts.util.PottsEnums.Direction; import static arcade.potts.util.PottsEnums.Region; diff --git a/src/arcade/potts/util/PottsPlaneFactory.java b/src/arcade/potts/util/PottsPlaneFactory.java index aa3df24b..82927a00 100644 --- a/src/arcade/potts/util/PottsPlaneFactory.java +++ b/src/arcade/potts/util/PottsPlaneFactory.java @@ -12,19 +12,24 @@ */ public final class PottsPlaneFactory { - // Mapping between Direction Enum and normal vectors - private static final Map normalVectorMap = new EnumMap<>(Direction.class); + /** Mapping between Direction Enum and normal vectors */ + private static final Map NORMAL_VECTOR_MAP = new EnumMap<>(Direction.class); static { - normalVectorMap.put(Direction.YZ_PLANE, new Vector3D(1, 0, 0)); - normalVectorMap.put(Direction.ZX_PLANE, new Vector3D(0, 1, 0)); - normalVectorMap.put(Direction.XY_PLANE, new Vector3D(0, 0, 1)); - normalVectorMap.put(Direction.POSITIVE_XY, new Vector3D(-1, 1, 0)); - normalVectorMap.put(Direction.NEGATIVE_XY, new Vector3D(-1, -1, 0)); - normalVectorMap.put(Direction.POSITIVE_YZ, new Vector3D(0, -1, 1)); - normalVectorMap.put(Direction.NEGATIVE_YZ, new Vector3D(0, -1, -1)); - normalVectorMap.put(Direction.POSITIVE_ZX, new Vector3D(1, 0, -1)); - normalVectorMap.put(Direction.NEGATIVE_ZX, new Vector3D(-1, 0, -1)); + NORMAL_VECTOR_MAP.put(Direction.YZ_PLANE, new Vector3D(1, 0, 0)); + NORMAL_VECTOR_MAP.put(Direction.ZX_PLANE, new Vector3D(0, 1, 0)); + NORMAL_VECTOR_MAP.put(Direction.XY_PLANE, new Vector3D(0, 0, 1)); + NORMAL_VECTOR_MAP.put(Direction.POSITIVE_XY, new Vector3D(-1, 1, 0)); + NORMAL_VECTOR_MAP.put(Direction.NEGATIVE_XY, new Vector3D(-1, -1, 0)); + NORMAL_VECTOR_MAP.put(Direction.POSITIVE_YZ, new Vector3D(0, -1, 1)); + NORMAL_VECTOR_MAP.put(Direction.NEGATIVE_YZ, new Vector3D(0, -1, -1)); + NORMAL_VECTOR_MAP.put(Direction.POSITIVE_ZX, new Vector3D(1, 0, -1)); + NORMAL_VECTOR_MAP.put(Direction.NEGATIVE_ZX, new Vector3D(-1, 0, -1)); + } + + /** Private constructor to prevent instantiation */ + private PottsPlaneFactory() { + throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } /** @@ -35,7 +40,7 @@ public final class PottsPlaneFactory { * @return a Plane */ public static Plane createPlane(Point3D point, Direction direction) { - Vector3D normalVector = normalVectorMap.get(direction); + Vector3D normalVector = NORMAL_VECTOR_MAP.get(direction); if (normalVector == null) { throw new IllegalArgumentException("No normal vector associated with this direction"); } @@ -49,6 +54,6 @@ public static Plane createPlane(Point3D point, Direction direction) { * @return the normal vector */ public static Vector3D getNormalVector(Direction direction) { - return normalVectorMap.get(direction); + return NORMAL_VECTOR_MAP.get(direction); } } From 78425a6cc11b7d62c3f4d204eac7bb9fe5b542ad Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 3 Oct 2024 19:56:50 -0700 Subject: [PATCH 09/30] formatting fixes --- src/arcade/core/util/PlaneContainer.java | 4 ++-- src/arcade/core/util/Point3D.java | 8 +++++--- src/arcade/core/util/Vector3D.java | 8 +++++--- src/arcade/potts/util/PottsPlaneFactory.java | 13 +++++++++---- test/arcade/core/util/Point3DTest.java | 2 +- .../potts/env/location/PottsLocationTest.java | 14 ++------------ 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/arcade/core/util/PlaneContainer.java b/src/arcade/core/util/PlaneContainer.java index 1c95d3a7..6530db7d 100644 --- a/src/arcade/core/util/PlaneContainer.java +++ b/src/arcade/core/util/PlaneContainer.java @@ -4,10 +4,10 @@ * Container class for a plane. */ public class PlaneContainer { - /** A point on the plane */ + /** A point on the plane. */ private final Point3D point; - /** The normal vector to the plane */ + /** The normal vector to the plane. */ private final Vector3D normalVector; /** diff --git a/src/arcade/core/util/Point3D.java b/src/arcade/core/util/Point3D.java index 0046d996..2e9e85e6 100644 --- a/src/arcade/core/util/Point3D.java +++ b/src/arcade/core/util/Point3D.java @@ -6,11 +6,13 @@ * A point in 3D space. */ public class Point3D { - /** The x coordinate of the point */ + /** The x coordinate of the point. */ private final int x; - /** The y coordinate of the point */ + + /** The y coordinate of the point. */ private final int y; - /** The z coordinate of the point */ + + /** The z coordinate of the point. */ private final int z; /** diff --git a/src/arcade/core/util/Vector3D.java b/src/arcade/core/util/Vector3D.java index b03e2b50..823bb2b2 100644 --- a/src/arcade/core/util/Vector3D.java +++ b/src/arcade/core/util/Vector3D.java @@ -4,11 +4,13 @@ * A 3D vector. */ public class Vector3D { - /** The x component of the vector */ + /** The x component of the vector. */ private final int a; - /** The y component of the vector */ + + /** The y component of the vector. */ private final int b; - /** The z component of the vector */ + + /** The z component of the vector. */ private final int c; /** diff --git a/src/arcade/potts/util/PottsPlaneFactory.java b/src/arcade/potts/util/PottsPlaneFactory.java index 82927a00..98e79d53 100644 --- a/src/arcade/potts/util/PottsPlaneFactory.java +++ b/src/arcade/potts/util/PottsPlaneFactory.java @@ -12,8 +12,12 @@ */ public final class PottsPlaneFactory { - /** Mapping between Direction Enum and normal vectors */ - private static final Map NORMAL_VECTOR_MAP = new EnumMap<>(Direction.class); + /** + * The mapping between the Direction Enum and normal vectors of + * each direction's plane. + */ + private static final Map NORMAL_VECTOR_MAP = + new EnumMap<>(Direction.class); static { NORMAL_VECTOR_MAP.put(Direction.YZ_PLANE, new Vector3D(1, 0, 0)); @@ -27,9 +31,10 @@ public final class PottsPlaneFactory { NORMAL_VECTOR_MAP.put(Direction.NEGATIVE_ZX, new Vector3D(-1, 0, -1)); } - /** Private constructor to prevent instantiation */ + /** Private constructor to prevent instantiation. */ private PottsPlaneFactory() { - throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); + throw new UnsupportedOperationException( + "This is a utility class and cannot be instantiated"); } /** diff --git a/test/arcade/core/util/Point3DTest.java b/test/arcade/core/util/Point3DTest.java index e344cd76..ea0280a7 100644 --- a/test/arcade/core/util/Point3DTest.java +++ b/test/arcade/core/util/Point3DTest.java @@ -1,8 +1,8 @@ package arcade.core.util; import org.junit.Test; -import static org.junit.Assert.*; import arcade.potts.env.location.Voxel; +import static org.junit.Assert.*; /** * Unit tests for the Point3D class. diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 5c4fdeee..b751aa28 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -1,24 +1,16 @@ package arcade.potts.env.location; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; import org.junit.BeforeClass; import org.junit.Test; import ec.util.MersenneTwisterFast; import arcade.core.util.Plane; import arcade.core.util.Point3D; import arcade.core.util.Vector3D; -import arcade.potts.util.PottsEnums.Direction; -import arcade.potts.util.PottsEnums.Region; -import arcade.potts.sim.Potts; import arcade.potts.util.PottsPlaneFactory; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; import static arcade.core.ARCADETestUtilities.*; import static arcade.potts.env.location.Voxel.VOXEL_COMPARATOR; @@ -28,8 +20,6 @@ public class PottsLocationTest { private static final double EPSILON = 1E-10; - private static final MersenneTwisterFast RANDOM = new MersenneTwisterFast(randomSeed()); - static MersenneTwisterFast randomDoubleZero; static MersenneTwisterFast randomDoubleOne; @@ -972,7 +962,7 @@ public void splitVoxels_negativeYZDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane negativeYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_YZ);; + Plane negativeYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_YZ); PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -997,7 +987,7 @@ public void splitVoxels_positiveYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane positiveYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_YZ);; + Plane positiveYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_YZ); PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); From 4c97365f733e3aa3bb12837bc34d0cf4da9034b7 Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 4 Oct 2024 11:31:03 -0700 Subject: [PATCH 10/30] moved all points and vectors to int3Ds, expanded direction enum, removed plane factory and container --- src/arcade/core/util/Plane.java | 24 ++-- src/arcade/core/util/PlaneContainer.java | 50 -------- src/arcade/core/util/Point3D.java | 91 --------------- src/arcade/core/util/Vector3D.java | 78 ------------- .../potts/env/location/PottsLocation.java | 32 +++--- src/arcade/potts/util/PottsEnums.java | 70 ++++++++---- src/arcade/potts/util/PottsPlaneFactory.java | 64 ----------- test/arcade/core/util/PlaneContainerTest.java | 48 -------- test/arcade/core/util/PlaneTest.java | 31 ++--- test/arcade/core/util/Point3DTest.java | 72 ------------ test/arcade/core/util/Vector3DTest.java | 60 ---------- .../potts/env/location/PottsLocationTest.java | 84 ++++++++------ .../potts/util/PottsPlaneFactoryTest.java | 108 ------------------ 13 files changed, 143 insertions(+), 669 deletions(-) delete mode 100644 src/arcade/core/util/PlaneContainer.java delete mode 100644 src/arcade/core/util/Point3D.java delete mode 100644 src/arcade/core/util/Vector3D.java delete mode 100644 src/arcade/potts/util/PottsPlaneFactory.java delete mode 100644 test/arcade/core/util/PlaneContainerTest.java delete mode 100644 test/arcade/core/util/Point3DTest.java delete mode 100644 test/arcade/core/util/Vector3DTest.java delete mode 100644 test/arcade/potts/util/PottsPlaneFactoryTest.java diff --git a/src/arcade/core/util/Plane.java b/src/arcade/core/util/Plane.java index 45bef947..ab0754b2 100644 --- a/src/arcade/core/util/Plane.java +++ b/src/arcade/core/util/Plane.java @@ -1,15 +1,17 @@ package arcade.core.util; +import sim.util.Int3D; + /** * A plane in 3D space. */ public final class Plane { /** A point on the plane. */ - public final Point3D point; + public final Int3D point; /** The normal vector to the plane. */ - public final Vector3D normalVector; + public final Int3D normalVector; /** * Creates a plane from a point and a vector. @@ -17,7 +19,7 @@ public final class Plane { * @param point a point on the plane * @param normalVector the normal vector to the plane */ - public Plane(Point3D point, Vector3D normalVector) { + public Plane(Int3D point, Int3D normalVector) { this.point = point; this.normalVector = normalVector; } @@ -29,10 +31,10 @@ public Plane(Point3D point, Vector3D normalVector) { * @return {@code true} if the point is on the plane * {@code false} otherwise */ - public boolean isOnPlane(Point3D p) { - return (p.getX() - point.getX()) * normalVector.getA() - + (p.getY() - point.getY()) * normalVector.getB() - + (p.getZ() - point.getZ()) * normalVector.getC() == 0; + public boolean isOnPlane(Int3D p) { + return (p.getX() - point.getX()) * normalVector.getX() + + (p.getY() - point.getY()) * normalVector.getY() + + (p.getZ() - point.getZ()) * normalVector.getZ() == 0; } /** @@ -44,10 +46,10 @@ public boolean isOnPlane(Point3D p) { * the same side of the plane as the normal vector * and negative if it is on the opposite side. */ - public double distanceToPlane(Point3D p) { - return (p.getX() - point.getX()) * normalVector.getA() - + (p.getY() - point.getY()) * normalVector.getB() - + (p.getZ() - point.getZ()) * normalVector.getC(); + public double distanceToPlane(Int3D p) { + return (p.getX() - point.getX()) * normalVector.getX() + + (p.getY() - point.getY()) * normalVector.getY() + + (p.getZ() - point.getZ()) * normalVector.getZ(); } /** diff --git a/src/arcade/core/util/PlaneContainer.java b/src/arcade/core/util/PlaneContainer.java deleted file mode 100644 index 6530db7d..00000000 --- a/src/arcade/core/util/PlaneContainer.java +++ /dev/null @@ -1,50 +0,0 @@ -package arcade.core.util; - -/** - * Container class for a plane. - */ -public class PlaneContainer { - /** A point on the plane. */ - private final Point3D point; - - /** The normal vector to the plane. */ - private final Vector3D normalVector; - - /** - * Creates a PlaneContainer from a point and a vector. - * - * @param point a point on the plane - * @param normalVector the normal vector to the plane - */ - public PlaneContainer(Point3D point, Vector3D normalVector) { - this.point = point; - this.normalVector = normalVector; - } - - /** - * Retrieves the point on the plane. - * - * @return the point - */ - public Point3D getPoint() { - return point; - } - - /** - * Retrieves the normal vector to the plane. - * - * @return the normal vector - */ - public Vector3D getNormalVector() { - return normalVector; - } - - /** - * Converts the PlaneContainer to a Plane. - * - * @return the Plane - */ - public Plane toPlane() { - return new Plane(point, normalVector); - } -} diff --git a/src/arcade/core/util/Point3D.java b/src/arcade/core/util/Point3D.java deleted file mode 100644 index 2e9e85e6..00000000 --- a/src/arcade/core/util/Point3D.java +++ /dev/null @@ -1,91 +0,0 @@ -package arcade.core.util; - -import arcade.potts.env.location.Voxel; - -/** - * A point in 3D space. - */ -public class Point3D { - /** The x coordinate of the point. */ - private final int x; - - /** The y coordinate of the point. */ - private final int y; - - /** The z coordinate of the point. */ - private final int z; - - /** - * Creates a point in 3D space. - * - * @param x the x coordinate - * @param y the y coordinate - * @param z the z coordinate - */ - public Point3D(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - /** - * Creates a point in the same location as a voxel. - * - * @param v the voxel - */ - public Point3D(Voxel v) { - this.x = v.x; - this.y = v.y; - this.z = v.z; - } - - /** - * Retrieves the x coordinate of the point. - * - * @return the x coordinate - */ - public int getX() { return x; } - - /** - * Retrieves the y coordinate of the point. - * - * @return the y coordinate - */ - public int getY() { return y; } - - /** - * Retrieves the z coordinate of the point. - * - * @return the z coordinate - */ - public int getZ() { return z; } - - /** - * Checks if two points have the same (x, y, z) coordinates. - * - * @param obj the point to compare - * @return {@code true} if coordinates are the same, {@code false} otherwise - */ - @Override - public boolean equals(Object obj) { - if (obj == null || getClass() != obj.getClass()) { - return false; - } - Point3D other = (Point3D) obj; - return x == other.x && y == other.y && z == other.z; - } - - /** - * Retrieves the hash code of the point. - * - * @return the hash code - */ - @Override - public int hashCode() { - int hash = 7; - hash = 31 * hash + x; - hash = 31 * hash + y; - hash = 31 * hash + z; - return hash; - } -} diff --git a/src/arcade/core/util/Vector3D.java b/src/arcade/core/util/Vector3D.java deleted file mode 100644 index 823bb2b2..00000000 --- a/src/arcade/core/util/Vector3D.java +++ /dev/null @@ -1,78 +0,0 @@ -package arcade.core.util; - -/** - * A 3D vector. - */ -public class Vector3D { - /** The x component of the vector. */ - private final int a; - - /** The y component of the vector. */ - private final int b; - - /** The z component of the vector. */ - private final int c; - - /** - * Creates a 3D vector. - * - * @param a the x component - * @param b the y component - * @param c the z component - */ - public Vector3D(int a, int b, int c) { - this.a = a; - this.b = b; - this.c = c; - } - - /** - * Retrieves the x component of the vector. - * - * @return the x component - */ - public int getA() { return a; } - - /** - * Retrieves the y component of the vector. - * - * @return the y component - */ - public int getB() { return b; } - - /** - * Retrieves the z component of the vector. - * - * @return the z component - */ - public int getC() { return c; } - - /** - * Determines if two vectors have the same (a, b, c) components. - * - * @param obj the vector to compare - * @return {@code true} if the vectors are equal, {@code false} otherwise - */ - @Override - public boolean equals(Object obj) { - if (obj == null || getClass() != obj.getClass()) { - return false; - } - Vector3D other = (Vector3D) obj; - return a == other.a && b == other.b && c == other.c; - } - - /** - * Generates a hash code for the vector. - * - * @return the hash code - */ - @Override - public int hashCode() { - int hash = 7; - hash = 53 * hash + this.a; - hash = 53 * hash + this.b; - hash = 53 * hash + this.c; - return hash; - } -} diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index 9f67881a..ef02070a 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -5,12 +5,11 @@ import java.util.HashMap; import java.util.LinkedHashSet; import ec.util.MersenneTwisterFast; +import sim.util.Int3D; import arcade.core.env.location.Location; import arcade.core.env.location.LocationContainer; import arcade.core.util.Utilities; import arcade.core.util.Plane; -import arcade.core.util.Point3D; -import arcade.potts.util.PottsPlaneFactory; import static arcade.potts.util.PottsEnums.Direction; import static arcade.potts.util.PottsEnums.Region; @@ -274,8 +273,10 @@ public void update(int id, int[][][] ids, int[][][] regions) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random) { - Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getCenter()), - getDirection(random)); + Voxel center = getCenter(); + Direction splitDirection = getDirection(random); + Plane divisionPlane = new Plane(new Int3D(center.x, center.y, center.z), + splitDirection.getVector()); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -292,8 +293,10 @@ public Location split(MersenneTwisterFast random) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random, ArrayList offsets) { - Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), - getDirection(random)); + Voxel splitPoint = getOffset(offsets); + Direction splitDirection = getDirection(random); + Plane divisionPlane = new Plane(new Int3D(splitPoint.x, splitPoint.y, splitPoint.z), + splitDirection.getVector()); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -312,8 +315,9 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { */ public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction) { - Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), - direction); + Voxel splitPoint = getOffset(offsets); + Plane divisionPlane = new Plane(new Int3D(splitPoint.x, splitPoint.y, splitPoint.z), + direction.getVector()); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -334,8 +338,9 @@ public Location split(MersenneTwisterFast random, ArrayList offsets, */ public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction, Double probability) { - Plane divisionPlane = PottsPlaneFactory.createPlane(new Point3D(getOffset(offsets)), - direction); + Voxel splitPoint = getOffset(offsets); + Plane divisionPlane = new Plane(new Int3D(splitPoint.x, splitPoint.y, splitPoint.z), + direction.getVector()); return split(random, divisionPlane, probability); } @@ -365,7 +370,8 @@ public Location split(MersenneTwisterFast random, splitVoxels(plane, voxels, voxelsA, voxelsB, random); connectVoxels(voxelsA, voxelsB, this, random); - if (plane.point.equals(new Point3D(getCenter()))) { + Voxel center = getCenter(); + if (plane.point.equals(new Int3D(center.x, center.y, center.z))) { balanceVoxels(voxelsA, voxelsB, this, random); } @@ -669,9 +675,9 @@ static void splitVoxels(Plane plane, ArrayList voxels, ArrayList voxelsA, ArrayList voxelsB, MersenneTwisterFast random) { for (Voxel voxel : voxels) { - if (plane.distanceToPlane(new Point3D(voxel)) < 0) { + if (plane.distanceToPlane(new Int3D(voxel.x, voxel.y, voxel.z)) < 0) { voxelsA.add(voxel); - } else if (plane.distanceToPlane(new Point3D(voxel)) > 0) { + } else if (plane.distanceToPlane(new Int3D(voxel.x, voxel.y, voxel.z)) > 0) { voxelsB.add(voxel); } else { if (random.nextDouble() > 0.5) { diff --git a/src/arcade/potts/util/PottsEnums.java b/src/arcade/potts/util/PottsEnums.java index ca441cae..82501bda 100644 --- a/src/arcade/potts/util/PottsEnums.java +++ b/src/arcade/potts/util/PottsEnums.java @@ -1,6 +1,7 @@ package arcade.potts.util; import ec.util.MersenneTwisterFast; +import sim.util.Int3D; import arcade.core.agent.cell.CellState; import arcade.core.agent.process.ProcessDomain; @@ -169,46 +170,65 @@ public static Phase random(MersenneTwisterFast rng) { } } - /** Location split directions for potts simulations. */ + /** Location split directions for Potts simulations. */ public enum Direction { /** Unspecified direction. */ - UNDEFINED, - + UNDEFINED(null), + /** Direction along the yz plane (y = 0, z = 0). */ - YZ_PLANE, - + YZ_PLANE(new Int3D(1, 0, 0)), + /** Direction along the zx plane (z = 0, x = 0). */ - ZX_PLANE, - + ZX_PLANE(new Int3D(0, 1, 0)), + /** Direction along the xy plane (x = 0, y = 0). */ - XY_PLANE, - + XY_PLANE(new Int3D(0, 0, 1)), + /** Direction along the positive xy axis (x = y, z = 0). */ - POSITIVE_XY, - + POSITIVE_XY(new Int3D(-1, 1, 0)), + /** Direction along the negative xy axis (x = -y, z = 0). */ - NEGATIVE_XY, - + NEGATIVE_XY(new Int3D(-1, -1, 0)), + /** Direction along the positive yz axis (y = z, x = 0). */ - POSITIVE_YZ, - + POSITIVE_YZ(new Int3D(0, -1, 1)), + /** Direction along the negative yz axis (y = -z, x = 0). */ - NEGATIVE_YZ, - + NEGATIVE_YZ(new Int3D(0, -1, -1)), + /** Direction along the positive zx axis (z = x, y = 0). */ - POSITIVE_ZX, - + POSITIVE_ZX(new Int3D(1, 0, -1)), + /** Direction along the negative zx axis (z = -x, y = 0). */ - NEGATIVE_ZX; - + NEGATIVE_ZX(new Int3D(-1, 0, -1)); + + private final Int3D vector; + + private Direction(Int3D vector) { + this.vector = vector; + } + /** - * Randomly selects a {@code Direction}. + * Returns the vector associated with this direction. * - * @param rng the random number generator - * @return a random {@code Direction} + * @return the associated {@code Int3D}, or {@code null} if undefined + */ + public Int3D getVector() { + return vector; + } + + /** + * Randomly selects a {@code Direction}, excluding {@code UNDEFINED}. + * + * @param rng the random number generator + * @return a random {@code Direction} */ public static Direction random(MersenneTwisterFast rng) { - return values()[rng.nextInt(values().length - 1) + 1]; + Direction[] directions = values(); + // Exclude UNDEFINED from the random selection + return directions[rng.nextInt(directions.length - 1) + 1]; } } + + } diff --git a/src/arcade/potts/util/PottsPlaneFactory.java b/src/arcade/potts/util/PottsPlaneFactory.java deleted file mode 100644 index 98e79d53..00000000 --- a/src/arcade/potts/util/PottsPlaneFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -package arcade.potts.util; - -import java.util.EnumMap; -import java.util.Map; -import arcade.core.util.Plane; -import arcade.core.util.Point3D; -import arcade.core.util.Vector3D; -import static arcade.potts.util.PottsEnums.Direction; - -/** - * Factory class for creating Potts Planes based on a Direction and a given point. - */ -public final class PottsPlaneFactory { - - /** - * The mapping between the Direction Enum and normal vectors of - * each direction's plane. - */ - private static final Map NORMAL_VECTOR_MAP = - new EnumMap<>(Direction.class); - - static { - NORMAL_VECTOR_MAP.put(Direction.YZ_PLANE, new Vector3D(1, 0, 0)); - NORMAL_VECTOR_MAP.put(Direction.ZX_PLANE, new Vector3D(0, 1, 0)); - NORMAL_VECTOR_MAP.put(Direction.XY_PLANE, new Vector3D(0, 0, 1)); - NORMAL_VECTOR_MAP.put(Direction.POSITIVE_XY, new Vector3D(-1, 1, 0)); - NORMAL_VECTOR_MAP.put(Direction.NEGATIVE_XY, new Vector3D(-1, -1, 0)); - NORMAL_VECTOR_MAP.put(Direction.POSITIVE_YZ, new Vector3D(0, -1, 1)); - NORMAL_VECTOR_MAP.put(Direction.NEGATIVE_YZ, new Vector3D(0, -1, -1)); - NORMAL_VECTOR_MAP.put(Direction.POSITIVE_ZX, new Vector3D(1, 0, -1)); - NORMAL_VECTOR_MAP.put(Direction.NEGATIVE_ZX, new Vector3D(-1, 0, -1)); - } - - /** Private constructor to prevent instantiation. */ - private PottsPlaneFactory() { - throw new UnsupportedOperationException( - "This is a utility class and cannot be instantiated"); - } - - /** - * Creates a Plane based on a Direction and a specified point. - * - * @param direction the Direction - * @param point the point on the plane - * @return a Plane - */ - public static Plane createPlane(Point3D point, Direction direction) { - Vector3D normalVector = NORMAL_VECTOR_MAP.get(direction); - if (normalVector == null) { - throw new IllegalArgumentException("No normal vector associated with this direction"); - } - return new Plane(point, normalVector); - } - - /** - * Retrieves the normal vector associated with a Direction. - * - * @param direction the Direction - * @return the normal vector - */ - public static Vector3D getNormalVector(Direction direction) { - return NORMAL_VECTOR_MAP.get(direction); - } -} diff --git a/test/arcade/core/util/PlaneContainerTest.java b/test/arcade/core/util/PlaneContainerTest.java deleted file mode 100644 index 507c7104..00000000 --- a/test/arcade/core/util/PlaneContainerTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package arcade.core.util; - -import org.junit.Test; -import static org.junit.Assert.*; - -public class PlaneContainerTest { - - @Test - public void constructor_givenPointAndNormalVector_returnsCorrectContainer() { - Point3D point = new Point3D(1, 2, 3); - Vector3D normalVector = new Vector3D(4, 5, 6); - - PlaneContainer container = new PlaneContainer(point, normalVector); - - assertEquals(point, container.getPoint()); - assertEquals(normalVector, container.getNormalVector()); - } - - @Test - public void getPoint_called_returnsCorrectPoint() { - Point3D point = new Point3D(1, 2, 3); - Vector3D normalVector = new Vector3D(4, 5, 6); - PlaneContainer container = new PlaneContainer(point, normalVector); - - assertEquals(point, container.getPoint()); - } - - @Test - public void getNormalVector_called_returnsCorrectNormalVector() { - Point3D point = new Point3D(1, 2, 3); - Vector3D normalVector = new Vector3D(4, 5, 6); - PlaneContainer container = new PlaneContainer(point, normalVector); - - assertEquals(normalVector, container.getNormalVector()); - } - - @Test - public void toPlane_called_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - Vector3D normalVector = new Vector3D(4, 5, 6); - PlaneContainer container = new PlaneContainer(point, normalVector); - - Plane plane = container.toPlane(); - - assertEquals(point, plane.point); - assertEquals(normalVector, plane.normalVector); - } -} diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java index 90c526cd..e0d041a0 100644 --- a/test/arcade/core/util/PlaneTest.java +++ b/test/arcade/core/util/PlaneTest.java @@ -2,13 +2,14 @@ import org.junit.Test; import static org.junit.Assert.*; +import sim.util.Int3D; public class PlaneTest { @Test public void constructor_givenPointAndVector_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - Vector3D normalVector = new Vector3D(4, 5, 6); + Int3D point = new Int3D(1, 2, 3); + Int3D normalVector = new Int3D(4, 5, 6); Plane plane = new Plane(point, normalVector); @@ -18,49 +19,49 @@ public void constructor_givenPointAndVector_returnsCorrectPlane() { @Test public void equals_givenDifferentPlane_returnsFalse() { - Plane plane1 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); - Plane plane2 = new Plane(new Point3D(4, 5, 6), new Vector3D(7, 8, 9)); + Plane plane1 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); + Plane plane2 = new Plane(new Int3D(4, 5, 6), new Int3D(7, 8, 9)); assertFalse(plane1.equals(plane2)); } @Test public void equals_givenSamePlane_returnsTrue() { - Plane plane1 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); - Plane plane2 = new Plane(new Point3D(1, 2, 3), new Vector3D(4, 5, 6)); + Plane plane1 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); + Plane plane2 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); assertTrue(plane1.equals(plane2)); } @Test public void distanceToPlane_givenPointOnPlane_returnsZero() { - Point3D pointOnPlane = new Point3D(0, 0, 0); - Vector3D normalVector = new Vector3D(1, 0, 0); + Int3D pointOnPlane = new Int3D(0, 0, 0); + Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - Point3D pointToTest = new Point3D(0, 0, 0); // Point is on the plane + Int3D pointToTest = new Int3D(0, 0, 0); // Point is on the plane assertEquals(0, plane.distanceToPlane(pointToTest), 0.0001); } @Test public void distanceToPlane_givenPointOnNormalSideOfPlane_returnsCorrectPositiveDistance() { - Point3D pointOnPlane = new Point3D(0, 0, 0); - Vector3D normalVector = new Vector3D(1, 0, 0); + Int3D pointOnPlane = new Int3D(0, 0, 0); + Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - Point3D pointToTest = new Point3D(1, 1, 1); // Point is not on the plane + Int3D pointToTest = new Int3D(1, 1, 1); // Point is not on the plane assertEquals(1, plane.distanceToPlane(pointToTest), 0.0001); } @Test public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegativeDistance() { - Point3D pointOnPlane = new Point3D(0, 0, 0); - Vector3D normalVector = new Vector3D(1, 0, 0); + Int3D pointOnPlane = new Int3D(0, 0, 0); + Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - Point3D pointToTest = new Point3D(-1, -1, -1); // Point is not on the plane + Int3D pointToTest = new Int3D(-1, -1, -1); // Point is not on the plane assertEquals(-1, plane.distanceToPlane(pointToTest), 0.0001); } diff --git a/test/arcade/core/util/Point3DTest.java b/test/arcade/core/util/Point3DTest.java deleted file mode 100644 index ea0280a7..00000000 --- a/test/arcade/core/util/Point3DTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package arcade.core.util; - -import org.junit.Test; -import arcade.potts.env.location.Voxel; -import static org.junit.Assert.*; - -/** - * Unit tests for the Point3D class. - */ -public class Point3DTest { - - @Test - public void constructor_givenInts_returnsCorrectPoint() { - int x = 1; - int y = 2; - int z = 3; - - Point3D point = new Point3D(x, y, z); - - assertEquals(x, point.getX()); - assertEquals(y, point.getY()); - assertEquals(z, point.getZ()); - } - - @Test - public void constructor_givenVoxel_returnsCorrectPoint() { - Voxel voxel = new Voxel(4, 5, 6); - - Point3D point = new Point3D(voxel); - - assertEquals(voxel.x, point.getX()); - assertEquals(voxel.y, point.getY()); - assertEquals(voxel.z, point.getZ()); - } - - @Test - public void getX_called_returnsX() { - Point3D point = new Point3D(7, 8, 9); - - assertEquals(7, point.getX()); - } - - @Test - public void getY_called_returnsY() { - Point3D point = new Point3D(7, 8, 9); - - assertEquals(8, point.getY()); - } - - @Test - public void getZ_called_returnsZ() { - Point3D point = new Point3D(7, 8, 9); - - assertEquals(9, point.getZ()); - } - - @Test - public void equals_givenDifferentPoint_returnsFalse() { - Point3D point1 = new Point3D(1, 2, 3); - Point3D point2 = new Point3D(4, 5, 6); - - assertFalse(point1.equals(point2)); - } - - @Test - public void equals_givenSamePoint_returnsTrue() { - Point3D point1 = new Point3D(1, 2, 3); - Point3D point2 = new Point3D(1, 2, 3); - - assertTrue(point1.equals(point2)); - } -} diff --git a/test/arcade/core/util/Vector3DTest.java b/test/arcade/core/util/Vector3DTest.java deleted file mode 100644 index 6270f614..00000000 --- a/test/arcade/core/util/Vector3DTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package arcade.core.util; - -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * Unit tests for the Vector3D class. - */ -public class Vector3DTest { - - @Test - public void constructor_givenInts_returnsCorrectVector() { - int a = 1; - int b = 2; - int c = 3; - - Vector3D vector = new Vector3D(a, b, c); - - assertEquals(a, vector.getA()); - assertEquals(b, vector.getB()); - assertEquals(c, vector.getC()); - } - - @Test - public void getA_called_returnsA() { - Vector3D vector = new Vector3D(4, 5, 6); - - assertEquals(4, vector.getA()); - } - - @Test - public void getB_called_returnsB() { - Vector3D vector = new Vector3D(4, 5, 6); - - assertEquals(5, vector.getB()); - } - - @Test - public void getC_called_returnsC() { - Vector3D vector = new Vector3D(4, 5, 6); - - assertEquals(6, vector.getC()); - } - - @Test - public void equals_givenDifferentVector_returnsFalse() { - Vector3D vector1 = new Vector3D(1, 2, 3); - Vector3D vector2 = new Vector3D(4, 5, 6); - - assertFalse(vector1.equals(vector2)); - } - - @Test - public void equals_givenSameVector_returnsTrue() { - Vector3D vector1 = new Vector3D(1, 2, 3); - Vector3D vector2 = new Vector3D(1, 2, 3); - - assertTrue(vector1.equals(vector2)); - } -} diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index b751aa28..82374116 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -6,10 +6,8 @@ import org.junit.BeforeClass; import org.junit.Test; import ec.util.MersenneTwisterFast; +import sim.util.Int3D; import arcade.core.util.Plane; -import arcade.core.util.Point3D; -import arcade.core.util.Vector3D; -import arcade.potts.util.PottsPlaneFactory; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import static arcade.core.ARCADETestUtilities.*; @@ -832,7 +830,8 @@ public void splitVoxels_YZPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane yzPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.YZ_PLANE); + Voxel center = loc.getCenter(); + Plane yzPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.YZ_PLANE.getVector()); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -862,7 +861,8 @@ public void splitVoxels_ZXPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane zxPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.ZX_PLANE); + Voxel center = loc.getCenter(); + Plane zxPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.ZX_PLANE.getVector()); PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -887,7 +887,8 @@ public void splitVoxels_XYPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane xyPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.XY_PLANE); + Voxel center = loc.getCenter(); + Plane xyPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.XY_PLANE.getVector()); PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -912,7 +913,8 @@ public void splitVoxels_negativeXYDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane negativeXYPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_XY); + Voxel center = loc.getCenter(); + Plane negativeXYPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_XY.getVector()); PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -937,8 +939,9 @@ public void splitVoxels_positiveXYDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane positiveXYPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_XY); - + Voxel center = loc.getCenter(); + Plane positiveXYPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_XY.getVector()); + PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); @@ -962,7 +965,8 @@ public void splitVoxels_negativeYZDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane negativeYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_YZ); + Voxel center = loc.getCenter(); + Plane negativeYZPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_YZ.getVector()); PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -987,7 +991,8 @@ public void splitVoxels_positiveYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - Plane positiveYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_YZ); + Voxel center = loc.getCenter(); + Plane positiveYZPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_YZ.getVector()); PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1012,7 +1017,8 @@ public void splitVoxels_negativeZXDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - Plane negativeZXPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_ZX); + Voxel center = loc.getCenter(); + Plane negativeZXPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_ZX.getVector()); PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1036,8 +1042,9 @@ public void splitVoxels_positiveZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - - Plane positiveZXPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_ZX); + + Voxel center = loc.getCenter(); + Plane positiveZXPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_ZX.getVector()); PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1061,8 +1068,9 @@ public void splitVoxels_YZPlaneDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - - Plane yzPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.YZ_PLANE); + + Voxel center = loc.getCenter(); + Plane yzPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.YZ_PLANE.getVector()); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1086,8 +1094,9 @@ public void splitVoxels_ZXPlaneDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - - Plane zxPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.ZX_PLANE); + + Voxel center = loc.getCenter(); + Plane zxPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.ZX_PLANE.getVector()); PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1111,8 +1120,9 @@ public void splitVoxels_XYPlaneDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - - Plane xyPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.XY_PLANE); + + Voxel center = loc.getCenter(); + Plane xyPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.XY_PLANE.getVector()); PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1136,8 +1146,9 @@ public void splitVoxels_negativeXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - - Plane negativeXYPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_XY); + + Voxel center = loc.getCenter(); + Plane negativeXYPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_XY.getVector()); PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1161,8 +1172,9 @@ public void splitVoxels_positiveXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - - Plane positiveXYPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_XY); + + Voxel center = loc.getCenter(); + Plane positiveXYPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_XY.getVector()); PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1186,8 +1198,9 @@ public void splitVoxels_negativeYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - - Plane negativeYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_YZ); + + Voxel center = loc.getCenter(); + Plane negativeYZPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_YZ.getVector()); PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1211,8 +1224,9 @@ public void splitVoxels_positiveYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - - Plane positiveYZPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_YZ); + + Voxel center = loc.getCenter(); + Plane positiveYZPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_YZ.getVector()); PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1236,8 +1250,9 @@ public void splitVoxels_negativeZXDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - - Plane negativeZXPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.NEGATIVE_ZX); + + Voxel center = loc.getCenter(); + Plane negativeZXPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_ZX.getVector()); PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1261,8 +1276,9 @@ public void splitVoxels_positiveZXDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - - Plane positiveZXPlane = PottsPlaneFactory.createPlane(new Point3D(loc.getCenter()), Direction.POSITIVE_ZX); + + Voxel center = loc.getCenter(); + Plane positiveZXPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_ZX.getVector()); PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1557,8 +1573,8 @@ public void split_withOddAnglePlaneThroughPointAndProbabilityOne_splitsVoxelsCor // Plane with normal vector (1, 2, 3) passing through point (1, 2, 1) // Plane equation: x + 2y + 3z = 8 - Point3D planePoint = new Point3D(1, 2, 1); - Vector3D normalVector = new Vector3D(1, 2, 3); + Int3D planePoint = new Int3D(1, 2, 1); + Int3D normalVector = new Int3D(1, 2, 3); Plane plane = new Plane(planePoint, normalVector); // Expected locVoxels: x + 2y + 3z < 8 diff --git a/test/arcade/potts/util/PottsPlaneFactoryTest.java b/test/arcade/potts/util/PottsPlaneFactoryTest.java deleted file mode 100644 index 062bc3da..00000000 --- a/test/arcade/potts/util/PottsPlaneFactoryTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package arcade.potts.util; - -import org.junit.Test; -import arcade.core.util.Plane; -import arcade.core.util.Point3D; -import arcade.core.util.Vector3D; -import arcade.potts.util.PottsEnums.Direction; -import static org.junit.Assert.*; - -public class PottsPlaneFactoryTest { - - @Test - public void createPlane_givenYZPlaneDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.YZ_PLANE); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(1, 0, 0), plane.normalVector); - } - - @Test - public void createPlane_givenZXPlaneDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.ZX_PLANE); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(0, 1, 0), plane.normalVector); - } - - @Test - public void createPlane_givenXYPlaneDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.XY_PLANE); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(0, 0, 1), plane.normalVector); - } - - @Test - public void createPlane_givenPositiveXYDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.POSITIVE_XY); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(-1, 1, 0), plane.normalVector); - } - - @Test - public void createPlane_givenNegativeXYDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.NEGATIVE_XY); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(-1, -1, 0), plane.normalVector); - } - - @Test - public void createPlane_givenPositiveYZDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.POSITIVE_YZ); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(0, -1, 1), plane.normalVector); - } - - @Test - public void createPlane_givenNegativeYZDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.NEGATIVE_YZ); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(0, -1, -1), plane.normalVector); - } - - @Test - public void createPlane_givenPositiveZXDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.POSITIVE_ZX); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(1, 0, -1), plane.normalVector); - } - - @Test - public void createPlane_givenNegativeZXDirection_returnsCorrectPlane() { - Point3D point = new Point3D(1, 2, 3); - - Plane plane = PottsPlaneFactory.createPlane(point, Direction.NEGATIVE_ZX); - - assertEquals(point, plane.point); - assertEquals(new Vector3D(-1, 0, -1), plane.normalVector); - } - - @Test(expected = IllegalArgumentException.class) - public void createPlane_givenUndefinedDirection_throwsIllegalArgumentException() { - Point3D point = new Point3D(1, 2, 3); - - PottsPlaneFactory.createPlane(point, Direction.UNDEFINED); - } -} From f1208b980d84b9ddea7faea6f71563f9764bb5c9 Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 4 Oct 2024 11:46:20 -0700 Subject: [PATCH 11/30] small changes to PottsEnums test, formatting fixes --- src/arcade/potts/util/PottsEnums.java | 38 ++++++++++++---------- test/arcade/core/util/PlaneTest.java | 2 +- test/arcade/potts/util/PottsEnumsTest.java | 28 ++++++++-------- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/arcade/potts/util/PottsEnums.java b/src/arcade/potts/util/PottsEnums.java index 82501bda..16bf404e 100644 --- a/src/arcade/potts/util/PottsEnums.java +++ b/src/arcade/potts/util/PottsEnums.java @@ -170,44 +170,50 @@ public static Phase random(MersenneTwisterFast rng) { } } - /** Location split directions for Potts simulations. */ + /** Location split directions for Potts simulations. */ public enum Direction { /** Unspecified direction. */ UNDEFINED(null), - + /** Direction along the yz plane (y = 0, z = 0). */ YZ_PLANE(new Int3D(1, 0, 0)), - + /** Direction along the zx plane (z = 0, x = 0). */ ZX_PLANE(new Int3D(0, 1, 0)), - + /** Direction along the xy plane (x = 0, y = 0). */ XY_PLANE(new Int3D(0, 0, 1)), - + /** Direction along the positive xy axis (x = y, z = 0). */ POSITIVE_XY(new Int3D(-1, 1, 0)), - + /** Direction along the negative xy axis (x = -y, z = 0). */ NEGATIVE_XY(new Int3D(-1, -1, 0)), - + /** Direction along the positive yz axis (y = z, x = 0). */ POSITIVE_YZ(new Int3D(0, -1, 1)), - + /** Direction along the negative yz axis (y = -z, x = 0). */ NEGATIVE_YZ(new Int3D(0, -1, -1)), - + /** Direction along the positive zx axis (z = x, y = 0). */ POSITIVE_ZX(new Int3D(1, 0, -1)), - + /** Direction along the negative zx axis (z = -x, y = 0). */ NEGATIVE_ZX(new Int3D(-1, 0, -1)); - + + /** The normal vector of the plane in this direction. */ private final Int3D vector; - - private Direction(Int3D vector) { + + /** + * Creates a new {@code Direction} with the given vector. + * + * @param vector the vector associated with this direction + */ + Direction(Int3D vector) { this.vector = vector; } - + /** * Returns the vector associated with this direction. * @@ -216,7 +222,7 @@ private Direction(Int3D vector) { public Int3D getVector() { return vector; } - + /** * Randomly selects a {@code Direction}, excluding {@code UNDEFINED}. * @@ -229,6 +235,4 @@ public static Direction random(MersenneTwisterFast rng) { return directions[rng.nextInt(directions.length - 1) + 1]; } } - - } diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java index e0d041a0..84d329fb 100644 --- a/test/arcade/core/util/PlaneTest.java +++ b/test/arcade/core/util/PlaneTest.java @@ -1,8 +1,8 @@ package arcade.core.util; +import sim.util.Int3D; import org.junit.Test; import static org.junit.Assert.*; -import sim.util.Int3D; public class PlaneTest { diff --git a/test/arcade/potts/util/PottsEnumsTest.java b/test/arcade/potts/util/PottsEnumsTest.java index 963f3a23..833dc96c 100644 --- a/test/arcade/potts/util/PottsEnumsTest.java +++ b/test/arcade/potts/util/PottsEnumsTest.java @@ -60,22 +60,24 @@ public void Term_random_returnsTerm() { @Test public void Direction_random_returnsDirection() { - // Create set of all values. - EnumSet enumSet = EnumSet.allOf(Direction.class); - enumSet.remove(Direction.UNDEFINED); - - // Create set of all random values. - ArrayList enumRandom = new ArrayList<>(); - - int n = Direction.values().length - 1; + // Create a set of all Direction values excluding UNDEFINED + EnumSet expectedDirections = EnumSet.complementOf(EnumSet.of(Direction.UNDEFINED)); + + // Create a set to hold the Directions returned by Direction.random + EnumSet randomDirections = EnumSet.noneOf(Direction.class); + + int n = Direction.values().length - 1; // Excluding UNDEFINED + + // Loop over all possible values that rng.nextInt(n) can return for (int i = 0; i < n; i++) { MersenneTwisterFast rng = mock(MersenneTwisterFast.class); doReturn(i).when(rng).nextInt(n); - enumRandom.add(Direction.random(rng)); + + Direction direction = Direction.random(rng); + randomDirections.add(direction); } - - // Compare resulting sets. - EnumSet enumSetRandom = EnumSet.copyOf(enumRandom); - assertEquals(enumSet, enumSetRandom); + + // Assert that the set of random directions equals the expected set + assertEquals(expectedDirections, randomDirections); } } From e61a6f17e8cc045614a9198ebfd8fd7a7b82f13e Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 4 Oct 2024 11:56:55 -0700 Subject: [PATCH 12/30] hopefully fixed import orders --- src/arcade/potts/env/location/PottsLocation.java | 4 ++-- src/arcade/potts/util/PottsEnums.java | 2 +- test/arcade/core/util/PlaneTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index ef02070a..1ba73749 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -4,12 +4,12 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedHashSet; -import ec.util.MersenneTwisterFast; import sim.util.Int3D; +import ec.util.MersenneTwisterFast; import arcade.core.env.location.Location; import arcade.core.env.location.LocationContainer; -import arcade.core.util.Utilities; import arcade.core.util.Plane; +import arcade.core.util.Utilities; import static arcade.potts.util.PottsEnums.Direction; import static arcade.potts.util.PottsEnums.Region; diff --git a/src/arcade/potts/util/PottsEnums.java b/src/arcade/potts/util/PottsEnums.java index 16bf404e..922eebf3 100644 --- a/src/arcade/potts/util/PottsEnums.java +++ b/src/arcade/potts/util/PottsEnums.java @@ -1,7 +1,7 @@ package arcade.potts.util; -import ec.util.MersenneTwisterFast; import sim.util.Int3D; +import ec.util.MersenneTwisterFast; import arcade.core.agent.cell.CellState; import arcade.core.agent.process.ProcessDomain; diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java index 84d329fb..94e67087 100644 --- a/test/arcade/core/util/PlaneTest.java +++ b/test/arcade/core/util/PlaneTest.java @@ -1,7 +1,7 @@ package arcade.core.util; -import sim.util.Int3D; import org.junit.Test; +import sim.util.Int3D; import static org.junit.Assert.*; public class PlaneTest { From 3207aab4e5073816af3e2de481e4c80c8887a84e Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 4 Oct 2024 12:01:17 -0700 Subject: [PATCH 13/30] small fixes --- .../potts/env/location/PottsLocationTest.java | 3 +- test/arcade/potts/util/PottsEnumsTest.java | 31 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 82374116..54f86db0 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -5,8 +5,8 @@ import java.util.HashMap; import org.junit.BeforeClass; import org.junit.Test; -import ec.util.MersenneTwisterFast; import sim.util.Int3D; +import ec.util.MersenneTwisterFast; import arcade.core.util.Plane; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -15,6 +15,7 @@ import static arcade.potts.util.PottsEnums.Direction; import static arcade.potts.util.PottsEnums.Region; + public class PottsLocationTest { private static final double EPSILON = 1E-10; diff --git a/test/arcade/potts/util/PottsEnumsTest.java b/test/arcade/potts/util/PottsEnumsTest.java index 833dc96c..80ce1999 100644 --- a/test/arcade/potts/util/PottsEnumsTest.java +++ b/test/arcade/potts/util/PottsEnumsTest.java @@ -3,6 +3,9 @@ import java.util.ArrayList; import java.util.EnumSet; import org.junit.Test; +import arcade.potts.util.PottsEnums.Direction; +import arcade.potts.util.PottsEnums.Phase; +import arcade.potts.util.PottsEnums.Term; import ec.util.MersenneTwisterFast; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -60,24 +63,22 @@ public void Term_random_returnsTerm() { @Test public void Direction_random_returnsDirection() { - // Create a set of all Direction values excluding UNDEFINED - EnumSet expectedDirections = EnumSet.complementOf(EnumSet.of(Direction.UNDEFINED)); - - // Create a set to hold the Directions returned by Direction.random - EnumSet randomDirections = EnumSet.noneOf(Direction.class); - - int n = Direction.values().length - 1; // Excluding UNDEFINED - - // Loop over all possible values that rng.nextInt(n) can return + // Create set of all values. + EnumSet enumSet = EnumSet.allOf(Direction.class); + enumSet.remove(Direction.UNDEFINED); + + // Create set of all random values. + ArrayList enumRandom = new ArrayList<>(); + + int n = Direction.values().length - 1; for (int i = 0; i < n; i++) { MersenneTwisterFast rng = mock(MersenneTwisterFast.class); doReturn(i).when(rng).nextInt(n); - - Direction direction = Direction.random(rng); - randomDirections.add(direction); + enumRandom.add(Direction.random(rng)); } - - // Assert that the set of random directions equals the expected set - assertEquals(expectedDirections, randomDirections); + + // Compare resulting sets. + EnumSet enumSetRandom = EnumSet.copyOf(enumRandom); + assertEquals(enumSet, enumSetRandom); } } From 70fdf740de30ac4a9fc077b1031582dfe22ebccb Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 4 Oct 2024 12:06:08 -0700 Subject: [PATCH 14/30] removed extra split function --- .../potts/env/location/PottsLocation.java | 21 ------------------- .../potts/env/location/PottsLocationTest.java | 8 ++++--- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index 1ba73749..ca9631fb 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -300,27 +300,6 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } - /** - * Splits location voxels into two lists with given offset and direction. - *

- * The location is split at the point specified by offsets along the given - * direction. The lists of locations are guaranteed to be connected. One of - * the splits is assigned to the current location and the other is - * returned. - * - * @param random the seeded random number generator - * @param offsets the percentage offset in each direction for split point - * @param direction the direction of the split - * @return a location with the split voxels - */ - public Location split(MersenneTwisterFast random, ArrayList offsets, - Direction direction) { - Voxel splitPoint = getOffset(offsets); - Plane divisionPlane = new Plane(new Int3D(splitPoint.x, splitPoint.y, splitPoint.z), - direction.getVector()); - return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); - } - /** * Splits location voxels into two lists with given offset, direction, and probability. *

diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 54f86db0..0f42cb2b 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import javax.xml.bind.annotation.XmlElement.DEFAULT; import org.junit.BeforeClass; import org.junit.Test; import sim.util.Int3D; @@ -1434,7 +1435,7 @@ public void split_withOffsetsNoDirection_splitsVoxelsCorrectly() { } @Test - public void split_withOffsetsWithDirection_splitsVoxelsCorrectly() { + public void split_withOffsetsWithDirectionWithProbability_splitsVoxelsCorrectly() { ArrayList voxels = new ArrayList<>(); ArrayList locVoxels = new ArrayList<>(); ArrayList splitVoxels = new ArrayList<>(); @@ -1469,9 +1470,10 @@ public void split_withOffsetsWithDirection_splitsVoxelsCorrectly() { } PottsLocation location = new PottsLocationMock(voxels); - + double probability = 0.5; // Call split - PottsLocation splitLocation = (PottsLocation) location.split(randomDoubleZero, offsets, Direction.POSITIVE_XY); + PottsLocation splitLocation = (PottsLocation) location.split(randomDoubleZero, offsets, + Direction.POSITIVE_XY, probability); // Verify the split occurred as expected int totalVoxels = location.voxels.size() + splitLocation.voxels.size(); From 67b2122abf902ff6fe96fa3bd537c52bd0b26f58 Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 4 Oct 2024 12:09:02 -0700 Subject: [PATCH 15/30] formatting fixes --- src/arcade/potts/util/PottsEnums.java | 2 +- test/arcade/potts/env/location/PottsLocationTest.java | 2 -- test/arcade/potts/util/PottsEnumsTest.java | 3 --- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/arcade/potts/util/PottsEnums.java b/src/arcade/potts/util/PottsEnums.java index 922eebf3..1f7655a4 100644 --- a/src/arcade/potts/util/PottsEnums.java +++ b/src/arcade/potts/util/PottsEnums.java @@ -170,7 +170,7 @@ public static Phase random(MersenneTwisterFast rng) { } } - /** Location split directions for Potts simulations. */ + /** Location split directions for potts simulations. */ public enum Direction { /** Unspecified direction. */ UNDEFINED(null), diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 0f42cb2b..4350421b 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import javax.xml.bind.annotation.XmlElement.DEFAULT; import org.junit.BeforeClass; import org.junit.Test; import sim.util.Int3D; @@ -16,7 +15,6 @@ import static arcade.potts.util.PottsEnums.Direction; import static arcade.potts.util.PottsEnums.Region; - public class PottsLocationTest { private static final double EPSILON = 1E-10; diff --git a/test/arcade/potts/util/PottsEnumsTest.java b/test/arcade/potts/util/PottsEnumsTest.java index 80ce1999..963f3a23 100644 --- a/test/arcade/potts/util/PottsEnumsTest.java +++ b/test/arcade/potts/util/PottsEnumsTest.java @@ -3,9 +3,6 @@ import java.util.ArrayList; import java.util.EnumSet; import org.junit.Test; -import arcade.potts.util.PottsEnums.Direction; -import arcade.potts.util.PottsEnums.Phase; -import arcade.potts.util.PottsEnums.Term; import ec.util.MersenneTwisterFast; import static org.junit.Assert.*; import static org.mockito.Mockito.*; From 00e33d88561434ed2ac8efb37ac4f7c165b31a53 Mon Sep 17 00:00:00 2001 From: daniellevahdat <158232064+daniellevahdat@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:16:11 -0700 Subject: [PATCH 16/30] Divide Distance to Plane by Normal Vector Magnitude (#52) * Signed distance to plane and tests for plane class * test * Signed distance to plane and tests * updated tests, renamed function * formatting fixes * small formatting fix --------- Co-authored-by: Danielle Vahdat Co-authored-by: daniellevahdat Co-authored-by: jannetty --- src/arcade/core/util/Plane.java | 23 ++++-- .../potts/env/location/PottsLocation.java | 4 +- test.class | Bin 0 -> 428 bytes test/arcade/core/util/PlaneTest.java | 76 +++++++++++++----- 4 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 test.class diff --git a/src/arcade/core/util/Plane.java b/src/arcade/core/util/Plane.java index ab0754b2..5d027436 100644 --- a/src/arcade/core/util/Plane.java +++ b/src/arcade/core/util/Plane.java @@ -9,10 +9,10 @@ public final class Plane { /** A point on the plane. */ public final Int3D point; - + /** The normal vector to the plane. */ public final Int3D normalVector; - + /** * Creates a plane from a point and a vector. * @@ -23,7 +23,7 @@ public Plane(Int3D point, Int3D normalVector) { this.point = point; this.normalVector = normalVector; } - + /** * Determines whether a point is on the plane. * @@ -36,7 +36,7 @@ public boolean isOnPlane(Int3D p) { + (p.getY() - point.getY()) * normalVector.getY() + (p.getZ() - point.getZ()) * normalVector.getZ() == 0; } - + /** * Determines distance from a point to the plane. * @@ -46,12 +46,19 @@ public boolean isOnPlane(Int3D p) { * the same side of the plane as the normal vector * and negative if it is on the opposite side. */ - public double distanceToPlane(Int3D p) { - return (p.getX() - point.getX()) * normalVector.getX() + public double signedDistanceToPlane(Int3D p) { + double dotProduct; + double normalVectorMagnitude; + + dotProduct = (p.getX() - point.getX()) * normalVector.getX() + (p.getY() - point.getY()) * normalVector.getY() + (p.getZ() - point.getZ()) * normalVector.getZ(); + normalVectorMagnitude = Math.sqrt(normalVector.getX() * normalVector.getX() + + normalVector.getY() * normalVector.getY() + + normalVector.getZ() * normalVector.getZ()); + return dotProduct / normalVectorMagnitude; } - + /** * Determines if two planes are equal. * @@ -66,7 +73,7 @@ public boolean equals(Object obj) { Plane other = (Plane) obj; return point.equals(other.point) && normalVector.equals(other.normalVector); } - + /** * Returns a hash code for the plane. * diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index ca9631fb..ca5e965b 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -654,9 +654,9 @@ static void splitVoxels(Plane plane, ArrayList voxels, ArrayList voxelsA, ArrayList voxelsB, MersenneTwisterFast random) { for (Voxel voxel : voxels) { - if (plane.distanceToPlane(new Int3D(voxel.x, voxel.y, voxel.z)) < 0) { + if (plane.signedDistanceToPlane(new Int3D(voxel.x, voxel.y, voxel.z)) < 0) { voxelsA.add(voxel); - } else if (plane.distanceToPlane(new Int3D(voxel.x, voxel.y, voxel.z)) > 0) { + } else if (plane.signedDistanceToPlane(new Int3D(voxel.x, voxel.y, voxel.z)) > 0) { voxelsB.add(voxel); } else { if (random.nextDouble() > 0.5) { diff --git a/test.class b/test.class new file mode 100644 index 0000000000000000000000000000000000000000..f6683ce5178b0a2897796537481994d0b3e5d6c7 GIT binary patch literal 428 zcmZvZ&rZTX5XQfSN@=ZvAo!Pri%Bs?9suJ7H69u<)ZoEWiyN|pZb{ji_*i<-#Dfpu zLm6lAU`*J)4{In1RHxBX)SX3o(jCN8IW_{NGo_U| z7byCjk%KZE8?J|Sc>nC-^TNo4Txm{4jbI5aCs}KTinC977UMV*3&{O728s=KdjFYF_8ro>kz<6<_k%7#lTC@w! u9KS=nkPz6V$j7W5>|vjFwjNO_XPsBrwT(Aa{_Ol2K#^u_k>!AN0f#@|{#S7T literal 0 HcmV?d00001 diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java index 94e67087..dd1c590a 100644 --- a/test/arcade/core/util/PlaneTest.java +++ b/test/arcade/core/util/PlaneTest.java @@ -5,64 +5,102 @@ import static org.junit.Assert.*; public class PlaneTest { - + @Test public void constructor_givenPointAndVector_returnsCorrectPlane() { Int3D point = new Int3D(1, 2, 3); Int3D normalVector = new Int3D(4, 5, 6); - + Plane plane = new Plane(point, normalVector); - + assertEquals(point, plane.point); assertEquals(normalVector, plane.normalVector); } - + @Test public void equals_givenDifferentPlane_returnsFalse() { Plane plane1 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); Plane plane2 = new Plane(new Int3D(4, 5, 6), new Int3D(7, 8, 9)); - + assertFalse(plane1.equals(plane2)); } - + @Test public void equals_givenSamePlane_returnsTrue() { Plane plane1 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); Plane plane2 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); - + assertTrue(plane1.equals(plane2)); } - + @Test public void distanceToPlane_givenPointOnPlane_returnsZero() { Int3D pointOnPlane = new Int3D(0, 0, 0); Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - + Int3D pointToTest = new Int3D(0, 0, 0); // Point is on the plane - - assertEquals(0, plane.distanceToPlane(pointToTest), 0.0001); + + assertEquals(0, plane.signedDistanceToPlane(pointToTest), 0.0001); } - + @Test public void distanceToPlane_givenPointOnNormalSideOfPlane_returnsCorrectPositiveDistance() { Int3D pointOnPlane = new Int3D(0, 0, 0); Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - + Int3D pointToTest = new Int3D(1, 1, 1); // Point is not on the plane - - assertEquals(1, plane.distanceToPlane(pointToTest), 0.0001); + + assertEquals(1, plane.signedDistanceToPlane(pointToTest), 0.0001); } - + @Test public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegativeDistance() { Int3D pointOnPlane = new Int3D(0, 0, 0); Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); + + Int3D pointToTest = new Int3D(-1, -1, -1); + + assertEquals(-1, plane.signedDistanceToPlane(pointToTest), 0.0001); + } + + @Test + public void signedDistanceToPlane_givenSimplePoint_returnsCorrectSignedDistance() { + Int3D point = new Int3D(0, 0, 0); + Int3D normalVector = new Int3D(0, 0, 1); + Plane plane = new Plane(point, normalVector); + + Int3D posTestPoint = new Int3D(0, 0, 5); + Int3D negTestPoint = new Int3D(0, 0, -5); + + assertEquals(5.0, plane.signedDistanceToPlane(posTestPoint), 0.001); + assertEquals(-5.0, plane.signedDistanceToPlane(negTestPoint), 0.001); + } + + @Test + public void complexTestSignedDistanceToPlane() { + Int3D point = new Int3D(1, 1, 2); + Int3D normalVector = new Int3D(1, 2, 2); + Plane plane = new Plane(point, normalVector); + + Int3D postestPoint = new Int3D(2, 2, 5); + Int3D negtestPoint = new Int3D(0, 0, -1); + + assertEquals(3.0, plane.signedDistanceToPlane(postestPoint), 0.001); + assertEquals(-3.0, plane.signedDistanceToPlane(negtestPoint), 0.001); + } - Int3D pointToTest = new Int3D(-1, -1, -1); // Point is not on the plane - - assertEquals(-1, plane.distanceToPlane(pointToTest), 0.0001); + @Test + public void testHashCodeConsistency() { + // Two planes with the same point and normal vector should have the same hash code + Int3D point = new Int3D(1, 2, 3); + Int3D normalVector = new Int3D(4, 5, 6); + + Plane plane1 = new Plane(point, normalVector); + Plane plane2 = new Plane(point, normalVector); + + assertEquals(plane1.hashCode(), plane2.hashCode()); } } From 21b70895320ece2f3b81346fc0c23be6bf10688c Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 10 Oct 2024 13:40:43 -0700 Subject: [PATCH 17/30] moved Plane to Potts, changed point type to Voxel, removed unused function --- .../potts/env/location/PottsLocation.java | 13 +-- src/arcade/{core => potts}/util/Plane.java | 51 +++------ test/arcade/core/util/PlaneTest.java | 106 ------------------ .../potts/env/location/PottsLocationTest.java | 40 +++---- test/arcade/potts/util/PlaneTest.java | 69 ++++++++++++ 5 files changed, 110 insertions(+), 169 deletions(-) rename src/arcade/{core => potts}/util/Plane.java (50%) delete mode 100644 test/arcade/core/util/PlaneTest.java create mode 100644 test/arcade/potts/util/PlaneTest.java diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index ca5e965b..748a4272 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -8,8 +8,8 @@ import ec.util.MersenneTwisterFast; import arcade.core.env.location.Location; import arcade.core.env.location.LocationContainer; -import arcade.core.util.Plane; import arcade.core.util.Utilities; +import arcade.potts.util.Plane; import static arcade.potts.util.PottsEnums.Direction; import static arcade.potts.util.PottsEnums.Region; @@ -275,8 +275,7 @@ public void update(int id, int[][][] ids, int[][][] regions) { public Location split(MersenneTwisterFast random) { Voxel center = getCenter(); Direction splitDirection = getDirection(random); - Plane divisionPlane = new Plane(new Int3D(center.x, center.y, center.z), - splitDirection.getVector()); + Plane divisionPlane = new Plane(center, splitDirection.getVector()); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -295,8 +294,7 @@ public Location split(MersenneTwisterFast random) { public Location split(MersenneTwisterFast random, ArrayList offsets) { Voxel splitPoint = getOffset(offsets); Direction splitDirection = getDirection(random); - Plane divisionPlane = new Plane(new Int3D(splitPoint.x, splitPoint.y, splitPoint.z), - splitDirection.getVector()); + Plane divisionPlane = new Plane(splitPoint, splitDirection.getVector()); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -318,8 +316,7 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction, Double probability) { Voxel splitPoint = getOffset(offsets); - Plane divisionPlane = new Plane(new Int3D(splitPoint.x, splitPoint.y, splitPoint.z), - direction.getVector()); + Plane divisionPlane = new Plane(splitPoint,direction.getVector()); return split(random, divisionPlane, probability); } @@ -350,7 +347,7 @@ public Location split(MersenneTwisterFast random, connectVoxels(voxelsA, voxelsB, this, random); Voxel center = getCenter(); - if (plane.point.equals(new Int3D(center.x, center.y, center.z))) { + if (plane.referencePoint.equals(new Int3D(center.x, center.y, center.z))) { balanceVoxels(voxelsA, voxelsB, this, random); } diff --git a/src/arcade/core/util/Plane.java b/src/arcade/potts/util/Plane.java similarity index 50% rename from src/arcade/core/util/Plane.java rename to src/arcade/potts/util/Plane.java index 5d027436..fea2f796 100644 --- a/src/arcade/core/util/Plane.java +++ b/src/arcade/potts/util/Plane.java @@ -1,6 +1,7 @@ -package arcade.core.util; +package arcade.potts.util; import sim.util.Int3D; +import arcade.potts.env.location.Voxel; /** * A plane in 3D space. @@ -8,35 +9,22 @@ public final class Plane { /** A point on the plane. */ - public final Int3D point; - + public final Voxel referencePoint; + /** The normal vector to the plane. */ public final Int3D normalVector; - + /** * Creates a plane from a point and a vector. * * @param point a point on the plane * @param normalVector the normal vector to the plane */ - public Plane(Int3D point, Int3D normalVector) { - this.point = point; + public Plane(Voxel voxel, Int3D normalVector) { + this.referencePoint = voxel; this.normalVector = normalVector; } - - /** - * Determines whether a point is on the plane. - * - * @param p the point to test - * @return {@code true} if the point is on the plane - * {@code false} otherwise - */ - public boolean isOnPlane(Int3D p) { - return (p.getX() - point.getX()) * normalVector.getX() - + (p.getY() - point.getY()) * normalVector.getY() - + (p.getZ() - point.getZ()) * normalVector.getZ() == 0; - } - + /** * Determines distance from a point to the plane. * @@ -46,19 +34,12 @@ public boolean isOnPlane(Int3D p) { * the same side of the plane as the normal vector * and negative if it is on the opposite side. */ - public double signedDistanceToPlane(Int3D p) { - double dotProduct; - double normalVectorMagnitude; - - dotProduct = (p.getX() - point.getX()) * normalVector.getX() - + (p.getY() - point.getY()) * normalVector.getY() - + (p.getZ() - point.getZ()) * normalVector.getZ(); - normalVectorMagnitude = Math.sqrt(normalVector.getX() * normalVector.getX() - + normalVector.getY() * normalVector.getY() - + normalVector.getZ() * normalVector.getZ()); - return dotProduct / normalVectorMagnitude; + public double distanceToPlane(Int3D p) { + return (p.getX() - referencePoint.x) * normalVector.getX() + + (p.getY() - referencePoint.y) * normalVector.getY() + + (p.getZ() - referencePoint.z) * normalVector.getZ(); } - + /** * Determines if two planes are equal. * @@ -71,9 +52,9 @@ public boolean equals(Object obj) { return false; } Plane other = (Plane) obj; - return point.equals(other.point) && normalVector.equals(other.normalVector); + return referencePoint.equals(other.referencePoint) && normalVector.equals(other.normalVector); } - + /** * Returns a hash code for the plane. * @@ -82,7 +63,7 @@ public boolean equals(Object obj) { @Override public int hashCode() { int hash = 7; - hash = 97 * hash + (this.point != null ? this.point.hashCode() : 0); + hash = 97 * hash + (this.referencePoint != null ? this.referencePoint.hashCode() : 0); hash = 97 * hash + (this.normalVector != null ? this.normalVector.hashCode() : 0); return hash; } diff --git a/test/arcade/core/util/PlaneTest.java b/test/arcade/core/util/PlaneTest.java deleted file mode 100644 index dd1c590a..00000000 --- a/test/arcade/core/util/PlaneTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package arcade.core.util; - -import org.junit.Test; -import sim.util.Int3D; -import static org.junit.Assert.*; - -public class PlaneTest { - - @Test - public void constructor_givenPointAndVector_returnsCorrectPlane() { - Int3D point = new Int3D(1, 2, 3); - Int3D normalVector = new Int3D(4, 5, 6); - - Plane plane = new Plane(point, normalVector); - - assertEquals(point, plane.point); - assertEquals(normalVector, plane.normalVector); - } - - @Test - public void equals_givenDifferentPlane_returnsFalse() { - Plane plane1 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); - Plane plane2 = new Plane(new Int3D(4, 5, 6), new Int3D(7, 8, 9)); - - assertFalse(plane1.equals(plane2)); - } - - @Test - public void equals_givenSamePlane_returnsTrue() { - Plane plane1 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); - Plane plane2 = new Plane(new Int3D(1, 2, 3), new Int3D(4, 5, 6)); - - assertTrue(plane1.equals(plane2)); - } - - @Test - public void distanceToPlane_givenPointOnPlane_returnsZero() { - Int3D pointOnPlane = new Int3D(0, 0, 0); - Int3D normalVector = new Int3D(1, 0, 0); - Plane plane = new Plane(pointOnPlane, normalVector); - - Int3D pointToTest = new Int3D(0, 0, 0); // Point is on the plane - - assertEquals(0, plane.signedDistanceToPlane(pointToTest), 0.0001); - } - - @Test - public void distanceToPlane_givenPointOnNormalSideOfPlane_returnsCorrectPositiveDistance() { - Int3D pointOnPlane = new Int3D(0, 0, 0); - Int3D normalVector = new Int3D(1, 0, 0); - Plane plane = new Plane(pointOnPlane, normalVector); - - Int3D pointToTest = new Int3D(1, 1, 1); // Point is not on the plane - - assertEquals(1, plane.signedDistanceToPlane(pointToTest), 0.0001); - } - - @Test - public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegativeDistance() { - Int3D pointOnPlane = new Int3D(0, 0, 0); - Int3D normalVector = new Int3D(1, 0, 0); - Plane plane = new Plane(pointOnPlane, normalVector); - - Int3D pointToTest = new Int3D(-1, -1, -1); - - assertEquals(-1, plane.signedDistanceToPlane(pointToTest), 0.0001); - } - - @Test - public void signedDistanceToPlane_givenSimplePoint_returnsCorrectSignedDistance() { - Int3D point = new Int3D(0, 0, 0); - Int3D normalVector = new Int3D(0, 0, 1); - Plane plane = new Plane(point, normalVector); - - Int3D posTestPoint = new Int3D(0, 0, 5); - Int3D negTestPoint = new Int3D(0, 0, -5); - - assertEquals(5.0, plane.signedDistanceToPlane(posTestPoint), 0.001); - assertEquals(-5.0, plane.signedDistanceToPlane(negTestPoint), 0.001); - } - - @Test - public void complexTestSignedDistanceToPlane() { - Int3D point = new Int3D(1, 1, 2); - Int3D normalVector = new Int3D(1, 2, 2); - Plane plane = new Plane(point, normalVector); - - Int3D postestPoint = new Int3D(2, 2, 5); - Int3D negtestPoint = new Int3D(0, 0, -1); - - assertEquals(3.0, plane.signedDistanceToPlane(postestPoint), 0.001); - assertEquals(-3.0, plane.signedDistanceToPlane(negtestPoint), 0.001); - } - - @Test - public void testHashCodeConsistency() { - // Two planes with the same point and normal vector should have the same hash code - Int3D point = new Int3D(1, 2, 3); - Int3D normalVector = new Int3D(4, 5, 6); - - Plane plane1 = new Plane(point, normalVector); - Plane plane2 = new Plane(point, normalVector); - - assertEquals(plane1.hashCode(), plane2.hashCode()); - } -} diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 4350421b..5f87fca5 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -5,9 +5,9 @@ import java.util.HashMap; import org.junit.BeforeClass; import org.junit.Test; +import arcade.potts.util.Plane; import sim.util.Int3D; import ec.util.MersenneTwisterFast; -import arcade.core.util.Plane; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import static arcade.core.ARCADETestUtilities.*; @@ -831,7 +831,7 @@ public void splitVoxels_YZPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane yzPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.YZ_PLANE.getVector()); + Plane yzPlane = new Plane(center, Direction.YZ_PLANE.getVector()); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -862,7 +862,7 @@ public void splitVoxels_ZXPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane zxPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.ZX_PLANE.getVector()); + Plane zxPlane = new Plane(center, Direction.ZX_PLANE.getVector()); PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -888,7 +888,7 @@ public void splitVoxels_XYPlaneDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane xyPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.XY_PLANE.getVector()); + Plane xyPlane = new Plane(center, Direction.XY_PLANE.getVector()); PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -914,7 +914,7 @@ public void splitVoxels_negativeXYDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeXYPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_XY.getVector()); + Plane negativeXYPlane = new Plane(center, Direction.NEGATIVE_XY.getVector()); PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -940,7 +940,7 @@ public void splitVoxels_positiveXYDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveXYPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_XY.getVector()); + Plane positiveXYPlane = new Plane(center, Direction.POSITIVE_XY.getVector()); PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -966,7 +966,7 @@ public void splitVoxels_negativeYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeYZPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_YZ.getVector()); + Plane negativeYZPlane = new Plane(center, Direction.NEGATIVE_YZ.getVector()); PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -992,7 +992,7 @@ public void splitVoxels_positiveYZDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveYZPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_YZ.getVector()); + Plane positiveYZPlane = new Plane(center, Direction.POSITIVE_YZ.getVector()); PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1018,7 +1018,7 @@ public void splitVoxels_negativeZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeZXPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_ZX.getVector()); + Plane negativeZXPlane = new Plane(center, Direction.NEGATIVE_ZX.getVector()); PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1044,7 +1044,7 @@ public void splitVoxels_positiveZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveZXPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_ZX.getVector()); + Plane positiveZXPlane = new Plane(center, Direction.POSITIVE_ZX.getVector()); PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1070,7 +1070,7 @@ public void splitVoxels_YZPlaneDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane yzPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.YZ_PLANE.getVector()); + Plane yzPlane = new Plane(center, Direction.YZ_PLANE.getVector()); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1096,7 +1096,7 @@ public void splitVoxels_ZXPlaneDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane zxPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.ZX_PLANE.getVector()); + Plane zxPlane = new Plane(center, Direction.ZX_PLANE.getVector()); PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1122,7 +1122,7 @@ public void splitVoxels_XYPlaneDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane xyPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.XY_PLANE.getVector()); + Plane xyPlane = new Plane(center, Direction.XY_PLANE.getVector()); PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1148,7 +1148,7 @@ public void splitVoxels_negativeXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeXYPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_XY.getVector()); + Plane negativeXYPlane = new Plane(center, Direction.NEGATIVE_XY.getVector()); PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1174,7 +1174,7 @@ public void splitVoxels_positiveXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveXYPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_XY.getVector()); + Plane positiveXYPlane = new Plane(center, Direction.POSITIVE_XY.getVector()); PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1200,7 +1200,7 @@ public void splitVoxels_negativeYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeYZPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_YZ.getVector()); + Plane negativeYZPlane = new Plane(center, Direction.NEGATIVE_YZ.getVector()); PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1226,7 +1226,7 @@ public void splitVoxels_positiveYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveYZPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_YZ.getVector()); + Plane positiveYZPlane = new Plane(center, Direction.POSITIVE_YZ.getVector()); PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1252,7 +1252,7 @@ public void splitVoxels_negativeZXDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeZXPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.NEGATIVE_ZX.getVector()); + Plane negativeZXPlane = new Plane(center, Direction.NEGATIVE_ZX.getVector()); PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1278,7 +1278,7 @@ public void splitVoxels_positiveZXDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveZXPlane = new Plane(new Int3D(center.x, center.y, center.z), Direction.POSITIVE_ZX.getVector()); + Plane positiveZXPlane = new Plane(center, Direction.POSITIVE_ZX.getVector()); PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1574,7 +1574,7 @@ public void split_withOddAnglePlaneThroughPointAndProbabilityOne_splitsVoxelsCor // Plane with normal vector (1, 2, 3) passing through point (1, 2, 1) // Plane equation: x + 2y + 3z = 8 - Int3D planePoint = new Int3D(1, 2, 1); + Voxel planePoint = new Voxel(1, 2, 1); Int3D normalVector = new Int3D(1, 2, 3); Plane plane = new Plane(planePoint, normalVector); diff --git a/test/arcade/potts/util/PlaneTest.java b/test/arcade/potts/util/PlaneTest.java new file mode 100644 index 00000000..321e4836 --- /dev/null +++ b/test/arcade/potts/util/PlaneTest.java @@ -0,0 +1,69 @@ +package arcade.potts.util; + +import org.junit.Test; +import sim.util.Int3D; +import arcade.potts.env.location.Voxel; +import static org.junit.Assert.*; + +public class PlaneTest { + + @Test + public void constructor_givenPointAndVector_returnsCorrectPlane() { + Voxel point = new Voxel(1, 2, 3); + Int3D normalVector = new Int3D(4, 5, 6); + + Plane plane = new Plane(point, normalVector); + + assertEquals(point, plane.referencePoint); + assertEquals(normalVector, plane.normalVector); + } + + @Test + public void equals_givenDifferentPlane_returnsFalse() { + Plane plane1 = new Plane(new Voxel(1, 2, 3), new Int3D(4, 5, 6)); + Plane plane2 = new Plane(new Voxel(4, 5, 6), new Int3D(7, 8, 9)); + + assertFalse(plane1.equals(plane2)); + } + + @Test + public void equals_givenSamePlane_returnsTrue() { + Plane plane1 = new Plane(new Voxel(1, 2, 3), new Int3D(4, 5, 6)); + Plane plane2 = new Plane(new Voxel(1, 2, 3), new Int3D(4, 5, 6)); + + assertTrue(plane1.equals(plane2)); + } + + @Test + public void distanceToPlane_givenPointOnPlane_returnsZero() { + Voxel pointOnPlane = new Voxel(0, 0, 0); + Int3D normalVector = new Int3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Int3D pointToTest = new Int3D(0, 0, 0); // Point is on the plane + + assertEquals(0, plane.distanceToPlane(pointToTest), 0.0001); + } + + @Test + public void distanceToPlane_givenPointOnNormalSideOfPlane_returnsCorrectPositiveDistance() { + Voxel pointOnPlane = new Voxel(0, 0, 0); + Int3D normalVector = new Int3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Int3D pointToTest = new Int3D(1, 1, 1); // Point is not on the plane + + assertEquals(1, plane.distanceToPlane(pointToTest), 0.0001); + } + + @Test + public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegativeDistance() { + Voxel pointOnPlane = new Voxel(0, 0, 0); + Int3D normalVector = new Int3D(1, 0, 0); + Plane plane = new Plane(pointOnPlane, normalVector); + + Int3D pointToTest = new Int3D(-1, -1, -1); // Point is not on the plane + + assertEquals(-1, plane.distanceToPlane(pointToTest), 0.0001); + } +} From 8430c2905f951616a2ac3dee2d841e27042f91c8 Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 10 Oct 2024 15:46:06 -0700 Subject: [PATCH 18/30] change plane to have point represented as voxel instead of int3d --- .../potts/env/location/PottsLocation.java | 2 +- src/arcade/potts/util/Plane.java | 11 ++++- test/arcade/potts/util/PlaneTest.java | 44 +++++++++++++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index 748a4272..a434fa6b 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -347,7 +347,7 @@ public Location split(MersenneTwisterFast random, connectVoxels(voxelsA, voxelsB, this, random); Voxel center = getCenter(); - if (plane.referencePoint.equals(new Int3D(center.x, center.y, center.z))) { + if (plane.referencePoint.equals(center)) { balanceVoxels(voxelsA, voxelsB, this, random); } diff --git a/src/arcade/potts/util/Plane.java b/src/arcade/potts/util/Plane.java index fea2f796..41b19cf3 100644 --- a/src/arcade/potts/util/Plane.java +++ b/src/arcade/potts/util/Plane.java @@ -34,10 +34,17 @@ public Plane(Voxel voxel, Int3D normalVector) { * the same side of the plane as the normal vector * and negative if it is on the opposite side. */ - public double distanceToPlane(Int3D p) { - return (p.getX() - referencePoint.x) * normalVector.getX() + public double signedDistanceToPlane(Int3D p) { + double dotProduct; + double normalVectorMagnitude; + + dotProduct = (p.getX() - referencePoint.x) * normalVector.getX() + (p.getY() - referencePoint.y) * normalVector.getY() + (p.getZ() - referencePoint.z) * normalVector.getZ(); + normalVectorMagnitude = Math.sqrt(normalVector.getX() * normalVector.getX() + + normalVector.getY() * normalVector.getY() + + normalVector.getZ() * normalVector.getZ()); + return dotProduct / normalVectorMagnitude; } /** diff --git a/test/arcade/potts/util/PlaneTest.java b/test/arcade/potts/util/PlaneTest.java index 321e4836..35f5b320 100644 --- a/test/arcade/potts/util/PlaneTest.java +++ b/test/arcade/potts/util/PlaneTest.java @@ -42,7 +42,7 @@ public void distanceToPlane_givenPointOnPlane_returnsZero() { Int3D pointToTest = new Int3D(0, 0, 0); // Point is on the plane - assertEquals(0, plane.distanceToPlane(pointToTest), 0.0001); + assertEquals(0, plane.signedDistanceToPlane(pointToTest), 0.0001); } @Test @@ -53,7 +53,7 @@ public void distanceToPlane_givenPointOnNormalSideOfPlane_returnsCorrectPositive Int3D pointToTest = new Int3D(1, 1, 1); // Point is not on the plane - assertEquals(1, plane.distanceToPlane(pointToTest), 0.0001); + assertEquals(1, plane.signedDistanceToPlane(pointToTest), 0.0001); } @Test @@ -64,6 +64,44 @@ public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegati Int3D pointToTest = new Int3D(-1, -1, -1); // Point is not on the plane - assertEquals(-1, plane.distanceToPlane(pointToTest), 0.0001); + assertEquals(-1, plane.signedDistanceToPlane(pointToTest), 0.0001); + } + + @Test + public void signedDistanceToPlane_givenPointOnAxis_returnsCorrectSignedDistance() { + Voxel point = new Voxel(0, 0, 0); + Int3D normalVector = new Int3D(0, 0, 1); + Plane plane = new Plane(point, normalVector); + + Int3D posTestPoint = new Int3D(0, 0, 5); + Int3D negTestPoint = new Int3D(0, 0, -5); + + assertEquals(5.0, plane.signedDistanceToPlane(posTestPoint), 0.001); + assertEquals(-5.0, plane.signedDistanceToPlane(negTestPoint), 0.001); + } + + @Test + public void signedDistanceToPlane_givenPointOffAxis_returnsCorrectSignedDistance() { + Voxel point = new Voxel(1, 1, 2); + Int3D normalVector = new Int3D(1, 2, 2); + Plane plane = new Plane(point, normalVector); + + Int3D postestPoint = new Int3D(2, 2, 5); + Int3D negtestPoint = new Int3D(0, 0, -1); + + assertEquals(3.0, plane.signedDistanceToPlane(postestPoint), 0.001); + assertEquals(-3.0, plane.signedDistanceToPlane(negtestPoint), 0.001); + } + + @Test + public void testHashCodeConsistency() { + // Two planes with the same point and normal vector should have the same hash code + Voxel point = new Voxel(1, 2, 3); + Int3D normalVector = new Int3D(4, 5, 6); + + Plane plane1 = new Plane(point, normalVector); + Plane plane2 = new Plane(point, normalVector); + + assertEquals(plane1.hashCode(), plane2.hashCode()); } } From 6e89218167f3191f74c8296460a9eb12c9339d5b Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 10 Oct 2024 15:56:07 -0700 Subject: [PATCH 19/30] changed signedDistance function to take voxel --- .../potts/env/location/PottsLocation.java | 9 +++++---- src/arcade/potts/util/Plane.java | 18 +++++++++--------- .../potts/env/location/PottsLocationTest.java | 16 ---------------- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index a434fa6b..a299cd32 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -346,8 +346,8 @@ public Location split(MersenneTwisterFast random, splitVoxels(plane, voxels, voxelsA, voxelsB, random); connectVoxels(voxelsA, voxelsB, this, random); - Voxel center = getCenter(); - if (plane.referencePoint.equals(center)) { + Voxel locCenter = getCenter(); + if (plane.referencePoint.equals(locCenter)) { balanceVoxels(voxelsA, voxelsB, this, random); } @@ -651,9 +651,10 @@ static void splitVoxels(Plane plane, ArrayList voxels, ArrayList voxelsA, ArrayList voxelsB, MersenneTwisterFast random) { for (Voxel voxel : voxels) { - if (plane.signedDistanceToPlane(new Int3D(voxel.x, voxel.y, voxel.z)) < 0) { + double distance = plane.signedDistanceToPlane(voxel); + if (distance < 0) { voxelsA.add(voxel); - } else if (plane.signedDistanceToPlane(new Int3D(voxel.x, voxel.y, voxel.z)) > 0) { + } else if (distance > 0) { voxelsB.add(voxel); } else { if (random.nextDouble() > 0.5) { diff --git a/src/arcade/potts/util/Plane.java b/src/arcade/potts/util/Plane.java index 41b19cf3..cf958848 100644 --- a/src/arcade/potts/util/Plane.java +++ b/src/arcade/potts/util/Plane.java @@ -10,10 +10,10 @@ public final class Plane { /** A point on the plane. */ public final Voxel referencePoint; - + /** The normal vector to the plane. */ public final Int3D normalVector; - + /** * Creates a plane from a point and a vector. * @@ -24,7 +24,7 @@ public Plane(Voxel voxel, Int3D normalVector) { this.referencePoint = voxel; this.normalVector = normalVector; } - + /** * Determines distance from a point to the plane. * @@ -34,19 +34,19 @@ public Plane(Voxel voxel, Int3D normalVector) { * the same side of the plane as the normal vector * and negative if it is on the opposite side. */ - public double signedDistanceToPlane(Int3D p) { + public double signedDistanceToPlane(Voxel p) { double dotProduct; double normalVectorMagnitude; - dotProduct = (p.getX() - referencePoint.x) * normalVector.getX() - + (p.getY() - referencePoint.y) * normalVector.getY() - + (p.getZ() - referencePoint.z) * normalVector.getZ(); + dotProduct = (p.x - referencePoint.x) * normalVector.getX() + + (p.y - referencePoint.y) * normalVector.getY() + + (p.z - referencePoint.z) * normalVector.getZ(); normalVectorMagnitude = Math.sqrt(normalVector.getX() * normalVector.getX() + normalVector.getY() * normalVector.getY() + normalVector.getZ() * normalVector.getZ()); return dotProduct / normalVectorMagnitude; } - + /** * Determines if two planes are equal. * @@ -61,7 +61,7 @@ public boolean equals(Object obj) { Plane other = (Plane) obj; return referencePoint.equals(other.referencePoint) && normalVector.equals(other.normalVector); } - + /** * Returns a hash code for the plane. * diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 5f87fca5..8868dcab 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -1367,10 +1367,6 @@ public void split_noOffsetsNoDirectionRandomDoubleZero_splitsVoxelsCorrectly() { PottsLocation loc = new PottsLocationMock(voxels); PottsLocation split = (PottsLocation) loc.split(randomDoubleZero); - // Verify that the total number of voxels remains the same - int totalVoxels = loc.voxels.size() + split.voxels.size(); - assertEquals(totalVoxels, voxels.size()); - locVoxels.sort(VOXEL_COMPARATOR); loc.voxels.sort(VOXEL_COMPARATOR); splitVoxels.sort(VOXEL_COMPARATOR); @@ -1418,10 +1414,6 @@ public void split_withOffsetsNoDirection_splitsVoxelsCorrectly() { // Call split PottsLocation splitLocation = (PottsLocation) location.split(randomDoubleZero, offsets); - // Verify the split occurred as expected - int totalVoxels = location.voxels.size() + splitLocation.voxels.size(); - assertEquals(totalVoxels, voxels.size()); - locVoxels.sort(VOXEL_COMPARATOR); location.voxels.sort(VOXEL_COMPARATOR); splitVoxels.sort(VOXEL_COMPARATOR); @@ -1473,10 +1465,6 @@ public void split_withOffsetsWithDirectionWithProbability_splitsVoxelsCorrectly( PottsLocation splitLocation = (PottsLocation) location.split(randomDoubleZero, offsets, Direction.POSITIVE_XY, probability); - // Verify the split occurred as expected - int totalVoxels = location.voxels.size() + splitLocation.voxels.size(); - assertEquals(totalVoxels, voxels.size()); - locVoxels.sort(VOXEL_COMPARATOR); location.voxels.sort(VOXEL_COMPARATOR); splitVoxels.sort(VOXEL_COMPARATOR); @@ -1595,10 +1583,6 @@ public void split_withOddAnglePlaneThroughPointAndProbabilityOne_splitsVoxelsCor // Call split PottsLocation split = (PottsLocation) loc.split(randomDoubleZero, plane, probability); - // Verify that the total number of voxels remains the same - int totalVoxels = loc.voxels.size() + split.voxels.size(); - assertEquals(voxels.size(), totalVoxels); - locVoxels.sort(VOXEL_COMPARATOR); loc.voxels.sort(VOXEL_COMPARATOR); splitVoxels.sort(VOXEL_COMPARATOR); From a095a9fd24659d871d0b119f394e9e264b1a8723 Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 10 Oct 2024 15:58:23 -0700 Subject: [PATCH 20/30] updated test --- test/arcade/potts/util/PlaneTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/arcade/potts/util/PlaneTest.java b/test/arcade/potts/util/PlaneTest.java index 35f5b320..d27a9670 100644 --- a/test/arcade/potts/util/PlaneTest.java +++ b/test/arcade/potts/util/PlaneTest.java @@ -40,7 +40,7 @@ public void distanceToPlane_givenPointOnPlane_returnsZero() { Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - Int3D pointToTest = new Int3D(0, 0, 0); // Point is on the plane + Voxel pointToTest = new Voxel(0, 0, 0); // Point is on the plane assertEquals(0, plane.signedDistanceToPlane(pointToTest), 0.0001); } @@ -51,7 +51,7 @@ public void distanceToPlane_givenPointOnNormalSideOfPlane_returnsCorrectPositive Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - Int3D pointToTest = new Int3D(1, 1, 1); // Point is not on the plane + Voxel pointToTest = new Voxel(1, 1, 1); // Point is not on the plane assertEquals(1, plane.signedDistanceToPlane(pointToTest), 0.0001); } @@ -62,7 +62,7 @@ public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegati Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - Int3D pointToTest = new Int3D(-1, -1, -1); // Point is not on the plane + Voxel pointToTest = new Voxel(-1, -1, -1); // Point is not on the plane assertEquals(-1, plane.signedDistanceToPlane(pointToTest), 0.0001); } @@ -73,8 +73,8 @@ public void signedDistanceToPlane_givenPointOnAxis_returnsCorrectSignedDistance( Int3D normalVector = new Int3D(0, 0, 1); Plane plane = new Plane(point, normalVector); - Int3D posTestPoint = new Int3D(0, 0, 5); - Int3D negTestPoint = new Int3D(0, 0, -5); + Voxel posTestPoint = new Voxel(0, 0, 5); + Voxel negTestPoint = new Voxel(0, 0, -5); assertEquals(5.0, plane.signedDistanceToPlane(posTestPoint), 0.001); assertEquals(-5.0, plane.signedDistanceToPlane(negTestPoint), 0.001); @@ -86,8 +86,8 @@ public void signedDistanceToPlane_givenPointOffAxis_returnsCorrectSignedDistance Int3D normalVector = new Int3D(1, 2, 2); Plane plane = new Plane(point, normalVector); - Int3D postestPoint = new Int3D(2, 2, 5); - Int3D negtestPoint = new Int3D(0, 0, -1); + Voxel postestPoint = new Voxel(2, 2, 5); + Voxel negtestPoint = new Voxel(0, 0, -1); assertEquals(3.0, plane.signedDistanceToPlane(postestPoint), 0.001); assertEquals(-3.0, plane.signedDistanceToPlane(negtestPoint), 0.001); From 25f5aa487f9c53aa7499fb97e23b002ca092a82c Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 10 Oct 2024 16:02:45 -0700 Subject: [PATCH 21/30] changed enum back, formatting fixes --- src/arcade/potts/env/location/PottsLocation.java | 3 +-- src/arcade/potts/util/Plane.java | 5 +++-- src/arcade/potts/util/PottsEnums.java | 4 +--- test/arcade/potts/env/location/PottsLocationTest.java | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index a299cd32..ad6729d5 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -4,7 +4,6 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedHashSet; -import sim.util.Int3D; import ec.util.MersenneTwisterFast; import arcade.core.env.location.Location; import arcade.core.env.location.LocationContainer; @@ -316,7 +315,7 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction, Double probability) { Voxel splitPoint = getOffset(offsets); - Plane divisionPlane = new Plane(splitPoint,direction.getVector()); + Plane divisionPlane = new Plane(splitPoint, direction.getVector()); return split(random, divisionPlane, probability); } diff --git a/src/arcade/potts/util/Plane.java b/src/arcade/potts/util/Plane.java index cf958848..fed28957 100644 --- a/src/arcade/potts/util/Plane.java +++ b/src/arcade/potts/util/Plane.java @@ -17,7 +17,7 @@ public final class Plane { /** * Creates a plane from a point and a vector. * - * @param point a point on the plane + * @param voxel a point on the plane * @param normalVector the normal vector to the plane */ public Plane(Voxel voxel, Int3D normalVector) { @@ -59,7 +59,8 @@ public boolean equals(Object obj) { return false; } Plane other = (Plane) obj; - return referencePoint.equals(other.referencePoint) && normalVector.equals(other.normalVector); + return referencePoint.equals(other.referencePoint) + && normalVector.equals(other.normalVector); } /** diff --git a/src/arcade/potts/util/PottsEnums.java b/src/arcade/potts/util/PottsEnums.java index 1f7655a4..bf2a1e12 100644 --- a/src/arcade/potts/util/PottsEnums.java +++ b/src/arcade/potts/util/PottsEnums.java @@ -230,9 +230,7 @@ public Int3D getVector() { * @return a random {@code Direction} */ public static Direction random(MersenneTwisterFast rng) { - Direction[] directions = values(); - // Exclude UNDEFINED from the random selection - return directions[rng.nextInt(directions.length - 1) + 1]; + return values()[rng.nextInt(values().length - 1) + 1]; } } } diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 8868dcab..86506982 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -5,8 +5,8 @@ import java.util.HashMap; import org.junit.BeforeClass; import org.junit.Test; -import arcade.potts.util.Plane; import sim.util.Int3D; +import arcade.potts.util.Plane; import ec.util.MersenneTwisterFast; import static org.junit.Assert.*; import static org.mockito.Mockito.*; From e8abcdf03baeb84da098b02297040e451c6b5e32 Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 10 Oct 2024 16:04:56 -0700 Subject: [PATCH 22/30] removing test.cass --- test.class | Bin 428 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test.class diff --git a/test.class b/test.class deleted file mode 100644 index f6683ce5178b0a2897796537481994d0b3e5d6c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 428 zcmZvZ&rZTX5XQfSN@=ZvAo!Pri%Bs?9suJ7H69u<)ZoEWiyN|pZb{ji_*i<-#Dfpu zLm6lAU`*J)4{In1RHxBX)SX3o(jCN8IW_{NGo_U| z7byCjk%KZE8?J|Sc>nC-^TNo4Txm{4jbI5aCs}KTinC977UMV*3&{O728s=KdjFYF_8ro>kz<6<_k%7#lTC@w! u9KS=nkPz6V$j7W5>|vjFwjNO_XPsBrwT(Aa{_Ol2K#^u_k>!AN0f#@|{#S7T From e4227fdc9f9ace033aa32517342dc682e266ae29 Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 10 Oct 2024 16:08:18 -0700 Subject: [PATCH 23/30] formatting fixes --- test/arcade/potts/env/location/PottsLocationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 86506982..465930e4 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -3,11 +3,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import ec.util.MersenneTwisterFast; import org.junit.BeforeClass; import org.junit.Test; import sim.util.Int3D; import arcade.potts.util.Plane; -import ec.util.MersenneTwisterFast; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import static arcade.core.ARCADETestUtilities.*; From 87bb9509ce6e312b129cc1728e36662cafca7445 Mon Sep 17 00:00:00 2001 From: jannetty Date: Thu, 10 Oct 2024 16:12:41 -0700 Subject: [PATCH 24/30] formatting fix --- test/arcade/potts/env/location/PottsLocationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 465930e4..65c879ac 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -3,10 +3,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import ec.util.MersenneTwisterFast; import org.junit.BeforeClass; import org.junit.Test; import sim.util.Int3D; +import ec.util.MersenneTwisterFast; import arcade.potts.util.Plane; import static org.junit.Assert.*; import static org.mockito.Mockito.*; From 2af086c5074b6c3c337db1e1d28099d8692139e4 Mon Sep 17 00:00:00 2001 From: "Sophia K. Jannetty" <76933289+Jannetty@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:43:25 -0700 Subject: [PATCH 25/30] Update src/arcade/potts/env/location/PottsLocation.java Co-authored-by: Jessica S. Yu <15913767+jessicasyu@users.noreply.github.com> --- src/arcade/potts/env/location/PottsLocation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index ad6729d5..2254cd43 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -638,7 +638,7 @@ Location separateVoxels(ArrayList voxelsA, ArrayList voxelsB, * The voxels are split into two lists based on their position relative to * the plane. Voxels on the plane are randomly assigned to one of the lists. * - * @param plane the plane to split the voxels along + * @param plane the plane to split the voxels along * @param voxels the list of voxels to split * @param voxelsA the container list for the first half of the split. * These voxels are on the side of the plane opposite the normal. From 157ea454207d8ae9d790898cd8af4c1c8a274e92 Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 11 Oct 2024 11:57:05 -0700 Subject: [PATCH 26/30] addressing Jess's comments. Normalizing plane normal vector. --- src/arcade/potts/env/location/Plane.java | 111 +++++++++++++++++ .../potts/env/location/PottsLocation.java | 47 +++---- src/arcade/potts/util/Plane.java | 78 ------------ src/arcade/potts/util/PottsEnums.java | 11 +- .../{util => env/location}/PlaneTest.java | 113 +++++++++++------ .../potts/env/location/PottsLocationTest.java | 115 +++++++----------- 6 files changed, 256 insertions(+), 219 deletions(-) create mode 100644 src/arcade/potts/env/location/Plane.java delete mode 100644 src/arcade/potts/util/Plane.java rename test/arcade/potts/{util => env/location}/PlaneTest.java (56%) diff --git a/src/arcade/potts/env/location/Plane.java b/src/arcade/potts/env/location/Plane.java new file mode 100644 index 00000000..92866874 --- /dev/null +++ b/src/arcade/potts/env/location/Plane.java @@ -0,0 +1,111 @@ +package arcade.potts.env.location; + +import sim.util.Double3D; +import sim.util.Int3D; +import arcade.potts.util.PottsEnums.Direction; + +/** + * A plane in 3D space. + */ + +public final class Plane { + /** A point on the plane. */ + public final Voxel referencePoint; + + /** The unit normal vector to the plane. */ + public final Double3D unitNormalVector; + + /** + * Creates a plane from a point and a vector. + * + * @param voxel a point on the plane + * @param normalVector the normal vector to the plane + */ + public Plane(Voxel voxel, Int3D normalVector) { + this.referencePoint = voxel; + this.unitNormalVector = scaleNormalVector(normalVector); + } + + /** + * Creates a plane from a point and a direction. + * + * @param voxel a point on the plane + * @param direction the direction of the plane + */ + public Plane(Voxel voxel, Direction direction) { + this(voxel, direction.vector); + } + + /** + * Determines the magnitude of the normal vector. + * + * @return the magnitude of the normal vector + */ + static public double getNormalVectorMagnitude(Int3D normalVector) { + return Math.sqrt(normalVector.getX() * normalVector.getX() + + normalVector.getY() * normalVector.getY() + + normalVector.getZ() * normalVector.getZ()); + } + + /** + * Scales the normal vector to a unit vector. + * + * @return the unit normal vector + */ + static public Double3D scaleNormalVector(Int3D normalVector) { + double magnitude = getNormalVectorMagnitude(normalVector); + double scaledX = normalVector.getX() / magnitude; + double scaledY = normalVector.getY() / magnitude; + double scaledZ = normalVector.getZ() / magnitude; + Double3D unitNormalVector = new Double3D(scaledX, scaledY, scaledZ); + return unitNormalVector; + } + + /** + * Determines distance from a point to the plane. + * + * The distance is positive if the point is on the same side of the plane + * as the normal vector and negative if it is on the opposite side. + * + * @param p the point + * @return the distance from the point to the plane. + * + */ + public double signedDistanceToPlane(Voxel point) { + double dotProduct = (point.x - referencePoint.x) * unitNormalVector.getX() + + (point.y - referencePoint.y) * unitNormalVector.getY() + + (point.z - referencePoint.z) * unitNormalVector.getZ(); + return dotProduct; + } + + /** + * Determines if two planes are equal. + * + * @param obj the plane to compare + * @return {@code true} if the planes are equal, {@code false} otherwise + */ + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + Plane other = (Plane) obj; + return referencePoint.equals(other.referencePoint) + && unitNormalVector.equals(other.unitNormalVector); + } + + /** + * Returns a hash code for the plane. + * + * @return a hash code for the plane + */ + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + referencePoint.hashCode(); + hash = 31 * hash + Double.hashCode(unitNormalVector.getX()); + hash = 31 * hash + Double.hashCode(unitNormalVector.getY()); + hash = 31 * hash + Double.hashCode(unitNormalVector.getZ()); + return hash; + } +} diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index 2254cd43..e1e0f267 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -8,7 +8,6 @@ import arcade.core.env.location.Location; import arcade.core.env.location.LocationContainer; import arcade.core.util.Utilities; -import arcade.potts.util.Plane; import static arcade.potts.util.PottsEnums.Direction; import static arcade.potts.util.PottsEnums.Region; @@ -272,9 +271,7 @@ public void update(int id, int[][][] ids, int[][][] regions) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random) { - Voxel center = getCenter(); - Direction splitDirection = getDirection(random); - Plane divisionPlane = new Plane(center, splitDirection.getVector()); + Plane divisionPlane = new Plane(getCenter(), getDirection(random)); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } @@ -291,20 +288,18 @@ public Location split(MersenneTwisterFast random) { * @return a location with the split voxels */ public Location split(MersenneTwisterFast random, ArrayList offsets) { - Voxel splitPoint = getOffset(offsets); - Direction splitDirection = getDirection(random); - Plane divisionPlane = new Plane(splitPoint, splitDirection.getVector()); + Plane divisionPlane = new Plane(getOffset(offsets), getDirection(random)); return split(random, divisionPlane, DEFAULT_SPLIT_SELECTION_PROBABILITY); } /** - * Splits location voxels into two lists with given offset, direction, and probability. + * Splits location voxels into two lists with given offset, direction, + * and probability. *

* The location is split at the point specified by offsets along the given * direction. The lists of locations are guaranteed to be connected. One of * the splits is assigned to the current location and the other is - * returned. One of the splits is assigned to the current location and the - * other returned with the given probability + * returned. * * @param random the seeded random number generator * @param offsets the percentage offset in each direction for split point @@ -314,22 +309,22 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { */ public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction, Double probability) { - Voxel splitPoint = getOffset(offsets); - Plane divisionPlane = new Plane(splitPoint, direction.getVector()); + Plane divisionPlane = new Plane(getOffset(offsets), direction.vector); return split(random, divisionPlane, probability); } /** * Splits location voxels into two lists. *

- * The location is split at the point specified by offsets along the given - * direction. One of the splits is assigned to the current location and the - * other is returned with the given probability. + * The location is split along the provided plane. One of the splits is + * assigned to the current location and the other is returned with the + * given probability. *

- * If offsets not are provided, the resulting lists are guaranteed to be - * connected, and generally will be balanced in size. If offsets is - * provided, the resulting lists are guaranteed to be connected but will not - * necessarily be balanced in size. + * If the plane of division is through the center of the location, the + * resulting lists are guaranteed to be connected, and generally will be + * balanced in size. If the plane of division is not through the center + * of the location, the resulting lists are guaranteed to be connected + * but will not necessarily be balanced in size. * * @param random the seeded random number generator * @param plane the plane of the split @@ -572,8 +567,8 @@ void updateCenter(int x, int y, int z, int change) { abstract ArrayList getSelected(Voxel focus, double n); /** - * Gets the direction of the slice through the location that - * has the smallest diameter. + * Gets the direction of the slice orthagonal to the direction with + * the smallest diameter. * * @param random the seeded random number generator * @return the direction of the slice @@ -633,17 +628,15 @@ Location separateVoxels(ArrayList voxelsA, ArrayList voxelsB, } /** - * Divides the voxels in the location into two lists along a given plane. + * Splits the voxels in the location into two lists along a given plane. *

* The voxels are split into two lists based on their position relative to * the plane. Voxels on the plane are randomly assigned to one of the lists. * - * @param plane the plane to split the voxels along + * @param plane the plane to split the voxels along * @param voxels the list of voxels to split - * @param voxelsA the container list for the first half of the split. - * These voxels are on the side of the plane opposite the normal. - * @param voxelsB the container list for the second half of the split. - * These voxels are on the side of the plane the normal points to. + * @param voxelsA list of voxels on side of plane the opposite the normal + * @param voxelsB list of voxels on side of plane the same as the normal * @param random the seeded random number generator */ static void splitVoxels(Plane plane, ArrayList voxels, diff --git a/src/arcade/potts/util/Plane.java b/src/arcade/potts/util/Plane.java deleted file mode 100644 index fed28957..00000000 --- a/src/arcade/potts/util/Plane.java +++ /dev/null @@ -1,78 +0,0 @@ -package arcade.potts.util; - -import sim.util.Int3D; -import arcade.potts.env.location.Voxel; - -/** - * A plane in 3D space. - */ - -public final class Plane { - /** A point on the plane. */ - public final Voxel referencePoint; - - /** The normal vector to the plane. */ - public final Int3D normalVector; - - /** - * Creates a plane from a point and a vector. - * - * @param voxel a point on the plane - * @param normalVector the normal vector to the plane - */ - public Plane(Voxel voxel, Int3D normalVector) { - this.referencePoint = voxel; - this.normalVector = normalVector; - } - - /** - * Determines distance from a point to the plane. - * - * @param p the point - * @return the distance from the point to the plane. - * The distance is positive if the point is on - * the same side of the plane as the normal vector - * and negative if it is on the opposite side. - */ - public double signedDistanceToPlane(Voxel p) { - double dotProduct; - double normalVectorMagnitude; - - dotProduct = (p.x - referencePoint.x) * normalVector.getX() - + (p.y - referencePoint.y) * normalVector.getY() - + (p.z - referencePoint.z) * normalVector.getZ(); - normalVectorMagnitude = Math.sqrt(normalVector.getX() * normalVector.getX() - + normalVector.getY() * normalVector.getY() - + normalVector.getZ() * normalVector.getZ()); - return dotProduct / normalVectorMagnitude; - } - - /** - * Determines if two planes are equal. - * - * @param obj the plane to compare - * @return {@code true} if the planes are equal, {@code false} otherwise - */ - @Override - public boolean equals(Object obj) { - if (obj == null || getClass() != obj.getClass()) { - return false; - } - Plane other = (Plane) obj; - return referencePoint.equals(other.referencePoint) - && normalVector.equals(other.normalVector); - } - - /** - * Returns a hash code for the plane. - * - * @return a hash code for the plane - */ - @Override - public int hashCode() { - int hash = 7; - hash = 97 * hash + (this.referencePoint != null ? this.referencePoint.hashCode() : 0); - hash = 97 * hash + (this.normalVector != null ? this.normalVector.hashCode() : 0); - return hash; - } -} diff --git a/src/arcade/potts/util/PottsEnums.java b/src/arcade/potts/util/PottsEnums.java index bf2a1e12..b8dada0a 100644 --- a/src/arcade/potts/util/PottsEnums.java +++ b/src/arcade/potts/util/PottsEnums.java @@ -203,7 +203,7 @@ public enum Direction { NEGATIVE_ZX(new Int3D(-1, 0, -1)); /** The normal vector of the plane in this direction. */ - private final Int3D vector; + public final Int3D vector; /** * Creates a new {@code Direction} with the given vector. @@ -214,15 +214,6 @@ public enum Direction { this.vector = vector; } - /** - * Returns the vector associated with this direction. - * - * @return the associated {@code Int3D}, or {@code null} if undefined - */ - public Int3D getVector() { - return vector; - } - /** * Randomly selects a {@code Direction}, excluding {@code UNDEFINED}. * diff --git a/test/arcade/potts/util/PlaneTest.java b/test/arcade/potts/env/location/PlaneTest.java similarity index 56% rename from test/arcade/potts/util/PlaneTest.java rename to test/arcade/potts/env/location/PlaneTest.java index d27a9670..a5fbe842 100644 --- a/test/arcade/potts/util/PlaneTest.java +++ b/test/arcade/potts/env/location/PlaneTest.java @@ -1,72 +1,114 @@ -package arcade.potts.util; +package arcade.potts.env.location; import org.junit.Test; +import sim.util.Double3D; import sim.util.Int3D; -import arcade.potts.env.location.Voxel; import static org.junit.Assert.*; public class PlaneTest { - + static final double EPSILON = 0.0001; + + @Test + public void constructor_givenPointAndUnitVector_returnsCorrectPlane() { + Voxel point = new Voxel(1, 2, 3); + Int3D normalVector = new Int3D(1, 0, 0); + Plane plane = new Plane(point, normalVector); + assertEquals(point, plane.referencePoint); + assertEquals(normalVector, plane.unitNormalVector); + } + @Test public void constructor_givenPointAndVector_returnsCorrectPlane() { Voxel point = new Voxel(1, 2, 3); - Int3D normalVector = new Int3D(4, 5, 6); - + Int3D normalVector = new Int3D(2, 2, 1); + Plane plane = new Plane(point, normalVector); - + + double expectedX = normalVector.getX()/3.0; + double expectedY = normalVector.getY()/3.0; + double expectedZ = normalVector.getZ()/3.0; + Double3D expectedUnitNormal = new Double3D(expectedX,expectedY,expectedZ); assertEquals(point, plane.referencePoint); - assertEquals(normalVector, plane.normalVector); + assertEquals(expectedUnitNormal, plane.unitNormalVector); } - + + @Test + public void getNormalVectorMagnitude_givenNormalVector_returnsCorrectMagnitude() { + double magnitude = Plane.getNormalVectorMagnitude(new Int3D(1, 2, 2)); + assertEquals(3, magnitude, EPSILON); + } + + @Test + public void getNormalVectorMagnitude_givenUnitVector_returnsOne() { + double magnitude = Plane.getNormalVectorMagnitude(new Int3D(1, 0, 0)); + assertEquals(1, magnitude, EPSILON); + } + + @Test + public void scaleNormalVector_givenUnitVector_returnsSameVector() { + Int3D normalVector = new Int3D(1, 0, 0); + Double3D unitNormalVector = Plane.scaleNormalVector(normalVector); + assertEquals(normalVector, unitNormalVector); + } + + @Test + public void scaleNormalVector_givenNonUnitVector_returnsUnitVector() { + Double3D unitNormalVector = Plane.scaleNormalVector(new Int3D(1, 2, 2)); + Double x = 1.0 / 3.0; + Double y = 2.0 / 3.0; + Double z = 2.0 / 3.0; + assertEquals(new Double3D(x, y, z), unitNormalVector); + } + @Test public void equals_givenDifferentPlane_returnsFalse() { Plane plane1 = new Plane(new Voxel(1, 2, 3), new Int3D(4, 5, 6)); Plane plane2 = new Plane(new Voxel(4, 5, 6), new Int3D(7, 8, 9)); - - assertFalse(plane1.equals(plane2)); + + assertNotEquals(plane1, plane2); } - + @Test public void equals_givenSamePlane_returnsTrue() { Plane plane1 = new Plane(new Voxel(1, 2, 3), new Int3D(4, 5, 6)); Plane plane2 = new Plane(new Voxel(1, 2, 3), new Int3D(4, 5, 6)); - - assertTrue(plane1.equals(plane2)); + + assertEquals(plane1, plane2); } - + @Test public void distanceToPlane_givenPointOnPlane_returnsZero() { Voxel pointOnPlane = new Voxel(0, 0, 0); Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - - Voxel pointToTest = new Voxel(0, 0, 0); // Point is on the plane - - assertEquals(0, plane.signedDistanceToPlane(pointToTest), 0.0001); + + Voxel pointToTest = new Voxel(0, 0, 0); + + assertEquals(0, plane.signedDistanceToPlane(pointToTest), EPSILON); } - + @Test public void distanceToPlane_givenPointOnNormalSideOfPlane_returnsCorrectPositiveDistance() { Voxel pointOnPlane = new Voxel(0, 0, 0); Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - - Voxel pointToTest = new Voxel(1, 1, 1); // Point is not on the plane - - assertEquals(1, plane.signedDistanceToPlane(pointToTest), 0.0001); + + Voxel pointToTest = new Voxel(1, 1, 1); + + assertEquals(1, plane.signedDistanceToPlane(pointToTest), EPSILON); } - + @Test public void distanceToPlane_givenPointOnOppositeSideOfPlane_returnsCorrectNegativeDistance() { Voxel pointOnPlane = new Voxel(0, 0, 0); Int3D normalVector = new Int3D(1, 0, 0); Plane plane = new Plane(pointOnPlane, normalVector); - - Voxel pointToTest = new Voxel(-1, -1, -1); // Point is not on the plane - - assertEquals(-1, plane.signedDistanceToPlane(pointToTest), 0.0001); + + Voxel pointToTest = new Voxel(-1, -1, -1); + + assertEquals(-1, plane.signedDistanceToPlane(pointToTest), EPSILON); } - + @Test public void signedDistanceToPlane_givenPointOnAxis_returnsCorrectSignedDistance() { Voxel point = new Voxel(0, 0, 0); @@ -76,8 +118,8 @@ public void signedDistanceToPlane_givenPointOnAxis_returnsCorrectSignedDistance( Voxel posTestPoint = new Voxel(0, 0, 5); Voxel negTestPoint = new Voxel(0, 0, -5); - assertEquals(5.0, plane.signedDistanceToPlane(posTestPoint), 0.001); - assertEquals(-5.0, plane.signedDistanceToPlane(negTestPoint), 0.001); + assertEquals(5.0, plane.signedDistanceToPlane(posTestPoint), EPSILON); + assertEquals(-5.0, plane.signedDistanceToPlane(negTestPoint), EPSILON); } @Test @@ -89,13 +131,12 @@ public void signedDistanceToPlane_givenPointOffAxis_returnsCorrectSignedDistance Voxel postestPoint = new Voxel(2, 2, 5); Voxel negtestPoint = new Voxel(0, 0, -1); - assertEquals(3.0, plane.signedDistanceToPlane(postestPoint), 0.001); - assertEquals(-3.0, plane.signedDistanceToPlane(negtestPoint), 0.001); + assertEquals(3.0, plane.signedDistanceToPlane(postestPoint), EPSILON); + assertEquals(-3.0, plane.signedDistanceToPlane(negtestPoint), EPSILON); } - + @Test - public void testHashCodeConsistency() { - // Two planes with the same point and normal vector should have the same hash code + public void hashCode_equalObjects_returnsSameCode() { Voxel point = new Voxel(1, 2, 3); Int3D normalVector = new Int3D(4, 5, 6); diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 65c879ac..8531c377 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -7,7 +7,6 @@ import org.junit.Test; import sim.util.Int3D; import ec.util.MersenneTwisterFast; -import arcade.potts.util.Plane; import static org.junit.Assert.*; import static org.mockito.Mockito.*; import static arcade.core.ARCADETestUtilities.*; @@ -831,7 +830,7 @@ public void splitVoxels_YZPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane yzPlane = new Plane(center, Direction.YZ_PLANE.getVector()); + Plane yzPlane = new Plane(center, Direction.YZ_PLANE.vector); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -862,7 +861,7 @@ public void splitVoxels_ZXPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane zxPlane = new Plane(center, Direction.ZX_PLANE.getVector()); + Plane zxPlane = new Plane(center, Direction.ZX_PLANE.vector); PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -888,7 +887,7 @@ public void splitVoxels_XYPlaneDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane xyPlane = new Plane(center, Direction.XY_PLANE.getVector()); + Plane xyPlane = new Plane(center, Direction.XY_PLANE.vector); PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -914,7 +913,7 @@ public void splitVoxels_negativeXYDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeXYPlane = new Plane(center, Direction.NEGATIVE_XY.getVector()); + Plane negativeXYPlane = new Plane(center, Direction.NEGATIVE_XY.vector); PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -940,7 +939,7 @@ public void splitVoxels_positiveXYDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveXYPlane = new Plane(center, Direction.POSITIVE_XY.getVector()); + Plane positiveXYPlane = new Plane(center, Direction.POSITIVE_XY.vector); PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -966,7 +965,7 @@ public void splitVoxels_negativeYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeYZPlane = new Plane(center, Direction.NEGATIVE_YZ.getVector()); + Plane negativeYZPlane = new Plane(center, Direction.NEGATIVE_YZ.vector); PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -992,7 +991,7 @@ public void splitVoxels_positiveYZDirectionRandomZero_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveYZPlane = new Plane(center, Direction.POSITIVE_YZ.getVector()); + Plane positiveYZPlane = new Plane(center, Direction.POSITIVE_YZ.vector); PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1018,7 +1017,7 @@ public void splitVoxels_negativeZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeZXPlane = new Plane(center, Direction.NEGATIVE_ZX.getVector()); + Plane negativeZXPlane = new Plane(center, Direction.NEGATIVE_ZX.vector); PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1044,7 +1043,7 @@ public void splitVoxels_positiveZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveZXPlane = new Plane(center, Direction.POSITIVE_ZX.getVector()); + Plane positiveZXPlane = new Plane(center, Direction.POSITIVE_ZX.vector); PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); @@ -1070,7 +1069,7 @@ public void splitVoxels_YZPlaneDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane yzPlane = new Plane(center, Direction.YZ_PLANE.getVector()); + Plane yzPlane = new Plane(center, Direction.YZ_PLANE.vector); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1096,7 +1095,7 @@ public void splitVoxels_ZXPlaneDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane zxPlane = new Plane(center, Direction.ZX_PLANE.getVector()); + Plane zxPlane = new Plane(center, Direction.ZX_PLANE.vector); PottsLocation.splitVoxels(zxPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1122,7 +1121,7 @@ public void splitVoxels_XYPlaneDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane xyPlane = new Plane(center, Direction.XY_PLANE.getVector()); + Plane xyPlane = new Plane(center, Direction.XY_PLANE.vector); PottsLocation.splitVoxels(xyPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1148,7 +1147,7 @@ public void splitVoxels_negativeXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeXYPlane = new Plane(center, Direction.NEGATIVE_XY.getVector()); + Plane negativeXYPlane = new Plane(center, Direction.NEGATIVE_XY.vector); PottsLocation.splitVoxels(negativeXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1174,7 +1173,7 @@ public void splitVoxels_positiveXYDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveXYPlane = new Plane(center, Direction.POSITIVE_XY.getVector()); + Plane positiveXYPlane = new Plane(center, Direction.POSITIVE_XY.vector); PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1200,7 +1199,7 @@ public void splitVoxels_negativeYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeYZPlane = new Plane(center, Direction.NEGATIVE_YZ.getVector()); + Plane negativeYZPlane = new Plane(center, Direction.NEGATIVE_YZ.vector); PottsLocation.splitVoxels(negativeYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1226,7 +1225,7 @@ public void splitVoxels_positiveYZDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveYZPlane = new Plane(center, Direction.POSITIVE_YZ.getVector()); + Plane positiveYZPlane = new Plane(center, Direction.POSITIVE_YZ.vector); PottsLocation.splitVoxels(positiveYZPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1252,7 +1251,7 @@ public void splitVoxels_negativeZXDirectionRandomOne_updatesLists() { voxelsASplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane negativeZXPlane = new Plane(center, Direction.NEGATIVE_ZX.getVector()); + Plane negativeZXPlane = new Plane(center, Direction.NEGATIVE_ZX.vector); PottsLocation.splitVoxels(negativeZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1278,7 +1277,7 @@ public void splitVoxels_positiveZXDirectionRandomOne_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane positiveZXPlane = new Plane(center, Direction.POSITIVE_ZX.getVector()); + Plane positiveZXPlane = new Plane(center, Direction.POSITIVE_ZX.vector); PottsLocation.splitVoxels(positiveZXPlane, voxels, voxelsA, voxelsB, randomDoubleOne); assertEquals(voxelsASplit, voxelsA); @@ -1337,9 +1336,9 @@ public void separateVoxels_validLists_updatesCenter() { assertEquals(1. / 3, split.cy, EPSILON); assertEquals(3. / 3, split.cz, EPSILON); } - + @Test - public void split_noOffsetsNoDirectionRandomDoubleZero_splitsVoxelsCorrectly() { + public void split_noOffsetsNoDirection_splitsVoxelsCorrectly() { ArrayList voxels = new ArrayList<>(); // Create a 2x2x2 cuboid of voxels @@ -1350,10 +1349,7 @@ public void split_noOffsetsNoDirectionRandomDoubleZero_splitsVoxelsCorrectly() { } } } - // Only diameter in mock is YZ plane, so plane of division will be ZX plane - // Expected voxels in splitVoxels: y >= 1, including the plane where y = 1 - // (because of randomDoubleZero as RNG) - // Expected voxels in locVoxels: y < 1 + ArrayList splitVoxels = new ArrayList<>(); ArrayList locVoxels = new ArrayList<>(); for (Voxel voxel : voxels) { @@ -1363,16 +1359,15 @@ public void split_noOffsetsNoDirectionRandomDoubleZero_splitsVoxelsCorrectly() { locVoxels.add(voxel); } } - + PottsLocation loc = new PottsLocationMock(voxels); PottsLocation split = (PottsLocation) loc.split(randomDoubleZero); - + locVoxels.sort(VOXEL_COMPARATOR); loc.voxels.sort(VOXEL_COMPARATOR); splitVoxels.sort(VOXEL_COMPARATOR); split.voxels.sort(VOXEL_COMPARATOR); - - // Verify that the voxels were split correctly + assertEquals(locVoxels, loc.voxels); assertEquals(splitVoxels, split.voxels); } @@ -1382,7 +1377,6 @@ public void split_withOffsetsNoDirection_splitsVoxelsCorrectly() { ArrayList voxels = new ArrayList<>(); ArrayList locVoxels = new ArrayList<>(); ArrayList splitVoxels = new ArrayList<>(); - // Create a 5x5x5 cuboid of voxels for (int x = 0; x < 5; x++) { @@ -1392,15 +1386,12 @@ public void split_withOffsetsNoDirection_splitsVoxelsCorrectly() { } } } - - // Only diameter in mock is YZ plane, so plane of division will be ZX plane + ArrayList offsets = new ArrayList<>(); offsets.add(20); // split centered at x = 1 offsets.add(20); // split centered at y = 1 offsets.add(20); // split centered at x = 1 - - // expected locVoxels: y >= 1 - // expected splitVoxels: y < 1 + for (Voxel voxel : voxels) { if (voxel.y >= 1) { splitVoxels.add(voxel); @@ -1408,18 +1399,15 @@ public void split_withOffsetsNoDirection_splitsVoxelsCorrectly() { locVoxels.add(voxel); } } - + PottsLocation location = new PottsLocationMock(voxels); - - // Call split PottsLocation splitLocation = (PottsLocation) location.split(randomDoubleZero, offsets); - + locVoxels.sort(VOXEL_COMPARATOR); location.voxels.sort(VOXEL_COMPARATOR); splitVoxels.sort(VOXEL_COMPARATOR); splitLocation.voxels.sort(VOXEL_COMPARATOR); - - // Verify that the voxels were split correctly + assertEquals(locVoxels, location.voxels); assertEquals(splitVoxels, splitLocation.voxels); } @@ -1429,7 +1417,6 @@ public void split_withOffsetsWithDirectionWithProbability_splitsVoxelsCorrectly( ArrayList voxels = new ArrayList<>(); ArrayList locVoxels = new ArrayList<>(); ArrayList splitVoxels = new ArrayList<>(); - // Create a 5x5x5 cuboid of voxels for (int x = 0; x < 5; x++) { @@ -1439,18 +1426,16 @@ public void split_withOffsetsWithDirectionWithProbability_splitsVoxelsCorrectly( } } } - + ArrayList offsets = new ArrayList<>(); offsets.add(50); // split centered at x = 2 offsets.add(75); // split centered at y = 3 offsets.add(100); // split centered at z = 1 - - // expected locVoxels: x - y + 1 >= 0 - // expected splitVoxels: x - y + 1 < 0 + for (Voxel voxel : voxels) { if (voxel.x - voxel.y + 1 > 0) { locVoxels.add(voxel); - } else if (voxel.x - voxel.y + 1 < 0) { + } else if ((voxel.x - voxel.y + 1) <= 0) { splitVoxels.add(voxel); } else { // distance == 0 @@ -1458,20 +1443,18 @@ public void split_withOffsetsWithDirectionWithProbability_splitsVoxelsCorrectly( splitVoxels.add(voxel); } } - + PottsLocation location = new PottsLocationMock(voxels); double probability = 0.5; - // Call split PottsLocation splitLocation = (PottsLocation) location.split(randomDoubleZero, offsets, Direction.POSITIVE_XY, probability); - + locVoxels.sort(VOXEL_COMPARATOR); location.voxels.sort(VOXEL_COMPARATOR); splitVoxels.sort(VOXEL_COMPARATOR); splitLocation.voxels.sort(VOXEL_COMPARATOR); - - // Verify that the voxels were split correctly - //assertEquals(locVoxels, location.voxels); + + assertEquals(locVoxels, location.voxels); assertEquals(splitVoxels, splitLocation.voxels); } @@ -1544,13 +1527,13 @@ public void split_withOffsetsWithZXDirectionWithProbability_splitsVoxelsCorrectl assertEquals(locVoxels, loc.voxels); assertEquals(splitVoxels, split.voxels); } - + @Test - public void split_withOddAnglePlaneThroughPointAndProbabilityOne_splitsVoxelsCorrectly() { + public void split_withOddAnglePlaneThroughPoint_splitsVoxelsCorrectly() { ArrayList voxels = new ArrayList<>(); ArrayList locVoxels = new ArrayList<>(); ArrayList splitVoxels = new ArrayList<>(); - + // Create a 3x3x3 grid of voxels (total of 27 voxels) for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { @@ -1559,36 +1542,32 @@ public void split_withOddAnglePlaneThroughPointAndProbabilityOne_splitsVoxelsCor } } } - + // Plane with normal vector (1, 2, 3) passing through point (1, 2, 1) // Plane equation: x + 2y + 3z = 8 Voxel planePoint = new Voxel(1, 2, 1); Int3D normalVector = new Int3D(1, 2, 3); Plane plane = new Plane(planePoint, normalVector); - - // Expected locVoxels: x + 2y + 3z < 8 - // Expected splitVoxels: x + 2y + 3z >= 8 + for (Voxel voxel : voxels) { int value = voxel.x + 2 * voxel.y + 3 * voxel.z; if (value < 8) { - locVoxels.add(voxel); // Voxels opposite the normal vector + locVoxels.add(voxel); } else { - splitVoxels.add(voxel); // Voxels on the normal vector side and on the plane + splitVoxels.add(voxel); } } - + PottsLocation loc = new PottsLocationMock(voxels); double probability = 1.0; - - // Call split + PottsLocation split = (PottsLocation) loc.split(randomDoubleZero, plane, probability); - + locVoxels.sort(VOXEL_COMPARATOR); loc.voxels.sort(VOXEL_COMPARATOR); splitVoxels.sort(VOXEL_COMPARATOR); split.voxels.sort(VOXEL_COMPARATOR); - - // Verify that the voxels were split correctly + assertEquals(locVoxels, loc.voxels); assertEquals(splitVoxels, split.voxels); } From c728a392a504494e60f9f7eed68c14ebb5888ce1 Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 11 Oct 2024 12:02:23 -0700 Subject: [PATCH 27/30] formatting fixes --- src/arcade/potts/env/location/Plane.java | 10 ++++++---- test/arcade/potts/env/location/PlaneTest.java | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/arcade/potts/env/location/Plane.java b/src/arcade/potts/env/location/Plane.java index 92866874..98dd1d6c 100644 --- a/src/arcade/potts/env/location/Plane.java +++ b/src/arcade/potts/env/location/Plane.java @@ -39,9 +39,10 @@ public Plane(Voxel voxel, Direction direction) { /** * Determines the magnitude of the normal vector. * + * @param normalVector the normal vector * @return the magnitude of the normal vector */ - static public double getNormalVectorMagnitude(Int3D normalVector) { + static double getNormalVectorMagnitude(Int3D normalVector) { return Math.sqrt(normalVector.getX() * normalVector.getX() + normalVector.getY() * normalVector.getY() + normalVector.getZ() * normalVector.getZ()); @@ -50,9 +51,10 @@ static public double getNormalVectorMagnitude(Int3D normalVector) { /** * Scales the normal vector to a unit vector. * + * @param normalVector the normal vector * @return the unit normal vector */ - static public Double3D scaleNormalVector(Int3D normalVector) { + static Double3D scaleNormalVector(Int3D normalVector) { double magnitude = getNormalVectorMagnitude(normalVector); double scaledX = normalVector.getX() / magnitude; double scaledY = normalVector.getY() / magnitude; @@ -67,8 +69,8 @@ static public Double3D scaleNormalVector(Int3D normalVector) { * The distance is positive if the point is on the same side of the plane * as the normal vector and negative if it is on the opposite side. * - * @param p the point - * @return the distance from the point to the plane. + * @param point the point + * @return the distance from the point to the plane. * */ public double signedDistanceToPlane(Voxel point) { diff --git a/test/arcade/potts/env/location/PlaneTest.java b/test/arcade/potts/env/location/PlaneTest.java index a5fbe842..dcf0ee3d 100644 --- a/test/arcade/potts/env/location/PlaneTest.java +++ b/test/arcade/potts/env/location/PlaneTest.java @@ -24,10 +24,10 @@ public void constructor_givenPointAndVector_returnsCorrectPlane() { Plane plane = new Plane(point, normalVector); - double expectedX = normalVector.getX()/3.0; - double expectedY = normalVector.getY()/3.0; - double expectedZ = normalVector.getZ()/3.0; - Double3D expectedUnitNormal = new Double3D(expectedX,expectedY,expectedZ); + double expectedX = normalVector.getX() / 3.0; + double expectedY = normalVector.getY() / 3.0; + double expectedZ = normalVector.getZ() / 3.0; + Double3D expectedUnitNormal = new Double3D(expectedX, expectedY, expectedZ); assertEquals(point, plane.referencePoint); assertEquals(expectedUnitNormal, plane.unitNormalVector); } From af59ba909bf685f7b2247ae6267de644e13e4fcc Mon Sep 17 00:00:00 2001 From: jannetty Date: Fri, 11 Oct 2024 12:04:53 -0700 Subject: [PATCH 28/30] added a few white spaces --- .../potts/env/location/PottsLocationTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index 8531c377..dbfd71c4 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -828,7 +828,7 @@ public void splitVoxels_YZPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - + Voxel center = loc.getCenter(); Plane yzPlane = new Plane(center, Direction.YZ_PLANE.vector); @@ -859,7 +859,7 @@ public void splitVoxels_ZXPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - + Voxel center = loc.getCenter(); Plane zxPlane = new Plane(center, Direction.ZX_PLANE.vector); @@ -885,7 +885,7 @@ public void splitVoxels_XYPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - + Voxel center = loc.getCenter(); Plane xyPlane = new Plane(center, Direction.XY_PLANE.vector); @@ -911,7 +911,7 @@ public void splitVoxels_negativeXYDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - + Voxel center = loc.getCenter(); Plane negativeXYPlane = new Plane(center, Direction.NEGATIVE_XY.vector); @@ -937,10 +937,10 @@ public void splitVoxels_positiveXYDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - + Voxel center = loc.getCenter(); Plane positiveXYPlane = new Plane(center, Direction.POSITIVE_XY.vector); - + PottsLocation.splitVoxels(positiveXYPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA); assertEquals(voxelsBSplit, voxelsB); @@ -963,7 +963,7 @@ public void splitVoxels_negativeYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - + Voxel center = loc.getCenter(); Plane negativeYZPlane = new Plane(center, Direction.NEGATIVE_YZ.vector); @@ -989,7 +989,7 @@ public void splitVoxels_positiveYZDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsBSplit.add(new Voxel(2, 2, 2)); voxelsASplit.add(new Voxel(2, 2, 0)); - + Voxel center = loc.getCenter(); Plane positiveYZPlane = new Plane(center, Direction.POSITIVE_YZ.vector); @@ -1015,7 +1015,7 @@ public void splitVoxels_negativeZXDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(1, 1, 1)); voxelsASplit.add(new Voxel(2, 2, 2)); voxelsBSplit.add(new Voxel(2, 2, 0)); - + Voxel center = loc.getCenter(); Plane negativeZXPlane = new Plane(center, Direction.NEGATIVE_ZX.vector); From ee9897ce1f5a1e574cc0ef00c7cabdf48710960c Mon Sep 17 00:00:00 2001 From: "Sophia K. Jannetty" <76933289+Jannetty@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:32:34 -0700 Subject: [PATCH 29/30] Update src/arcade/potts/env/location/PottsLocation.java Co-authored-by: Jessica S. Yu <15913767+jessicasyu@users.noreply.github.com> --- src/arcade/potts/env/location/PottsLocation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arcade/potts/env/location/PottsLocation.java b/src/arcade/potts/env/location/PottsLocation.java index e1e0f267..7a39cfda 100644 --- a/src/arcade/potts/env/location/PottsLocation.java +++ b/src/arcade/potts/env/location/PottsLocation.java @@ -309,7 +309,7 @@ public Location split(MersenneTwisterFast random, ArrayList offsets) { */ public Location split(MersenneTwisterFast random, ArrayList offsets, Direction direction, Double probability) { - Plane divisionPlane = new Plane(getOffset(offsets), direction.vector); + Plane divisionPlane = new Plane(getOffset(offsets), direction); return split(random, divisionPlane, probability); } From e9bdd349caa8cf41f9435a1fd77c51fb978de787 Mon Sep 17 00:00:00 2001 From: "Sophia K. Jannetty" <76933289+Jannetty@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:32:41 -0700 Subject: [PATCH 30/30] Update test/arcade/potts/env/location/PottsLocationTest.java Co-authored-by: Jessica S. Yu <15913767+jessicasyu@users.noreply.github.com> --- test/arcade/potts/env/location/PottsLocationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/arcade/potts/env/location/PottsLocationTest.java b/test/arcade/potts/env/location/PottsLocationTest.java index dbfd71c4..3474e5d3 100644 --- a/test/arcade/potts/env/location/PottsLocationTest.java +++ b/test/arcade/potts/env/location/PottsLocationTest.java @@ -830,7 +830,7 @@ public void splitVoxels_YZPlaneDirectionRandomZero_updatesLists() { voxelsBSplit.add(new Voxel(2, 2, 0)); Voxel center = loc.getCenter(); - Plane yzPlane = new Plane(center, Direction.YZ_PLANE.vector); + Plane yzPlane = new Plane(center, Direction.YZ_PLANE); PottsLocation.splitVoxels(yzPlane, voxels, voxelsA, voxelsB, randomDoubleZero); assertEquals(voxelsASplit, voxelsA);