This commit is contained in:
treeform 2021-12-03 16:50:02 -08:00
parent f522dbb9ff
commit 5ec38c068d
5 changed files with 54 additions and 75 deletions

View file

@ -64,6 +64,10 @@ var hourGlass = parsePath("""
M 20 20 L 180 20 L 20 180 L 180 180 z M 20 20 L 180 20 L 20 180 L 180 180 z
""") """)
var hourGlass2 = parsePath("""
M 20 20 L 180 20 L 20 180 L 180 180 z M 62 24 L 132 24 L 50 173 L 156 173 z
""")
# Hole # Hole
var hole = parsePath(""" var hole = parsePath("""
M 40 40 L 40 160 L 160 160 L 160 40 z M 40 40 L 40 160 L 160 160 L 160 40 z
@ -88,6 +92,8 @@ when defined(bench):
test("cricle", cricle, 100) test("cricle", cricle, 100)
test("halfAarc", halfAarc, 100) test("halfAarc", halfAarc, 100)
test("hourGlass", hourGlass, 100) test("hourGlass", hourGlass, 100)
test("hourGlass2", hourGlass2, wr=wrNonZero)
test("hourGlass2", hourGlass2, wr=wrEvenOdd)
test("hole", hole, 100) test("hole", hole, 100)
test("holeEvenOdd", holeEvenOdd, 100, wr=wrNonZero) test("holeEvenOdd", holeEvenOdd, 100, wr=wrNonZero)
test("holeEvenOdd", holeEvenOdd, 100, wr=wrEvenOdd) test("holeEvenOdd", holeEvenOdd, 100, wr=wrEvenOdd)
@ -99,7 +105,8 @@ else:
# test("cricle", cricle) # test("cricle", cricle)
# test("halfAarc", halfAarc) # test("halfAarc", halfAarc)
# test("hourGlass", hourGlass) # test("hourGlass", hourGlass)
#test("hole", hole, wr=wrEvenOdd) test("hourGlass2", hourGlass2, wr=wrEvenOdd)
test("holeEvenOdd", holeEvenOdd, wr=wrNonZero) # test("hole", hole, wr=wrEvenOdd)
test("holeEvenOdd", holeEvenOdd, wr=wrEvenOdd) # test("holeEvenOdd", holeEvenOdd, wr=wrNonZero)
# test("holeEvenOdd", holeEvenOdd, wr=wrEvenOdd)
# test("letterG", letterG) # test("letterG", letterG)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View file

@ -2,6 +2,7 @@
import chroma, pixie/common, pixie/images, pixie/internal, pixie/paints, import chroma, pixie/common, pixie/images, pixie/internal, pixie/paints,
pixie/paths, strutils, tables, vmath, xmlparser, xmltree pixie/paths, strutils, tables, vmath, xmlparser, xmltree
when defined(pixieDebugSvg): when defined(pixieDebugSvg):
import strtabs import strtabs

View file

@ -2267,78 +2267,46 @@ when defined(pixieSweeps):
i = 0 i = 0
while i < sweeps.len: while i < sweeps.len:
# TODO: Maybe finds all cuts first, add them to array, cut all lines at once. # TODO: Maybe finds all cuts first, add them to array, cut all lines at once.
for t in 0 ..< 10: # TODO: maybe while true: var crossCuts: seq[float32]
# keep cutting sweep
var needsCut = false
var cutterLine: float32 = 0
block doubleFor:
for a in sweeps[i]:
let aSeg = segment(
vec2(a.atx, cutLines[i]),
vec2(a.tox, cutLines[i+1])
)
for b in sweeps[i]:
let bSeg = segment(
vec2(b.atx, cutLines[i]),
vec2(b.tox, cutLines[i+1])
)
var at: Vec2
if intersectsInner(aSeg, bSeg, at):
needsCut = true
cutterLine = at.y
break doubleFor
# TODO enable?
if false and needsCut:
# Doing a cut.
var
thisSweep = sweeps[i]
sweeps[i].setLen(0)
sweeps.insert(newSeq[SweepLine](), i + 1)
for a in thisSweep:
let seg = segment(vec2(a.atx, cutLines[i]), vec2(a.tox, cutLines[i+1]))
var at: Vec2
if intersects(line(vec2(0, cutterLine), vec2(1, cutterLine)), seg, at):
sweeps[i+0].add(toLine((segment(seg.at, at), a.winding)))
sweeps[i+1].add(toLine((segment(at, seg.to), a.winding)))
cutLines.binaryInsert(cutterLine)
else:
break
inc i
# i = 0 # echo i, " cut?"
# while i < sweeps.len:
# # TODO: Maybe finds all cuts first, add them to array, cut all lines at once. for aIndex in 0 ..< sweeps[i].len:
# for t in 0 ..< 10: # TODO: maybe while true: let a = sweeps[i][aIndex]
# # keep cutting sweep # echo i, ":", sweeps.len, ":", cutLines.len
# var needsCut = false let aSeg = segment(vec2(a.atx, cutLines[i]), vec2(a.tox, cutLines[i+1]))
# var cutterLine: float32 = 0 for bIndex in aIndex + 1 ..< sweeps[i].len:
# block doubleFor: let b = sweeps[i][bIndex]
# for a in sweeps[i]: let bSeg = segment(vec2(b.atx, cutLines[i]), vec2(b.tox, cutLines[i+1]))
# let aSeg = segment(vec2(a.atx, cutLines[i]), vec2(a.tox, cutLines[i+1])) var at: Vec2
# for b in sweeps[i]: if intersectsInner(aSeg, bSeg, at):
# let bSeg = segment(vec2(b.atx, cutLines[i]), vec2(b.tox, cutLines[i+1])) crossCuts.binaryInsert(at.y)
# var at: Vec2
# if intersectsInner(aSeg, bSeg, at): if crossCuts.len > 0:
# needsCut = true var
# cutterLine = at.y thisSweep = sweeps[i]
# break doubleFor yTop = cutLines[i]
# # TODO enable? yBottom = cutLines[i + 1]
# if false and needsCut: sweeps[i].setLen(0)
# # Doing a cut.
# var for k in crossCuts:
# thisSweep = sweeps[i] let prevLen = cutLines.len
# sweeps[i].setLen(0) cutLines.binaryInsert(k)
# sweeps.insert(newSeq[SweepLine](), i + 1) if prevLen != cutLines.len:
# for a in thisSweep: sweeps.insert(newSeq[SweepLine](), i + 1)
# let seg = segment(vec2(a.atx, cutLines[i]), vec2(a.tox, cutLines[i+1]))
# var at: Vec2 for a in thisSweep:
# if intersects(line(vec2(0, cutterLine), vec2(1, cutterLine)), seg, at): var seg = segment(vec2(a.atx, yTop), vec2(a.tox, yBottom))
# sweeps[i+0].add(toLine((segment(seg.at, at), a.winding))) var at: Vec2
# sweeps[i+1].add(toLine((segment(at, seg.to), a.winding))) for j, cutterLine in crossCuts:
# cutLines.binaryInsert(cutterLine) if intersects(line(vec2(0, cutterLine), vec2(1, cutterLine)), seg, at):
# else: sweeps[i+j].add(toLine((segment(seg.at, at), a.winding)))
# break seg = segment(at, seg.to)
# inc i sweeps[i+crossCuts.len].add(toLine((seg, a.winding)))
i += crossCuts.len
inc i
i = 0 i = 0
while i < sweeps.len: while i < sweeps.len:

View file

@ -1,6 +1,9 @@
import benchy, pixie/fileformats/svg import benchy, pixie/fileformats/svg, pixie/fileformats/png
let data = readFile("tests/fileformats/svg/Ghostscript_Tiger.svg") let data = readFile("tests/fileformats/svg/Ghostscript_Tiger.svg")
#let data = readFile("tests/fileformats/svg/rotatedRect.svg")
writeFile("tiger.png", decodeSvg(data).encodePng())
timeIt "svg decode": timeIt "svg decode":
discard decodeSvg(data) discard decodeSvg(data)