check for fenv epsilon instead of literal 0

This commit is contained in:
Ryan Oldenburg 2022-03-24 12:00:30 -05:00
parent 2262459b5d
commit 64b63d421d
2 changed files with 30 additions and 9 deletions

View file

@ -1,4 +1,4 @@
import blends, bumpy, chroma, common, images, internal, masks, paints, strutils, vmath
import blends, bumpy, chroma, common, images, internal, masks, paints, strutils, vmath, fenv
when defined(amd64) and not defined(pixieNoSimd):
import nimsimd/sse2
@ -686,6 +686,8 @@ proc commandsToShapes(
next = compute(at, ctrl1, ctrl2, to, t + step)
halfway = compute(at, ctrl1, ctrl2, to, t + step / 2)
while true:
if step <= epsilon(float32):
raise newException(PixieError, "Unable to discretize cubic")
let
midpoint = (prev + next) / 2
error = (midpoint - halfway).lengthSq
@ -693,8 +695,6 @@ proc commandsToShapes(
next = halfway
halfway = compute(at, ctrl1, ctrl2, to, t + step / 4)
step /= 2
if step == 0:
raise newException(PixieError, "Unable to discretize cubic")
else:
shape.addSegment(prev, next)
t += step
@ -720,6 +720,8 @@ proc commandsToShapes(
halfway = compute(at, ctrl, to, t + step / 2)
halfStepping = false
while true:
if step <= epsilon(float32):
raise newException(PixieError, "Unable to discretize quadratic")
let
midpoint = (prev + next) / 2
error = (midpoint - halfway).lengthSq
@ -728,8 +730,6 @@ proc commandsToShapes(
halfway = compute(at, ctrl, to, t + step / 4)
halfStepping = true
step /= 2
if step == 0:
raise newException(PixieError, "Unable to discretize quadratic")
else:
shape.addSegment(prev, next)
t += step
@ -838,6 +838,8 @@ proc commandsToShapes(
step = 1.float32 # How far we want to try to move along the curve
prev = at
while t != 1:
if step <= epsilon(float32):
raise newException(PixieError, "Unable to discretize arc")
let
aPrev = arc.theta + arc.delta * t
a = arc.theta + arc.delta * (t + step)
@ -857,8 +859,6 @@ proc commandsToShapes(
step = min(step / 2, 1 - t) # Assume next steps hould be the same size
else:
step = step / 4 # We know a half-step is too big
if step == 0:
raise newException(PixieError, "Unable to discretize arc")
else:
shape.addSegment(prev, next)
prev = next

View file

@ -704,8 +704,7 @@ block:
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
let
pathStr ="""
let pathStr ="""
L -16370.0 -18156.0
A 4100 4100 0 1 0 -19670 -14134
Z
@ -721,3 +720,25 @@ block:
path,
paint
)
block:
let image = newImage(200, 200)
image.fill(rgba(255, 255, 255, 255))
let pathStr = """
L 3473901.0 1136732.75
A 31888.0 31888.0 0 0 1 3493390.25 1076022.375
L 32563.0 -2081.0"""
let paint = newPaint(SolidPaint)
paint.color = color(255, 255, 255, 255)
let path = parsePath(pathStr)
doAssertRaises PixieError:
image.fillPath(
path,
paint,
mat3(),
NonZero
)