Skip to content

Commit 595d2be

Browse files
committed
- coherenced all byteArray and byteBuffer constructors
- hashCode()
1 parent e97b965 commit 595d2be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+346
-295
lines changed

src/main/kotlin/glm_/extensions.kt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ infix fun Int.xor(b: Char) = this xor b.i
5757

5858
val Int.uc get() = (this % 256).c // TODO others
5959

60-
fun ByteArray.getFloat(index: Int, bigEndianess: Boolean = true) = Float.intBitsToFloat(
61-
if (bigEndianess) this[index].i and 0xFF or
60+
fun ByteArray.getFloat(index: Int, bigEndian: Boolean = true) = Float.intBitsToFloat(
61+
if (bigEndian) this[index].i and 0xFF or
6262
(this[index + 1].i and 0xFF shl 8) or
6363
(this[index + 2].i and 0xFF shl 16) or
6464
(this[index + 3].i and 0xFF shl 24)
@@ -68,8 +68,8 @@ fun ByteArray.getFloat(index: Int, bigEndianess: Boolean = true) = Float.intBits
6868
(this[index].i and 0xFF shl 24)
6969
)
7070

71-
fun ByteArray.getDouble(index: Int, bigEndianess: Boolean = true) = Double.longBitsToDouble(
72-
if (bigEndianess) this[index].L and 0xFF or
71+
fun ByteArray.getDouble(index: Int, bigEndian: Boolean = true) = Double.longBitsToDouble(
72+
if (bigEndian) this[index].L and 0xFF or
7373
(this[index + 1].L and 0xFF shl 8) or
7474
(this[index + 2].L and 0xFF shl 16) or
7575
(this[index + 3].L and 0xFF shl 24) or
@@ -86,8 +86,8 @@ fun ByteArray.getDouble(index: Int, bigEndianess: Boolean = true) = Double.longB
8686
(this[index + 1].L and 0xFF shl 48) or
8787
(this[index].L and 0xFF shl 56))
8888

89-
fun ByteArray.getInt(index: Int, bigEndianess: Boolean = true) =
90-
if (bigEndianess) this[index].i and 0xFF or
89+
fun ByteArray.getInt(index: Int, bigEndian: Boolean = true) =
90+
if (bigEndian) this[index].i and 0xFF or
9191
(this[index + 1].i and 0xFF shl 8) or
9292
(this[index + 2].i and 0xFF shl 16) or
9393
(this[index + 3].i and 0xFF shl 24)
@@ -96,8 +96,8 @@ fun ByteArray.getInt(index: Int, bigEndianess: Boolean = true) =
9696
(this[index + 1].i and 0xFF shl 16) or
9797
(this[index].i and 0xFF shl 24)
9898

99-
fun ByteArray.getLong(index: Int, bigEndianess: Boolean = true) =
100-
if (bigEndianess) this[index].L and 0xFF or
99+
fun ByteArray.getLong(index: Int, bigEndian: Boolean = true) =
100+
if (bigEndian) this[index].L and 0xFF or
101101
(this[index + 1].L and 0xFF shl 8) or
102102
(this[index + 2].L and 0xFF shl 16) or
103103
(this[index + 3].L and 0xFF shl 24) or
@@ -114,17 +114,17 @@ fun ByteArray.getLong(index: Int, bigEndianess: Boolean = true) =
114114
(this[index + 1].L and 0xFF shl 48) or
115115
(this[index].L and 0xFF shl 56)
116116

117-
fun ByteArray.getShort(index: Int, bigEndianess: Boolean = true) =
118-
if (bigEndianess)
117+
fun ByteArray.getShort(index: Int, bigEndian: Boolean = true) =
118+
if (bigEndian)
119119
this[index].s and 0xFF or (this[index + 1].s and 0xFF shl 8)
120120
else
121121
this[index + 1].s and 0xFF or (this[index].s and 0xFF shl 56)
122122

123123
// skipping getUbyte, since it'main.getS a simply .main.getUb
124-
fun ByteArray.getUint(index: Int, bigEndianess: Boolean = true) = getInt(index, bigEndianess).ui
124+
fun ByteArray.getUint(index: Int, bigEndian: Boolean = true) = getInt(index, bigEndian).ui
125125

126-
fun ByteArray.getUlong(index: Int, bigEndianess: Boolean = true) = getLong(index, bigEndianess).ul
127-
fun ByteArray.getUshort(index: Int, bigEndianess: Boolean = true) = getShort(index, bigEndianess).us
126+
fun ByteArray.getUlong(index: Int, bigEndian: Boolean = true) = getLong(index, bigEndian).ul
127+
fun ByteArray.getUshort(index: Int, bigEndian: Boolean = true) = getShort(index, bigEndian).us
128128

129129

130130
infix fun Byte.shl(other: Byte) = (i shl other.i).b
@@ -170,42 +170,42 @@ val String.us get() = Ushort(this)
170170
val String.bi get() = if (startsWith("0x")) BigInteger(substring(2), 16) else BigInteger(this)
171171

172172

173-
fun InputStream.int(bigEndianess: Boolean = true): Int {
173+
fun InputStream.int(bigEndian: Boolean = true): Int {
174174
val a = read()
175175
val b = read()
176176
val c = read()
177177
val d = read()
178-
if (bigEndianess)
178+
if (bigEndian)
179179
return (a shl 24) + (b shl 16) + (c shl 8) + d
180180
else
181181
return (d shl 24) + (c shl 16) + (b shl 8) + a
182182
}
183183

184-
fun InputStream.short(bigEndianess: Boolean = true): Int {
184+
fun InputStream.short(bigEndian: Boolean = true): Int {
185185
val a = read()
186186
val b = read()
187-
if (bigEndianess)
187+
if (bigEndian)
188188
return (a shl 8) + b
189189
else
190190
return (b shl 8) + a
191191
}
192192

193193
fun InputStream.byte() = read().b
194194

195-
fun InputStream.float(bigEndianess: Boolean = true) = Float.intBitsToFloat(int(bigEndianess))
196-
fun InputStream.double(bigEndianess: Boolean = true) = Double.longBitsToDouble(long(bigEndianess))
195+
fun InputStream.float(bigEndian: Boolean = true) = Float.intBitsToFloat(int(bigEndian))
196+
fun InputStream.double(bigEndian: Boolean = true) = Double.longBitsToDouble(long(bigEndian))
197197

198-
fun InputStream.long(bigEndianess: Boolean = true): Long {
199-
val a = int(bigEndianess)
200-
val b = int(bigEndianess)
198+
fun InputStream.long(bigEndian: Boolean = true): Long {
199+
val a = int(bigEndian)
200+
val b = int(bigEndian)
201201
return (b.L shl 32) + a
202202
}
203203

204-
fun InputStream.mat4(bigEndianess: Boolean = true) = Mat4(
205-
float(bigEndianess), float(bigEndianess), float(bigEndianess), float(bigEndianess),
206-
float(bigEndianess), float(bigEndianess), float(bigEndianess), float(bigEndianess),
207-
float(bigEndianess), float(bigEndianess), float(bigEndianess), float(bigEndianess),
208-
float(bigEndianess), float(bigEndianess), float(bigEndianess), float(bigEndianess))
204+
fun InputStream.mat4(bigEndian: Boolean = true) = Mat4(
205+
float(bigEndian), float(bigEndian), float(bigEndian), float(bigEndian),
206+
float(bigEndian), float(bigEndian), float(bigEndian), float(bigEndian),
207+
float(bigEndian), float(bigEndian), float(bigEndian), float(bigEndian),
208+
float(bigEndian), float(bigEndian), float(bigEndian), float(bigEndian))
209209

210210
val Any.toFloat: Float
211211
get() = when (this) {

src/main/kotlin/glm_/mat2x2/Mat2.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,5 @@ data class Mat2(override var value: MutableList<Vec2>) : Mat2x2t<Vec2>(value) {
218218
override fun equals(other: Any?) = other is Mat2 &&
219219
this[0, 0] == other[0, 0] && this[0, 1] == other[0, 1] &&
220220
this[1, 0] == other[1, 0] && this[1, 1] == other[1, 1]
221+
override fun hashCode() = 31 * value[0].hashCode() + value[1].hashCode()
221222
}

src/main/kotlin/glm_/mat2x2/Mat2d.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,5 @@ data class Mat2d(override var value: MutableList<Vec2d>) : Mat2x2t<Vec2d>(value)
219219
override fun equals(other: Any?) = other is Mat2 &&
220220
this[0, 0] == other[0, 0] && this[0, 1] == other[0, 1] &&
221221
this[1, 0] == other[1, 0] && this[1, 1] == other[1, 1]
222+
override fun hashCode() = 31 * value[0].hashCode() + value[1].hashCode()
222223
}

src/main/kotlin/glm_/mat3x3/Mat3.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,5 @@ data class Mat3(override var value: MutableList<Vec3>) : Mat3x3t<Vec3>(value) {
379379
this[0, 0] == other[0, 0] && this[0, 1] == other[0, 1] && this[0, 2] == other[0, 2] &&
380380
this[1, 0] == other[1, 0] && this[1, 1] == other[1, 1] && this[1, 2] == other[1, 2] &&
381381
this[2, 0] == other[2, 0] && this[2, 1] == other[2, 1] && this[2, 2] == other[2, 2]
382+
override fun hashCode() = 31 * (31 * value[0].hashCode() + value[1].hashCode()) + value[2].hashCode()
382383
}

src/main/kotlin/glm_/mat3x3/Mat3d.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,5 @@ data class Mat3d(override var value: MutableList<Vec3d>) : Mat3x3t<Vec3d>(value)
363363
this[0, 0] == other[0, 0] && this[0, 1] == other[0, 1] && this[0, 2] == other[0, 2] &&
364364
this[1, 0] == other[1, 0] && this[1, 1] == other[1, 1] && this[1, 2] == other[1, 2] &&
365365
this[2, 0] == other[2, 0] && this[2, 1] == other[2, 1] && this[2, 2] == other[2, 2]
366+
override fun hashCode() = 31 * (31 * value[0].hashCode() + value[1].hashCode()) + value[2].hashCode()
366367
}

src/main/kotlin/glm_/mat4x4/Mat4.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ data class Mat4(override var value: MutableList<Vec4>) : Mat4x4t<Vec4>(value) {
137137
Vec4(floats, 12)))
138138

139139
// TODO others
140-
constructor(inputStream: InputStream, bigEndianess: Boolean = true) : this(
141-
inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess),
142-
inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess),
143-
inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess),
144-
inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess))
140+
constructor(inputStream: InputStream, bigEndian: Boolean = true) : this(
141+
inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian),
142+
inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian),
143+
inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian),
144+
inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian))
145145

