-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add intersection logic to the shape structure #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b892f12
feat(shape): add intersect inheritance
theEvilReaper f177ccd
feat(shape): add intersect implementation
theEvilReaper 82a93ec
feat(shape): add tests for the intersection
theEvilReaper eb92dd9
chore(shape): cleanup unused import statements
theEvilReaper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/test/java/net/onelitefeather/coris/shape/intersect/CuboidShapeIntersectTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| 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; | ||
|
|
||
| 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<Arguments> 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<Arguments> 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)); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/test/java/net/onelitefeather/coris/shape/intersect/PointShapeIntersectTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package net.onelitefeather.coris.shape.intersect; | ||
|
|
||
| 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<Arguments> 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)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no real difference for points. Two points intersect if they share the same position, so intersect2D simply delegates to intersect3D to avoid code duplication.