Skip to content

Commit 0c90ac2

Browse files
committed
some more conversion constructors
reduces memory overhead by not casting them to a Number
1 parent e5a3195 commit 0c90ac2

File tree

12 files changed

+23
-7
lines changed

12 files changed

+23
-7
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Vec2(@JvmField var ofs: Int, @JvmField var array: FloatArray) : Vec2t<Floa
4343

4444
// -- Conversion constructors --
4545

46-
4746
constructor(v: Number) : this(v.f)
4847
constructor(x: Number, y: Number) : this(x.f, y.f)
4948
constructor(x: Int, y: Int) : this(x.f, y.f)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Vec2i(@JvmField var ofs: Int, @JvmField var array: IntArray) : Vec2t<Int>,
4444

4545
constructor(v: Number) : this(v.i)
4646
constructor(x: Number, y: Number) : this(x.i, y.i)
47+
constructor(x: Float, y: Float) : this(x.i, y.i)
4748

4849
// Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
4950

src/main/kotlin/glm_/vec3/Vec3.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ class Vec3(@JvmField var ofs: Int, @JvmField var array: FloatArray) : Vec3t<Floa
3636

3737
// -- Implicit basic constructors --
3838

39-
constructor() : this(0, 0, 0)
39+
constructor() : this(0)
4040
constructor(v: Vec3) : this(v.x, v.y, v.z)
4141

4242
// -- Explicit basic constructors --
4343

44+
4445
@JvmOverloads
4546
constructor(x: Float, y: Float = x, z: Float = x) : this(0, floatArrayOf(x, y, z))
47+
constructor(x: Int, y: Int = x, z: Int = x) : this(0, floatArrayOf(x.f, y.f, z.f))
4648

4749
// -- Conversion scalar constructors --
4850

src/main/kotlin/glm_/vec3/Vec3b.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Vec3b(@JvmField var ofs: Int, @JvmField var array: ByteArray) : Vec3t<Byte
3737

3838
// -- Implicit basic constructors --
3939

40-
constructor() : this(0, 0, 0)
40+
constructor() : this(0)
4141
constructor(v: Vec3b) : this(v.x, v.y, v.z)
4242
constructor(v: Vec2b) : this(v.x, v.y, 0)
4343

src/main/kotlin/glm_/vec3/Vec3d.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ class Vec3d(@JvmField var ofs: Int, @JvmField var array: DoubleArray) : Vec3t<Do
3636

3737
// -- Implicit basic constructors --
3838

39-
constructor() : this(0, 0, 0)
39+
constructor() : this(0)
4040
constructor(v: Vec3d) : this(v.x, v.y, v.z)
4141
constructor(v: Vec2d) : this(v.x, v.y, 0.0)
4242

4343
// -- Explicit basic constructors --
4444

4545
@JvmOverloads
4646
constructor(x: Double, y: Double = x, z: Double = x) : this(0, doubleArrayOf(x, y, z))
47+
constructor(x: Float, y: Float = x, z: Float = x) : this(0, doubleArrayOf(x.d, y.d, z.d))
48+
constructor(x: Int, y: Int = x, z: Int = x) : this(0, doubleArrayOf(x.d, y.d, z.d))
4749

4850
// -- Conversion scalar constructors --
4951

src/main/kotlin/glm_/vec3/Vec3i.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ class Vec3i(@JvmField var ofs: Int, @JvmField var array: IntArray) : Vec3t<Int>,
3333

3434
// -- Implicit basic constructors --
3535

36-
constructor() : this(0, 0, 0)
36+
constructor() : this(0)
3737
constructor(v: Vec3i) : this(v.x, v.y, v.z)
3838
constructor(v: Vec2i) : this(v.x, v.y, 0)
3939

4040
// -- Explicit basic constructors --
4141

4242
@JvmOverloads
4343
constructor(x: Int, y: Int = x, z: Int = x) : this(0, intArrayOf(x.i, y.i, z.i))
44+
constructor(x: Float, y: Float = x, z: Float = x) : this(0, intArrayOf(x.i, y.i, z.i))
4445

4546
// -- Conversion scalar constructors --
4647

src/main/kotlin/glm_/vec3/Vec3l.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ class Vec3l(@JvmField var ofs: Int, @JvmField var array: LongArray) : Vec3t<Long
3333

3434
// -- Implicit basic constructors --
3535

36-
constructor() : this(0, 0, 0)
36+
constructor() : this(0)
3737
constructor(v: Vec3l) : this(v.x, v.y, v.z)
3838
constructor(v: Vec2l) : this(v.x, v.y, 0)
3939

4040
// -- Explicit basic constructors --
4141

4242
@JvmOverloads
4343
constructor(x: Long, y: Long = x, z: Long = x) : this(0, longArrayOf(x.L, y.L, z.L))
44+
constructor(x: Int, y: Int = x, z: Int = x) : this(0, longArrayOf(x.L, y.L, z.L))
4445

4546
// -- Conversion scalar constructors --
4647

src/main/kotlin/glm_/vec3/Vec3s.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Vec3s(@JvmField var ofs: Int, @JvmField var array: ShortArray) : Vec3t<Sho
3333

3434
// -- Implicit basic constructors --
3535

36-
constructor() : this(0, 0, 0)
36+
constructor() : this(0)
3737
constructor(v: Vec3s) : this(v.x, v.y, v.z)
3838
constructor(v: Vec2s) : this(v.x, v.y, 0)
3939

src/main/kotlin/glm_/vec4/Vec4.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class Vec4(@JvmField var ofs: Int, @JvmField var array: FloatArray) : Vec4t<Floa
4747
// -- Explicit basic constructors --
4848

4949
constructor(x: Float) : this(x, x, x, x)
50+
constructor(x: Int) : this(x.f)
51+
5052
constructor(x: Float, y: Float, z: Float, w: Float) : this(0, floatArrayOf(x, y, z, w))
53+
constructor(x: Int, y: Int, z: Int, w: Int) : this(0, floatArrayOf(x.f, y.f, z.f, w.f))
5154

5255
// -- Conversion scalar constructors --
5356

src/main/kotlin/glm_/vec4/Vec4d.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ class Vec4d(@JvmField var ofs: Int, @JvmField var array: DoubleArray) : Vec4t<Do
4747
// -- Explicit basic constructors --
4848

4949
constructor(x: Double) : this(x, x, x, x)
50+
constructor(x: Int) : this(x.d)
51+
constructor(x: Float) : this(x.d)
52+
5053
constructor(x: Double, y: Double, z: Double, w: Double) : this(0, doubleArrayOf(x, y, z, w))
54+
constructor(x: Float, y: Float, z: Float, w: Float) : this(0, doubleArrayOf(x.d, y.d, z.d, w.d))
55+
constructor(x: Int, y: Int, z: Int, w: Int) : this(0, doubleArrayOf(x.d, y.d, z.d, w.d))
5156

5257
// -- Conversion scalar constructors --
5358

0 commit comments

Comments
 (0)