How to round output rectangles of SquarifiedTreemap algorithm so they can fit a grid with every tile being 1x1

24 Views Asked by At

This can be trivial but nonetheless I need help... :)

I have a grid, every tile of the grid is 1x1. I'm using SquarifiedTreemap algorithm to divide the grid in rooms, but the result values are in floating point whereas I need integer values.

I've tried to round the values of the rectangles to the nearest integer, but results are inconsistent, sometime one rectangle overlap another, some other time there's a gap between two rectangles.

Here's an example with a grid 20x10, ratios are [30, 28, 15].

regular: (x:0.00, y:0.00, width:8.41, height:10.00)
rounded: (0, 0, 8, 10)

regular: (x:8.41, y:0.00, width:7.25, height:10.00)
rounded: (8, 0, 7, 10)

regular: (x:15.65, y:0.00, width:4.35, height:10.00)
rounded: (16, 0, 4, 10)

As you can see, the total area of the grid is 200, but the total area of rounded rectangles is 190. In fact, in my grid there's a 1x10 gap between two rectangles.

Thank you.