parsePolygonNode method
ShapePath
parsePolygonNode(
- XmlElement node
Implementation
ShapePath parsePolygonNode(XmlElement node) {
console.info("SVGLoader: parsePolygonNode todo test.");
// final regex = /(-?[\d\.?]+)[,|\s](-?[\d\.?]+)/g;
final regex = RegExp(r"(-?[\d\.?]+)[,|\s](-?[\d\.?]+)");
final path = ShapePath();
int index = 0;
// Function iterator = (match, a, b) {
// final x = parseFloatWithUnits(a);
// final y = parseFloatWithUnits(b);
// if (index == 0) {
// path.moveTo(x, y);
// } else {
// path.lineTo(x, y);
// }
// index++;
// };
// node.getAttribute('points').replace(regex, iterator);
String points = node.getAttribute('points')!;
final matches = regex.allMatches(points);
for (final match in matches) {
final a = match.group(1);
final b = match.group(2);
final x = parseFloatWithUnits(a);
final y = parseFloatWithUnits(b);
if (index == 0) {
path.moveTo(x, y);
} else {
path.lineTo(x, y);
}
index++;
}
path.currentPath.autoClose = true;
return path;
}