From 2db0d0c52f8c4e96e659d488e44140bbf8a0b71f Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Tue, 16 Jul 2024 00:26:21 +0530 Subject: [PATCH] feat: get grid --- mx-interpreter/browserSide/scraper.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mx-interpreter/browserSide/scraper.js b/mx-interpreter/browserSide/scraper.js index d9e5a0d9..719d8f59 100644 --- a/mx-interpreter/browserSide/scraper.js +++ b/mx-interpreter/browserSide/scraper.js @@ -50,4 +50,23 @@ function scrapableHeuristics(maxCountPerPage = 50, minArea = 20000, scrolls = 3, * @typedef {Array<{x: number, y: number}>} Grid */ - \ No newline at end of file + /** + * Returns an array of grid-aligned {x,y} points. + * @param {number} [granularity=0.005] sets the number of generated points + * (the higher the granularity, the more points). + * @returns {Grid} Array of {x, y} objects. + */ + function getGrid(startX = 0, startY = 0, granularity = 0.005) { + const width = window.innerWidth; + const height = window.innerHeight; + + const out = []; + for (let x = 0; x < width; x += 1 / granularity) { + for (let y = 0; y < height; y += 1 / granularity) { + out.push({ x: startX + x, y: startY + y }); + } + } + return out; + } + + \ No newline at end of file