js destructuring assignment bug
js destructuring assignment bug
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
const getShapeCenterPoint = (points = [], type = "object") => {
// 设置旋转的 origin,为 polygon 的中心,旋转偏移量
let [top, left, right, bottom] = ["", "", "", ""];
// bug ???
// points.forEach((type === "object" ? {x, y} : [x, y], i) => {
// points.forEach(({x, y}, i) => {
// points.forEach(([x, y], i) => {
points.forEach(type === "object" ? {x, y} : [x, y], i => {
if (i === 0) {
top = y;
bottom = y;
left = x;
right = x;
} else {
top = Math.min(top, y);
bottom = Math.max(bottom, y);
left = Math.min(left, x);
right = Math.max(right, x);
}
});
const point = {
cx: (left + right) / 2,
cy: (top + bottom) / 2,
};
return point;
}
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/12449524.html
未经授权禁止转载,违者必究!