0

In my tile editor, user can draw over 50x50 grid containing 1x1 squares. However, I need a fast algorithm for me to take such a grid and export list of rectangles/squares of groups of polygons with same type (and not separated by a wall in between).

In the following image you can see cut from such a grid:

Example

What I would like is to output 1x3 blue rectangle, 1x3 white rectangle, 3x2 ping rectangle, 4x2 blue rectangle, 3x3 white rectangle, 4x2 black rectangle, 1x3 black rectangle and either 9x2 and 2x2 yellow rectangle or 7x2 and 2x4 yellow rectangle.

What would be the fastest algorithm for doing something like this?

Enerccio
  • 257
  • 1
  • 10
  • 23
  • At 50x50 you might be better off looking for the simplest solution rather than the fastest (e.g. row by row select the largest rectangles you can and repeat until done). – pmorken Jan 08 '15 at 23:16
  • @pmorken Grid is 50x50, but number of grids is actually 648x6... – Enerccio Jan 08 '15 at 23:39

0 Answers0