diff --git a/pixie.nimble b/pixie.nimble index ece146c..ee6c20a 100644 --- a/pixie.nimble +++ b/pixie.nimble @@ -1,4 +1,4 @@ -version = "0.0.12" +version = "0.0.13" author = "Andre von Houck and Ryan Oldenburg" description = "Full-featured 2d graphics library for Nim." license = "MIT" diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 1da08e6..3439251 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -211,7 +211,7 @@ proc toAlphy*(image: Image) = for j in countup(i, image.data.len - 4, 4): var - color = mm_load_si128(image.data[j].addr) + color = mm_loadu_si128(image.data[j].addr) alpha = mm_and_si128(color, alphaMask) alpha = mm_or_si128(alpha, mm_srli_epi32(alpha, 16)) @@ -230,7 +230,7 @@ proc toAlphy*(image: Image) = mm_and_si128(alpha, alphaMask), mm_and_si128(color, alphaMaskComp) ) - mm_store_si128(image.data[j].addr, color) + mm_storeu_si128(image.data[j].addr, color) i += 4 # Convert whatever is left for j in i ..< image.data.len: diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index f060909..9925ca8 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -233,34 +233,25 @@ proc commandsToPolygons*(commands: seq[PathCommand]): seq[seq[Vec2]] = discretize(1, 1) - proc drawQuad(at, ctrl, to: Vec2) = + proc drawQuad(p0, p1, p2: Vec2) = + let devx = p0.x - 2.0 * p1.x + p2.x + let devy = p0.y - 2.0 * p1.y + p2.y + let devsq = devx * devx + devy * devy + if devsq < 0.333: + drawLine(p0, p2) + return + let tol = 3.0 + let n = 1 + (tol * (devsq)).sqrt().sqrt().floor() + var p = p0 + let nrecip = 1 / n + var t = 0.0 + for i in 0 ..< int(n): + t += nrecip + let pn = lerp(lerp(p0, p1, t), lerp(p1, p2, t), t) + drawLine(p, pn) + p = pn - proc compute(at, ctrl, to: Vec2, t: float32): Vec2 {.inline.} = - pow(1 - t, 2) * at + - 2 * (1 - t) * t * ctrl + - pow(t, 2) * to - - var prev = at - - proc discretize(i, steps: int) = - # Closure captures at, ctrl, to and prev - let - tPrev = (i - 1).float32 / steps.float32 - t = i.float32 / steps.float32 - next = compute(at, ctrl, to, t) - halfway = compute(at, ctrl, to, tPrev + (t - tPrev) / 2) - midpoint = (prev + next) / 2 - error = (midpoint - halfway).length - - if error >= 0.25: - # Error too large, double precision for this step - discretize(i * 2 - 1, steps * 2) - discretize(i * 2, steps * 2) - else: - drawLine(prev, next) - prev = next - - discretize(1, 1) + drawLine(p, p2) proc drawArc( at, radii: Vec2, diff --git a/tests/images/paths/pathHeart.png b/tests/images/paths/pathHeart.png index 60bcb67..524f694 100644 Binary files a/tests/images/paths/pathHeart.png and b/tests/images/paths/pathHeart.png differ diff --git a/tests/images/svg/quad01.png b/tests/images/svg/quad01.png index 63e9998..452a9e2 100644 Binary files a/tests/images/svg/quad01.png and b/tests/images/svg/quad01.png differ