146146
fun put(v0: Vec4, v1: Vec4, v2: Vec4, v3: Vec4) {
147147
value[0] to v0
@@ -546,5 +546,5 @@ data class Mat4(override var value: MutableList<Vec4>) : Mat4x4t<Vec4>(value) {
546546
this[1, 0] == other[1, 0] && this[1, 1] == other[1, 1] && this[1, 2] == other[1, 2] && this[1, 3] == other[1, 3] &&
547547
this[2, 0] == other[2, 0] && this[2, 1] == other[2, 1] && this[2, 2] == other[2, 2] && this[2, 3] == other[2, 3] &&
548548
this[3, 0] == other[3, 0] && this[3, 1] == other[3, 1] && this[3, 2] == other[3, 2] && this[3, 3] == other[3, 3]
549-
}
550-
549+
override fun hashCode() = 31 * (31 * (31 * value[0].hashCode() + value[1].hashCode()) + value[2].hashCode()) + value[3].hashCode()
550+
}

src/main/kotlin/glm_/mat4x4/Mat4d.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,11 @@ data class Mat4d(override var value: MutableList<Vec4d>) : Mat4x4t<Vec4d>(value)
522522
this[0][2] == 0.0 && this[1][2] == 0.0 && this[2][2] == 1.0 && this[3][2] == 0.0 &&
523523
this[0][3] == 0.0 && this[1][3] == 0.0 && this[2][3] == 0.0 && this[3][3] == 1.0
524524

