faster partitioning by pre-sizing partition entries
This commit is contained in:
parent
f93da30d08
commit
3bdc6c3266
1 changed files with 29 additions and 11 deletions
|
@ -1131,25 +1131,43 @@ proc partitionSegments(
|
||||||
startY = top.uint32
|
startY = top.uint32
|
||||||
partitionHeight = height.uint32 div numPartitions
|
partitionHeight = height.uint32 div numPartitions
|
||||||
|
|
||||||
for (segment, winding) in segments:
|
var entries = newSeq[PartitionEntry](segments.len)
|
||||||
var entry = initPartitionEntry(segment, winding)
|
for i, (segment, winding) in segments:
|
||||||
if partitionHeight == 0:
|
entries[i] = initPartitionEntry(segment, winding)
|
||||||
result[0].entries.add(move entry)
|
|
||||||
else:
|
if numPartitions == 1:
|
||||||
|
result[0].entries = move entries
|
||||||
|
else:
|
||||||
|
iterator partitionRange(
|
||||||
|
segment: Segment,
|
||||||
|
numPartitions, startY, partitionHeight: uint32
|
||||||
|
): uint32 =
|
||||||
var
|
var
|
||||||
atPartition = max(0, segment.at.y - startY.float32).uint32
|
atPartition = max(0, segment.at.y - startY.float32).uint32
|
||||||
toPartition = max(0, segment.to.y - startY.float32).uint32
|
toPartition = max(0, segment.to.y - startY.float32).uint32
|
||||||
atPartition = atPartition div partitionHeight
|
atPartition = atPartition div partitionHeight
|
||||||
toPartition = toPartition div partitionHeight
|
toPartition = toPartition div partitionHeight
|
||||||
atPartition = min(atPartition, result.high.uint32)
|
atPartition = min(atPartition, numPartitions - 1)
|
||||||
toPartition = min(toPartition, result.high.uint32)
|
toPartition = min(toPartition, numPartitions - 1)
|
||||||
for i in atPartition .. toPartition:
|
for partitionIndex in atPartition .. toPartition:
|
||||||
result[i].entries.add(entry)
|
yield partitionIndex
|
||||||
|
|
||||||
|
var entryCounts = newSeq[int](numPartitions)
|
||||||
|
for (segment, _) in segments:
|
||||||
|
for partitionIndex in segment.partitionRange(numPartitions, startY, partitionHeight):
|
||||||
|
inc entryCounts[partitionIndex]
|
||||||
|
|
||||||
|
for partitionIndex, entryCounts in entryCounts:
|
||||||
|
result[partitionIndex].entries.setLen(entryCounts)
|
||||||
|
|
||||||
|
var indexes = newSeq[int](numPartitions)
|
||||||
|
for i, (segment, winding) in segments:
|
||||||
|
for partitionIndex in segment.partitionRange(numPartitions, startY, partitionHeight):
|
||||||
|
result[partitionIndex].entries[indexes[partitionIndex]] = entries[i]
|
||||||
|
inc indexes[partitionIndex]
|
||||||
|
|
||||||
# Set the bottom values for the partitions (y value where this partition ends)
|
# Set the bottom values for the partitions (y value where this partition ends)
|
||||||
|
|
||||||
var partitionBottom = top + partitionHeight.int
|
var partitionBottom = top + partitionHeight.int
|
||||||
|
|
||||||
for partition in result.mitems:
|
for partition in result.mitems:
|
||||||
partition.bottom = partitionBottom
|
partition.bottom = partitionBottom
|
||||||
partition.requiresAntiAliasing =
|
partition.requiresAntiAliasing =
|
||||||
|
|
Loading…
Reference in a new issue