From 5dc663b0fb1085198f2ce12a3cf5d0f413f57e75 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Fri, 25 Oct 2019 21:21:33 +0800 Subject: [PATCH 1/2] Add support for SVG Q, S and T path segment formats --- src/thi/ng/geom/svg/core.cljc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/thi/ng/geom/svg/core.cljc b/src/thi/ng/geom/svg/core.cljc index 230eea27..c94f7eff 100644 --- a/src/thi/ng/geom/svg/core.cljc +++ b/src/thi/ng/geom/svg/core.cljc @@ -52,8 +52,6 @@ (repeat n) (interpose " ")))) -;; TODO add missing path segment types (Q, T) - (def path-segment-formats {:M ["M" *fmt-vec* " "] :m ["m" *fmt-vec* " "] @@ -61,6 +59,12 @@ :l ["l" *fmt-vec* " "] :C ["C" *fmt-vec* " " *fmt-vec* " " *fmt-vec* " "] :c ["c" *fmt-vec* " " *fmt-vec* " " *fmt-vec* " "] + :Q ["Q" *fmt-vec* " " *fmt-vec* " "] + :q ["q" *fmt-vec* " " *fmt-vec* " "] + :S ["S" *fmt-vec* " " *fmt-vec* " "] + :s ["s" *fmt-vec* " " *fmt-vec* " "] + :T ["T" *fmt-vec* " "] + :t ["t" *fmt-vec* " "] :A ["A" *fmt-vec* " " *ff* " " str " " str " " *fmt-vec* " "] :a ["a" *fmt-vec* " " *ff* " " str " " str " " *fmt-vec* " "] :Z ["Z"] From 813e0ee075035e3725ff788d02d3f7189d508f00 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Fri, 25 Oct 2019 21:25:11 +0800 Subject: [PATCH 2/2] Document thi.ng.geom.svg.core/path function --- src/thi/ng/geom/svg/core.cljc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/thi/ng/geom/svg/core.cljc b/src/thi/ng/geom/svg/core.cljc index c94f7eff..5c5b9226 100644 --- a/src/thi/ng/geom/svg/core.cljc +++ b/src/thi/ng/geom/svg/core.cljc @@ -193,6 +193,31 @@ (into [:g (svg-attribs attribs nil)] body)) (defn path + "Represents an SVG path element. + `segments` is a sequence of path segments, in the format + [ & args] + that corresponds to the SVG path language, eg. + + (path [[:M [0 0]] [:l [20 30]] [:Z]] + {:fill \"red\"}) + + For reference, the available commands are as follows. + Each has an uppercase (absolute coordinates) + and lowercase (relative coordinates) variant. + + | Command | Name | Arguments | + |---------+--------------------------+-------------------------------------------------------| + | M/m | moveto | [pt] | + | L/l | lineto | [pt] | + | H/h | horizontal lineto | [x] | + | V/v | vertical lineto | [y] | + | C/c | cubic curveto | [pt1 pt2 endpt] | + | S/s | smooth cubic curveto | [pt2 endpt] | + | Q/q | quadratic curveto | [pt1 endpt] | + | T/t | smooth quadratic curveto | [endpt] | + | A/a | elliptical arc | [rx ry x-axis-rotation large-arc-flag sweep-flag x y] | + | Z/z | closepath | [] | + " ([segments] (path segments nil)) ([segments attribs]