normalizePath = function(path, geometryFunction, closeGaps) {
if (closeGaps === undefined) closeGaps = true;
let command_letters = 'mlhvaqtcs',
commands = [],
newPath = '';
let i;
for (i=0; i<path.length; i++) {
let c = path[i].toLowerCase();
for (var j=0; j<command_letters.length; j++) {
if (c == command_letters[j]) {
if (c == 'm') commands.push('M');
else commands.push('L');
break;
}
}
}
let num = commands.length,
coords;
if (num == 1) {
coords = geometryFunction(0);
newPath = commands[0] + coords[0] + ',' + coords[1];
}
else {
for (i=0; i<num; i++) {
newPath += commands[i];
if (closeGaps && commands[i] == 'M' && i>0) {
coords = geometryFunction((i-1)/(num-1));
}
else {
coords = geometryFunction(i/(num-1));
}
newPath += coords[0] + ',' + coords[1];
}
return newPath;
}
}