525-
525+
override fun equals(other: Any?) = other is Mat4d &&
526+
this[0, 0] == other[0, 0] && this[0, 1] == other[0, 1] && this[0, 2] == other[0, 2] && this[0, 3] == other[0, 3] &&
527+
this[1, 0] == other[1, 0] && this[1, 1] == other[1, 1] && this[1, 2] == other[1, 2] && this[1, 3] == other[1, 3] &&
528+
this[2, 0] == other[2, 0] && this[2, 1] == other[2, 1] && this[2, 2] == other[2, 2] && this[2, 3] == other[2, 3] &&
529+
this[3, 0] == other[3, 0] && this[3, 1] == other[3, 1] && this[3, 2] == other[3, 2] && this[3, 3] == other[3, 3]
530+
override fun hashCode() = 31 * (31 * (31 * value[0].hashCode() + value[1].hashCode()) + value[2].hashCode()) + value[3].hashCode()
526531
override fun toString() = super.toString()
527-
}
528-
532+
}

src/main/kotlin/glm_/quat/Quat.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class Quat(w: Float, x: Float, y: Float, z: Float) : QuatT<Float>(w, x, y, z) {
5959
// quat_cast(m, this)
6060
// }
6161

62-
constructor(inputStream: InputStream, bigEndianess: Boolean = true) :
63-
this(inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess), inputStream.float(bigEndianess))
62+
constructor(inputStream: InputStream, bigEndian: Boolean = true) :
63+
this(inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian), inputStream.float(bigEndian))
6464

