little better

This commit is contained in:
Ryan Oldenburg 2021-11-12 19:42:35 -06:00
parent 695ca9eb05
commit 85a9842369
2 changed files with 70 additions and 65 deletions

View file

@ -23,7 +23,7 @@ block:
a.fill(rgba(255, 255, 255, 255)) a.fill(rgba(255, 255, 255, 255))
timeIt "pixie1": timeIt "pixie1":
var p: pixie.Path let p = newPath()
p.moveTo(0, 0) p.moveTo(0, 0)
p.lineTo(1920, 0) p.lineTo(1920, 0)
p.lineTo(1920, 1080) p.lineTo(1920, 1080)
@ -56,7 +56,7 @@ block:
a.fill(rgba(255, 255, 255, 255)) a.fill(rgba(255, 255, 255, 255))
timeIt "pixie2": timeIt "pixie2":
var p: pixie.Path let p = newPath()
p.moveTo(500, 240) p.moveTo(500, 240)
p.lineTo(1500, 240) p.lineTo(1500, 240)
p.lineTo(1920, 600) p.lineTo(1920, 600)
@ -66,31 +66,31 @@ block:
# a.writeFile("pixie2.png") # a.writeFile("pixie2.png")
block: # block:
let # let
a = imageSurfaceCreate(FORMAT_ARGB32, 1000, 1000) # a = imageSurfaceCreate(FORMAT_ARGB32, 1000, 1000)
b = imageSurfaceCreate(FORMAT_ARGB32, 500, 500) # b = imageSurfaceCreate(FORMAT_ARGB32, 500, 500)
ac = a.create() # ac = a.create()
bc = b.create() # bc = b.create()
ac.setSourceRgba(1, 0, 0, 1) # ac.setSourceRgba(1, 0, 0, 1)
ac.newPath() # ac.newPath()
ac.rectangle(0, 0, 1000, 1000) # ac.rectangle(0, 0, 1000, 1000)
ac.fill() # ac.fill()
bc.setSourceRgba(0, 1, 0, 1) # bc.setSourceRgba(0, 1, 0, 1)
bc.newPath() # bc.newPath()
bc.rectangle(0, 0, 500, 500) # bc.rectangle(0, 0, 500, 500)
bc.fill() # bc.fill()
let pattern = patternCreateForSurface(b) # let pattern = patternCreateForSurface(b)
timeIt "a": # timeIt "a":
ac.setSource(pattern) # ac.setSource(pattern)
ac.save() # ac.save()
ac.translate(25.2, 25.2) # ac.translate(25.2, 25.2)
ac.rectangle(0, 0, 500, 500) # ac.rectangle(0, 0, 500, 500)
ac.fill() # ac.fill()
ac.restore() # ac.restore()
discard a.writeToPng("a.png") # discard a.writeToPng("a.png")

View file

@ -1201,12 +1201,14 @@ proc computeCoverages(
segment = partitioning.partitions[partitionIndex][i][0] segment = partitioning.partitions[partitionIndex][i][0]
winding = partitioning.partitions[partitionIndex][i][1] winding = partitioning.partitions[partitionIndex][i][1]
if segment.at.y <= yLine and segment.to.y >= yLine: if segment.at.y <= yLine and segment.to.y >= yLine:
let x = let
if segment.at.x - segment.to.x == 0: d = segment.at.x - segment.to.x
x =
if d == 0:
segment.at.x segment.at.x
else: else:
let let
m = (segment.at.y - segment.to.y) / (segment.at.x - segment.to.x) m = (segment.at.y - segment.to.y) / d
b = segment.at.y - m * segment.at.x b = segment.at.y - m * segment.at.x
(yLine - b) / m (yLine - b) / m
@ -1215,9 +1217,12 @@ proc computeCoverages(
hits[numHits] = (min(x, width), winding) hits[numHits] = (min(x, width), winding)
inc numHits inc numHits
if numHits > 0:
sort(hits, 0, numHits - 1) sort(hits, 0, numHits - 1)
if aa: if not aa:
continue
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, width): for (prevAt, at, count) in hits.walk(numHits, windingRule, y, width):
var fillStart = prevAt.int var fillStart = prevAt.int