Rename LineCap and LineJoin enum.

This commit is contained in:
treeform 2022-02-12 10:35:19 -08:00
parent e4805f7c08
commit 9fdb3b8b0d
12 changed files with 73 additions and 73 deletions

View file

@ -128,8 +128,8 @@ proc strokeMask*(
path: SomePath, path: SomePath,
width, height: int, width, height: int,
strokeWidth: float32 = 1.0, strokeWidth: float32 = 1.0,
lineCap = lcButt, lineCap = ButtCap,
lineJoin = ljMiter, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,
dashes: seq[float32] = @[] dashes: seq[float32] = @[]
): Mask = ): Mask =
@ -151,8 +151,8 @@ proc strokeImage*(
width, height: int, width, height: int,
color: SomeColor, color: SomeColor,
strokeWidth: float32 = 1.0, strokeWidth: float32 = 1.0,
lineCap = lcButt, lineCap = ButtCap,
lineJoin = ljMiter, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,
dashes: seq[float32] = @[] dashes: seq[float32] = @[]
): Image = ): Image =

View file

@ -229,11 +229,11 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx =
else: else:
case strokeLineCap: case strokeLineCap:
of "butt": of "butt":
result.strokeLineCap = lcButt result.strokeLineCap = ButtCap
of "round": of "round":
result.strokeLineCap = lcRound result.strokeLineCap = RoundCap
of "square": of "square":
result.strokeLineCap = lcSquare result.strokeLineCap = SquareCap
of "inherit": of "inherit":
discard discard
else: else:
@ -246,11 +246,11 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx =
else: else:
case strokeLineJoin: case strokeLineJoin:
of "miter": of "miter":
result.strokeLineJoin = ljMiter result.strokeLineJoin = MiterJoin
of "round": of "round":
result.strokeLineJoin = ljRound result.strokeLineJoin = RoundJoin
of "bevel": of "bevel":
result.strokeLineJoin = ljBevel result.strokeLineJoin = BevelJoin
of "inherit": of "inherit":
discard discard
else: else:
@ -343,20 +343,20 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
proc cairoLineCap(lineCap: LineCap): cairo.LineCap = proc cairoLineCap(lineCap: LineCap): cairo.LineCap =
case lineCap: case lineCap:
of lcButt: of ButtCap:
LineCapButt LineCapButt
of lcRound: of RoundCap:
LineCapRound LineCapRound
of lcSquare: of SquareCap:
LineCapSquare LineCapSquare
proc cairoLineJoin(lineJoin: LineJoin): cairo.LineJoin = proc cairoLineJoin(lineJoin: LineJoin): cairo.LineJoin =
case lineJoin: case lineJoin:
of ljMiter: of MiterJoin:
LineJoinMiter LineJoinMiter
of ljBevel: of BevelJoin:
LineJoinBevel LineJoinBevel
of ljRound: of RoundJoin:
LineJoinRound LineJoinRound
proc fill(c: ptr Context, ctx: Ctx, path: Path) {.inline.} = proc fill(c: ptr Context, ctx: Ctx, path: Path) {.inline.} =

View file

@ -212,11 +212,11 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx =
else: else:
case strokeLineCap: case strokeLineCap:
of "butt": of "butt":
result.strokeLineCap = lcButt result.strokeLineCap = ButtCap
of "round": of "round":
result.strokeLineCap = lcRound result.strokeLineCap = RoundCap
of "square": of "square":
result.strokeLineCap = lcSquare result.strokeLineCap = SquareCap
of "inherit": of "inherit":
discard discard
else: else:
@ -229,11 +229,11 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx =
else: else:
case strokeLineJoin: case strokeLineJoin:
of "miter": of "miter":
result.strokeLineJoin = ljMiter result.strokeLineJoin = MiterJoin
of "round": of "round":
result.strokeLineJoin = ljRound result.strokeLineJoin = RoundJoin
of "bevel": of "bevel":
result.strokeLineJoin = ljBevel result.strokeLineJoin = BevelJoin
of "inherit": of "inherit":
discard discard
else: else:

View file

@ -500,8 +500,8 @@ proc textUber(
arrangement: Arrangement, arrangement: Arrangement,
transform = mat3(), transform = mat3(),
strokeWidth: float32 = 1.0, strokeWidth: float32 = 1.0,
lineCap = lcButt, lineCap = ButtCap,
lineJoin = ljMiter, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,
dashes: seq[float32] = @[], dashes: seq[float32] = @[],
stroke: static[bool] = false stroke: static[bool] = false
@ -611,8 +611,8 @@ proc strokeText*(
arrangement: Arrangement, arrangement: Arrangement,
transform = mat3(), transform = mat3(),
strokeWidth: float32 = 1.0, strokeWidth: float32 = 1.0,
lineCap = lcButt, lineCap = ButtCap,
lineJoin = ljMiter, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,
dashes: seq[float32] = @[] dashes: seq[float32] = @[]
) {.inline, raises: [PixieError].} = ) {.inline, raises: [PixieError].} =
@ -638,8 +638,8 @@ proc strokeText*(
bounds = vec2(0, 0), bounds = vec2(0, 0),
hAlign = haLeft, hAlign = haLeft,
vAlign = vaTop, vAlign = vaTop,
lineCap = lcButt, lineCap = ButtCap,
lineJoin = ljMiter, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,
dashes: seq[float32] = @[] dashes: seq[float32] = @[]
) {.inline, raises: [PixieError].} = ) {.inline, raises: [PixieError].} =

View file

