Prints out all path commands it can parse.
This commit is contained in:
parent
3ae54dad41
commit
4ae59d51da
2 changed files with 56 additions and 12 deletions
|
@ -48,7 +48,10 @@ proc parsePath*(path: string): Path =
|
||||||
if command != Start:
|
if command != Start:
|
||||||
let num = commandNumbers(command)
|
let num = commandNumbers(command)
|
||||||
if num > 0:
|
if num > 0:
|
||||||
assert numbers.len mod num == 0
|
if numbers.len mod num != 0:
|
||||||
|
raise newException(PixieError,
|
||||||
|
"Could not parse path: " & $command & " has wrong number of prams," &
|
||||||
|
" got " & $numbers.len & " but expected " & $num & ".")
|
||||||
for batch in 0 ..< numbers.len div num:
|
for batch in 0 ..< numbers.len div num:
|
||||||
result.commands.add PathCommand(
|
result.commands.add PathCommand(
|
||||||
kind: command,
|
kind: command,
|
||||||
|
@ -145,17 +148,27 @@ proc parsePath*(path: string): Path =
|
||||||
|
|
||||||
proc `$`*(path: Path): string =
|
proc `$`*(path: Path): string =
|
||||||
for command in path.commands:
|
for command in path.commands:
|
||||||
case command.kind:
|
case command.kind
|
||||||
of Move:
|
of Move: result.add "M"
|
||||||
result.add "M"
|
of Line: result.add "L"
|
||||||
of Arc:
|
of HLine: result.add "H"
|
||||||
result.add "A"
|
of VLine: result.add "V"
|
||||||
of Line:
|
of Cubic: result.add "C"
|
||||||
result.add "L"
|
of SCurve: result.add "S"
|
||||||
of End:
|
of Quad: result.add "Q"
|
||||||
result.add "Z"
|
of TQuad: result.add "T"
|
||||||
else:
|
of Arc: result.add "A"
|
||||||
result.add "?"
|
of RMove: result.add "m"
|
||||||
|
of RLine: result.add "l"
|
||||||
|
of RHLine: result.add "h"
|
||||||
|
of RVLine: result.add "v"
|
||||||
|
of RCubic: result.add "c"
|
||||||
|
of RSCurve: result.add "s"
|
||||||
|
of RQuad: result.add "q"
|
||||||
|
of RTQuad: result.add "t"
|
||||||
|
of RArc: result.add "a"
|
||||||
|
of End: result.add "Z"
|
||||||
|
of Start: result.add "?"
|
||||||
for number in command.numbers:
|
for number in command.numbers:
|
||||||
if floor(number) == number:
|
if floor(number) == number:
|
||||||
result.add $(number.int)
|
result.add $(number.int)
|
||||||
|
|
|
@ -1,5 +1,36 @@
|
||||||
import pixie, chroma
|
import pixie, chroma
|
||||||
|
|
||||||
|
block:
|
||||||
|
let pathStr = """
|
||||||
|
m 1 2
|
||||||
|
l 3 4
|
||||||
|
h 5
|
||||||
|
v 6
|
||||||
|
c 0 0 0 0 0 0
|
||||||
|
q 1 1 1 1
|
||||||
|
t 2 2
|
||||||
|
a 7 7 7 7 7 7 7
|
||||||
|
z
|
||||||
|
"""
|
||||||
|
let path = parsePath(pathStr)
|
||||||
|
doAssert $path == "m1 2 l3 4 h5 v6 c0 0 0 0 0 0 q1 1 1 1 t2 2 a7 7 7 7 7 7 7 Z"
|
||||||
|
|
||||||
|
block:
|
||||||
|
let pathStr = """
|
||||||
|
M 1 2
|
||||||
|
L 3 4
|
||||||
|
H 5
|
||||||
|
V 6
|
||||||
|
C 0 0 0 0 0 0
|
||||||
|
Q 1 1 1 1
|
||||||
|
T 2 2
|
||||||
|
A 7 7 7 7 7 7 7
|
||||||
|
z
|
||||||
|
"""
|
||||||
|
let path = parsePath(pathStr)
|
||||||
|
doAssert $path == "M1 2 L3 4 H5 V6 C0 0 0 0 0 0 Q1 1 1 1 T2 2 A7 7 7 7 7 7 7 Z"
|
||||||
|
|
||||||
|
|
||||||
block:
|
block:
|
||||||
let pathStr = "M 0.1E-10 0.1e10 L2+2 L3-3 L0.1E+10-1"
|
let pathStr = "M 0.1E-10 0.1e10 L2+2 L3-3 L0.1E+10-1"
|
||||||
let path = parsePath(pathStr)
|
let path = parsePath(pathStr)
|
||||||
|
|
Loading…
Reference in a new issue