Skip to content

Commit 8c544f3

Browse files
committed
fix #123: enhance cuboid containment checks to optionally ignore y-dimension and update related assertions
1 parent fa9ab98 commit 8c544f3

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ java {
1515
}
1616

1717
group = "cn.lunadeer"
18-
version = "4.5.0" // << The main version should keep consistent with the core module
18+
version = "4.5.1" // << The main version should keep consistent with the core module
1919

2020
// utf-8
2121
tasks.withType<JavaCompile> {

src/main/java/cn/lunadeer/dominion/api/dtos/CuboidDTO.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,22 @@ public boolean intersectWith(CuboidDTO cuboid) {
282282
* @return true if this cuboid contains the other cuboid, false otherwise
283283
*/
284284
public boolean contain(CuboidDTO cuboid) {
285-
return x1() <= cuboid.x1() && x2() >= cuboid.x2() && y1() <= cuboid.y1() && y2() >= cuboid.y2() && z1() <= cuboid.z1() && z2() >= cuboid.z2();
285+
return contain(cuboid, false);
286+
}
287+
288+
/**
289+
* Checks if this cuboid contains another cuboid, optionally ignoring the y-dimension.
290+
*
291+
* @param cuboid the other cuboid to check for containment
292+
* @param ignoreY if true, ignores the y-dimension in the containment check
293+
* @return true if this cuboid contains the other cuboid, false otherwise
294+
*/
295+
public boolean contain(CuboidDTO cuboid, boolean ignoreY) {
296+
if (ignoreY) {
297+
return x1() <= cuboid.x1() && x2() >= cuboid.x2() && z1() <= cuboid.z1() && z2() >= cuboid.z2();
298+
} else {
299+
return x1() <= cuboid.x1() && x2() >= cuboid.x2() && y1() <= cuboid.y1() && y2() >= cuboid.y2() && z1() <= cuboid.z1() && z2() >= cuboid.z2();
300+
}
286301
}
287302

288303
/**

0 commit comments

Comments
 (0)