From 23deffc7619adc9a6c0b188b48556066ab4b97d0 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Wed, 22 Jun 2022 02:12:15 -0500 Subject: [PATCH] simplify --- src/pixie/paths.nim | 66 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index 694f1af..1c8efe1 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -46,10 +46,6 @@ type requiresAntiAliasing: bool bottom: int - Partitioning = object - partitions: seq[Partition] - startY, partitionHeight: uint32 - Fixed32 = int32 ## 24.8 fixed point const @@ -1123,49 +1119,51 @@ proc requiresAntiAliasing(entries: var seq[PartitionEntry]): bool = proc partitionSegments( segments: seq[(Segment, int16)], top, height: int -): Partitioning = +): seq[Partition] = ## Puts segments into the height partitions they intersect with. let maxPartitions = max(1, height div 4).uint32 numPartitions = min(maxPartitions, max(1, segments.len div 2).uint32) - result.partitions.setLen(numPartitions) - result.startY = top.uint32 - result.partitionHeight = height.uint32 div numPartitions + result.setLen(numPartitions) + + let + startY = top.uint32 + partitionHeight = height.uint32 div numPartitions for (segment, winding) in segments: var entry = initPartitionEntry(segment, winding) - if result.partitionHeight == 0: - result.partitions[0].entries.add(move entry) + if partitionHeight == 0: + result[0].entries.add(move entry) else: var - atPartition = max(0, segment.at.y - result.startY.float32).uint32 - toPartition = max(0, segment.to.y - result.startY.float32).uint32 - atPartition = atPartition div result.partitionHeight - toPartition = toPartition div result.partitionHeight - atPartition = min(atPartition, result.partitions.high.uint32) - toPartition = min(toPartition, result.partitions.high.uint32) + atPartition = max(0, segment.at.y - startY.float32).uint32 + toPartition = max(0, segment.to.y - startY.float32).uint32 + atPartition = atPartition div partitionHeight + toPartition = toPartition div partitionHeight + atPartition = min(atPartition, result.high.uint32) + toPartition = min(toPartition, result.high.uint32) for i in atPartition .. toPartition: - result.partitions[i].entries.add(entry) + result[i].entries.add(entry) # Set the bottom values for the partitions (y value where this partition ends) - var partitionBottom = top + result.partitionHeight.int + var partitionBottom = top + partitionHeight.int - for partition in result.partitions.mitems: + for partition in result.mitems: partition.bottom = partitionBottom partition.requiresAntiAliasing = requiresAntiAliasing(partition.entries) - partitionBottom += result.partitionHeight.int + partitionBottom += partitionHeight.int # Ensure the final partition goes to the actual bottom # This is needed since the final partition includes # height - (height div numPartitions) * numPartitions - result.partitions[^1].bottom = top + height + result[^1].bottom = top + height -proc maxEntryCount(partitioning: var Partitioning): int = - for i in 0 ..< partitioning.partitions.len: - result = max(result, partitioning.partitions[i].entries.len) +proc maxEntryCount(partitions: var seq[Partition]): int = + for i in 0 ..< partitions.len: + result = max(result, partitions[i].entries.len) proc fixed32(f: float32): Fixed32 {.inline.} = Fixed32(f * 256) @@ -1256,14 +1254,14 @@ proc computeCoverage( aa: var bool, width: int, y, startX: int, - partitioning: var Partitioning, + partitions: var seq[Partition], partitionIndex: var int, windingRule: WindingRule ) {.inline.} = - if y >= partitioning.partitions[partitionIndex].bottom: + if y >= partitions[partitionIndex].bottom: inc partitionIndex - aa = partitioning.partitions[partitionIndex].requiresAntiAliasing + aa = partitions[partitionIndex].requiresAntiAliasing let quality = if aa: 5 else: 1 # Must divide 255 cleanly (1, 3, 5, 15, 17, 51, 85) @@ -1275,7 +1273,7 @@ proc computeCoverage( for m in 0 ..< quality: yLine += offset numHits = 0 - for entry in partitioning.partitions[partitionIndex].entries.mitems: + for entry in partitions[partitionIndex].entries.mitems: if entry.segment.at.y <= yLine and entry.segment.to.y >= yLine: let x = if entry.m == 0: @@ -1800,10 +1798,10 @@ proc fillShapes( raise newException(PixieError, "Path int overflow detected") var - partitioning = partitionSegments(segments, startY, pathHeight - startY) + partitions = partitionSegments(segments, startY, pathHeight - startY) partitionIndex: int coverages = newSeq[uint8](pathWidth) - hits = newSeq[(Fixed32, int16)](partitioning.maxEntryCount) + hits = newSeq[(Fixed32, int16)](partitions.maxEntryCount) numHits: int aa: bool @@ -1816,7 +1814,7 @@ proc fillShapes( image.width, y, startX, - partitioning, + partitions, partitionIndex, windingRule ) @@ -1871,10 +1869,10 @@ proc fillShapes( raise newException(PixieError, "Path int overflow detected") var - partitioning = partitionSegments(segments, startY, pathHeight) + partitions = partitionSegments(segments, startY, pathHeight) partitionIndex: int coverages = newSeq[uint8](pathWidth) - hits = newSeq[(Fixed32, int16)](partitioning.maxEntryCount) + hits = newSeq[(Fixed32, int16)](partitions.maxEntryCount) numHits: int aa: bool @@ -1887,7 +1885,7 @@ proc fillShapes( mask.width, y, startX, - partitioning, + partitions, partitionIndex, windingRule )