toPathData method
Convert the Path to a string of path data instructions
See http://www.w3.org/TR/SVG/paths.html#PathData
@param {number} decimalPlaces=2
- The amount of decimal places for floating-point values
@return {string}
Implementation
toPathData(int decimalPlaces) {
decimalPlaces = decimalPlaces != null ? decimalPlaces : 2;
Function floatToString = (num v) {
if (v.round() == v) {
return '' + v.round().toString();
} else {
return v.toStringAsFixed(decimalPlaces);
}
};
Function packValues = (List<num> args) {
var s = '';
for (var i = 0; i < args.length; i += 1) {
var v = args[i];
if (v >= 0 && i > 0) {
s += ' ';
}
s += floatToString(v);
}
return s;
};
var d = '';
for (var i = 0; i < this.commands.length; i += 1) {
var cmd = this.commands[i];
if (cmd["type"] == 'M') {
d += 'M' + packValues([cmd["x"], cmd["y"]]);
} else if (cmd["type"] == 'L') {
d += 'L' + packValues([cmd["x"], cmd["y"]]);
} else if (cmd["type"] == 'C') {
d += 'C' + packValues([cmd["x1"], cmd["y1"], cmd["x2"], cmd["y2"], cmd["x"], cmd["y"]]);
} else if (cmd["type"] == 'Q') {
d += 'Q' + packValues([cmd["x1"], cmd["y1"], cmd["x"], cmd["y"]]);
} else if (cmd["type"] == 'Z') {
d += 'Z';
}
}
return d;
}