MCPcopy Index your code
hub / github.com/processing/processing / parsePath

Method parsePath

core/src/processing/core/PShapeSVG.java:506–885  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

504
505
506 protected void parsePath() {
507 family = PATH;
508 kind = 0;
509
510 String pathData = element.getString("d");
511 if (pathData == null || PApplet.trim(pathData).length() == 0) {
512 return;
513 }
514 char[] pathDataChars = pathData.toCharArray();
515
516 StringBuilder pathBuffer = new StringBuilder();
517 boolean lastSeparate = false;
518
519 for (int i = 0; i < pathDataChars.length; i++) {
520 char c = pathDataChars[i];
521 boolean separate = false;
522
523 if (c == 'M' || c == 'm' ||
524 c == 'L' || c == 'l' ||
525 c == 'H' || c == 'h' ||
526 c == 'V' || c == 'v' ||
527 c == 'C' || c == 'c' || // beziers
528 c == 'S' || c == 's' ||
529 c == 'Q' || c == 'q' || // quadratic beziers
530 c == 'T' || c == 't' ||
531 c == 'A' || c == 'a' || // elliptical arc
532 c == 'Z' || c == 'z' || // closepath
533 c == ',') {
534 separate = true;
535 if (i != 0) {
536 pathBuffer.append("|");
537 }
538 }
539 if (c == 'Z' || c == 'z') {
540 separate = false;
541 }
542 if (c == '-' && !lastSeparate) {
543 // allow for 'e' notation in numbers, e.g. 2.10e-9
544 // http://dev.processing.org/bugs/show_bug.cgi?id=1408
545 if (i == 0 || pathDataChars[i-1] != 'e') {
546 pathBuffer.append("|");
547 }
548 }
549 if (c != ',') {
550 pathBuffer.append(c); //"" + pathDataBuffer.charAt(i));
551 }
552 if (separate && c != ',' && c != '-') {
553 pathBuffer.append("|");
554 }
555 lastSeparate = separate;
556 }
557
558 // use whitespace constant to get rid of extra spaces and CR or LF
559 String[] pathTokens =
560 PApplet.splitTokens(pathBuffer.toString(), "|" + WHITESPACE);
561 vertices = new float[pathTokens.length][2];
562 vertexCodes = new int[pathTokens.length];
563

Callers 2

parseChildMethod · 0.95
FontGlyphMethod · 0.80

Calls 14

trimMethod · 0.95
splitTokensMethod · 0.95
parseFloatMethod · 0.95
parsePathMovetoMethod · 0.95
parsePathLinetoMethod · 0.95
parsePathCurvetoMethod · 0.95
parsePathQuadtoMethod · 0.95
parsePathArctoMethod · 0.95
joinMethod · 0.95
subsetMethod · 0.95
getStringMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected