In my project, I have the ability to draw tiles on an x-y grid and paint a provided png image. The objective is to then save these tiles as a .json file.
Illustration of the issue:
https://i.sstatic.net/XUfoS.png
Currently, the JSON structure is created like this:
"woodenCrate":[[x,y],[x,y],[x,y]...]
However, I would like to transform it into:
"woodenCrate":[[xstart, xend, ystart, yend],[xstart, xend, ystart, yend]...]
This means consolidating individual points into larger chunks that can be drawn. My plan is to identify large rectangles within the data, and then repeat the process with the remaining pieces until only big rectangles and a few single-sized boxes remain.
The tiles are placed at integer positions in [x, y].
For example:
[[0,1],[0,2],[0,3],[1,1],[1,2][1,3]]
should be transformed into:
[[0,1,1,3]]
A solution that converts to
[[startX, startY, width, height]]
is also acceptable.
How should I go about solving this problem? I am using Javascript.