hits iterator
This commit is contained in:
parent
39b598b7c0
commit
2e1f9a81b8
1 changed files with 62 additions and 54 deletions
|
@ -1110,6 +1110,35 @@ proc shouldFill(windingRule: WindingRule, count: int): bool {.inline.} =
|
||||||
of wrEvenOdd:
|
of wrEvenOdd:
|
||||||
count mod 2 != 0
|
count mod 2 != 0
|
||||||
|
|
||||||
|
iterator walk(
|
||||||
|
hits: seq[(float32, int16)],
|
||||||
|
numHits: int,
|
||||||
|
windingRule: WindingRule,
|
||||||
|
y: int,
|
||||||
|
size: Vec2
|
||||||
|
): (float32, float32, int32) =
|
||||||
|
var
|
||||||
|
prevAt: float32
|
||||||
|
count: int32
|
||||||
|
for i in 0 ..< numHits:
|
||||||
|
let (at, winding) = hits[i]
|
||||||
|
if windingRule == wrNonZero and
|
||||||
|
(count != 0) == (count + winding != 0) and
|
||||||
|
i < numHits - 1:
|
||||||
|
# Shortcut: if nonzero rule, we only care about when the count changes
|
||||||
|
# between zero and nonzero (or the last hit)
|
||||||
|
count += winding
|
||||||
|
continue
|
||||||
|
if at > 0:
|
||||||
|
if shouldFill(windingRule, count):
|
||||||
|
yield (prevAt, at, count)
|
||||||
|
prevAt = at
|
||||||
|
count += winding
|
||||||
|
|
||||||
|
when defined(pixieLeakCheck):
|
||||||
|
if prevAt != size.x and count != 0:
|
||||||
|
echo "Leak detected: ", count, " @ (", prevAt, ", ", y, ")"
|
||||||
|
|
||||||
proc computeCoverages(
|
proc computeCoverages(
|
||||||
coverages: var seq[uint8],
|
coverages: var seq[uint8],
|
||||||
hits: var seq[(float32, int16)],
|
hits: var seq[(float32, int16)],
|
||||||
|
@ -1155,20 +1184,7 @@ proc computeCoverages(
|
||||||
else:
|
else:
|
||||||
insertionSort(hits, numHits - 1)
|
insertionSort(hits, numHits - 1)
|
||||||
|
|
||||||
var
|
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, size):
|
||||||
prevAt: float32
|
|
||||||
count: int
|
|
||||||
for i in 0 ..< numHits:
|
|
||||||
let (at, winding) = hits[i]
|
|
||||||
if windingRule == wrNonZero and
|
|
||||||
(count != 0) == (count + winding != 0) and
|
|
||||||
i < numHits - 1:
|
|
||||||
# Shortcut: if nonzero rule, we only care about when the count changes
|
|
||||||
# between zero and nonzero (or the last hit)
|
|
||||||
count += winding
|
|
||||||
continue
|
|
||||||
if at > 0:
|
|
||||||
if shouldFill(windingRule, count):
|
|
||||||
var fillStart = prevAt.int
|
var fillStart = prevAt.int
|
||||||
|
|
||||||
let
|
let
|
||||||
|
@ -1203,14 +1219,6 @@ proc computeCoverages(
|
||||||
else:
|
else:
|
||||||
nimSetMem(coverages[fillStart].addr, sampleCoverage.cint, fillLen)
|
nimSetMem(coverages[fillStart].addr, sampleCoverage.cint, fillLen)
|
||||||
|
|
||||||
prevAt = at
|
|
||||||
|
|
||||||
count += winding
|
|
||||||
|
|
||||||
when defined(pixieLeakCheck):
|
|
||||||
if prevAt != size.x and count != 0:
|
|
||||||
echo "Leak detected: ", count, " @ (", prevAt, ", ", y, ")"
|
|
||||||
|
|
||||||
proc fillShapes(
|
proc fillShapes(
|
||||||
image: Image,
|
image: Image,
|
||||||
shapes: seq[seq[Vec2]],
|
shapes: seq[seq[Vec2]],
|
||||||
|
@ -1397,9 +1405,9 @@ proc strokeShapes(
|
||||||
if strokeWidth <= 0:
|
if strokeWidth <= 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
let miterAngleLimit = miterLimitToAngle(miterLimit)
|
let
|
||||||
|
halfStroke = strokeWidth / 2
|
||||||
let halfStroke = strokeWidth / 2
|
miterAngleLimit = miterLimitToAngle(miterLimit)
|
||||||
|
|
||||||
proc makeCircle(at: Vec2): seq[Vec2] =
|
proc makeCircle(at: Vec2): seq[Vec2] =
|
||||||
var path: Path
|
var path: Path
|
||||||
|
|
Loading…
Reference in a new issue