diff options
author | Dico <dico.karssiens@gmail.com> | 2018-09-27 07:03:02 +0100 |
---|---|---|
committer | Dico <dico.karssiens@gmail.com> | 2018-09-27 07:03:02 +0100 |
commit | 842e52bd92f0c67aa1906b899ce600ecb3b26bda (patch) | |
tree | f0e03e66ba0dfeb8d3aee58a09acd6889f5ee20e /src/main/kotlin/io/dico/parcels2/util/math/Region.kt | |
parent | 307b7aee4af34e47139259db7049a85c682b7be2 (diff) |
Fixes n tweaks
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/util/math/Region.kt')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/util/math/Region.kt | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/util/math/Region.kt b/src/main/kotlin/io/dico/parcels2/util/math/Region.kt new file mode 100644 index 0000000..cdbd497 --- /dev/null +++ b/src/main/kotlin/io/dico/parcels2/util/math/Region.kt @@ -0,0 +1,37 @@ +package io.dico.parcels2.util.math + +data class Region(val origin: Vec3i, val size: Vec3i) { + val blockCount: Int get() = size.x * size.y * size.z + + val center: Vec3d + get() { + val x = (origin.x + size.x) / 2.0 + val y = (origin.y + size.y) / 2.0 + val z = (origin.z + size.z) / 2.0 + return Vec3d(x, y, z) + } + + val end: Vec3i + get() = origin + size + + val max: Vec3i + get() = Vec3i(origin.x + size.x - 1, origin.y + size.y - 1, origin.z + size.z - 1) + + fun withSize(size: Vec3i): Region { + if (size == this.size) return this + return Region(origin, size) + } + + operator fun contains(loc: Vec3i): Boolean = getFirstUncontainedDimensionOf(loc) == null + + fun getFirstUncontainedDimensionOf(loc: Vec3i): Dimension? { + val max = max + return when { + loc.x !in origin.x..max.x -> Dimension.X + loc.z !in origin.z..max.z -> Dimension.Z + loc.y !in origin.y..max.y -> Dimension.Y + else -> null + } + } + +}
\ No newline at end of file |