MCPcopy Index your code
hub / github.com/benfry/processing4 / parseSingleTransform

Method parseSingleTransform

core/src/processing/core/PShapeSVG.java:1087–1131  ·  view source on GitHub ↗
(String matrixStr)

Source from the content-addressed store, hash-verified

1085
1086
1087 static protected PMatrix2D parseSingleTransform(String matrixStr) {
1088 //String[] pieces = PApplet.match(matrixStr, "^\\s*(\\w+)\\((.*)\\)\\s*$");
1089 String[] pieces = PApplet.match(matrixStr, "[,\\s]*(\\w+)\\((.*)\\)");
1090 if (pieces == null) {
1091 System.err.println("Could not parse transform " + matrixStr);
1092 return null;
1093 }
1094 float[] m = PApplet.parseFloat(PApplet.splitTokens(pieces[2], ", "));
1095 if (pieces[1].equals("matrix")) {
1096 return new PMatrix2D(m[0], m[2], m[4], m[1], m[3], m[5]);
1097
1098 } else if (pieces[1].equals("translate")) {
1099 float tx = m[0];
1100 float ty = (m.length == 2) ? m[1] : m[0];
1101 return new PMatrix2D(1, 0, tx, 0, 1, ty);
1102
1103 } else if (pieces[1].equals("scale")) {
1104 float sx = m[0];
1105 float sy = (m.length == 2) ? m[1] : m[0];
1106 return new PMatrix2D(sx, 0, 0, 0, sy, 0);
1107
1108 } else if (pieces[1].equals("rotate")) {
1109 float angle = m[0];
1110
1111 if (m.length == 1) {
1112 float c = PApplet.cos(angle);
1113 float s = PApplet.sin(angle);
1114 // SVG version is cos(a) sin(a) -sin(a) cos(a) 0 0
1115 return new PMatrix2D(c, -s, 0, s, c, 0);
1116
1117 } else if (m.length == 3) {
1118 PMatrix2D mat = new PMatrix2D(0, 1, m[1], 1, 0, m[2]);
1119 mat.rotate(m[0]);
1120 mat.translate(-m[1], -m[2]);
1121 return mat;
1122 }
1123
1124 } else if (pieces[1].equals("skewX")) {
1125 return new PMatrix2D(1, 0, 1, PApplet.tan(m[0]), 0, 0);
1126
1127 } else if (pieces[1].equals("skewY")) {
1128 return new PMatrix2D(1, 0, 1, 0, PApplet.tan(m[0]), 0);
1129 }
1130 return null;
1131 }
1132
1133
1134 protected void parseColors(XML properties) {

Callers 1

parseTransformMethod · 0.95

Calls 10

matchMethod · 0.95
parseFloatMethod · 0.95
splitTokensMethod · 0.95
cosMethod · 0.95
sinMethod · 0.95
rotateMethod · 0.95
translateMethod · 0.95
tanMethod · 0.95
printlnMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected