Skip to content

Commit 4c3a8b7

Browse files
committed
- vec1 to
- removed Any. conversions
1 parent 9aba3bf commit 4c3a8b7

40 files changed

+99
-88
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import glm.glm
2323

2424
fun camera(translate: Float, rotate: Vec2): Mat4 {
2525

26-
val projection = glm.perspective(glm.PIf * 0.25f, 4.0f / 3.0f, 0.1f, 100.f)
26+
val projection = glm.perspective(glm.PIf * 0.25f, 4.0f / 3.0f, 0.1f, 100.`toFloat()`)
2727
var view = glm.translate(Mat4(1.0f), Vec3(0.0f, 0.0f, -translate))
2828
view = glm.rotate(view, rotate.y, Vec3(-1.0f, 0.0f, 0.0f))
2929
view = glm.rotate(view, rotate.x, Vec3(0.0f, 1.0f, 0.0f))

src/main/kotlin/glm_/extensions.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ fun InputStream.mat4(bigEndianess: Boolean = true) = Mat4(
207207
float(bigEndianess), float(bigEndianess), float(bigEndianess), float(bigEndianess),
208208
float(bigEndianess), float(bigEndianess), float(bigEndianess), float(bigEndianess))
209209

210-
val Any.f
210+
val Any.toFloat: Float
211211
get() = when (this) {
212212
is Number -> this.f
213213
is Char -> this.f
@@ -216,7 +216,7 @@ val Any.f
216216
else -> throw ArithmeticException("incompatible type")
217217
}
218218

219-
val Any.b
219+
val Any.toByte: Byte
220220
get() = when (this) {
221221
is Number -> this.b
222222
is Char -> this.b
@@ -225,7 +225,7 @@ val Any.b
225225
else -> throw ArithmeticException("incompatible type")
226226
}
227227

228-
val Any.d
228+
val Any.toDouble: Double
229229
get() = when (this) {
230230
is Number -> this.d
231231
is Char -> this.d
@@ -234,16 +234,16 @@ val Any.d
234234
else -> throw ArithmeticException("incompatible type")
235235
}
236236

237-
val Any.i
237+
val Any.toInt: Int
238238
get() = when (this) {
239-
is Number -> this.d
240-
is Char -> this.d
241-
is Boolean -> this.d
242-
is String -> this.d
239+
is Number -> this.i
240+
is Char -> this.i
241+
is Boolean -> this.i
242+
is String -> this.i
243243
else -> throw ArithmeticException("incompatible type")
244244
}
245245

246-
val Any.L
246+
val Any.toLong: Long
247247
get() = when (this) {
248248
is Number -> this.L
249249
is Char -> this.L
@@ -252,7 +252,7 @@ val Any.L
252252
else -> throw ArithmeticException("incompatible type")
253253
}
254254

255-
val Any.s
255+
val Any.toShort: Short
256256
get() = when (this) {
257257
is Number -> this.s
258258
is Char -> this.s

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package glm_.mat2x2
22

33
import glm_.BYTES
4-
import glm_.f
4+
import glm_.d
55
import glm_.glm
66
import glm_.mat2x2.operators.mat2d_operators
77
import glm_.mat2x3.Mat2x3t
@@ -80,14 +80,14 @@ data class Mat2d(override var value: MutableList<Vec2d>) : Mat2x2t<Vec2d>(value)
8080

8181
fun to(scalar: Number) {
8282
value = mutableListOf(
83-
Vec2d(scalar.f, 0),
84-
Vec2d(0, scalar.f))
83+
Vec2d(scalar.d, 0),
84+
Vec2d(0, scalar.d))
8585
}
8686

8787
fun to(x0: Number, x1: Number, y0: Number, y1: Number) {
8888
value = mutableListOf(
89-
Vec2d(x0.f, y0.f),
90-
Vec2d(x1.f, y1.f))
89+
Vec2d(x0.d, y0.d),
90+
Vec2d(x1.d, y1.d))
9191
}
9292

9393
fun to(v0: Vec2t<*>, v1: Vec2t<*>) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package glm_.quat
22

