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) =
let
initialShapeLen = polygon.len
step = arc.delta / steps.float32
var prev = at var prev = at
for i in 1 .. steps:
proc discretize(arc: ArcParams, i, steps: int) =
let let
step = arc.delta / steps.float32
aPrev = arc.theta + step * (i - 1).float32 aPrev = arc.theta + step * (i - 1).float32
a = arc.theta + step * i.float32 a = arc.theta + step * i.float32
next = arc.compute(a) next = arc.compute(a)
halfway = arc.compute(aPrev + (a - aPrev) / 2) halfway = arc.compute(aPrev + (a - aPrev) / 2)
midpoint = (prev + next) / 2 midpoint = (prev + next) / 2
error = (midpoint - halfway).length error = (midpoint - halfway).length
if error >= 0.25: if error >= 0.25:
# Error too large, try again with doubled precision # Error too large, try again with doubled precision
polygon.setLen(initialShapeLen) discretize(arc, i * 2 - 1, steps * 2)
discretize(arc, steps * 2) discretize(arc, i * 2, steps * 2)
return else:
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