Skip to content

Commit

Permalink
refactor(geom): update skipWS() helper for pathFromSVG()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 5, 2020
1 parent 6ed20c1 commit ec07ddd
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions packages/geom/src/ctors/path-from-svg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { illegalState } from "@thi.ng/errors";
import { rad } from "@thi.ng/math";
import { WS } from "@thi.ng/strings";
import { PathBuilder } from "./path-builder";
import type { Vec } from "@thi.ng/vectors";

Expand Down Expand Up @@ -37,25 +38,21 @@ export const pathFromSvg = (svg: string) => {
case "q":
[pa, i] = readPoint(svg, i);
[p, i] = readPoint(svg, i);
// console.log("quadratic", pa.toString(), p.toString());
b.quadraticTo(pa, p, cmd === "q");
break;
case "c":
[pa, i] = readPoint(svg, i);
[pb, i] = readPoint(svg, i);
[p, i] = readPoint(svg, i);
// console.log("cubic", pa.toString(), pb.toString(), p.toString());
b.cubicTo(pa, pb, p, cmd === "c");
break;
case "s":
[pa, i] = readPoint(svg, i);
[p, i] = readPoint(svg, i);
// console.log("cubicChain", pa.toString(), p.toString());
b.cubicChainTo(pa, p, cmd === "s");
break;
case "t":
[p, i] = readPoint(svg, i);
// console.log("quadraticChain", p.toString());
b.quadraticChainTo(p, cmd === "t");
break;
case "a": {
Expand All @@ -64,7 +61,6 @@ export const pathFromSvg = (svg: string) => {
[t2, i] = readFlag(svg, i);
[t3, i] = readFlag(svg, i);
[pb, i] = readPoint(svg, i);
// console.log("arc", pa.toString(), rad(t1), t2, t3, pb.toString());
b.arcTo(pb, pa, rad(t1), t2, t3, cmd === "a");
break;
}
Expand All @@ -85,11 +81,9 @@ export const pathFromSvg = (svg: string) => {
}
};

const isWS = (c: string) => c === " " || c === "\n" || c === "\r" || c === "\t";

const skipWS = (src: string, i: number) => {
const n = src.length;
while (i < n && isWS(src.charAt(i))) i++;
while (i < n && WS[src.charAt(i)]) i++;
return i;
};

Expand Down Expand Up @@ -123,7 +117,6 @@ const readFloat = (src: string, index: number) => {
let i = index;
for (let n = src.length; i < n; i++) {
const c = src.charAt(i);
// console.log("float", src.substring(index, i + 1));
if ("0" <= c && c <= "9") {
expOk = true;
commaOk = true;
Expand Down

0 comments on commit ec07ddd

Please sign in to comment.