@@ -25,6 +25,7 @@ import net.minecraft.util.math.Vec3d
2525import net.minecraft.util.math.Vec3i
2626import kotlin.math.pow
2727import kotlin.math.roundToInt
28+ import kotlin.math.sqrt
2829
2930object VecUtils {
3031 val Vec3d .blockPos: BlockPos
@@ -39,33 +40,30 @@ object VecUtils {
3940 get() =
4041 CENTER + vector.vec3d * 0.5
4142
42- infix fun Vec3d.dist (other : Vec3d ): Double = this .distanceTo(other)
43-
43+ fun Vec3d.approximate (other : Vec3d , precision : Double = 2.0E-4): Boolean = (subtract(other) distSq Vec3d .ZERO ) > precision.pow(2 )
44+ infix fun Vec3d.dist (other : Vec3d ): Double = sqrt(this distSq other)
45+ infix fun Vec3d.dist (other : Vec3i ): Double = sqrt(this distSq other)
4446 infix fun Vec3d.distSq (other : Vec3d ): Double = this .squaredDistanceTo(other)
45-
46- fun Vec3d.approximate (other : Vec3d , precision : Double = 2.0E-4): Boolean =
47- (subtract(other) distSq Vec3d .ZERO ) > precision.pow(2 )
48-
49- infix fun Vec3i.distSq (other : Vec3d ): Double = Vec3d .of(this ) distSq other
50-
51- infix fun Vec3i.distSq (other : Vec3i ): Int = (this .x - other.x).sq + (this .y - other.y).sq + (this .z - other.z).sq
52-
53- infix fun Entity.distSq (other : Vec3d ): Double = this .pos distSq other
54-
55- infix fun Entity.distSq (other : Vec3i ): Int = this .blockPos distSq other
56-
47+ infix fun Vec3d.distSq (other : Vec3i ): Double = this .squaredDistanceTo(other.x.toDouble(), other.y.toDouble(), other.z.toDouble())
5748 infix operator fun Vec3d.plus (other : Vec3d ): Vec3d = this .add(other)
58-
5949 infix operator fun Vec3d.minus (other : Vec3d ): Vec3d = this .subtract(other)
60-
6150 infix operator fun Vec3d.times (other : Vec3d ): Vec3d = this .multiply(other)
62-
6351 infix operator fun Vec3d.div (other : Vec3d ): Vec3d = this .multiply(1.0 / other.x, 1.0 / other.y, 1.0 / other.z)
64-
6552 infix operator fun Vec3d.times (other : Double ): Vec3d = this .multiply(other)
66-
6753 infix operator fun Vec3d.div (other : Double ): Vec3d = this .multiply(1.0 / other)
6854
55+ infix fun Vec3i.dist (other : Vec3d ): Double = sqrt(this distSq other)
56+ infix fun Vec3i.dist (other : Vec3i ): Double = sqrt((this distSq other).toDouble())
57+ infix fun Vec3i.distSq (other : Vec3d ): Double = this .getSquaredDistance(other)
58+ infix fun Vec3i.distSq (other : Vec3i ): Int = (this .x - other.x).sq + (this .y - other.y).sq + (this .z - other.z).sq
59+
60+ infix fun Entity.dist (other : Vec3d ): Double = pos dist other
61+ infix fun Entity.dist (other : Vec3i ): Double = blockPos dist other
62+ infix fun Entity.dist (other : Entity ): Double = distanceTo(other).toDouble()
63+ infix fun Entity.distSq (other : Vec3d ): Double = this .pos distSq other
64+ infix fun Entity.distSq (other : Vec3i ): Int = this .blockPos distSq other
65+ infix fun Entity.distSq (other : Entity ): Double = squaredDistanceTo(other)
66+
6967 val UP = Vec3d (0.0 , 1.0 , 0.0 )
7068 val DOWN = Vec3d (0.0 , - 1.0 , 0.0 )
7169 val CENTER = Vec3d (0.5 , 0.5 , 0.5 )
0 commit comments