Skip to content

Commit 198fe60

Browse files
committed
added more chunkpos formulas
1 parent e217024 commit 198fe60

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/kotlin/com/lambda/util/math/Vectors.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ val ChunkPos.center: ChunkPos
8686
infix fun ChunkPos.dist(other: Vec3i): Double = other dist this
8787
infix fun ChunkPos.dist(other: Vec3d): Double = other dist this
8888
infix fun ChunkPos.dist(other: ChunkPos): Double = sqrt((this distSq other).toDouble())
89+
infix fun ChunkPos.distCenter(other: Vec3i): Double = sqrt((this distSqCenter other).toDouble())
90+
infix fun ChunkPos.distCenter(other: Vec3d): Double = sqrt(this distSqCenter other)
8991
infix fun ChunkPos.distCenter(other: ChunkPos): Double = sqrt((this distSqCenter other).toDouble())
9092
infix fun ChunkPos.distSq(other: Vec3i): Int = other distSq this
9193
infix fun ChunkPos.distSq(other: Vec3d): Double = other distSq this
9294
infix fun ChunkPos.distSq(other: ChunkPos): Int = (other.x - x).sq + (other.z - z).sq
95+
infix fun ChunkPos.distSqCenter(other: Vec3i): Int = (other.x - centerX).sq + (other.z - centerZ).sq
96+
infix fun ChunkPos.distSqCenter(other: Vec3d): Double = (other.x - centerX).sq + (other.z - centerZ).sq
9397
infix fun ChunkPos.distSqCenter(other: ChunkPos): Int = (other.centerX - centerX).sq + (other.centerZ - centerZ).sq
9498

9599
/* Vec3d */
@@ -117,7 +121,7 @@ infix fun Vec3d.dist(other: Vec3i): Double = sqrt(this distSq other)
117121
infix fun Vec3d.dist(other: ChunkPos): Double = sqrt(this distSq other)
118122
infix fun Vec3d.distSq(other: Vec3d): Double = (other.x - x).sq + (other.y - y).sq + (other.z - z).sq
119123
infix fun Vec3d.distSq(other: Vec3i): Double = (other.x - x).sq + (other.y - y).sq + (other.z - z).sq
120-
infix fun Vec3d.distSq(other: ChunkPos): Double = (other.x - x).sq + (other.z - z).sq
124+
infix fun Vec3d.distSq(other: ChunkPos): Double = (other.x * 16 - x).sq + (other.z * 16 - z).sq
121125

122126
infix operator fun Vec3d.plus(other: Vec3d): Vec3d = add(other)
123127
infix operator fun Vec3d.plus(other: Vec3i): Vec3d = Vec3d(x + other.x, y + other.y, z + other.z)
@@ -166,7 +170,7 @@ infix fun Vec3i.dist(other: Vec3i): Double = sqrt((this distSq other).toDouble()
166170
infix fun Vec3i.dist(other: ChunkPos): Double = sqrt((this distSq other).toDouble())
167171
infix fun Vec3i.distSq(other: Vec3d): Double = getSquaredDistance(other)
168172
infix fun Vec3i.distSq(other: Vec3i): Int = (x - other.x).sq + (y - other.y).sq + (z - other.z).sq
169-
infix fun Vec3i.distSq(other: ChunkPos): Int = (other.x - x).sq + (other.z - z).sq
173+
infix fun Vec3i.distSq(other: ChunkPos): Int = (other.x * 16 - x).sq + (other.z * 16 - z).sq
170174

171175
infix operator fun Vec3i.plus(other: Vec3i): Vec3i = add(other)
172176
infix operator fun Vec3i.plus(other: Int): Vec3i = add(other, other, other)

0 commit comments

Comments
 (0)