Skip to content

Commit 65121fa

Browse files
committed
add comments
1 parent 11ca32b commit 65121fa

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

core/src/processing/core/PShapeSVG.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -972,20 +972,31 @@ else if (lexState == LexState.EXP_HEAD) {
972972
if (isCompactArcNotation(token4)) {
973973
fa = token4.charAt(0) == '1';
974974
fs = token4.charAt(1) == '1';
975+
// Case: flags and x-coordinate are concatenated (e.g. "01100")
976+
// token4 contains flags + x, so y is at i+5.
977+
// We consume 2 fewer tokens than standard (8-2=6).
975978
if (token4.length() > 2) {
976979
endX = PApplet.parseFloat(token4.substring(2));
977980
endY = PApplet.parseFloat(pathTokens[i + 5]);
978981
tokenOffset = -2;
979982
} else {
983+
// Case: flags are concatenated but separated from x (e.g. "01 100")
984+
// token4 is flags, x is at i+5, y is at i+6.
985+
// We consume 1 fewer token than standard (8-1=7).
980986
endX = PApplet.parseFloat(pathTokens[i + 5]);
981987
endY = PApplet.parseFloat(pathTokens[i + 6]);
982988
tokenOffset = -1;
983989
}
984990
} else {
991+
// Standard notation: flags and coordinates are separate tokens.
992+
// The 'A' command takes 7 arguments:
993+
// rx, ry, x-axis-rotation, large-arc-flag, sweep-flag, x, y
994+
// Here, we've already parsed rx (i+1), ry (i+2), and angle (i+3).
995+
// token4 (i+4) is the large-arc-flag.
985996
fa = PApplet.parseFloat(token4) != 0;
986-
fs = PApplet.parseFloat(pathTokens[i + 5]) != 0;
987-
endX = PApplet.parseFloat(pathTokens[i + 6]);
988-
endY = PApplet.parseFloat(pathTokens[i + 7]);
997+
fs = PApplet.parseFloat(pathTokens[i + 5]) != 0; // sweep-flag
998+
endX = PApplet.parseFloat(pathTokens[i + 6]); // x
999+
endY = PApplet.parseFloat(pathTokens[i + 7]); // y
9891000
}
9901001
parsePathArcto(cx, cy, rx, ry, angle, fa, fs, endX, endY);
9911002
cx = endX;
@@ -1009,20 +1020,27 @@ else if (lexState == LexState.EXP_HEAD) {
10091020
if (isCompactArcNotation(token4)) {
10101021
fa = token4.charAt(0) == '1';
10111022
fs = token4.charAt(1) == '1';
1023+
// Case: flags and x-coordinate are concatenated
10121024
if (token4.length() > 2) {
10131025
endX = cx + PApplet.parseFloat(token4.substring(2));
10141026
endY = cy + PApplet.parseFloat(pathTokens[i + 5]);
10151027
tokenOffset = -2;
10161028
} else {
1029+
// Case: flags are concatenated but separated from x
10171030
endX = cx + PApplet.parseFloat(pathTokens[i + 5]);
10181031
endY = cy + PApplet.parseFloat(pathTokens[i + 6]);
10191032
tokenOffset = -1;
10201033
}
10211034
} else {
1035+
// Standard notation: flags and coordinates are separate tokens.
1036+
// The 'a' command takes 7 arguments:
1037+
// rx, ry, x-axis-rotation, large-arc-flag, sweep-flag, x, y
1038+
// Here, we've already parsed rx (i+1), ry (i+2), and angle (i+3).
1039+
// token4 (i+4) is the large-arc-flag.
10221040
fa = PApplet.parseFloat(token4) != 0;
1023-
fs = PApplet.parseFloat(pathTokens[i + 5]) != 0;
1024-
endX = cx + PApplet.parseFloat(pathTokens[i + 6]);
1025-
endY = cy + PApplet.parseFloat(pathTokens[i + 7]);
1041+
fs = PApplet.parseFloat(pathTokens[i + 5]) != 0; // sweep-flag
1042+
endX = cx + PApplet.parseFloat(pathTokens[i + 6]); // x
1043+
endY = cy + PApplet.parseFloat(pathTokens[i + 7]); // y
10261044
}
10271045
parsePathArcto(cx, cy, rx, ry, angle, fa, fs, endX, endY);
10281046
cx = endX;
@@ -1108,9 +1126,13 @@ private boolean isCompactArcNotation(String token) {
11081126
return false;
11091127
}
11101128
return token.length() > 1 &&
1129+
// First two characters must be '0' or '1' (flags)
11111130
(token.charAt(0) == '0' || token.charAt(0) == '1') &&
11121131
(token.charAt(1) == '0' || token.charAt(1) == '1') &&
1132+
// Either it's just the flags (length 2),
11131133
(token.length() == 2 ||
1134+
// Or the flags are followed by the start of a number coordinate
1135+
// (digit, sign, or decimal point)
11141136
(token.length() > 2 && (
11151137
Character.isDigit(token.charAt(2)) ||
11161138
token.charAt(2) == '+' ||

0 commit comments

Comments
 (0)