andre feedback

This commit is contained in:
Ryan Oldenburg 2022-06-14 16:17:23 -05:00
parent b75ae4c7fd
commit 5336ccfc36

View file

@ -49,7 +49,7 @@ type
partitions: seq[Partition] partitions: seq[Partition]
startY, partitionHeight: uint32 startY, partitionHeight: uint32
FixedPoint = int32 ## 24.8 fixed point Fixed32 = int32 ## 24.8 fixed point
const const
epsilon: float32 = 0.0001 * PI ## Tiny value used for some computations. epsilon: float32 = 0.0001 * PI ## Tiny value used for some computations.
@ -1155,16 +1155,16 @@ proc maxEntryCount(partitioning: var Partitioning): int =
for i in 0 ..< partitioning.partitions.len: for i in 0 ..< partitioning.partitions.len:
result = max(result, partitioning.partitions[i].entries.len) result = max(result, partitioning.partitions[i].entries.len)
proc fixedPoint(f: float32): FixedPoint {.inline.} = proc fixed32(f: float32): Fixed32 {.inline.} =
FixedPoint(f * 256) Fixed32(f * 256)
proc pixel(p: FixedPoint): int {.inline.} = proc integer(p: Fixed32): int {.inline.} =
p div 256 p div 256
proc trunc(p: FixedPoint): FixedPoint {.inline.} = proc trunc(p: Fixed32): Fixed32 {.inline.} =
(p div 256) * 256 (p div 256) * 256
proc sortHits(hits: var seq[(FixedPoint, int16)], inl, inr: int) = proc sortHits(hits: var seq[(Fixed32, int16)], inl, inr: int) =
## Quicksort + insertion sort, in-place and faster than standard lib sort. ## Quicksort + insertion sort, in-place and faster than standard lib sort.
let n = inr - inl + 1 let n = inr - inl + 1
if n < 32: # Use insertion sort for the rest if n < 32: # Use insertion sort for the rest
@ -1204,15 +1204,15 @@ proc shouldFill(
count mod 2 != 0 count mod 2 != 0
iterator walk( iterator walk(
hits: seq[(FixedPoint, int16)], hits: seq[(Fixed32, int16)],
numHits: int, numHits: int,
windingRule: WindingRule, windingRule: WindingRule,
y: int, y: int,
width: int width: int
): (FixedPoint, FixedPoint, int) = ): (Fixed32, Fixed32, int) =
var var
i, count: int i, count: int
prevAt: FixedPoint prevAt: Fixed32
while i < numHits: while i < numHits:
let (at, winding) = hits[i] let (at, winding) = hits[i]
if at > 0: if at > 0:
@ -1238,12 +1238,12 @@ iterator walk(
inc i inc i
when defined(pixieLeakCheck): when defined(pixieLeakCheck):
if prevAt != fixedPoint(width.float32) and count != 0: if prevAt != width.float32.fixed32 and count != 0:
echo "Leak detected: ", count, " @ (", prevAt, ", ", y, ")" echo "Leak detected: ", count, " @ (", prevAt, ", ", y, ")"
proc computeCoverage( proc computeCoverage(
coverages: ptr UncheckedArray[uint8], coverages: ptr UncheckedArray[uint8],
hits: var seq[(FixedPoint, int16)], hits: var seq[(Fixed32, int16)],
numHits: var int, numHits: var int,
aa: var bool, aa: var bool,
width: int, width: int,
@ -1280,7 +1280,7 @@ proc computeCoverage(
else: else:
(yLine - entry.b) / entry.m (yLine - entry.b) / entry.m
hits[numHits] = (fixedPoint(min(x, width.float32)), entry.winding) hits[numHits] = (min(x, width.float32).fixed32, entry.winding)
inc numHits inc numHits
if numHits > 0: if numHits > 0:
@ -1288,27 +1288,27 @@ proc computeCoverage(
if aa: if aa:
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.pixel var fillStart = prevAt.integer
let let
pixelCrossed = at.pixel != prevAt.pixel pixelCrossed = at.integer != prevAt.integer
leftCover = leftCover =
if pixelCrossed: if pixelCrossed:
prevAt.trunc + fixedPoint(1.0) - prevAt prevAt.trunc + 1.0.fixed32 - prevAt
else: else:
at - prevAt at - prevAt
if leftCover != 0: if leftCover != 0:
inc fillStart inc fillStart
coverages[prevAt.pixel - startX] += coverages[prevAt.integer - startX] +=
(leftCover * sampleCoverage.int32).pixel.uint8 (leftCover * sampleCoverage.int32).integer.uint8
if pixelCrossed: if pixelCrossed:
let rightCover = at - at.trunc let rightCover = at - at.trunc
if rightCover > 0: if rightCover > 0:
coverages[at.pixel - startX] += coverages[at.integer - startX] +=
(rightCover * sampleCoverage.int32).pixel.uint8 (rightCover * sampleCoverage.int32).integer.uint8
let fillLen = at.pixel - fillStart let fillLen = at.integer - fillStart
if fillLen > 0: if fillLen > 0:
var i = fillStart var i = fillStart
when defined(amd64) and allowSimd: when defined(amd64) and allowSimd:
@ -1503,7 +1503,7 @@ proc fillHits(
image: Image, image: Image,
rgbx: ColorRGBX, rgbx: ColorRGBX,
startX, y: int, startX, y: int,
hits: seq[(FixedPoint, int16)], hits: seq[(Fixed32, int16)],
numHits: int, numHits: int,
windingRule: WindingRule, windingRule: WindingRule,
blendMode: BlendMode blendMode: BlendMode
@ -1512,8 +1512,8 @@ proc fillHits(
var filledTo: int var filledTo: int
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, image.width): for (prevAt, at, count) in hits.walk(numHits, windingRule, y, image.width):
let let
fillStart = prevAt.pixel fillStart = prevAt.integer
fillLen = at.pixel - fillStart fillLen = at.integer - fillStart
if fillLen <= 0: if fillLen <= 0:
continue continue
@ -1563,7 +1563,7 @@ proc fillHits(
proc fillHits( proc fillHits(
mask: Mask, mask: Mask,
startX, y: int, startX, y: int,
hits: seq[(FixedPoint, int16)], hits: seq[(Fixed32, int16)],
numHits: int, numHits: int,
windingRule: WindingRule, windingRule: WindingRule,
blendMode: BlendMode blendMode: BlendMode
@ -1572,8 +1572,8 @@ proc fillHits(
var filledTo: int var filledTo: int
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, mask.width): for (prevAt, at, count) in hits.walk(numHits, windingRule, y, mask.width):
let let
fillStart = prevAt.pixel fillStart = prevAt.integer
fillLen = at.pixel - fillStart fillLen = at.integer - fillStart
if fillLen <= 0: if fillLen <= 0:
continue continue
@ -1638,7 +1638,7 @@ proc fillShapes(
var var
partitioning = partitionSegments(segments, startY, pathHeight - startY) partitioning = partitionSegments(segments, startY, pathHeight - startY)
coverages = newSeq[uint8](pathWidth) coverages = newSeq[uint8](pathWidth)
hits = newSeq[(FixedPoint, int16)](partitioning.maxEntryCount) hits = newSeq[(Fixed32, int16)](partitioning.maxEntryCount)
numHits: int numHits: int
aa: bool aa: bool
@ -1707,7 +1707,7 @@ proc fillShapes(
var var
partitioning = partitionSegments(segments, startY, pathHeight) partitioning = partitionSegments(segments, startY, pathHeight)
coverages = newSeq[uint8](pathWidth) coverages = newSeq[uint8](pathWidth)
hits = newSeq[(FixedPoint, int16)](partitioning.maxEntryCount) hits = newSeq[(Fixed32, int16)](partitioning.maxEntryCount)
numHits: int numHits: int
aa: bool aa: bool
@ -2076,7 +2076,7 @@ proc overlaps(
test: Vec2, test: Vec2,
windingRule: WindingRule windingRule: WindingRule
): bool = ): bool =
var hits: seq[(FixedPoint, int16)] var hits: seq[(Fixed32, int16)]
let let
scanline = line(vec2(0, test.y), vec2(1000, test.y)) scanline = line(vec2(0, test.y), vec2(1000, test.y))
@ -2086,11 +2086,11 @@ proc overlaps(
var at: Vec2 var at: Vec2
if scanline.intersects(segment, at): if scanline.intersects(segment, at):
if segment.to != at: if segment.to != at:
hits.add((fixedPoint(at.x), winding)) hits.add((at.x.fixed32, winding))
sortHits(hits, 0, hits.high) sortHits(hits, 0, hits.high)
let testX = fixedPoint(test.x) let testX = test.x.fixed32
var count: int var count: int
for (at, winding) in hits: for (at, winding) in hits: