handleCommand method
Implementation
void handleCommand(String command, String coordString,
[String prevCommand = '']) {
var isRelative = command.isLowerCase;
command = command.toUpperCase();
var startPoint = hasPoints() ? getLastPoint() : Vector3(0, 0, 0);
var newPoints = stringToPoints(
command: command,
isRelative: isRelative,
coordString: coordString,
startPoint: startPoint,
);
switch (command) {
case 'M':
startNewPath(newPoints[0]);
for (var p in withoutFirst(newPoints)) {
addLineTo(p);
}
return;
case 'H':
case 'V':
case 'L':
for (var p in newPoints) {
addLineTo(p);
}
return;
case 'C':
for (var i in range(end: newPoints.length, step: 3)) {
addCubicBezierCurveTo(
newPoints[i + 0],
newPoints[i + 1],
newPoints[i + 2],
);
}
return;
case 'S':
var prevHandle = startPoint;
if (['C', 'S'].contains(prevCommand.toUpperCase())) {
prevHandle = points[points.length - 2];
}
for (var i in range(end: newPoints.length, step: 2)) {
var newHandle = startPoint * 2 - prevHandle;
addCubicBezierCurveTo(newHandle, newPoints[i], newPoints[i + 1]);
startPoint = newPoints[i + 1];
prevHandle = newPoints[i];
}
return;
case 'Q':
for (var i in range(end: newPoints.length, step: 2)) {
addQuadraticBezierCurveTo(newPoints[i], newPoints[i + 1]);
}
return;
case 'T':
var prevQuadHandle = startPoint;
if (['Q', 'T'].contains(prevCommand.toUpperCase())) {
prevQuadHandle = points[points.length - 2] * 1.5 - points.last * 0.5;
}
for (var p in newPoints) {
var newQuadHandle = startPoint * 2 - prevQuadHandle;
addQuadraticBezierCurveTo(newQuadHandle, p);
startPoint = p;
prevQuadHandle = newQuadHandle;
}
return;
case 'A':
for (var i in range(end: newPoints.length, step: 3)) {
addCubicBezierCurveTo(
newPoints[i], newPoints[i + 1], newPoints[i + 2]);
}
return;
case 'Z':
closePath();
return;
}
}