simpler
This commit is contained in:
parent
4cdb9db0f6
commit
b232a3a8c2
1 changed files with 14 additions and 27 deletions
|
@ -744,13 +744,14 @@ proc quickSort(a: var seq[(float32, bool)], inl, inr: int) =
|
||||||
quickSort(a, inl, r)
|
quickSort(a, inl, r)
|
||||||
quickSort(a, l, inr)
|
quickSort(a, l, inr)
|
||||||
|
|
||||||
proc computeBounds(shape: seq[Vec2]): Rect =
|
proc computeBounds(shapes: seq[seq[(Segment, bool)]]): Rect =
|
||||||
var
|
var
|
||||||
xMin = float32.high
|
xMin = float32.high
|
||||||
xMax = float32.low
|
xMax = float32.low
|
||||||
yMin = float32.high
|
yMin = float32.high
|
||||||
yMax = float32.low
|
yMax = float32.low
|
||||||
for segment in shape.segments:
|
for shape in shapes:
|
||||||
|
for (segment, _) in shape:
|
||||||
xMin = min(xMin, min(segment.at.x, segment.to.x))
|
xMin = min(xMin, min(segment.at.x, segment.to.x))
|
||||||
xMax = max(xMax, max(segment.at.x, segment.to.x))
|
xMax = max(xMax, max(segment.at.x, segment.to.x))
|
||||||
yMin = min(yMin, min(segment.at.y, segment.to.y))
|
yMin = min(yMin, min(segment.at.y, segment.to.y))
|
||||||
|
@ -772,11 +773,8 @@ proc fillShapes(
|
||||||
color: ColorRGBA,
|
color: ColorRGBA,
|
||||||
windingRule: WindingRule
|
windingRule: WindingRule
|
||||||
) =
|
) =
|
||||||
var
|
var sortedShapes = newSeq[seq[(Segment, bool)]](shapes.len)
|
||||||
sortedShapes = newSeq[seq[(Segment, bool)]](shapes.len)
|
|
||||||
bounds = newSeq[Rect](shapes.len)
|
|
||||||
for i, sorted in sortedShapes.mpairs:
|
for i, sorted in sortedShapes.mpairs:
|
||||||
bounds[i] = computeBounds(shapes[i])
|
|
||||||
for segment in shapes[i].segments:
|
for segment in shapes[i].segments:
|
||||||
if segment.at.y == segment.to.y: # Skip horizontal
|
if segment.at.y == segment.to.y: # Skip horizontal
|
||||||
continue
|
continue
|
||||||
|
@ -788,21 +786,13 @@ proc fillShapes(
|
||||||
else:
|
else:
|
||||||
sorted.add((segment, winding))
|
sorted.add((segment, winding))
|
||||||
|
|
||||||
# Figure out the total bounds of all the shapes
|
# Figure out the total bounds of all the shapes,
|
||||||
var
|
# rasterize only within the total bounds
|
||||||
minX = float32.high
|
|
||||||
minY = float32.high
|
|
||||||
maxY = float32.low
|
|
||||||
for bounds in bounds:
|
|
||||||
minX = min(minX, bounds.x)
|
|
||||||
minY = min(minY, bounds.y)
|
|
||||||
maxY = max(maxY, bounds.y + bounds.h)
|
|
||||||
|
|
||||||
# Rasterize only within the total bounds
|
|
||||||
let
|
let
|
||||||
startX = max(0, minX.int)
|
bounds = computeBounds(sortedShapes)
|
||||||
startY = max(0, miny.int)
|
startX = max(0, bounds.x.int)
|
||||||
stopY = min(image.height, maxY.int)
|
startY = max(0, bounds.y.int)
|
||||||
|
stopY = min(image.height, (bounds.y + bounds.h).int)
|
||||||
|
|
||||||
const
|
const
|
||||||
quality = 5 # Must divide 255 cleanly
|
quality = 5 # Must divide 255 cleanly
|
||||||
|
@ -827,9 +817,6 @@ proc fillShapes(
|
||||||
scanline = Line(a: vec2(0, yLine), b: vec2(1000, yLine))
|
scanline = Line(a: vec2(0, yLine), b: vec2(1000, yLine))
|
||||||
numHits = 0
|
numHits = 0
|
||||||
for i, shape in sortedShapes:
|
for i, shape in sortedShapes:
|
||||||
let bounds = bounds[i]
|
|
||||||
if bounds.y > y.float32 or bounds.y + bounds.h < y.float32:
|
|
||||||
continue
|
|
||||||
for (segment, winding) in shape:
|
for (segment, winding) in shape:
|
||||||
if segment.at.y > yLine or segment.to.y < y.float32:
|
if segment.at.y > yLine or segment.to.y < y.float32:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue