like quad, cubic

This commit is contained in:
Ryan Oldenburg 2021-01-22 08:56:18 -06:00
parent 7271cdfe80
commit 9aafd87def

View file

@ -346,29 +346,28 @@ proc commandsToPolygons*(commands: seq[PathCommand]): seq[seq[Vec2]] =
result = vec2(cos(a) * arc.radii.x, sin(a) * arc.radii.y) result = vec2(cos(a) * arc.radii.x, sin(a) * arc.radii.y)
result = arc.rotMat * result + arc.center result = arc.rotMat * result + arc.center
proc discretize(arc: ArcParams, steps: int) = var prev = at
proc discretize(arc: ArcParams, i, steps: int) =
let let
initialShapeLen = polygon.len
step = arc.delta / steps.float32 step = arc.delta / steps.float32
var prev = at aPrev = arc.theta + step * (i - 1).float32
for i in 1 .. steps: a = arc.theta + step * i.float32
let next = arc.compute(a)
aPrev = arc.theta + step * (i - 1).float32 halfway = arc.compute(aPrev + (a - aPrev) / 2)
a = arc.theta + step * i.float32 midpoint = (prev + next) / 2
next = arc.compute(a) error = (midpoint - halfway).length
halfway = arc.compute(aPrev + (a - aPrev) / 2)
midpoint = (prev + next) / 2 if error >= 0.25:
error = (midpoint - halfway).length # Error too large, try again with doubled precision
if error >= 0.25: discretize(arc, i * 2 - 1, steps * 2)
# Error too large, try again with doubled precision discretize(arc, i * 2, steps * 2)
polygon.setLen(initialShapeLen) else:
discretize(arc, steps * 2)
return
drawLine(prev, next) drawLine(prev, next)
prev = next prev = next
let arc = endpointToCenterArcParams(at, radii, rotation, large, sweep, to) let arc = endpointToCenterArcParams(at, radii, rotation, large, sweep, to)
discretize(arc, 4) discretize(arc, 1, 1)
for command in commands: for command in commands:
case command.kind case command.kind