/** * Same as {@code {@link #expandTo3D(Region3i)}}} but with a Vector3i instead of a Region3i. * @param size The size to be used. * @return The 3D world representation with the additional space added to it in the 3 dimensions. */ public Region3i expandTo3D(Vector3i size) { return Region3i.createFromMinMax(new Vector3i(-sides, -bottom, -sides), new Vector3i(size.x + sides - 1, size.y + top - 1, size.z + sides - 1)); }
/** * Creates a new region that is the same as this region but expanded in all directions by the given amount * * @param amount * @return A new region */ public Region3i expand(int amount) { Vector3i expandedMin = min(); expandedMin.sub(amount, amount, amount); Vector3i expandedMax = max(); expandedMax.add(amount, amount, amount); return createFromMinMax(expandedMin, expandedMax); }
public Region3i expand(BaseVector3i amount) { Vector3i expandedMin = min(); expandedMin.sub(amount); Vector3i expandedMax = max(); expandedMax.add(amount); return createFromMinMax(expandedMin, expandedMax); }
public Region3i expandToContain(BaseVector3i adjPos) { Vector3i expandedMin = min(); expandedMin.min(adjPos); Vector3i expandedMax = max(); expandedMax.max(adjPos); return createFromMinMax(expandedMin, expandedMax); }
/** * Create a region by two point * @param a vertex a * @param b the diagonal vertex of a * @return a new region base on vertex a and b */ public static Region3i createBounded(BaseVector3i a, BaseVector3i b) { Vector3i min = new Vector3i(a); min.min(b); Vector3i max = new Vector3i(a); max.max(b); return createFromMinMax(min, max); }
public static Region3i getChunkRegionAroundWorldPos(Vector3i pos, int extent) { Vector3i minPos = new Vector3i(-extent, -extent, -extent); minPos.add(pos); Vector3i maxPos = new Vector3i(extent, extent, extent); maxPos.add(pos); Vector3i minChunk = calcChunkPos(minPos); Vector3i maxChunk = calcChunkPos(maxPos); return Region3i.createFromMinMax(minChunk, maxChunk); }
/** * @param other * @return The region that is encompassed by both this and other. If they * do not overlap then the empty region is returned */ public Region3i intersect(Region3i other) { Vector3i intersectMin = min(); intersectMin.max(other.min()); Vector3i intersectMax = max(); intersectMax.min(other.max()); return createFromMinMax(intersectMin, intersectMax); }
/** * Create a region with center point and extents size * @param center the center point of region * @param extent the extents size of region * @return a new region base on the center point and extents size */ public static Region3i createFromCenterExtents(BaseVector3i center, int extent) { Vector3i min = new Vector3i(center.x() - extent, center.y() - extent, center.z() - extent); Vector3i max = new Vector3i(center.x() + extent, center.y() + extent, center.z() + extent); return createFromMinMax(min, max); }
/** * Returns a 3D representation of the workd, a region in this case. With the borders added to it. * @param region The region to be expanded with the borders. * @return The 3D world representation with the additional space added to it in the 3 dimensions. */ public Region3i expandTo3D(Region3i region) { return Region3i.createFromMinMax(new Vector3i(region.minX() - sides, region.minY() - bottom, region.minZ() - sides), new Vector3i(region.maxX() + sides, region.maxY() + top, region.maxZ() + sides)); }
@Test public void testSimpleIntersect() { Region3i region1 = Region3i.createFromMinMax(new Vector3i(), new Vector3i(32, 32, 32)); Region3i region2 = Region3i.createFromMinMax(new Vector3i(1, 1, 1), new Vector3i(17, 17, 17)); assertEquals(region2, region1.intersect(region2)); }
public static Region3i createEncompassing(Region3i a, Region3i b) { if (a.isEmpty()) { return b; } if (b.isEmpty()) { return a; } Vector3i min = a.min(); min.min(b.min()); Vector3i max = a.max(); max.max(b.max()); return createFromMinMax(min, max); }
@Test public void testNonTouchingIntersect() { Region3i region1 = Region3i.createFromMinMax(new Vector3i(), new Vector3i(32, 32, 32)); Region3i region2 = Region3i.createFromMinMax(new Vector3i(103, 103, 103), new Vector3i(170, 170, 170)); assertEquals(Region3i.empty(), region1.intersect(region2)); }
@Override public void setDirtyAround(Region3i region) { Vector3i minPos = new Vector3i(region.min()); minPos.sub(1, 1, 1); Vector3i maxPos = new Vector3i(region.max()); maxPos.add(1, 1, 1); Vector3i minChunk = ChunkMath.calcChunkPos(minPos, chunkPower); Vector3i maxChunk = ChunkMath.calcChunkPos(maxPos, chunkPower); for (Vector3i pos : Region3i.createFromMinMax(minChunk, maxChunk)) { chunks[pos.x + offset.x + chunkRegion.size().x * (pos.z + offset.z)].setDirty(true); } }
@Test public void testRegionEmptyIfMaxLessThanMin() { Region3i region = Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(-1, 0, 0)); assertTrue(region.isEmpty()); }
/** * Create a region with center point and x,y,z coordinate extents size * @param center the center point of region * @param extents the extents size of each side of region * @return a new region base on the center point and extents size */ public static Region3i createFromCenterExtents(BaseVector3i center, BaseVector3i extents) { Vector3i min = new Vector3i(center.x() - extents.x(), center.y() - extents.y(), center.z() - extents.z()); Vector3i max = new Vector3i(center.x() + extents.x(), center.y() + extents.y(), center.z() + extents.z()); return createFromMinMax(min, max); }
@Test public void testNearestPointToAlongSide() { Region3i region = Region3i.createFromMinMax(new Vector3i(), new Vector3i(4, 4, 4)); assertEquals(new Vector3i(4, 2, 1), region.getNearestPointTo(new Vector3i(15, 2, 1))); }
@Test public void testNearestPointToAwayFromCorner() { Region3i region = Region3i.createFromMinMax(new Vector3i(), new Vector3i(4, 4, 4)); assertEquals(new Vector3i(4, 4, 4), region.getNearestPointTo(new Vector3i(15, 12, 7))); } }
@Test public void testGetEdgeRegion() { Region3i region = Region3i.createFromMinAndSize(new Vector3i(16, 0, 16), new Vector3i(16, 128, 16)); assertEquals(Region3i.createFromMinMax(new Vector3i(16, 0, 16), new Vector3i(16, 127, 31)), ChunkMath.getEdgeRegion(region, Side.LEFT)); }
private Region3i determineRequiredRegion(Region3i region) { int newMinX = region.minX() - IntMath.mod(region.minX(), sampleRate); int newMinY = region.minY() - IntMath.mod(region.minY(), sampleRate); int newMinZ = region.minZ() - IntMath.mod(region.minZ(), sampleRate); int newMaxX = region.maxX() + 4 - IntMath.mod(region.maxX(), sampleRate) - 1; int newMaxY = region.maxY() + 4 - IntMath.mod(region.maxY(), sampleRate) - 1; int newMaxZ = region.maxZ() + 4 - IntMath.mod(region.maxZ(), sampleRate) - 1; return Region3i.createFromMinMax(new Vector3i(newMinX, newMinY, newMinZ), new Vector3i(newMaxX, newMaxY, newMaxZ)); } }
private Region3i determineRequiredRegion(Region3i region) { int newMinX = region.minX() - IntMath.mod(region.minX(), sampleRate); int newMinY = region.minY() - IntMath.mod(region.minY(), sampleRate); int newMinZ = region.minZ() - IntMath.mod(region.minZ(), sampleRate); int newMaxX = region.maxX() + 4 - IntMath.mod(region.maxX(), sampleRate) - 1; int newMaxY = region.maxY() + 4 - IntMath.mod(region.maxY(), sampleRate) - 1; int newMaxZ = region.maxZ() + 4 - IntMath.mod(region.maxZ(), sampleRate) - 1; return Region3i.createFromMinMax(new Vector3i(newMinX, newMinY, newMinZ), new Vector3i(newMaxX, newMaxY, newMaxZ)); } }