1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-12-16 01:10:30 +02:00

Fix false positives in collinear-segments rule (#10599)

This commit is contained in:
Álvaro Mondéjar 2024-03-08 23:36:38 +01:00 committed by GitHub
parent a26ec24a84
commit 955b608858
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 39 deletions

File diff suppressed because one or more lines are too long

View File

@ -669,104 +669,112 @@ export default {
_resetStartPoint = false; _resetStartPoint = false;
for (let s = 0; s < segments.length; s++) { for (let s = 0; s < segments.length; s++) {
let seg = segments[s].params, const seg = segments[s],
cmd = seg[0], parms = seg.params,
cmd = parms[0],
nextCmd = s + 1 < segments.length ? segments[s + 1][0] : null; nextCmd = s + 1 < segments.length ? segments[s + 1][0] : null;
switch (cmd) { switch (cmd) {
// Next switch cases have been ordered by frequency // Next switch cases have been ordered by frequency
// of occurrence in the SVG paths of the icons // of occurrence in the SVG paths of the icons
case 'M': case 'M':
currAbsCoord[0] = seg[1]; currAbsCoord[0] = parms[1];
currAbsCoord[1] = seg[2]; currAbsCoord[1] = parms[2];
startPoint = undefined; // SVG 1.1:
// If a moveto is followed by multiple pairs of coordinates,
// the subsequent pairs are treated as implicit lineto commands.
if (!seg.chained || seg.chainStart === seg.start) {
startPoint = undefined;
}
break; break;
case 'm': case 'm':
currAbsCoord[0] = currAbsCoord[0] =
(!currAbsCoord[0] ? 0 : currAbsCoord[0]) + seg[1]; (!currAbsCoord[0] ? 0 : currAbsCoord[0]) + parms[1];
currAbsCoord[1] = currAbsCoord[1] =
(!currAbsCoord[1] ? 0 : currAbsCoord[1]) + seg[2]; (!currAbsCoord[1] ? 0 : currAbsCoord[1]) + parms[2];
startPoint = undefined; if (!seg.chained || seg.chainStart === seg.start) {
startPoint = undefined;
}
break; break;
case 'H': case 'H':
currAbsCoord[0] = seg[1]; currAbsCoord[0] = parms[1];
break; break;
case 'h': case 'h':
currAbsCoord[0] = currAbsCoord[0] =
(!currAbsCoord[0] ? 0 : currAbsCoord[0]) + seg[1]; (!currAbsCoord[0] ? 0 : currAbsCoord[0]) + parms[1];
break; break;
case 'V': case 'V':
currAbsCoord[1] = seg[1]; currAbsCoord[1] = parms[1];
break; break;
case 'v': case 'v':
currAbsCoord[1] = currAbsCoord[1] =
(!currAbsCoord[1] ? 0 : currAbsCoord[1]) + seg[1]; (!currAbsCoord[1] ? 0 : currAbsCoord[1]) + parms[1];
break; break;
case 'L': case 'L':
currAbsCoord[0] = seg[1]; currAbsCoord[0] = parms[1];
currAbsCoord[1] = seg[2]; currAbsCoord[1] = parms[2];
break; break;
case 'l': case 'l':
currAbsCoord[0] = currAbsCoord[0] =
(!currAbsCoord[0] ? 0 : currAbsCoord[0]) + seg[1]; (!currAbsCoord[0] ? 0 : currAbsCoord[0]) + parms[1];
currAbsCoord[1] = currAbsCoord[1] =
(!currAbsCoord[1] ? 0 : currAbsCoord[1]) + seg[2]; (!currAbsCoord[1] ? 0 : currAbsCoord[1]) + parms[2];
break; break;
case 'Z': case 'Z':
case 'z': case 'z':
// Overlapping in Z should be handled in another rule // TODO: Overlapping in Z should be handled in another rule
currAbsCoord = [startPoint[0], startPoint[1]]; currAbsCoord = [startPoint[0], startPoint[1]];
_resetStartPoint = true; _resetStartPoint = true;
break; break;
case 'C': case 'C':
currAbsCoord[0] = seg[5]; currAbsCoord[0] = parms[5];
currAbsCoord[1] = seg[6]; currAbsCoord[1] = parms[6];
break; break;
case 'c': case 'c':
currAbsCoord[0] = currAbsCoord[0] =
(!currAbsCoord[0] ? 0 : currAbsCoord[0]) + seg[5]; (!currAbsCoord[0] ? 0 : currAbsCoord[0]) + parms[5];
currAbsCoord[1] = currAbsCoord[1] =
(!currAbsCoord[1] ? 0 : currAbsCoord[1]) + seg[6]; (!currAbsCoord[1] ? 0 : currAbsCoord[1]) + parms[6];
break; break;
case 'A': case 'A':
currAbsCoord[0] = seg[6]; currAbsCoord[0] = parms[6];
currAbsCoord[1] = seg[7]; currAbsCoord[1] = parms[7];
break; break;
case 'a': case 'a':
currAbsCoord[0] = currAbsCoord[0] =
(!currAbsCoord[0] ? 0 : currAbsCoord[0]) + seg[6]; (!currAbsCoord[0] ? 0 : currAbsCoord[0]) + parms[6];
currAbsCoord[1] = currAbsCoord[1] =
(!currAbsCoord[1] ? 0 : currAbsCoord[1]) + seg[7]; (!currAbsCoord[1] ? 0 : currAbsCoord[1]) + parms[7];
break; break;
case 's': case 's':
currAbsCoord[0] = currAbsCoord[0] =
(!currAbsCoord[0] ? 0 : currAbsCoord[0]) + seg[1]; (!currAbsCoord[0] ? 0 : currAbsCoord[0]) + parms[1];
currAbsCoord[1] = currAbsCoord[1] =
(!currAbsCoord[1] ? 0 : currAbsCoord[1]) + seg[2]; (!currAbsCoord[1] ? 0 : currAbsCoord[1]) + parms[2];
break; break;
case 'S': case 'S':
currAbsCoord[0] = seg[1]; currAbsCoord[0] = parms[1];
currAbsCoord[1] = seg[2]; currAbsCoord[1] = parms[2];
break; break;
case 't': case 't':
currAbsCoord[0] = currAbsCoord[0] =
(!currAbsCoord[0] ? 0 : currAbsCoord[0]) + seg[1]; (!currAbsCoord[0] ? 0 : currAbsCoord[0]) + parms[1];
currAbsCoord[1] = currAbsCoord[1] =
(!currAbsCoord[1] ? 0 : currAbsCoord[1]) + seg[2]; (!currAbsCoord[1] ? 0 : currAbsCoord[1]) + parms[2];
break; break;
case 'T': case 'T':
currAbsCoord[0] = seg[1]; currAbsCoord[0] = parms[1];
currAbsCoord[1] = seg[2]; currAbsCoord[1] = parms[2];
break; break;
case 'Q': case 'Q':
currAbsCoord[0] = seg[3]; currAbsCoord[0] = parms[3];
currAbsCoord[1] = seg[4]; currAbsCoord[1] = parms[4];
break; break;
case 'q': case 'q':
currAbsCoord[0] = currAbsCoord[0] =
(!currAbsCoord[0] ? 0 : currAbsCoord[0]) + seg[3]; (!currAbsCoord[0] ? 0 : currAbsCoord[0]) + parms[3];
currAbsCoord[1] = currAbsCoord[1] =
(!currAbsCoord[1] ? 0 : currAbsCoord[1]) + seg[4]; (!currAbsCoord[1] ? 0 : currAbsCoord[1]) + parms[4];
break; break;
default: default:
throw new Error(`"${cmd}" command not handled`); throw new Error(`"${cmd}" command not handled`);