Skip to content

Commit af4271b

Browse files
committed
Vec1b
1 parent a7098f1 commit af4271b

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ apply plugin: 'java'
55
apply plugin: 'maven'
66
group = 'com.github.kotlin-graphics'
77

8+
apply plugin: 'com.github.johnrengelman.shadow'
9+
810
buildscript {
911

1012
ext.kotlinVersion = '1.2-M2'
1113

1214
repositories {
15+
jcenter() // shadow
1316
mavenCentral()
1417
maven { url "https://dl.bintray.com/kotlin/kotlin-dev" }
1518
}
1619
dependencies {
1720
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
21+
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
1822
}
1923
}
2024

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package glm_.vec1
2+
3+
import glm_.BYTES
4+
import glm_.b
5+
import glm_.i
6+
import glm_.vec2.Vec2bool
7+
import glm_.vec2.Vec2t
8+
import glm_.vec3.Vec3bool
9+
import glm_.vec3.Vec3t
10+
import glm_.vec4.Vec4bool
11+
import glm_.vec4.Vec4t
12+
import java.nio.*
13+
14+
class Vec1b(x: Byte) : Vec1t<Byte>(x) {
15+
16+
// -- Explicit basic, conversion other main.and conversion vector constructors --
17+
18+
constructor() : this(0)
19+
20+
constructor(v: Vec2t<out Number>) : this(v.x)
21+
constructor(v: Vec3t<out Number>) : this(v.x)
22+
constructor(v: Vec4t<out Number>) : this(v.x)
23+
24+
constructor(v: Vec2bool) : this(v.x.b)
25+
constructor(v: Vec3bool) : this(v.x.b)
26+
constructor(v: Vec4bool) : this(v.x.b)
27+
28+
constructor(bytes: ByteArray, index: Int = 0) : this(bytes[index])
29+
constructor(chars: CharArray, index: Int = 0) : this(chars[index].b)
30+
constructor(shorts: ShortArray, index: Int = 0) : this(shorts[index])
31+
constructor(ints: IntArray, index: Int = 0) : this(ints[index])
32+
constructor(longs: LongArray, index: Int = 0) : this(longs[index])
33+
constructor(floats: FloatArray, index: Int = 0) : this(floats[index])
34+
constructor(doubles: DoubleArray, index: Int = 0) : this(doubles[index])
35+
constructor(booleans: BooleanArray, index: Int = 0) : this(booleans[index].b)
36+
37+
constructor(numbers: Array<out Number>, index: Int = 0) : this(numbers[index])
38+
constructor(chars: Array<Char>, index: Int = 0) : this(chars[index].b)
39+
constructor(booleans: Array<Boolean>, index: Int = 0) : this(booleans[index].b)
40+
41+
constructor(list: List<Any>, index: Int = 0) : this(list[index].b)
42+
43+
constructor(bytes: ByteBuffer, index: Int = bytes.position()) : this(bytes[index])
44+
constructor(chars: CharBuffer, index: Int = chars.position()) : this(chars[index].b)
45+
constructor(shorts: ShortBuffer, index: Int = shorts.position()) : this(shorts[index])
46+
constructor(ints: IntBuffer, index: Int = ints.position()) : this(ints[index])
47+
constructor(longs: LongBuffer, index: Int = longs.position()) : this(longs[index])
48+
constructor(floats: FloatBuffer, index: Int = floats.position()) : this(floats[index])
49+
constructor(doubles: DoubleBuffer, index: Int = doubles.position()) : this(doubles[index])
50+
51+
constructor(x: Number) : this(x.b)
52+
53+
54+
fun put(x: Byte, y: Byte): Vec1b {
55+
this.x = x
56+
return this
57+
}
58+
59+
override fun put(x: Number): Vec1b {
60+
this.x = x.b
61+
return this
62+
}
63+
64+
65+
// -- Component accesses --
66+
67+
operator fun get(i: Int) = when (i) {
68+
0 -> x
69+
else -> throw ArrayIndexOutOfBoundsException()
70+
}
71+
72+
operator fun set(i: Int, s: Byte) = when (i) {
73+
0 -> x = s
74+
else -> throw ArrayIndexOutOfBoundsException()
75+
}
76+
77+
operator fun set(i: Int, s: Number) = when (i) {
78+
0 -> x = s.b
79+
else -> throw ArrayIndexOutOfBoundsException()
80+
}
81+
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,5 @@ class Vec3i(x: Int, y: Int, z: Int) : Vec3t<Int>(x, y, z) {
403403
fun shr_(bX: Number, bY: Number, bZ: Number) = shr(this, this, bX.i, bY.i, bZ.i)
404404

405405

406-
override fun equals(other: Any?) =
407-
if (other is Vec3i)
408-
this[0] == other[0] && this[1] == other[1] && this[2] == other[2]
409-
else false
406+
override fun equals(other: Any?) = if (other is Vec3i) this[0] == other[0] && this[1] == other[1] && this[2] == other[2] else false
410407
}

0 commit comments

Comments
 (0)