check for fenv epsilon instead of literal 0
This commit is contained in:
parent
2262459b5d
commit
64b63d421d
2 changed files with 30 additions and 9 deletions
|
@ -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):
|
when defined(amd64) and not defined(pixieNoSimd):
|
||||||
import nimsimd/sse2
|
import nimsimd/sse2
|
||||||
|
@ -686,6 +686,8 @@ proc commandsToShapes(
|
||||||
next = compute(at, ctrl1, ctrl2, to, t + step)
|
next = compute(at, ctrl1, ctrl2, to, t + step)
|
||||||
halfway = compute(at, ctrl1, ctrl2, to, t + step / 2)
|
halfway = compute(at, ctrl1, ctrl2, to, t + step / 2)
|
||||||
while true:
|
while true:
|
||||||
|
if step <= epsilon(float32):
|
||||||
|
raise newException(PixieError, "Unable to discretize cubic")
|
||||||
let
|
let
|
||||||
midpoint = (prev + next) / 2
|
midpoint = (prev + next) / 2
|
||||||
error = (midpoint - halfway).lengthSq
|
error = (midpoint - halfway).lengthSq
|
||||||
|
@ -693,8 +695,6 @@ proc commandsToShapes(
|
||||||
next = halfway
|
next = halfway
|
||||||
halfway = compute(at, ctrl1, ctrl2, to, t + step / 4)
|
halfway = compute(at, ctrl1, ctrl2, to, t + step / 4)
|
||||||
step /= 2
|
step /= 2
|
||||||
if step == 0:
|
|
||||||
raise newException(PixieError, "Unable to discretize cubic")
|
|
||||||
else:
|
else:
|
||||||
shape.addSegment(prev, next)
|
shape.addSegment(prev, next)
|
||||||
t += step
|
t += step
|
||||||
|
@ -720,6 +720,8 @@ proc commandsToShapes(
|
||||||
halfway = compute(at, ctrl, to, t + step / 2)
|
halfway = compute(at, ctrl, to, t + step / 2)
|
||||||
halfStepping = false
|
halfStepping = false
|
||||||
while true:
|
while true:
|
||||||
|
if step <= epsilon(float32):
|
||||||
|
raise newException(PixieError, "Unable to discretize quadratic")
|
||||||
let
|
let
|
||||||
midpoint = (prev + next) / 2
|
midpoint = (prev + next) / 2
|
||||||
error = (midpoint - halfway).lengthSq
|
error = (midpoint - halfway).lengthSq
|
||||||
|
@ -728,8 +730,6 @@ proc commandsToShapes(
|
||||||
halfway = compute(at, ctrl, to, t + step / 4)
|
halfway = compute(at, ctrl, to, t + step / 4)
|
||||||
halfStepping = true
|
halfStepping = true
|
||||||
step /= 2
|
step /= 2
|
||||||
if step == 0:
|
|
||||||
raise newException(PixieError, "Unable to discretize quadratic")
|
|
||||||
else:
|
else:
|
||||||
shape.addSegment(prev, next)
|
shape.addSegment(prev, next)
|
||||||
t += step
|
t += step
|
||||||
|
@ -838,6 +838,8 @@ proc commandsToShapes(
|
||||||
step = 1.float32 # How far we want to try to move along the curve
|
step = 1.float32 # How far we want to try to move along the curve
|
||||||
prev = at
|
prev = at
|
||||||
while t != 1:
|
while t != 1:
|
||||||
|
if step <= epsilon(float32):
|
||||||
|
raise newException(PixieError, "Unable to discretize arc")
|
||||||
let
|
let
|
||||||
aPrev = arc.theta + arc.delta * t
|
aPrev = arc.theta + arc.delta * t
|
||||||
a = arc.theta + arc.delta * (t + step)
|
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
|
step = min(step / 2, 1 - t) # Assume next steps hould be the same size
|
||||||
else:
|
else:
|
||||||
step = step / 4 # We know a half-step is too big
|
step = step / 4 # We know a half-step is too big
|
||||||
if step == 0:
|
|
||||||
raise newException(PixieError, "Unable to discretize arc")
|
|
||||||
else:
|
else:
|
||||||
shape.addSegment(prev, next)
|
shape.addSegment(prev, next)
|
||||||
prev = next
|
prev = next
|
||||||
|
|
|
@ -704,8 +704,7 @@ block:
|
||||||
let image = newImage(200, 200)
|
let image = newImage(200, 200)
|
||||||
image.fill(rgba(255, 255, 255, 255))
|
image.fill(rgba(255, 255, 255, 255))
|
||||||
|
|
||||||
let
|
let pathStr ="""
|
||||||
pathStr ="""
|
|
||||||
L -16370.0 -18156.0
|
L -16370.0 -18156.0
|
||||||
A 4100 4100 0 1 0 -19670 -14134
|
A 4100 4100 0 1 0 -19670 -14134
|
||||||
Z
|
Z
|
||||||
|
@ -721,3 +720,25 @@ block:
|
||||||
path,
|
path,
|
||||||
paint
|
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
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue