I would like to find nearest "nice" tiling of "ruler" given rough number of tiles and range to display. To be more specific about "nice" the width of tiles should be like on money: 1,2,5,10,20... etc. Or more precisely 1*10eN, 2*10eN or 5.0*10eN where N is integer (=values like 0.1 are also valid).
Preferred language is C#.
For example if I wanted to display range from -1 to 12 and wanted roughly 3 tiles on ruler, the output of the algorithm would be 3 tiles, 10 units wide from value -10 (to 20).
In cause the algorithm would decide to take tile width 2 and values from -2 to 12, the number of tiles would be 6 which is worse approximation of 3 tiles than 3 tiles(for 1st option). Or if width was 5, and ruler from -5 to 15, the number if tiles would be 4 which is "further away" from 3 tiles than 3 tiles(for 1st option).
class Tiling {
double width;
double from;
double count;
}
Tiling findTiling(double range_from, double range_to, double aprox_tiles)
{ /*???*/}
As real-world example, open your favourite image editor and look at legend of axes as you zoom - the numbers on ruler change but the total number of tiles of ruler on screen keep roughly the same. This problem is similar except the range(in case of image editor pixels of image from 0 to width/height) does not start from zero and the resolution can go below 1 unit (pixel).