diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index 9739a2f..4719508 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -683,9 +683,8 @@ proc commandsToShapes( ctrl2 * (-3*t3 + 3*t2) + to * (t3) - proc computeDerv(at, ctrl1, ctrl2, to: Vec2, t: float32): Vec2 {.inline.} = - let - t2 = t*t + proc computeDeriv(at, ctrl1, ctrl2, to: Vec2, t: float32): Vec2 {.inline.} = + let t2 = t*t at * (-3*t2 + 6*t - 3) + ctrl1 * (9*t2 - 12*t + 3) + ctrl2 * (-9*t2 + 6*t) + @@ -703,11 +702,11 @@ proc commandsToShapes( let midpoint = (prev + next) / 2 lineTangent = midpoint - prev - curveTangent = computeDerv(at, ctrl1, ctrl2, to, t + step / 2) + curveTangent = computeDeriv(at, ctrl1, ctrl2, to, t + step / 2) curveTangentScaled = curveTangent.normalize() * lineTangent.length() - error = (midpoint - halfway).lengthSq + - (lineTangent - curveTangentScaled).lengthSq - if error > errorMarginSq: + error = (midpoint - halfway).lengthSq + errorTangent = (lineTangent - curveTangentScaled).lengthSq + if error + errorTangent > errorMarginSq: next = halfway halfway = compute(at, ctrl1, ctrl2, to, t + step / 4) step /= 2 diff --git a/tests/paths/pathSwish.png b/tests/paths/pathSwish.png new file mode 100644 index 0000000..a58993c Binary files /dev/null and b/tests/paths/pathSwish.png differ diff --git a/tests/test_path2.nim b/tests/test_path2.nim deleted file mode 100644 index bc6f70a..0000000 --- a/tests/test_path2.nim +++ /dev/null @@ -1,12 +0,0 @@ -import chroma, pixie, pixie/fileformats/png, strformat - -block: - let - image = newImage(100, 100) - pathStr = """ - M 40 40 L 40 80 L 80 80 L 80 40 C 80 -20 40 100 40 40 - """ - color = rgba(0, 0, 0, 255) - image.fill(rgba(255, 255, 255, 255)) - image.fillPath(pathStr, color) - image.writeFile("tests/paths/pathSwish.png") diff --git a/tests/test_paths.nim b/tests/test_paths.nim index edd4faa..b5de9cc 100644 --- a/tests/test_paths.nim +++ b/tests/test_paths.nim @@ -773,3 +773,14 @@ block: mat3(), NonZero ) + +block: + let + image = newImage(100, 100) + pathStr = """ + M 40 40 L 40 80 L 80 80 L 80 40 C 80 -20 40 100 40 40 + """ + color = rgba(0, 0, 0, 255) + image.fill(rgba(255, 255, 255, 255)) + image.fillPath(pathStr, color) + image.writeFile("tests/paths/pathSwish.png")