From 0ccd4a935a7bc719a8a38ac460fd035a6660de71 Mon Sep 17 00:00:00 2001 From: Lakto Date: Fri, 10 Feb 2023 00:34:20 -0800 Subject: [PATCH] convert 1d index to 2d array --- helper.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/helper.js b/helper.js index f36b4e5..dc3940b 100644 --- a/helper.js +++ b/helper.js @@ -107,6 +107,16 @@ async function unSelect() { return result } +/** + * Convert 1d index to 2d array + * @param {number} index sequential index + * @param {number} width width of 2d array + * @returns {number[]} [x,y] + */ +function indexToXY(index, width) { + return [index % width, Math.floor(index / width)] +} + // async function layerToSelectionHelper () { // // console.log("executeAsModal layer.translate")