Skip to content

Commit 074c483

Browse files
committed
vec1i operators
1 parent 595d2be commit 074c483

File tree

7 files changed

+142
-11
lines changed

7 files changed

+142
-11
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
99

1010
buildscript {
1111

12-
ext.kotlinVersion = '1.2-M2'
12+
ext.kotlinVersion = '1.2.0-beta-31'
1313

1414
repositories {
1515
jcenter() // shadow
@@ -27,7 +27,7 @@ dependencies {
2727

2828
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
2929

30-
compile 'com.github.kotlin-graphics:kotlin-unsigned:2f996d45ec42c5972b597ce6a6469afce777424a'
30+
compile 'com.github.kotlin-graphics:kotlin-unsigned:2dd9c3c02957cc21fc9da154ad50646359e572ad'
3131

3232
testCompile 'com.github.elect86:kotlintest:43281b7e1b'
3333
}

src/main/kotlin/glm_/detail/noise.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import glm_.glm.floor
44
import glm_.vec2.Vec2
55
import glm_.vec2.Vec2d
66
import glm_.vec2.Vec2t
7-
import glm_.vec2.operators.minus
8-
import glm_.vec2.operators.times
7+
import glm_.vec1.operators.times
98
import glm_.vec3.Vec3
109
import glm_.vec3.Vec3d
1110
import glm_.vec3.Vec3t

src/main/kotlin/glm_/noise.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ package glm_
77
import glm_.glm.floor
88
import glm_.vec2.Vec2
99
import glm_.vec2.Vec2d
10-
import glm_.vec2.operators.minus
11-
import glm_.vec2.operators.times
10+
import glm_.vec1.operators.minus
11+
import glm_.vec1.operators.times
1212
import glm_.vec3.Vec3
1313
import glm_.vec3.Vec3d
1414
import glm_.vec3.operators.minus

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import glm_.BYTES
44
import glm_.getInt
55
import glm_.i
66
import glm_.set
7+
import glm_.vec1.operators.vec1i_operators
78
import glm_.vec2.Vec2bool
89
import glm_.vec2.Vec2t
910
import glm_.vec3.Vec3bool
@@ -115,7 +116,7 @@ class Vec1i(x: Int) : Vec1t<Int>(x) {
115116
else -> throw ArrayIndexOutOfBoundsException()
116117
}
117118

118-
companion object {//TODO : vec2b_operators {
119+
companion object : vec1i_operators {
119120
@JvmField
120121
val length = 1
121122
@JvmField
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package glm_.vec1.operators
2+
3+
import glm_.i
4+
import glm_.vec1.Vec1i
5+
import glm_.vec1.Vec1i.Companion.div
6+
import glm_.vec1.Vec1i.Companion.minus
7+
import glm_.vec1.Vec1i.Companion.plus
8+
import glm_.vec1.Vec1i.Companion.rem
9+
import glm_.vec1.Vec1i.Companion.times
10+
11+
/**
12+
* Created by GBarbieri on 08.11.2016.
13+
*/
14+
interface vec1i_operators {
15+
16+
fun plus(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
17+
res.x = a.x + bX
18+
return res
19+
}
20+
21+
fun minus(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
22+
res.x = a.x - bX
23+
return res
24+
}
25+
26+
fun minus(res: Vec1i, aX: Int, b: Vec1i): Vec1i {
27+
res.x = aX - b.x
28+
return res
29+
}
30+
31+
fun times(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
32+
res.x = a.x * bX
33+
return res
34+
}
35+
36+
fun div(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
37+
res.x = a.x / bX
38+
return res
39+
}
40+
41+
fun div(res: Vec1i, aX: Int, b: Vec1i): Vec1i {
42+
res.x = aX / b.x
43+
return res
44+
}
45+
46+
fun rem(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
47+
res.x = a.x % bX
48+
return res
49+
}
50+
51+
fun rem(res: Vec1i, aX: Int, b: Vec1i): Vec1i {
52+
res.x = aX % b.x
53+
return res
54+
}
55+
56+
fun and(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
57+
res.x = a.x and bX
58+
return res
59+
}
60+
61+
fun or(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
62+
res.x = a.x or bX
63+
return res
64+
}
65+
66+
fun xor(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
67+
res.x = a.x xor bX
68+
return res
69+
}
70+
71+
fun shl(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
72+
res.x = a.x shl bX
73+
return res
74+
}
75+
76+
fun shr(res: Vec1i, a: Vec1i, bX: Int): Vec1i {
77+
res.x = a.x shr bX
78+
return res
79+
}
80+
81+
fun inv(res: Vec1i, a: Vec1i): Vec1i {
82+
res.x = a.x.inv()
83+
return res
84+
}
85+
}
86+
87+
88+
// -- Specific binary arithmetic operators --
89+
90+
infix operator fun Int.plus(b: Vec1i) = plus(Vec1i(), b, this)
91+
fun Int.plus(b: Vec1i, res: Vec1i) = plus(res, b, this)
92+
infix fun Int.plus_(b: Vec1i) = plus(b, b, this)
93+
94+
infix operator fun Int.minus(b: Vec1i) = minus(Vec1i(), this, b)
95+
fun Int.minus(b: Vec1i, res: Vec1i) = minus(res, b, this)
96+
infix fun Int.minus_(b: Vec1i) = minus(b, this, b)
97+
98+
infix operator fun Int.times(b: Vec1i) = times(Vec1i(), b, this)
99+
fun Int.times(b: Vec1i, res: Vec1i) = times(res, b, this)
100+
infix fun Int.times_(b: Vec1i) = times(b, b, this)
101+
102+
infix operator fun Int.div(b: Vec1i) = div(Vec1i(), this, b)
103+
fun Int.div(b: Vec1i, res: Vec1i) = div(res, b, this)
104+
infix fun Int.div_(b: Vec1i) = div(b, this, b)
105+
106+
infix operator fun Int.rem(b: Vec1i) = rem(Vec1i(), this, b)
107+
fun Int.rem(b: Vec1i, res: Vec1i) = rem(res, b, this)
108+
infix fun Int.rem_(b: Vec1i) = rem(b, this, b)
109+
110+
111+
// -- Generic binary arithmetic operators --
112+
113+
infix operator fun Number.plus(b: Vec1i) = plus(Vec1i(), b, this.i)
114+
fun Number.plus(b: Vec1i, res: Vec1i) = plus(res, b, this.i)
115+
infix fun Number.plus_(b: Vec1i) = plus(b, b, this.i)
116+
117+
infix operator fun Number.minus(b: Vec1i) = minus(Vec1i(), this.i, b)
118+
fun Number.minus(b: Vec1i, res: Vec1i) = minus(res, b, this.i)
119+
infix fun Number.minus_(b: Vec1i) = minus(b, this.i, b)
120+
121+
infix operator fun Number.times(b: Vec1i) = times(Vec1i(), b, this.i)
122+
fun Number.times(b: Vec1i, res: Vec1i) = times(res, b, this.i)
123+
infix fun Number.times_(b: Vec1i) = times(b, b, this.i)
124+
125+
infix operator fun Number.div(b: Vec1i) = div(Vec1i(), this.i, b)
126+
fun Number.div(b: Vec1i, res: Vec1i) = div(res, b, this.i)
127+
infix fun Number.div_(b: Vec1i) = div(b, this.i, b)
128+
129+
infix operator fun Number.rem(b: Vec1i) = rem(Vec1i(), this.i, b)
130+
fun Number.rem(b: Vec1i, res: Vec1i) = rem(res, b, this.i)
131+
infix fun Number.rem_(b: Vec1i) = rem(b, this.i, b)

src/test/kotlin/glm_/coreVec2.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ package glm_
66

77
import glm_.vec2.Vec2
88
import glm_.vec2.Vec2i
9-
import glm_.vec2.operators.div
10-
import glm_.vec2.operators.minus
11-
import glm_.vec2.operators.plus
12-
import glm_.vec2.operators.times
9+
import glm_.vec1.operators.div
10+
import glm_.vec1.operators.minus
11+
import glm_.vec1.operators.plus
12+
import glm_.vec1.operators.times
1313
import io.kotlintest.matchers.shouldBe
1414
import io.kotlintest.specs.StringSpec
1515

0 commit comments

Comments
 (0)