bounds
This commit is contained in:
parent
3908825db8
commit
74169e4c15
2 changed files with 19 additions and 13 deletions
|
@ -312,7 +312,8 @@ proc commandsToPolygons*(commands: seq[PathCommand]): seq[seq[Vec2]] =
|
||||||
t = i.float32 / steps.float32
|
t = i.float32 / steps.float32
|
||||||
next = compute(at, ctrl1, ctrl2, to, t)
|
next = compute(at, ctrl1, ctrl2, to, t)
|
||||||
halfway = compute(at, ctrl1, ctrl2, to, tPrev + (t - tPrev) / 2)
|
halfway = compute(at, ctrl1, ctrl2, to, tPrev + (t - tPrev) / 2)
|
||||||
error = ((prev + next) / 2 - halfway).length
|
midpoint = (prev + next) / 2
|
||||||
|
error = (midpoint - halfway).length
|
||||||
|
|
||||||
if error >= 0.25:
|
if error >= 0.25:
|
||||||
# Error too large, double precision for this step
|
# Error too large, double precision for this step
|
||||||
|
@ -322,8 +323,7 @@ proc commandsToPolygons*(commands: seq[PathCommand]): seq[seq[Vec2]] =
|
||||||
drawLine(prev, next)
|
drawLine(prev, next)
|
||||||
prev = next
|
prev = next
|
||||||
|
|
||||||
for i in 1 .. 2:
|
discretize(1, 1)
|
||||||
discretize(i, 2)
|
|
||||||
|
|
||||||
proc drawQuad(p0, p1, p2: Vec2) =
|
proc drawQuad(p0, p1, p2: Vec2) =
|
||||||
let devx = p0.x - 2.0 * p1.x + p2.x
|
let devx = p0.x - 2.0 * p1.x + p2.x
|
||||||
|
@ -587,8 +587,8 @@ proc strokePolygons*(ps: seq[seq[Vec2]], strokeWidthR, strokeWidthL: float32): s
|
||||||
|
|
||||||
result.add(poly)
|
result.add(poly)
|
||||||
|
|
||||||
proc computeBounds(polys: seq[seq[Vec2]]): Rect =
|
proc computeBounds(poly: seq[Vec2]): Rect =
|
||||||
if polys.len == 0 or polys[0].len == 0:
|
if poly.len == 0:
|
||||||
return
|
return
|
||||||
proc min(a, b: Vec2): Vec2 =
|
proc min(a, b: Vec2): Vec2 =
|
||||||
result.x = min(a.x, b.x)
|
result.x = min(a.x, b.x)
|
||||||
|
@ -603,12 +603,11 @@ proc computeBounds(polys: seq[seq[Vec2]]): Rect =
|
||||||
result.x = a.x.ceil
|
result.x = a.x.ceil
|
||||||
result.y = a.y.ceil
|
result.y = a.y.ceil
|
||||||
var
|
var
|
||||||
vMin = polys[0][0]
|
vMin = poly[0]
|
||||||
vMax = polys[0][0]
|
vMax = poly[0]
|
||||||
for poly in polys:
|
for v in poly:
|
||||||
for v in poly:
|
vMin = min(v, vMin)
|
||||||
vMin = min(v, vMin)
|
vMax = max(v, vMax)
|
||||||
vMax = max(v, vMax)
|
|
||||||
result.xy = vMin.floor
|
result.xy = vMin.floor
|
||||||
result.wh = (vMax - vMin).ceil
|
result.wh = (vMax - vMin).ceil
|
||||||
|
|
||||||
|
@ -623,12 +622,16 @@ proc fillPolygons*(
|
||||||
blendMode: BlendMode = bmNormal,
|
blendMode: BlendMode = bmNormal,
|
||||||
quality = 4
|
quality = 4
|
||||||
) =
|
) =
|
||||||
|
var bounds = newSeq[Rect](polys.len)
|
||||||
|
for i, poly in polys:
|
||||||
|
bounds[i] = computeBounds(poly)
|
||||||
|
|
||||||
const ep = 0.0001 * PI
|
const ep = 0.0001 * PI
|
||||||
let mixer = blendMode.mixer()
|
let mixer = blendMode.mixer()
|
||||||
|
|
||||||
proc scanLineHits(
|
proc scanLineHits(
|
||||||
polys: seq[seq[Vec2]],
|
polys: seq[seq[Vec2]],
|
||||||
|
bounds: seq[Rect],
|
||||||
hits: var seq[(float32, bool)],
|
hits: var seq[(float32, bool)],
|
||||||
size: Vec2,
|
size: Vec2,
|
||||||
y: int,
|
y: int,
|
||||||
|
@ -640,7 +643,10 @@ proc fillPolygons*(
|
||||||
yLine = y.float32 + ep + shiftY
|
yLine = y.float32 + ep + shiftY
|
||||||
scan = Line(a: vec2(-10000, yLine), b: vec2(10000, yLine))
|
scan = Line(a: vec2(-10000, yLine), b: vec2(10000, yLine))
|
||||||
|
|
||||||
for poly in polys:
|
for i, poly in polys:
|
||||||
|
let bounds = bounds[i]
|
||||||
|
if bounds.y > y.float32 or bounds.y + bounds.h < y.float32:
|
||||||
|
continue
|
||||||
for line in poly.segments:
|
for line in poly.segments:
|
||||||
var line2 = line
|
var line2 = line
|
||||||
if line2.at.y > line2.to.y: # Sort order doesn't actually matter
|
if line2.at.y > line2.to.y: # Sort order doesn't actually matter
|
||||||
|
@ -664,7 +670,7 @@ proc fillPolygons*(
|
||||||
|
|
||||||
# Do scan lines for this row.
|
# Do scan lines for this row.
|
||||||
for m in 0 ..< quality:
|
for m in 0 ..< quality:
|
||||||
polys.scanLineHits(hits, size, y, float32(m) / float32(quality))
|
polys.scanLineHits(bounds, hits, size, y, float32(m) / float32(quality))
|
||||||
if hits.len == 0:
|
if hits.len == 0:
|
||||||
continue
|
continue
|
||||||
var
|
var
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 347 KiB After Width: | Height: | Size: 347 KiB |
Loading…
Reference in a new issue