stringToPoints method
Implementation
List<Vector3> stringToPoints({
required String command,
required bool isRelative,
required String coordString,
required Vector3 startPoint,
}) {
var numbers = stringToNumbers(coordString);
var result = <Vector3>[];
if (command == 'A') {
Vector3? lastEndPoint;
for (var ellipticNumbers in grouped(numbers, 2)) {
if (lastEndPoint != null) {
startPoint = lastEndPoint;
}
if (isRelative) {
ellipticNumbers[5] += startPoint.x;
ellipticNumbers[6] += startPoint.y;
}
if (startPoint.x == ellipticNumbers[5] &&
startPoint.y == ellipticNumbers[6]) {
continue;
}
result.addAll(
ellipticalArcToCubicBezier(
startPoint,
ellipticNumbers[0],
ellipticNumbers[1],
ellipticNumbers[2],
ellipticNumbers[3],
ellipticNumbers[4],
Vector3(ellipticNumbers[5], ellipticNumbers[6], 0),
),
);
lastEndPoint = Vector3(ellipticNumbers[5], ellipticNumbers[6], 0);
}
return result;
} else if (command == 'H') {
if (isRelative) {
result = [for (var x in numbers) Vector3(x, 0, 0)];
} else {
result = [for (var x in numbers) Vector3(x, startPoint.y, 0)];
}
} else if (command == 'V') {
if (isRelative) {
result = [for (var y in numbers) Vector3(0, y, 0)];
} else {
result = [for (var y in numbers) Vector3(startPoint.x, y, 0)];
}
} else {
result = [for (var xy in grouped(numbers, 2)) Vector3(xy[0], xy[1], 0)];
}
if (!isRelative) {
return result;
}
var entries = 1;
if (command == 'Q' || command == 'S') {
entries = 2;
} else if (command == 'C') {
entries = 3;
}
var offset = startPoint;
for (var i in range(end: result.length)) {
result[i] += offset;
if ((i + 1) % entries == 0) {
offset = result[i];
}
}
return result;
}