Some improvements to 2d vector hashing
This commit is contained in:
parent
6cc27fb6e0
commit
44de54d9f9
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=2.12.3
|
projectVersion=2.13.0
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -63,6 +63,8 @@ data class AABB(val mins: Vector2d, val maxs: Vector2d) {
|
|||||||
return x in mins.x .. maxs.x && y in mins.y .. maxs.y
|
return x in mins.x .. maxs.x && y in mins.y .. maxs.y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator fun contains(point: IStruct2d) = isInside(point)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whenever is this AABB intersect with [other]
|
* Checks whenever is this AABB intersect with [other]
|
||||||
*
|
*
|
||||||
@ -183,6 +185,8 @@ data class AABB(val mins: Vector2d, val maxs: Vector2d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun expand(value: IStruct2d) = expand(value.component1(), value.component2())
|
fun expand(value: IStruct2d) = expand(value.component1(), value.component2())
|
||||||
|
fun padded(value: IStruct2d) = expand(value.component1(), value.component2())
|
||||||
|
fun padded(x: Double, y: Double) = expand(x, y)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns AABB which edges are expanded by [x] and [y] along their normals
|
* Returns AABB which edges are expanded by [x] and [y] along their normals
|
||||||
|
@ -53,6 +53,8 @@ data class AABBi(val mins: Vector2i, val maxs: Vector2i) {
|
|||||||
return x in mins.x .. maxs.x && y in mins.y .. maxs.y
|
return x in mins.x .. maxs.x && y in mins.y .. maxs.y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator fun contains(point: IStruct2i) = isInside(point)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whenever is this AABBi intersect with [other]
|
* Checks whenever is this AABBi intersect with [other]
|
||||||
*
|
*
|
||||||
@ -96,6 +98,8 @@ data class AABBi(val mins: Vector2i, val maxs: Vector2i) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun padded(x: Int, y: Int) = expand(x, y)
|
||||||
|
fun padded(value: IStruct2i) = expand(value.component1(), value.component2())
|
||||||
fun expand(value: IStruct2i) = expand(value.component1(), value.component2())
|
fun expand(value: IStruct2i) = expand(value.component1(), value.component2())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,6 +111,18 @@ data class Vector2d(
|
|||||||
|
|
||||||
operator fun unaryMinus(): Vector2d = Vector2d(-x, -y)
|
operator fun unaryMinus(): Vector2d = Vector2d(-x, -y)
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return other is Vector2d && x == other.x && y == other.y
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return x.hashCode().rotateLeft(16) xor y.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y]"
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2D vector cross product (Z coordinate)
|
* 2D vector cross product (Z coordinate)
|
||||||
*/
|
*/
|
||||||
|
@ -111,6 +111,18 @@ data class Vector2f(
|
|||||||
|
|
||||||
operator fun unaryMinus(): Vector2f = Vector2f(-x, -y)
|
operator fun unaryMinus(): Vector2f = Vector2f(-x, -y)
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return other is Vector2f && x == other.x && y == other.y
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return x.hashCode().rotateLeft(16) xor y.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y]"
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2D vector cross product (Z coordinate)
|
* 2D vector cross product (Z coordinate)
|
||||||
*/
|
*/
|
||||||
|
@ -88,6 +88,18 @@ data class Vector2i(
|
|||||||
|
|
||||||
operator fun unaryMinus(): Vector2i = Vector2i(-x, -y)
|
operator fun unaryMinus(): Vector2i = Vector2i(-x, -y)
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return other is Vector2i && x == other.x && y == other.y
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return x.rotateLeft(16) xor y
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y]"
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2D vector cross product (Z coordinate)
|
* 2D vector cross product (Z coordinate)
|
||||||
*/
|
*/
|
||||||
|
@ -208,6 +208,10 @@ data class Vector3d(
|
|||||||
fun toDoubleVector() = this
|
fun toDoubleVector() = this
|
||||||
fun toFloatVector() = Vector3f(x.toFloat(), y.toFloat(), z.toFloat())
|
fun toFloatVector() = Vector3f(x.toFloat(), y.toFloat(), z.toFloat())
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y, $z]"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField val ZERO = Vector3d()
|
@JvmField val ZERO = Vector3d()
|
||||||
@JvmField val POSITIVE_X = Vector3d(x = 1.0)
|
@JvmField val POSITIVE_X = Vector3d(x = 1.0)
|
||||||
|
@ -208,6 +208,10 @@ data class Vector3f(
|
|||||||
fun toDoubleVector() = Vector3d(x.toDouble(), y.toDouble(), z.toDouble())
|
fun toDoubleVector() = Vector3d(x.toDouble(), y.toDouble(), z.toDouble())
|
||||||
fun toFloatVector() = this
|
fun toFloatVector() = this
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y, $z]"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField val ZERO = Vector3f()
|
@JvmField val ZERO = Vector3f()
|
||||||
@JvmField val POSITIVE_X = Vector3f(x = 1.0f)
|
@JvmField val POSITIVE_X = Vector3f(x = 1.0f)
|
||||||
|
@ -171,6 +171,10 @@ data class Vector3i(
|
|||||||
fun toDoubleVector() = Vector3d(x.toDouble(), y.toDouble(), z.toDouble())
|
fun toDoubleVector() = Vector3d(x.toDouble(), y.toDouble(), z.toDouble())
|
||||||
fun toFloatVector() = Vector3f(x.toFloat(), y.toFloat(), z.toFloat())
|
fun toFloatVector() = Vector3f(x.toFloat(), y.toFloat(), z.toFloat())
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y, $z]"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField val ZERO = Vector3i()
|
@JvmField val ZERO = Vector3i()
|
||||||
@JvmField val POSITIVE_X = Vector3i(x = 1)
|
@JvmField val POSITIVE_X = Vector3i(x = 1)
|
||||||
|
@ -229,6 +229,10 @@ data class Vector4d(
|
|||||||
fun toDoubleVector() = this
|
fun toDoubleVector() = this
|
||||||
fun toFloatVector() = Vector4f(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat())
|
fun toFloatVector() = Vector4f(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat())
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y, $z, $w]"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField val ZERO = Vector4d()
|
@JvmField val ZERO = Vector4d()
|
||||||
@JvmField val POSITIVE_X = Vector4d(x = 1.0)
|
@JvmField val POSITIVE_X = Vector4d(x = 1.0)
|
||||||
|
@ -231,6 +231,10 @@ data class Vector4f(
|
|||||||
fun toDoubleVector() = Vector4d(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble())
|
fun toDoubleVector() = Vector4d(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble())
|
||||||
fun toFloatVector() = this
|
fun toFloatVector() = this
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y, $z, $w]"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField val ZERO = Vector4f()
|
@JvmField val ZERO = Vector4f()
|
||||||
@JvmField val POSITIVE_X = Vector4f(x = 1.0f)
|
@JvmField val POSITIVE_X = Vector4f(x = 1.0f)
|
||||||
|
@ -199,6 +199,10 @@ data class Vector4i(
|
|||||||
fun toDoubleVector() = Vector4d(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble())
|
fun toDoubleVector() = Vector4d(x.toDouble(), y.toDouble(), z.toDouble(), w.toDouble())
|
||||||
fun toFloatVector() = Vector4f(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat())
|
fun toFloatVector() = Vector4f(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat())
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "[$x, $y, $z, $w]"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField val ZERO = Vector4i()
|
@JvmField val ZERO = Vector4i()
|
||||||
@JvmField val POSITIVE_X = Vector4i(x = 1)
|
@JvmField val POSITIVE_X = Vector4i(x = 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user