svg rect to polygon points & points order bug
https://codepen.io/xgqfrms/pen/vYOWjYr?editors=1000
points 数据类型转换 bug, string + string !== number + number
https://codepen.io/xgqfrms/pen/vYOWjYr?editors=1000
error
const x = rect.getAttribute('x');
const y = rect.getAttribute('y');
const width = rect.getAttribute('width');
const height = rect.getAttribute('height');
const points = [];
points.push(pointGenerator(x, y));
points.push(pointGenerator((x + width), y));
points.push(pointGenerator((x + width), (y + height)));
points.push(pointGenerator(x, (y + height)));
OK
const x = +rect.getAttribute('x');
const y = +rect.getAttribute('y');
const width = +rect.getAttribute('width');
const height = +rect.getAttribute('height');
const points = [];
points.push(pointGenerator(x, y));
points.push(pointGenerator((x + width), y));
points.push(pointGenerator((x + width), (y + height)));
points.push(pointGenerator(x, (y + height)));
object map to array, order change bug
bug
const pointGenerator = (x, y) => {
// return [
// x,
// y,
// ];
return {
x,
y,
};
}
// const points_str = points.flat(2).join(` `);
const points_str = points.map(({x, y}) => [x, y]).flat(2).join(` `);
ok
const pointGenerator = (x, y) => {
return [
x,
y,
];
// return {
// x,
// y,
// };
}
const points_str = points.flat(2).join(` `);
// const points_str = points.map(({x, y}) => [x, y]).flat(2).join(` `);