6565
infix fun to(res: Mat3) = glm.mat3_cast(this, res)
6666
fun toMat3() = glm.mat3_cast(this, Mat3())
@@ -188,6 +188,7 @@ class Quat(w: Float, x: Float, y: Float, z: Float) : QuatT<Float>(w, x, y, z) {
188188
override fun toString() = "($w | $x, $y, $z)"
189189

190190
override fun equals(other: Any?) = other is Quat && this[0] == other[0] && this[1] == other[1] && this[2] == other[2] && this[3] == other[3]
191+
override fun hashCode() = 31 * (31 * (31 * w.hashCode() + x.hashCode()) + y.hashCode()) + z.hashCode()
191192

192193
@JvmOverloads
193194
fun vectorize(res: Vec4 = Vec4()) = res.put(x, y, z, w)

src/main/kotlin/glm_/quat/QuatD.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class QuatD(w: Double, x: Double, y: Double, z: Double) : QuatT<Double>(w, x, y,
181181
override fun toString() = "($x, $y, $z), $w"
182182

183183
override fun equals(other: Any?) = other is QuatD && this[0] == other[0] && this[1] == other[1] && this[2] == other[2] && this[3] == other[3]
184+
override fun hashCode() = 31 * (31 * (31 * w.hashCode() + x.hashCode()) + y.hashCode()) + z.hashCode()
184185

185186
@JvmOverloads
186187
fun vectorize(res: Vec4d = Vec4d()) = res.put(x, y, z, w)

src/main/kotlin/glm_/vec1/Vec1.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Vec1(x: Float) : Vec1t<Float>(x) {
3232
constructor(v: Vec3bool) : this(v.x.f)
3333
constructor(v: Vec4bool) : this(v.x.f)
3434

35-
constructor(bytes: ByteArray, index: Int = 0, oneByteOneFloat: Boolean = true, bigEndianess: Boolean = true)
36-
: this(if (oneByteOneFloat) bytes[index].f else bytes.getFloat(index, bigEndianess))
35+
constructor(bytes: ByteArray, index: Int = 0, oneByteOneFloat: Boolean = false, bigEndian: Boolean = true)
36+
: this(if (oneByteOneFloat) bytes[index].f else bytes.getFloat(index, bigEndian))
3737

3838
constructor(chars: CharArray, index: Int = 0) : this(chars[index].f)
3939
constructor(shorts: ShortArray, index: Int = 0) : this(shorts[index])
@@ -51,7 +51,7 @@ class Vec1(x: Float) : Vec1t<Float>(x) {
5151
put(list, index)
5252
}
5353

54-
constructor(bytes: ByteBuffer, index: Int = bytes.position(), oneByteOneFloat: Boolean = true)
54+
constructor(bytes: ByteBuffer, index: Int = bytes.position(), oneByteOneFloat: Boolean = false)
5555
: this(if (oneByteOneFloat) bytes[index].f else bytes.getFloat(index))
5656

5757
constructor(chars: CharBuffer, index: Int = chars.position()) : this(chars[index].f)
@@ -64,11 +64,11 @@ class Vec1(x: Float) : Vec1t<Float>(x) {
6464
constructor(s: Number) : this(s.f)
6565

6666

67-
fun set(bytes: ByteArray, index: Int = 0, oneByteOneFloat: Boolean = true, bigEndianess: Boolean = true) {
68-
x = if (oneByteOneFloat) bytes[index].f else bytes.getFloat(index, bigEndianess)
67+
fun set(bytes: ByteArray, index: Int = 0, oneByteOneFloat: Boolean = false, bigEndian: Boolean = true) {
68+
x = if (oneByteOneFloat) bytes[index].f else bytes.getFloat(index, bigEndian)
6969
}
7070

71-
fun set(bytes: ByteBuffer, index: Int = bytes.position(), oneByteOneFloat: Boolean = true) {
71+
fun set(bytes: ByteBuffer, index: Int = bytes.position(), oneByteOneFloat: Boolean = false) {
7272
x = if (oneByteOneFloat) bytes[index].f else bytes.getFloat(index)
7373
}
7474

@@ -124,4 +124,5 @@ class Vec1(x: Float) : Vec1t<Float>(x) {
124124
}
125125

126126
override fun equals(other: Any?) = other is Vec1 && this[0] == other[0]
127+
override fun hashCode() = x.hashCode()
127128
}

0 commit comments

Comments
 (0)