Update formatting
This commit is contained in:
@@ -32,10 +32,11 @@ data class SimpleChunkLocation(
|
||||
val x: Int,
|
||||
val z: Int,
|
||||
)
|
||||
|
||||
// CONVERTER
|
||||
fun Location.toSimple() = SimpleLocation3D(x, y, z)
|
||||
fun Chunk.toSimple() = SimpleChunkLocation(x, z)
|
||||
fun SimpleLocation3D.withWorld(world: World) = Location(world, x, y, z).apply { direction = this@withWorld.direction }
|
||||
fun SimpleChunkLocation.withWorld(world: World) = world.getChunkAt(x, z)
|
||||
fun Vector.toSimpleLoc() = SimpleLocation3D(x, y, z)
|
||||
fun SimpleLocation3D.toVector() = Vector(x, y, z)
|
||||
fun SimpleLocation3D.toVector() = Vector(x, y, z)
|
||||
|
@@ -14,8 +14,10 @@ class SimpleLocationPair(loc1: Location, loc2: Location) {
|
||||
if (it == loc2.worldOrException) it
|
||||
else throw IllegalArgumentException("The given locations worlds are not the same!")
|
||||
}
|
||||
|
||||
val minSimpleLoc = SimpleLocation3D(min(loc1.x, loc2.x), min(loc1.y, loc2.y), min(loc1.z, loc2.z))
|
||||
val maxSimpleLoc = SimpleLocation3D(max(loc1.x, loc2.x), max(loc1.y, loc2.y), max(loc1.z, loc2.z))
|
||||
|
||||
fun isInArea(
|
||||
loc: Location,
|
||||
check3d: Boolean = true,
|
||||
@@ -59,14 +61,19 @@ class LocationArea(loc1: Location, loc2: Location) {
|
||||
field = value
|
||||
simpleLocationPair = SimpleLocationPair(loc1, value)
|
||||
}
|
||||
|
||||
var simpleLocationPair = SimpleLocationPair(loc1, loc2); private set
|
||||
|
||||
val world: World get() = simpleLocationPair.world
|
||||
|
||||
val minLoc: Location get() = simpleLocationPair.minSimpleLoc.withWorld(simpleLocationPair.world)
|
||||
val maxLoc: Location get() = simpleLocationPair.maxSimpleLoc.withWorld(simpleLocationPair.world)
|
||||
|
||||
val touchedChunks: Set<Chunk> get() = simpleLocationPair.touchedSimpleChunks.mapTo(HashSet()) { it.withWorld(world) }
|
||||
|
||||
fun isInArea(
|
||||
loc: Location,
|
||||
check3d: Boolean = true,
|
||||
tolerance: Int = 0,
|
||||
) = simpleLocationPair.isInArea(loc, check3d, tolerance)
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ infix fun Location.reduceZ(distance: Number) = subtract(0.0, 0.0, distance)
|
||||
infix fun Location.reduceXY(distance: Number) = subtract(distance, distance, 0.0)
|
||||
infix fun Location.reduceYZ(distance: Number) = subtract(0.0, distance, distance)
|
||||
infix fun Location.reduceXZ(distance: Number) = subtract(distance, 0.0, distance)
|
||||
|
||||
// extensions
|
||||
fun Location.add(x: Number, y: Number, z: Number) = add(x.toDouble(), y.toDouble(), z.toDouble())
|
||||
fun Location.subtract(x: Number, y: Number, z: Number) = subtract(x.toDouble(), y.toDouble(), z.toDouble())
|
||||
@@ -83,9 +84,11 @@ infix fun Location.increase(loc: Location) = add(loc)
|
||||
infix fun Location.reduce(loc: Location) = subtract(loc)
|
||||
infix fun Location.increase(loc: SimpleLocation3D) = add(loc.x, loc.y, loc.z)
|
||||
infix fun Location.reduce(loc: SimpleLocation3D) = subtract(loc.x, loc.y, loc.z)
|
||||
|
||||
/*
|
||||
* VECTOR
|
||||
*/
|
||||
|
||||
val Vector.isFinite: Boolean get() = x.isFinite() && y.isFinite() && z.isFinite()
|
||||
|
||||
// fast construct
|
||||
@@ -125,4 +128,4 @@ operator fun Vector.timesAssign(num: Number) {
|
||||
infix fun Vector.increase(vec: Vector) = add(vec)
|
||||
infix fun Vector.reduce(vec: Vector) = subtract(vec)
|
||||
infix fun Vector.multiply(vec: Vector) = multiply(vec)
|
||||
infix fun Vector.multiply(num: Number) = multiply(num.toDouble())
|
||||
infix fun Vector.multiply(num: Number) = multiply(num.toDouble())
|
||||
|
Reference in New Issue
Block a user