Merge pull request #206 from guzba/master

fix path parse bug for m 1 2 3 4 5 6...
This commit is contained in:
treeform 2021-05-24 17:41:25 -07:00 committed by GitHub
commit 122956a893
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View file

@ -136,6 +136,11 @@ proc parsePath*(path: string): Path =
"Invalid path, wrong number of parameters"
)
for batch in 0 ..< numbers.len div paramCount:
if batch > 0:
if kind == Move:
kind = Line
elif kind == RMove:
kind = RLine
result.commands.add(PathCommand(
kind: kind,
numbers: numbers[batch * paramCount ..< (batch + 1) * paramCount]
@ -1523,7 +1528,11 @@ proc fillPath*(
mask = newMask(image.width, image.height)
fill = newImage(image.width, image.height)
mask.fillPath(parseSomePath(path), transform, windingRule)
mask.fillPath(
parseSomePath(path, transform.pixelScale()),
transform,
windingRule
)
case paint.kind:
of pkSolid:
@ -1595,7 +1604,7 @@ proc strokePath*(
fill = newImage(image.width, image.height)
mask.strokePath(
parseSomePath(path),
parseSomePath(path, transform.pixelScale()),
transform,
strokeWidth,
lineCap,

View file

@ -0,0 +1,24 @@
import benchy, pixie
let image = newImage(2560, 1440)
image.fill(rgba(50, 100, 150, 200))
timeIt "x then y":
var sum: uint64
for x in 0 ..< image.width:
for y in 0 ..< image.height:
let pixel = image.getRgbaUnsafe(x, y)
sum += pixel.r + pixel.g + pixel.b + pixel.a
if sum == 0:
echo "0"
keep sum
timeIt "y then x":
var sum: uint64
for y in 0 ..< image.height:
for x in 0 ..< image.width:
let pixel = image.getRgbaUnsafe(x, y)
sum += pixel.r + pixel.g + pixel.b + pixel.a
if sum == 0:
echo "0"
keep sum

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 357 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 631 KiB

After

Width:  |  Height:  |  Size: 636 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View file

@ -5,7 +5,14 @@ block:
m 1 2 3 4 5 6
"""
let path = parsePath(pathStr)
doAssert $path == "m1 2 m3 4 m5 6"
doAssert $path == "m1 2 l3 4 l5 6"
block:
let pathStr = """
l 1 2 3 4 5 6
"""
let path = parsePath(pathStr)
doAssert $path == "l1 2 l3 4 l5 6"
block:
let pathStr = """