33
import glm_.BYTES
44
import glm_.d
5-
import glm_.f
65
import glm_.glm
76
import glm_.mat.QuatT
87
import glm_.vec3.Vec3
@@ -63,7 +62,7 @@ class QuatD(w: Double, x: Double, y: Double, z: Double) : QuatT<Double>(w, x, y,
6362

6463
// -- Explicit basic constructors --
6564

66-
constructor(q: QuatD) : this(q.w.f, q.x.f, q.y.f, q.z.f)
65+
constructor(q: QuatD) : this(q.w.d, q.x.d, q.y.d, q.z.d)
6766
constructor(w: Number, x: Number, y: Number, z: Number) : this(w.d, x.d, y.d, z.d)
6867
constructor(vec4: Vec4t<*>) : this(vec4.w.d, vec4.x.d, vec4.y.d, vec4.z.d)
6968

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package glm_.vec1
22

33
import glm_.BYTES
44
import glm_.b
5-
import glm_.i
5+
import glm_.set
6+
import glm_.toByte
67
import glm_.vec2.Vec2bool
78
import glm_.vec2.Vec2t
89
import glm_.vec3.Vec3bool
@@ -38,7 +39,7 @@ class Vec1b(x: Byte) : Vec1t<Byte>(x) {
3839
constructor(chars: Array<Char>, index: Int = 0) : this(chars[index].b)
3940
constructor(booleans: Array<Boolean>, index: Int = 0) : this(booleans[index].b)
4041

41-
constructor(list: List<Any>, index: Int = 0) : this(list[index].b)
42+
constructor(list: List<Any>, index: Int = 0) : this(list[index].toByte)
4243

4344
constructor(bytes: ByteBuffer, index: Int = bytes.position()) : this(bytes[index])
4445
constructor(chars: CharBuffer, index: Int = chars.position()) : this(chars[index].b)
@@ -51,7 +52,7 @@ class Vec1b(x: Byte) : Vec1t<Byte>(x) {
5152
constructor(x: Number) : this(x.b)
5253

5354

54-
fun put(x: Byte, y: Byte): Vec1b {
55+
fun put(x: Byte): Vec1b {
5556
this.x = x
5657
return this
5758
}
@@ -61,6 +62,8 @@ class Vec1b(x: Byte) : Vec1t<Byte>(x) {
6162
return this
6263
}
6364

65+
infix fun to(bytes: ByteBuffer) = to(bytes, bytes.position())
66+
fun to(bytes: ByteBuffer, index: Int): ByteBuffer = bytes.put(index, x)
6467

6568
// -- Component accesses --
6669

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package glm_.vec1
33
import glm_.BYTES
44
import glm_.getInt
55
import glm_.i
6+
import glm_.set
67
import glm_.vec2.Vec2bool
78
import glm_.vec2.Vec2t
89
import glm_.vec3.Vec3bool
@@ -82,6 +83,22 @@ class Vec1i(x: Int) : Vec1t<Int>(x) {
8283
return this
8384
}
8485

86+
infix fun to(ints: IntArray) = to(ints, 0)
87+
88+
fun to(ints: IntArray, index: Int): IntArray {
89+
ints[index] = x
90+
return ints
91+
}
92+
93+
infix fun to(ints: IntBuffer) = to(ints, ints.position())
94+
95+
fun to(ints: IntBuffer, index: Int): IntBuffer {
96+
ints[index] = x
97+
return ints
98+
}
99+
100+
infix fun to(bytes: ByteBuffer) = to(bytes, bytes.position())
101+
fun to(bytes: ByteBuffer, index: Int): ByteBuffer = bytes.putInt(index, x)
85102

86103
// -- Component accesses --
87104

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ abstract class Vec1t<T : Number>(_x: T) {
128128

129129

130130
var s
131-
@JvmName("s") get() = x
132-
@JvmName("s") set(value) {
131+
@JvmName("toShort") get() = x
132+
@JvmName("toShort") set(value) {
133133
x = value
134134
}
135135
}

src/main/kotlin/glm_/vec2/Vec2.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Vec2(x: Float, y: Float) : Vec2t<Float>(x, y) {
4242
constructor(chars: Array<Char>, index: Int = 0) : this(chars[index].f, chars[index + 1].f)
4343
constructor(booleans: Array<Boolean>, index: Int = 0) : this(booleans[index].f, booleans[index + 1].f)
4444

45-
constructor(list: List<Any>, index: Int = 0) : this(list[index].f, list[index + 1].f)
45+
constructor(list: List<Any>, index: Int = 0) : this(list[index].toFloat, list[index + 1].toFloat)
4646

4747
constructor(bytes: ByteBuffer, index: Int = bytes.position(), oneByteOneFloat: Boolean = false) : this(
4848
if (oneByteOneFloat) bytes[index].f else bytes.getFloat(index),

src/main/kotlin/glm_/vec2/Vec2b.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package glm_.vec2
33
import glm_.BYTES
44
import glm_.b
55
import glm_.i
6+
import glm_.toByte
67
import glm_.vec2.operators.vec2b_operators
78
import glm_.vec3.Vec3bool
89
import glm_.vec3.Vec3t
@@ -41,7 +42,7 @@ class Vec2b(x: Byte, y: Byte) : Vec2t<Byte>(x, y) {
4142
constructor(chars: Array<Char>, index: Int = 0) : this(chars[index].b, chars[index + 1].b)
4243
constructor(booleans: Array<Boolean>, index: Int = 0) : this(booleans[index].b, booleans[index + 1].b)
4344

44-
constructor(list: List<Any>, index: Int = 0) : this(list[index].b, list[index + 1].b)
45+
constructor(list: List<Any>, index: Int = 0) : this(list[index].toByte, list[index + 1].toByte)
4546

4647
constructor(bytes: ByteBuffer, index: Int = bytes.position()) : this(bytes[index], bytes[index + 1])
4748
constructor(chars: CharBuffer, index: Int = chars.position()) : this(chars[index].b, chars[index + 1].b)

src/main/kotlin/glm_/vec2/Vec2d.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package glm_.vec2
22

3-
import glm_.BYTES
4-
import glm_.d
5-
import glm_.getDouble
6-
import glm_.glm
3+
import glm_.*
74
import glm_.vec2.operators.vec2d_operators
85
import glm_.vec3.Vec3bool
96
import glm_.vec3.Vec3t
@@ -45,7 +42,7 @@ class Vec2d(x: Double, y: Double) : Vec2t<Double>(x, y) {
4542
constructor(chars: Array<Char>, index: Int = 0) : this(chars[index].d, chars[index + 1].d)
4643
constructor(booleans: Array<Boolean>, index: Int = 0) : this(booleans[index].d, booleans[index + 1].d)
4744

48-
constructor(list: List<Any>, index: Int = 0) : this(list[index].d, list[index + 1].d)
45+
constructor(list: List<Any>, index: Int = 0) : this(list[index].toDouble, list[index + 1].toDouble)
4946

5047
constructor(bytes: ByteBuffer, index: Int = bytes.position(), oneByteOneDouble: Boolean = true) : this(
5148
if (oneByteOneDouble) bytes[index].d else bytes.getDouble(index),

0 commit comments

Comments
 (0)