Skip to content

Commit 4d8005f

Browse files
committed
Define vmath value bindings
1 parent b42af64 commit 4d8005f

1 file changed

Lines changed: 33 additions & 30 deletions

File tree

bindings/bindings.nim

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import genny, pixie, pixie/internal, unicode, bumpy, chroma
1+
import genny, pixie, pixie/internal, unicode, bumpy, chroma, vmath
22

33
var lastError: ref PixieError
44

@@ -9,30 +9,14 @@ proc takeError(): string =
99
proc checkError(): bool =
1010
result = lastError != nil
1111

12-
type
13-
Vector2* {.bycopy.} = object
14-
x*, y*: float32
12+
proc translate(x, y: float32): Mat3 =
13+
vmath.translate(vec2(x, y))
1514

16-
Matrix3* {.bycopy.} = object
17-
values*: array[9, float32]
15+
proc rotate(angle: float32): Mat3 =
16+
vmath.rotate(angle)
1817

19-
proc matrix3(): Matrix3 =
20-
cast[Matrix3](mat3())
21-
22-
proc mul(a, b: Matrix3): Matrix3 =
23-
cast[Matrix3](cast[Mat3](a) * cast[Mat3](b))
24-
25-
proc translate(x, y: float32): Matrix3 =
26-
cast[Matrix3](translate(vec2(x, y)))
27-
28-
proc rotate(angle: float32): Matrix3 =
29-
cast[Matrix3](rotate(angle))
30-
31-
proc scale(x, y: float32): Matrix3 =
32-
cast[Matrix3](scale(vec2(x, y)))
33-
34-
proc inverse(m: Matrix3): Matrix3 =
35-
cast[Matrix3](inverse(cast[Mat3](m)))
18+
proc scale(x, y: float32): Mat3 =
19+
vmath.scale(vec2(x, y))
3620

3721
proc parseColor(s: string): Color {.raises: [PixieError]} =
3822
try:
@@ -72,14 +56,33 @@ exportProcs:
7256
checkError
7357
takeError
7458

75-
exportObject Vector2:
76-
discard
77-
78-
exportObject Matrix3:
59+
exportObject vmath.Vec2:
60+
fields:
61+
x: float32
62+
y: float32
63+
procs:
64+
`+`(Vec2, Vec2)
65+
`-`(Vec2, Vec2)
66+
`*`(Vec2, Vec2)
67+
`/`(Vec2, Vec2)
68+
`*`(Vec2, float32)
69+
`/`(Vec2, float32)
70+
length(Vec2)
71+
normalize(Vec2)
72+
dot(Vec2, Vec2)
73+
dist(Vec2, Vec2)
74+
75+
exportObject vmath.Mat3:
76+
fields:
77+
values: array[9, float32]
7978
constructor:
80-
matrix3
79+
mat3()
8180
procs:
82-
mul(Matrix3, Matrix3)
81+
`*`(Mat3, Mat3)
82+
`*`(Mat3, Vec2)
83+
inverse(Mat3)
84+
transpose(Mat3)
85+
determinant(Mat3)
8386

8487
exportObject bumpy.Rect:
8588
discard
@@ -306,7 +309,7 @@ exportProcs:
306309
translate(float32, float32)
307310
rotate(float32)
308311
scale(float32, float32)
309-
inverse(Matrix3)
312+
inverse(Mat3)
310313
snapToPixels
311314
mix(Color, Color, float32)
312315

0 commit comments

Comments
 (0)