diff --git a/experiments/benchmark_cairo.nim b/experiments/benchmark_cairo.nim index 778ebeb..1bc2d05 100644 --- a/experiments/benchmark_cairo.nim +++ b/experiments/benchmark_cairo.nim @@ -128,8 +128,8 @@ proc strokeMask*( path: SomePath, width, height: int, strokeWidth: float32 = 1.0, - lineCap = lcButt, - lineJoin = ljMiter, + lineCap = ButtCap, + lineJoin = MiterJoin, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[] ): Mask = @@ -151,8 +151,8 @@ proc strokeImage*( width, height: int, color: SomeColor, strokeWidth: float32 = 1.0, - lineCap = lcButt, - lineJoin = ljMiter, + lineCap = ButtCap, + lineJoin = MiterJoin, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[] ): Image = diff --git a/experiments/svg_cairo.nim b/experiments/svg_cairo.nim index b9c5c9a..99bc928 100644 --- a/experiments/svg_cairo.nim +++ b/experiments/svg_cairo.nim @@ -229,11 +229,11 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx = else: case strokeLineCap: of "butt": - result.strokeLineCap = lcButt + result.strokeLineCap = ButtCap of "round": - result.strokeLineCap = lcRound + result.strokeLineCap = RoundCap of "square": - result.strokeLineCap = lcSquare + result.strokeLineCap = SquareCap of "inherit": discard else: @@ -246,11 +246,11 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx = else: case strokeLineJoin: of "miter": - result.strokeLineJoin = ljMiter + result.strokeLineJoin = MiterJoin of "round": - result.strokeLineJoin = ljRound + result.strokeLineJoin = RoundJoin of "bevel": - result.strokeLineJoin = ljBevel + result.strokeLineJoin = BevelJoin of "inherit": discard else: @@ -343,20 +343,20 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx = proc cairoLineCap(lineCap: LineCap): cairo.LineCap = case lineCap: - of lcButt: + of ButtCap: LineCapButt - of lcRound: + of RoundCap: LineCapRound - of lcSquare: + of SquareCap: LineCapSquare proc cairoLineJoin(lineJoin: LineJoin): cairo.LineJoin = case lineJoin: - of ljMiter: + of MiterJoin: LineJoinMiter - of ljBevel: + of BevelJoin: LineJoinBevel - of ljRound: + of RoundJoin: LineJoinRound proc fill(c: ptr Context, ctx: Ctx, path: Path) {.inline.} = diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index 09a6674..b5c7520 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -212,11 +212,11 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx = else: case strokeLineCap: of "butt": - result.strokeLineCap = lcButt + result.strokeLineCap = ButtCap of "round": - result.strokeLineCap = lcRound + result.strokeLineCap = RoundCap of "square": - result.strokeLineCap = lcSquare + result.strokeLineCap = SquareCap of "inherit": discard else: @@ -229,11 +229,11 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx = else: case strokeLineJoin: of "miter": - result.strokeLineJoin = ljMiter + result.strokeLineJoin = MiterJoin of "round": - result.strokeLineJoin = ljRound + result.strokeLineJoin = RoundJoin of "bevel": - result.strokeLineJoin = ljBevel + result.strokeLineJoin = BevelJoin of "inherit": discard else: diff --git a/src/pixie/fonts.nim b/src/pixie/fonts.nim index 415b090..a67d79f 100644 --- a/src/pixie/fonts.nim +++ b/src/pixie/fonts.nim @@ -500,8 +500,8 @@ proc textUber( arrangement: Arrangement, transform = mat3(), strokeWidth: float32 = 1.0, - lineCap = lcButt, - lineJoin = ljMiter, + lineCap = ButtCap, + lineJoin = MiterJoin, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[], stroke: static[bool] = false @@ -611,8 +611,8 @@ proc strokeText*( arrangement: Arrangement, transform = mat3(), strokeWidth: float32 = 1.0, - lineCap = lcButt, - lineJoin = ljMiter, + lineCap = ButtCap, + lineJoin = MiterJoin, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[] ) {.inline, raises: [PixieError].} = @@ -638,8 +638,8 @@ proc strokeText*( bounds = vec2(0, 0), hAlign = haLeft, vAlign = vaTop, - lineCap = lcButt, - lineJoin = ljMiter, + lineCap = ButtCap, + lineJoin = MiterJoin, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[] ) {.inline, raises: [PixieError].} = diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index a4e2d54..81837c9 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -11,11 +11,11 @@ type LineCap* = enum ## Line cap type for strokes. - lcButt, lcRound, lcSquare + ButtCap, RoundCap, SquareCap LineJoin* = enum ## Line join type for strokes. - ljMiter, ljRound, ljBevel + MiterJoin, RoundJoin, BevelJoin PathCommandKind = enum ## Type of path commands @@ -1759,7 +1759,7 @@ proc strokeShapes( proc addJoin(shape: var seq[seq[Vec2]], prevPos, pos, nextPos: Vec2) = let minArea = pixelErrorMargin / pixelScale - if lineJoin == ljRound: + if lineJoin == RoundJoin: let area = PI.float32 * halfStroke * halfStroke if area > minArea: shape.add makeCircle(pos) @@ -1778,11 +1778,11 @@ proc strokeShapes( b = vec2(-b.y, b.x) var lineJoin = lineJoin - if lineJoin == ljMiter and abs(angle) < miterAngleLimit: - lineJoin = ljBevel + if lineJoin == MiterJoin and abs(angle) < miterAngleLimit: + lineJoin = BevelJoin case lineJoin: - of ljMiter: + of MiterJoin: let la = line(prevPos + a, pos + a) lb = line(nextPos + b, pos + b) @@ -1796,12 +1796,12 @@ proc strokeShapes( if areaSq > (minArea * minArea): shape.add @[pos + a, at, pos + b, pos, pos + a] - of ljBevel: + of BevelJoin: let areaSq = 0.25.float32 * a.lengthSq * b.lengthSq if areaSq > (minArea * minArea): shape.add @[a + pos, b + pos, pos, a + pos] - of ljRound: + of RoundJoin: discard # Handled above, skipping angle calculation for shape in shapes: @@ -1811,11 +1811,11 @@ proc strokeShapes( # This shape does not end at the same point it starts so draw the # first line cap. case lineCap: - of lcButt: + of ButtCap: discard - of lcRound: + of RoundCap: shapeStroke.add(makeCircle(shape[0])) - of lcSquare: + of SquareCap: let tangent = (shape[1] - shape[0]).normalize() shapeStroke.add(makeRect( shape[0] - tangent * halfStroke, @@ -1856,11 +1856,11 @@ proc strokeShapes( shapeStroke.addJoin(shape[^2], shape[^1], shape[1]) else: case lineCap: - of lcButt: + of ButtCap: discard - of lcRound: + of RoundCap: shapeStroke.add(makeCircle(shape[^1])) - of lcSquare: + of SquareCap: let tangent = (shape[^1] - shape[^2]).normalize() shapeStroke.add(makeRect( shape[^1] + tangent * halfStroke, @@ -1944,8 +1944,8 @@ proc strokePath*( path: SomePath, transform = mat3(), strokeWidth: float32 = 1.0, - lineCap = lcButt, - lineJoin = ljMiter, + lineCap = ButtCap, + lineJoin = MiterJoin, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[], blendMode = BlendNormal @@ -1970,8 +1970,8 @@ proc strokePath*( paint: Paint, transform = mat3(), strokeWidth: float32 = 1.0, - lineCap = lcButt, - lineJoin = ljMiter, + lineCap = ButtCap, + lineJoin = MiterJoin, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[] ) {.raises: [PixieError].} = @@ -2074,8 +2074,8 @@ proc strokeOverlaps*( test: Vec2, transform = mat3(), ## Applied to the path, not the test point. strokeWidth: float32 = 1.0, - lineCap = lcButt, - lineJoin = ljMiter, + lineCap = ButtCap, + lineJoin = MiterJoin, miterLimit = defaultMiterLimit, dashes: seq[float32] = @[], ): bool {.raises: [PixieError].} = diff --git a/tests/fuzz_leaks.nim b/tests/fuzz_leaks.nim index c15d3b3..348716d 100644 --- a/tests/fuzz_leaks.nim +++ b/tests/fuzz_leaks.nim @@ -16,8 +16,8 @@ for i in 0 ..< 100_000: ctx.rotate(rand(0.0 .. 2*PI)) ctx.strokeStyle = "#000000" - ctx.lineCap = sample([lcRound, lcButt, lcSquare]) - ctx.lineJoin = sample([ljMiter, ljRound, ljBevel]) + ctx.lineCap = sample([RoundCap, ButtCap, SquareCap]) + ctx.lineJoin = sample([MiterJoin, RoundJoin, BevelJoin]) ctx.miterLimit = 2 ctx.lineWidth = rand(0.1 .. 20.0) diff --git a/tests/fuzz_leaks2.nim b/tests/fuzz_leaks2.nim index 8458d4f..425a374 100644 --- a/tests/fuzz_leaks2.nim +++ b/tests/fuzz_leaks2.nim @@ -16,8 +16,8 @@ for i in 0 ..< 100_000: ctx.rotate(rand(0.0 .. 2*PI)) ctx.strokeStyle = "#000000" - ctx.lineCap = sample([lcRound, lcButt, lcSquare]) - ctx.lineJoin = sample([ljMiter, ljRound, ljBevel]) + ctx.lineCap = sample([RoundCap, ButtCap, SquareCap]) + ctx.lineJoin = sample([MiterJoin, RoundJoin, BevelJoin]) ctx.lineWidth = rand(0.1 .. 1.0) var first = true diff --git a/tests/paths/lcButt.png b/tests/paths/ButtCap.png similarity index 100% rename from tests/paths/lcButt.png rename to tests/paths/ButtCap.png diff --git a/tests/paths/lcRound.png b/tests/paths/RoundCap.png similarity index 100% rename from tests/paths/lcRound.png rename to tests/paths/RoundCap.png diff --git a/tests/paths/lcSquare.png b/tests/paths/SquareCap.png similarity index 100% rename from tests/paths/lcSquare.png rename to tests/paths/SquareCap.png diff --git a/tests/test_contexts.nim b/tests/test_contexts.nim index 7df8613..fd6bfe7 100644 --- a/tests/test_contexts.nim +++ b/tests/test_contexts.nim @@ -191,7 +191,7 @@ block: block: let ctx = newContext(newImage(300, 150)) - ctx.lineJoin = ljBevel + ctx.lineJoin = BevelJoin ctx.lineWidth = 15 ctx.strokeStyle = "#38f" ctx.strokeRect(30, 30, 160, 90) diff --git a/tests/test_paths.nim b/tests/test_paths.nim index 155bb7a..22abf6b 100644 --- a/tests/test_paths.nim +++ b/tests/test_paths.nim @@ -214,7 +214,7 @@ block: path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20 Z") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcRound, ljRound + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, RoundCap, RoundJoin ) image.writeFile("tests/paths/boxRound.png") @@ -225,7 +225,7 @@ block: path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20 Z") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcRound, ljBevel + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, RoundCap, BevelJoin ) image.writeFile("tests/paths/boxBevel.png") @@ -236,7 +236,7 @@ block: path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20 Z") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcRound, ljMiter + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, RoundCap, MiterJoin ) image.writeFile("tests/paths/boxMiter.png") @@ -247,10 +247,10 @@ block: path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcButt, ljBevel + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, ButtCap, BevelJoin ) - image.writeFile("tests/paths/lcButt.png") + image.writeFile("tests/paths/ButtCap.png") block: let @@ -258,10 +258,10 @@ block: path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcRound, ljBevel + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, RoundCap, BevelJoin ) - image.writeFile("tests/paths/lcRound.png") + image.writeFile("tests/paths/RoundCap.png") block: let @@ -269,10 +269,10 @@ block: path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcSquare, ljBevel + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, SquareCap, BevelJoin ) - image.writeFile("tests/paths/lcSquare.png") + image.writeFile("tests/paths/SquareCap.png") block: let @@ -281,31 +281,31 @@ block: image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(5, 5)), 10, lcButt, ljBevel, + path, rgba(0, 0, 0, 255), translate(vec2(5, 5)), 10, ButtCap, BevelJoin, ) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(5, 25)), 10, lcButt, ljBevel, + path, rgba(0, 0, 0, 255), translate(vec2(5, 25)), 10, ButtCap, BevelJoin, dashes = @[2.float32, 2] ) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(5, 45)), 10, lcButt, ljBevel, + path, rgba(0, 0, 0, 255), translate(vec2(5, 45)), 10, ButtCap, BevelJoin, dashes = @[4.float32, 4] ) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(5, 65)), 10, lcButt, ljBevel, + path, rgba(0, 0, 0, 255), translate(vec2(5, 65)), 10, ButtCap, BevelJoin, dashes = @[2.float32, 4, 6, 2] ) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(5, 85)), 10, lcButt, ljBevel, + path, rgba(0, 0, 0, 255), translate(vec2(5, 85)), 10, ButtCap, BevelJoin, dashes = @[1.float32] ) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(5, 105)), 10, lcButt, ljBevel, + path, rgba(0, 0, 0, 255), translate(vec2(5, 105)), 10, ButtCap, BevelJoin, dashes = @[1.float32, 2, 3, 4, 5, 6, 7, 8, 9] ) @@ -323,7 +323,7 @@ block: path.lineTo(sin(th)*20, cos(th)*20) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(30, 30)), 8, lcButt, ljMiter, + path, rgba(0, 0, 0, 255), translate(vec2(30, 30)), 8, ButtCap, MiterJoin, miterLimit = limit ) image.writeFile(&"tests/paths/miterLimit_{angle.int}deg_{limit:0.2f}num.png") @@ -353,7 +353,7 @@ block: path = parsePath("M 3 3 L 3 3 L 3 3") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcSquare, ljMiter + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, SquareCap, MiterJoin ) block: @@ -362,7 +362,7 @@ block: path = parsePath("L 0 0 L 0 0") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcSquare, ljMiter + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, SquareCap, MiterJoin ) block: @@ -371,7 +371,7 @@ block: path = parsePath("L 1 1") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcSquare, ljMiter + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, SquareCap, MiterJoin ) block: @@ -380,7 +380,7 @@ block: path = parsePath("L 0 0") image.fill(rgba(255, 255, 255, 255)) image.strokePath( - path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, lcSquare, ljMiter + path, rgba(0, 0, 0, 255), translate(vec2(10, 10)), 10, SquareCap, MiterJoin ) block: