diff --git a/experiments/benchmark_cairo.nim b/experiments/benchmark_cairo.nim index 8d08aeb..778ebeb 100644 --- a/experiments/benchmark_cairo.nim +++ b/experiments/benchmark_cairo.nim @@ -12,7 +12,7 @@ when defined(release): {.push checks: off.} proc fillMask( - shapes: seq[seq[Vec2]], width, height: int, windingRule = wrNonZero + shapes: seq[seq[Vec2]], width, height: int, windingRule = NonZero ): Mask = result = newMask(width, height) @@ -48,7 +48,7 @@ proc fillMask( fillUnsafe(result.data, 255, startIndex, len) proc fillMask*( - path: SomePath, width, height: int, windingRule = wrNonZero + path: SomePath, width, height: int, windingRule = NonZero ): Mask = ## Returns a new mask with the path filled. This is a faster alternative ## to `newMask` + `fillPath`. @@ -59,7 +59,7 @@ proc fillImage( shapes: seq[seq[Vec2]], width, height: int, color: SomeColor, - windingRule = wrNonZero + windingRule = NonZero ): Image = result = newImage(width, height) @@ -117,7 +117,7 @@ proc fillImage( result.data[i].a = ((channels[3] * coverage) div 255).uint8 proc fillImage*( - path: SomePath, width, height: int, color: SomeColor, windingRule = wrNonZero + path: SomePath, width, height: int, color: SomeColor, windingRule = NonZero ): Image = ## Returns a new image with the path filled. This is a faster alternative ## to `newImage` + `fillPath`. @@ -144,7 +144,7 @@ proc strokeMask*( dashes, 1 ) - result = strokeShapes.fillMask(width, height, wrNonZero) + result = strokeShapes.fillMask(width, height, NonZero) proc strokeImage*( path: SomePath, @@ -167,7 +167,7 @@ proc strokeImage*( dashes, 1 ) - result = strokeShapes.fillImage(width, height, color, wrNonZero) + result = strokeShapes.fillImage(width, height, color, NonZero) when defined(release): {.pop.} diff --git a/experiments/svg_cairo.nim b/experiments/svg_cairo.nim index 0756bce..b9c5c9a 100644 --- a/experiments/svg_cairo.nim +++ b/experiments/svg_cairo.nim @@ -24,7 +24,7 @@ proc prepare( paint: Paint, mat: Mat3, closeSubpaths: bool, - windingRule = wrNonZero + windingRule = NonZero ) = let color = paint.color @@ -39,7 +39,7 @@ proc prepare( c.setSourceRgba(color.r, color.g, color.b, color.a) c.setMatrix(matrix.unsafeAddr) case windingRule: - of wrNonZero: + of NonZero: c.setFillRule(FillRuleWinding) else: c.setFillRule(FillRuleEvenOdd) @@ -176,9 +176,9 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx = if fillRule == "": discard # Inherit elif fillRule == "nonzero": - result.fillRule = wrNonZero + result.fillRule = NonZero elif fillRule == "evenodd": - result.fillRule = wrEvenOdd + result.fillRule = EvenOdd else: raise newException( PixieError, "Invalid fill-rule value " & fillRule diff --git a/experiments/sweeps2.nim b/experiments/sweeps2.nim index c2ad328..f30256d 100644 --- a/experiments/sweeps2.nim +++ b/experiments/sweeps2.nim @@ -157,7 +157,7 @@ proc binaryInsert(arr: var seq[float32], v: float32) = arr.insert(v, L + 1) -proc fillPath2(image: Image, p: Path, color: Color, windingRule = wrNonZero, blendMode = BlendNormal) = +proc fillPath2(image: Image, p: Path, color: Color, windingRule = NonZero, blendMode = BlendNormal) = const q = 1/256.0 let rgbx = color.rgbx var segments = p.commandsToShapes(true, 1.0).shapesToSegments() @@ -380,7 +380,7 @@ when defined(release): {.pop.} -template test(name: string, p: Path, a: static int = 1, wr = wrNonZero) = +template test(name: string, p: Path, a: static int = 1, wr = NonZero) = echo name var image = newImage(200, 200) timeIt " sweeps", a: @@ -465,8 +465,8 @@ when defined(bench): test("halfAarc", halfAarc, 100) test("hourGlass", hourGlass, 100) test("hole", hole, 100) - test("holeNonZero", holeEvenOdd, 100, wr=wrNonZero) - test("holeEvenOdd", holeEvenOdd, 100, wr=wrEvenOdd) + test("holeNonZero", holeEvenOdd, 100, wr=NonZero) + test("holeEvenOdd", holeEvenOdd, 100, wr=EvenOdd) test("letterG", letterG, 100) else: # test("rect", rect) @@ -475,7 +475,7 @@ else: # test("cricle", cricle) # test("halfAarc", halfAarc) # test("hourGlass", hourGlass) - #test("hole", hole, wr=wrEvenOdd) - test("holeNonZero", holeEvenOdd, wr=wrNonZero) - test("holeEvenOdd", holeEvenOdd, wr=wrEvenOdd) + #test("hole", hole, wr=EvenOdd) + test("holeNonZero", holeEvenOdd, wr=NonZero) + test("holeEvenOdd", holeEvenOdd, wr=EvenOdd) # test("letterG", letterG) diff --git a/experiments/sweeps3.nim b/experiments/sweeps3.nim index 6d81fbd..7940fb4 100644 --- a/experiments/sweeps3.nim +++ b/experiments/sweeps3.nim @@ -4,7 +4,7 @@ import algorithm, chroma, pixie/images, vmath, benchy import pixie, pixie/paths {.all.} -template test(name: string, p: Path, a: static int = 1, wr = wrNonZero) = +template test(name: string, p: Path, a: static int = 1, wr = NonZero) = echo name var image = newImage(200, 200) timeIt " sweeps", a: @@ -92,11 +92,11 @@ when defined(bench): test("cricle", cricle, 100) test("halfAarc", halfAarc, 100) test("hourGlass", hourGlass, 100) - test("hourGlass2", hourGlass2, wr=wrNonZero) - test("hourGlass2", hourGlass2, wr=wrEvenOdd) + test("hourGlass2", hourGlass2, wr=NonZero) + test("hourGlass2", hourGlass2, wr=EvenOdd) test("hole", hole, 100) - test("holeEvenOdd", holeEvenOdd, 100, wr=wrNonZero) - test("holeEvenOdd", holeEvenOdd, 100, wr=wrEvenOdd) + test("holeEvenOdd", holeEvenOdd, 100, wr=NonZero) + test("holeEvenOdd", holeEvenOdd, 100, wr=EvenOdd) test("letterG", letterG, 100) else: # test("rect", rect) @@ -105,8 +105,8 @@ else: # test("cricle", cricle) # test("halfAarc", halfAarc) # test("hourGlass", hourGlass) - test("hourGlass2", hourGlass2, wr=wrEvenOdd) - # test("hole", hole, wr=wrEvenOdd) - # test("holeEvenOdd", holeEvenOdd, wr=wrNonZero) - # test("holeEvenOdd", holeEvenOdd, wr=wrEvenOdd) + test("hourGlass2", hourGlass2, wr=EvenOdd) + # test("hole", hole, wr=EvenOdd) + # test("holeEvenOdd", holeEvenOdd, wr=NonZero) + # test("holeEvenOdd", holeEvenOdd, wr=EvenOdd) # test("letterG", letterG) diff --git a/src/pixie/contexts.nim b/src/pixie/contexts.nim index ddc2486..468a566 100644 --- a/src/pixie/contexts.nim +++ b/src/pixie/contexts.nim @@ -342,7 +342,7 @@ proc ellipse*(ctx: Context, x, y, rx, ry: float32) {.inline, raises: [].} = ctx.path.ellipse(x, y, rx, ry) proc fill*( - ctx: Context, path: Path, windingRule = wrNonZero + ctx: Context, path: Path, windingRule = NonZero ) {.raises: [PixieError].} = ## Fills the path with the current fillStyle. if ctx.mask != nil and ctx.layer == nil: @@ -355,13 +355,13 @@ proc fill*( ctx.fill(ctx.image, path, windingRule) proc fill*( - ctx: Context, windingRule = wrNonZero + ctx: Context, windingRule = NonZero ) {.inline, raises: [PixieError].} = ## Fills the current path with the current fillStyle. ctx.fill(ctx.path, windingRule) proc clip*( - ctx: Context, path: Path, windingRule = wrNonZero + ctx: Context, path: Path, windingRule = NonZero ) {.raises: [PixieError].} = ## Turns the path into the current clipping region. The previous clipping ## region, if any, is intersected with the current or given path to create @@ -373,7 +373,7 @@ proc clip*( ctx.mask.fillPath(path, windingRule = windingRule, blendMode = BlendMask) proc clip*( - ctx: Context, windingRule = wrNonZero + ctx: Context, windingRule = NonZero ) {.inline, raises: [PixieError].} = ## Turns the current path into the current clipping region. The previous ## clipping region, if any, is intersected with the current or given path @@ -584,25 +584,25 @@ proc drawImage*(ctx: Context, image: Image, src, dest: Rect) {.raises: [PixieErr ) proc isPointInPath*( - ctx: Context, path: Path, pos: Vec2, windingRule = wrNonZero + ctx: Context, path: Path, pos: Vec2, windingRule = NonZero ): bool {.raises: [PixieError].} = ## Returns whether or not the specified point is contained in the current path. path.fillOverlaps(pos, ctx.mat, windingRule) proc isPointInPath*( - ctx: Context, path: Path, x, y: float32, windingRule = wrNonZero + ctx: Context, path: Path, x, y: float32, windingRule = NonZero ): bool {.inline, raises: [PixieError].} = ## Returns whether or not the specified point is contained in the current path. ctx.isPointInPath(path, vec2(x, y), windingRule) proc isPointInPath*( - ctx: Context, pos: Vec2, windingRule = wrNonZero + ctx: Context, pos: Vec2, windingRule = NonZero ): bool {.inline, raises: [PixieError].} = ## Returns whether or not the specified point is contained in the current path. ctx.isPointInPath(ctx.path, pos, windingRule) proc isPointInPath*( - ctx: Context, x, y: float32, windingRule = wrNonZero + ctx: Context, x, y: float32, windingRule = NonZero ): bool {.inline, raises: [PixieError].} = ## Returns whether or not the specified point is contained in the current path. ctx.isPointInPath(ctx.path, vec2(x, y), windingRule) diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index cee82c7..09a6674 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -153,9 +153,9 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx = if fillRule == "": discard # Inherit elif fillRule == "nonzero": - result.fillRule = wrNonZero + result.fillRule = NonZero elif fillRule == "evenodd": - result.fillRule = wrEvenOdd + result.fillRule = EvenOdd else: raise newException( PixieError, "Invalid fill-rule value " & fillRule diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index c71dfab..a4e2d54 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -6,8 +6,8 @@ when defined(amd64) and not defined(pixieNoSimd): type WindingRule* = enum ## Winding rules. - wrNonZero - wrEvenOdd + NonZero + EvenOdd LineCap* = enum ## Line cap type for strokes. @@ -1177,9 +1177,9 @@ proc shouldFill( ): bool {.inline.} = ## Should we fill based on the current winding rule and count? case windingRule: - of wrNonZero: + of NonZero: count != 0 - of wrEvenOdd: + of EvenOdd: count mod 2 != 0 iterator walk( @@ -1207,7 +1207,7 @@ iterator walk( continue # Shortcut: we only care about when we stop filling (or the last hit). # If we continue filling, move to next hit. - if windingRule == wrNonZero and count + winding != 0: + if windingRule == NonZero and count + winding != 0: count += winding inc i continue @@ -1882,7 +1882,7 @@ proc fillPath*( mask: Mask, path: SomePath, transform = mat3(), - windingRule = wrNonZero, + windingRule = NonZero, blendMode = BlendNormal ) {.raises: [PixieError].} = ## Fills a path. @@ -1895,7 +1895,7 @@ proc fillPath*( path: SomePath, paint: Paint, transform = mat3(), - windingRule = wrNonZero + windingRule = NonZero ) {.raises: [PixieError].} = ## Fills a path. if paint.opacity == 0: @@ -1962,7 +1962,7 @@ proc strokePath*( pixelScale ) strokeShapes.transform(transform) - mask.fillShapes(strokeShapes, wrNonZero, blendMode) + mask.fillShapes(strokeShapes, NonZero, blendMode) proc strokePath*( image: Image, @@ -1993,7 +1993,7 @@ proc strokePath*( strokeShapes.transform(transform) var color = paint.color color.a *= paint.opacity - image.fillShapes(strokeShapes, color, wrNonZero, paint.blendMode) + image.fillShapes(strokeShapes, color, NonZero, paint.blendMode) return let @@ -2062,7 +2062,7 @@ proc fillOverlaps*( path: Path, test: Vec2, transform = mat3(), ## Applied to the path, not the test point. - windingRule = wrNonZero + windingRule = NonZero ): bool {.raises: [PixieError].} = ## Returns whether or not the specified point is contained in the current path. var shapes = path.commandsToShapes(true, transform.pixelScale()) @@ -2092,4 +2092,4 @@ proc strokeOverlaps*( pixelScale ) strokeShapes.transform(transform) - strokeShapes.overlaps(test, wrNonZero) + strokeShapes.overlaps(test, NonZero) diff --git a/tests/test_contexts.nim b/tests/test_contexts.nim index 657cc1d..7df8613 100644 --- a/tests/test_contexts.nim +++ b/tests/test_contexts.nim @@ -61,7 +61,7 @@ block: region.closePath() ctx.fillStyle = "green" - ctx.fill(region, wrEvenOdd) + ctx.fill(region, EvenOdd) ctx.image.writeFile("tests/contexts/fill_1.png") @@ -441,7 +441,7 @@ block: let region = newPath() region.rect(80, 10, 20, 130) region.rect(40, 50, 100, 50) - ctx.clip(region, wrEvenOdd) + ctx.clip(region, EvenOdd) ctx.fillStyle = "blue" ctx.fillRect(0, 0, ctx.image.width.float32, ctx.image.height.float32)