@ -11,11 +11,11 @@ type
LineCap* = enum LineCap* = enum
## Line cap type for strokes. ## Line cap type for strokes.
lcButt, lcRound, lcSquare ButtCap, RoundCap, SquareCap
LineJoin* = enum LineJoin* = enum
## Line join type for strokes. ## Line join type for strokes.
ljMiter, ljRound, ljBevel MiterJoin, RoundJoin, BevelJoin
PathCommandKind = enum PathCommandKind = enum
## Type of path commands ## Type of path commands
@ -1759,7 +1759,7 @@ proc strokeShapes(
proc addJoin(shape: var seq[seq[Vec2]], prevPos, pos, nextPos: Vec2) = proc addJoin(shape: var seq[seq[Vec2]], prevPos, pos, nextPos: Vec2) =
let minArea = pixelErrorMargin / pixelScale let minArea = pixelErrorMargin / pixelScale
if lineJoin == ljRound: if lineJoin == RoundJoin:
let area = PI.float32 * halfStroke * halfStroke let area = PI.float32 * halfStroke * halfStroke
if area > minArea: if area > minArea:
shape.add makeCircle(pos) shape.add makeCircle(pos)
@ -1778,11 +1778,11 @@ proc strokeShapes(
b = vec2(-b.y, b.x) b = vec2(-b.y, b.x)
var lineJoin = lineJoin var lineJoin = lineJoin
if lineJoin == ljMiter and abs(angle) < miterAngleLimit: if lineJoin == MiterJoin and abs(angle) < miterAngleLimit:
lineJoin = ljBevel lineJoin = BevelJoin
case lineJoin: case lineJoin:
of ljMiter: of MiterJoin:
let let
la = line(prevPos + a, pos + a) la = line(prevPos + a, pos + a)
lb = line(nextPos + b, pos + b) lb = line(nextPos + b, pos + b)
@ -1796,12 +1796,12 @@ proc strokeShapes(
if areaSq > (minArea * minArea): if areaSq > (minArea * minArea):
shape.add @[pos + a, at, pos + b, pos, pos + a] shape.add @[pos + a, at, pos + b, pos, pos + a]
of ljBevel: of BevelJoin:
let areaSq = 0.25.float32 * a.lengthSq * b.lengthSq let areaSq = 0.25.float32 * a.lengthSq * b.lengthSq
if areaSq > (minArea * minArea): if areaSq > (minArea * minArea):
shape.add @[a + pos, b + pos, pos, a + pos] shape.add @[a + pos, b + pos, pos, a + pos]
of ljRound: of RoundJoin:
discard # Handled above, skipping angle calculation discard # Handled above, skipping angle calculation
for shape in shapes: for shape in shapes:
@ -1811,11 +1811,11 @@ proc strokeShapes(
# This shape does not end at the same point it starts so draw the # This shape does not end at the same point it starts so draw the
# first line cap. # first line cap.
case lineCap: case lineCap:
of lcButt: of ButtCap:
discard discard
of lcRound: of RoundCap:
shapeStroke.add(makeCircle(shape[0])) shapeStroke.add(makeCircle(shape[0]))
of lcSquare: of SquareCap:
let tangent = (shape[1] - shape[0]).normalize() let tangent = (shape[1] - shape[0]).normalize()
shapeStroke.add(makeRect( shapeStroke.add(makeRect(
shape[0] - tangent * halfStroke, shape[0] - tangent * halfStroke,
@ -1856,11 +1856,11 @@ proc strokeShapes(
shapeStroke.addJoin(shape[^2], shape[^1], shape[1]) shapeStroke.addJoin(shape[^2], shape[^1], shape[1])
else: else:
case lineCap: case lineCap:
of lcButt: of ButtCap:
discard discard
of lcRound: of RoundCap:
shapeStroke.add(makeCircle(shape[^1])) shapeStroke.add(makeCircle(shape[^1]))
of lcSquare: of SquareCap:
let tangent = (shape[^1] - shape[^2]).normalize() let tangent = (shape[^1] - shape[^2]).normalize()
shapeStroke.add(makeRect( shapeStroke.add(makeRect(
shape[^1] + tangent * halfStroke, shape[^1] + tangent * halfStroke,
@ -1944,8 +1944,8 @@ proc strokePath*(
path: SomePath, path: SomePath,
transform = mat3(), transform = mat3(),
strokeWidth: float32 = 1.0, strokeWidth: float32 = 1.0,
lineCap = lcButt, lineCap = ButtCap,
lineJoin = ljMiter, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,
dashes: seq[float32] = @[], dashes: seq[float32] = @[],
blendMode = BlendNormal blendMode = BlendNormal
@ -1970,8 +1970,8 @@ proc strokePath*(
paint: Paint, paint: Paint,
transform = mat3(), transform = mat3(),
strokeWidth: float32 = 1.0, strokeWidth: float32 = 1.0,
lineCap = lcButt, lineCap = ButtCap,
lineJoin = ljMiter, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,
dashes: seq[float32] = @[] dashes: seq[float32] = @[]
) {.raises: [PixieError].} = ) {.raises: [PixieError].} =
@ -2074,8 +2074,8 @@ proc strokeOverlaps*(
test: Vec2, test: Vec2,
transform = mat3(), ## Applied to the path, not the test point. transform = mat3(), ## Applied to the path, not the test point.
strokeWidth: float32 = 1.0, strokeWidth: float32 = 1.0,
lineCap = lcButt, lineCap = ButtCap,
lineJoin = ljMiter, lineJoin = MiterJoin,
miterLimit = defaultMiterLimit, miterLimit = defaultMiterLimit,
dashes: seq[float32] = @[], dashes: seq[float32] = @[],
): bool {.raises: [PixieError].} = ): bool {.raises: [PixieError].} =

View file

@ -16,8 +16,8 @@ for i in 0 ..< 100_000:
ctx.rotate(rand(0.0 .. 2*PI)) ctx.rotate(rand(0.0 .. 2*PI))
ctx.strokeStyle = "#000000" ctx.strokeStyle = "#000000"
ctx.lineCap = sample([lcRound, lcButt, lcSquare]) ctx.lineCap = sample([RoundCap, ButtCap, SquareCap])
ctx.lineJoin = sample([ljMiter, ljRound, ljBevel]) ctx.lineJoin = sample([MiterJoin, RoundJoin, BevelJoin])
ctx.miterLimit = 2 ctx.miterLimit = 2
ctx.lineWidth = rand(0.1 .. 20.0) ctx.lineWidth = rand(0.1 .. 20.0)

View file

@ -16,8 +16,8 @@ for i in 0 ..< 100_000:
ctx.rotate(rand(0.0 .. 2*PI)) ctx.rotate(rand(0.0 .. 2*PI))
ctx.strokeStyle = "#000000" ctx.strokeStyle = "#000000"
ctx.lineCap = sample([lcRound, lcButt, lcSquare]) ctx.lineCap = sample([RoundCap, ButtCap, SquareCap])
ctx.lineJoin = sample([ljMiter, ljRound, ljBevel]) ctx.lineJoin = sample([MiterJoin, RoundJoin, BevelJoin])
ctx.lineWidth = rand(0.1 .. 1.0) ctx.lineWidth = rand(0.1 .. 1.0)
var first = true var first = true

View file

Before

Width:  |  Height:  |  Size: 305 B

After

Width:  |  Height:  |  Size: 305 B

View file

Before

Width:  |  Height:  |  Size: 471 B

After

Width:  |  Height:  |  Size: 471 B

View file

Before

Width:  |  Height:  |  Size: 305 B

After

Width:  |  Height:  |  Size: 305 B

View file

@ -191,7 +191,7 @@ block:
block: block:
let ctx = newContext(newImage(300, 150)) let ctx = newContext(newImage(300, 150))
ctx.lineJoin = ljBevel ctx.lineJoin = BevelJoin
ctx.lineWidth = 15 ctx.lineWidth = 15
ctx.strokeStyle = "#38f" ctx.strokeStyle = "#38f"
ctx.strokeRect(30, 30, 160, 90) ctx.strokeRect(30, 30, 160, 90)

View file

@ -214,7 +214,7 @@ block:
path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20 Z") path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20 Z")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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") 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") path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20 Z")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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") 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") path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20 Z")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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") 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") path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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: block:
let let
@ -258,10 +258,10 @@ block:
path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20") path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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: block:
let let
@ -269,10 +269,10 @@ block:
path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20") path = parsePath("M 3 3 L 20 3 L 20 20 L 3 20")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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: block:
let let
@ -281,31 +281,31 @@ block:
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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( 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] dashes = @[2.float32, 2]
) )
image.strokePath( 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] dashes = @[4.float32, 4]
) )
image.strokePath( 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] dashes = @[2.float32, 4, 6, 2]
) )
image.strokePath( 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] dashes = @[1.float32]
) )
image.strokePath( 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] dashes = @[1.float32, 2, 3, 4, 5, 6, 7, 8, 9]
) )
@ -323,7 +323,7 @@ block:
path.lineTo(sin(th)*20, cos(th)*20) path.lineTo(sin(th)*20, cos(th)*20)
image.strokePath( 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 miterLimit = limit
) )
image.writeFile(&"tests/paths/miterLimit_{angle.int}deg_{limit:0.2f}num.png") 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") path = parsePath("M 3 3 L 3 3 L 3 3")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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: block:
@ -362,7 +362,7 @@ block:
path = parsePath("L 0 0 L 0 0") path = parsePath("L 0 0 L 0 0")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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: block:
@ -371,7 +371,7 @@ block:
path = parsePath("L 1 1") path = parsePath("L 1 1")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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: block:
@ -380,7 +380,7 @@ block:
path = parsePath("L 0 0") path = parsePath("L 0 0")
image.fill(rgba(255, 255, 255, 255)) image.fill(rgba(255, 255, 255, 255))
image.strokePath( 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: block: