I think you are just having an issue with the named tuple syntax. I don't think
you can have the names in the constructor of a tuple. I feel like a tuple is a
wrong thing to use here, just create a normal object
Fixed:
import vmath
type
Seg = array[4, Vec2]
Segs = array[4, Seg]
Spline = object
t: seq[float32]
xy: seq[Vec2]
v: seq[Vec2]
a: seq[Vec2]
lengt: seq[float32]
proc bezier(segment: Seg, res: int): Spline =
var t: seq[float32]
let
t1 = 1 / float32(res)
t2 = t1 * t1
t3 = t2 * t1
b0 = segment[0]
b1 = segment[1]
b2 = segment[2]
b3 = segment[3]
a = -b0 + 3 * b1 + -3 * b2 + b3
b = 3 * b0 + -6 * b1 + 3 * b2
c = -3 * b0 + 3 * b1
var
d = b0
fd1 = a * t3 + b * t2 + c * t1 #initial velocity
fd2 = 6 * a * t3 + 2 * b * t2 #initial acceleration
fd3 = 6 * a * t3 #acceleration change
seqt = @[float32(0.0)]
seqxy = @[d]
seqfd1 = @[fd1]
seqfd2 = @[fd2]
seqlen = @[length(d)]
for i in 1 .. res:
d += fd1
fd1 += fd2 #speed
fd2 += fd3 #acceleration
seqt.add(float32(i)*t1)
seqxy.add(d)
seqfd1.add(fd1)
seqfd2.add(fd2)
seqlen.add(length(d))
let spline = Spline(t: seqt, xy: seqxy, v: seqfd1, a: seqfd2)
return spline
Run