From b892f12788c66be1f8f9cf994529040e7855c68e Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Thu, 5 Mar 2026 22:31:27 +0100 Subject: [PATCH 1/4] feat(shape): add intersect inheritance --- .../net/onelitefeather/coris/shape/Shape.java | 6 ++- .../intersect/CuboidShapeIntersectTest.java | 50 +++++++++++++++++++ .../intersect/PointShapeIntersectTest.java | 4 ++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java create mode 100644 src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java diff --git a/src/main/java/net/onelitefeather/coris/shape/Shape.java b/src/main/java/net/onelitefeather/coris/shape/Shape.java index 22a1e57..f8b3539 100644 --- a/src/main/java/net/onelitefeather/coris/shape/Shape.java +++ b/src/main/java/net/onelitefeather/coris/shape/Shape.java @@ -1,5 +1,7 @@ package net.onelitefeather.coris.shape; +import net.minestom.server.coordinate.Point; +import net.onelitefeather.coris.util.Intersect; import org.jetbrains.annotations.ApiStatus; /** @@ -8,9 +10,9 @@ * The shape is a 2D or 3D representation of the area. * * @author theEvilReaper - * @version 1.2.0 + * @version 1.3.0 * @since 0.1.0 */ @ApiStatus.Experimental -public interface Shape extends Comparable { +public interface Shape extends Comparable, Intersect { } diff --git a/src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java b/src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java new file mode 100644 index 0000000..a26dba1 --- /dev/null +++ b/src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java @@ -0,0 +1,50 @@ +package net.onelitefeather.coris.shape; + +import net.minestom.server.coordinate.Vec; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class CuboidShapeIntersectTest { + + private static final CuboidShape SHAPE = new CuboidShape(new Vec(0, 0, 0), new Vec(5, 5, 5)); + + static Stream intersect3DProvider() { + return Stream.of( + Arguments.of(new Vec(2, 2, 2), true, "Inside shape"), + Arguments.of(new Vec(0, 0, 0), true, "On start border"), + Arguments.of(new Vec(5, 5, 5), true, "On end border"), + Arguments.of(new Vec(6, 6, 6), false, "Outside shape"), + Arguments.of(new Vec(-1, 2, 2), false, "Negative X outside"), + Arguments.of(new Vec(2, 6, 2), false, "Outside only Y") + ); + } + + static Stream intersect2DProvider() { + return Stream.of( + Arguments.of(new Vec(2, 99, 2), true, "Inside, Y ignored"), + Arguments.of(new Vec(0, 0, 0), true, "On start border"), + Arguments.of(new Vec(5, 0, 5), true, "On end border XZ"), + Arguments.of(new Vec(6, 2, 2), false, "Outside X"), + Arguments.of(new Vec(2, 2, 6), false, "Outside Z"), + Arguments.of(new Vec(2, 999, 2), true, "Large Y ignored"), + Arguments.of(new Vec(2, -999, 2), true, "Negative Y ignored") + ); + } + + @ParameterizedTest(name = "{2}") + @MethodSource("intersect3DProvider") + void testIntersect3D(Vec position, boolean expected, String description) { + assertEquals(expected, SHAPE.intersect3D(position)); + } + + @ParameterizedTest(name = "{2}") + @MethodSource("intersect2DProvider") + void testIntersect2D(Vec position, boolean expected, String description) { + assertEquals(expected, SHAPE.intersect2D(position)); + } +} diff --git a/src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java b/src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java new file mode 100644 index 0000000..bfaf37c --- /dev/null +++ b/src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java @@ -0,0 +1,4 @@ +package net.onelitefeather.coris.shape; + +public class PointShapeIntersectTest { +} From f177ccdb8a848275cf1d92f23a410a45c793544a Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Thu, 5 Mar 2026 22:31:44 +0100 Subject: [PATCH 2/4] feat(shape): add intersect implementation --- .../coris/shape/CuboidShape.java | 26 ++++++++++++++++++- .../coris/shape/PointShape.java | 23 +++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/onelitefeather/coris/shape/CuboidShape.java b/src/main/java/net/onelitefeather/coris/shape/CuboidShape.java index a8b3282..c775429 100644 --- a/src/main/java/net/onelitefeather/coris/shape/CuboidShape.java +++ b/src/main/java/net/onelitefeather/coris/shape/CuboidShape.java @@ -1,6 +1,8 @@ package net.onelitefeather.coris.shape; +import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Vec; +import net.onelitefeather.coris.util.Intersect; import org.jetbrains.annotations.ApiStatus; /** @@ -9,7 +11,7 @@ * @param start the starting point of the cuboid * @param end the ending point of the cuboid * @author theEvilReaper - * @version 1.3.0 + * @version 1.4.0 * @since 0.1.0 */ @ApiStatus.Experimental @@ -30,6 +32,9 @@ public record CuboidShape(Vec start, Vec end) implements Shape { } } + /** + * {@inheritDoc} + */ @Override public int compareTo(Shape o) { if (!(o instanceof CuboidShape(Vec start1, Vec end1))) { @@ -40,6 +45,25 @@ public int compareTo(Shape o) { return compareVec(this.end, end1); } + /** + * {@inheritDoc} + */ + @Override + public boolean intersect2D(Point position) { + return position.blockX() >= start.blockX() && position.blockX() <= end.blockX() && + position.blockZ() >= start.blockZ() && position.blockZ() <= end.blockZ(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean intersect3D(Point position) { + return position.blockX() >= start.blockX() && position.blockX() <= end.blockX() && + position.blockY() >= start.blockY() && position.blockY() <= end.blockY() && + position.blockZ() >= start.blockZ() && position.blockZ() <= end.blockZ(); + } + /** * Compares two vectors lexicographically. * diff --git a/src/main/java/net/onelitefeather/coris/shape/PointShape.java b/src/main/java/net/onelitefeather/coris/shape/PointShape.java index 045e0f0..3a1e574 100644 --- a/src/main/java/net/onelitefeather/coris/shape/PointShape.java +++ b/src/main/java/net/onelitefeather/coris/shape/PointShape.java @@ -1,6 +1,8 @@ package net.onelitefeather.coris.shape; +import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Vec; +import net.onelitefeather.coris.util.Intersect; /** * The {@link PointShape} represents an implementation of the {@link Shape} interface which describes a single point in a 3D space. @@ -8,11 +10,14 @@ * * @param position the position of the point in the 3D space * @author theEvilReaper - * @version 1.3.0 + * @version 1.4.0 * @since 0.1.0 */ public record PointShape(Vec position) implements Shape { + /** + * {@inheritDoc} + */ @Override public int compareTo(Shape o) { if (!(o instanceof PointShape(Vec position1))) return -1; @@ -22,4 +27,20 @@ public int compareTo(Shape o) { if (cmpY != 0) return cmpY; return Double.compare(this.position.z(), position1.z()); } + + /** + * {@inheritDoc} + */ + @Override + public boolean intersect2D(Point position) { + return this.intersect3D(position); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean intersect3D(Point position) { + return this.position.equals(position); + } } From 82a93ec8e43e75a905a7de9d19d0768c7956cb2e Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Thu, 5 Mar 2026 22:32:14 +0100 Subject: [PATCH 3/4] feat(shape): add tests for the intersection --- .../intersect/CuboidShapeIntersectTest.java | 3 +- .../intersect/PointShapeIntersectTest.java | 39 +++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java b/src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java index a26dba1..c787f52 100644 --- a/src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java +++ b/src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java @@ -1,6 +1,7 @@ -package net.onelitefeather.coris.shape; +package net.onelitefeather.coris.shape.intersect; import net.minestom.server.coordinate.Vec; +import net.onelitefeather.coris.shape.CuboidShape; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; diff --git a/src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java b/src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java index bfaf37c..5dead7d 100644 --- a/src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java +++ b/src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java @@ -1,4 +1,37 @@ -package net.onelitefeather.coris.shape; +package net.onelitefeather.coris.shape.intersect; -public class PointShapeIntersectTest { -} +import net.minestom.server.coordinate.Vec; +import net.onelitefeather.coris.shape.PointShape; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class PointShapeIntersectTest { + + private static final PointShape SHAPE = new PointShape(new Vec(2, 2, 2)); + + static Stream intersectProvider() { + return Stream.of( + Arguments.of(new Vec(2, 2, 2), true, "Exact match"), + Arguments.of(new Vec(3, 2, 2), false, "X mismatch"), + Arguments.of(new Vec(2, 3, 2), false, "Y mismatch"), + Arguments.of(new Vec(2, 2, 3), false, "Z mismatch") + ); + } + + @ParameterizedTest(name = "{2}") + @MethodSource("intersectProvider") + void testIntersect3D(Vec position, boolean expected, String description) { + assertEquals(expected, SHAPE.intersect3D(position)); + } + + @ParameterizedTest(name = "{2}") + @MethodSource("intersectProvider") + void testIntersect2D(Vec position, boolean expected, String description) { + assertEquals(expected, SHAPE.intersect2D(position)); + } +} \ No newline at end of file From eb92dd9ef2b9efe0e96d3043a39a9a2a968e888a Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Thu, 5 Mar 2026 22:32:23 +0100 Subject: [PATCH 4/4] chore(shape): cleanup unused import statements --- src/main/java/net/onelitefeather/coris/shape/CuboidShape.java | 1 - src/main/java/net/onelitefeather/coris/shape/PointShape.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/net/onelitefeather/coris/shape/CuboidShape.java b/src/main/java/net/onelitefeather/coris/shape/CuboidShape.java index c775429..62b8cbe 100644 --- a/src/main/java/net/onelitefeather/coris/shape/CuboidShape.java +++ b/src/main/java/net/onelitefeather/coris/shape/CuboidShape.java @@ -2,7 +2,6 @@ import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Vec; -import net.onelitefeather.coris.util.Intersect; import org.jetbrains.annotations.ApiStatus; /** diff --git a/src/main/java/net/onelitefeather/coris/shape/PointShape.java b/src/main/java/net/onelitefeather/coris/shape/PointShape.java index 3a1e574..7989f20 100644 --- a/src/main/java/net/onelitefeather/coris/shape/PointShape.java +++ b/src/main/java/net/onelitefeather/coris/shape/PointShape.java @@ -2,7 +2,6 @@ import net.minestom.server.coordinate.Point; import net.minestom.server.coordinate.Vec; -import net.onelitefeather.coris.util.Intersect; /** * The {@link PointShape} represents an implementation of the {@link Shape} interface which describes a single point in a 3D space.