Added konva array convert helper

This commit is contained in:
Mitchell McCaffrey 2021-01-02 18:01:16 +11:00
parent 2482196876
commit 651b0d7c6c

View File

@ -243,3 +243,17 @@ export function getRelativePointerPositionNormalized(node) {
y: relativePosition.y / node.height(),
};
}
/**
* Converts points from alternating array form to vector array form
* @param {number[]} points points in an x, y alternating array
* @returns {Vector2[]} a `Vector2` array
*/
export function convertPointArray(points) {
return points.reduce((acc, _, i, arr) => {
if (i % 2 === 0) {
acc.push({ x: arr[i], y: arr[i + 1] });
}
return acc;
}, []);
}