I'm working on word cloud generation.
My words should appear in a rectangle of (0, 0, w, h), where w is the max width and h is the max height.
I already have an algorithm for generating the word cloud, but sometimes the words go outside the bounds of the rectangle or there is too much unused space. The real bounds of a word cloud are of (0, 0, maxX, maxY).
My idea of scaling looks like this:
if (maxX > w) then
if (maxY > h) then
if (maxX / w) > (maxY / h) then
scale(w / maxX)
else
scale(h / maxY)
end if
else
scale(w / maxX)
end if
else if (maxY > h) then
scale(h / maxY)
else if ((maxX < w) and (maxY < h)) then
if (maxX / w) > (maxY / h) then
scale(w / maxX)
else
scale(h / maxY)
end if
end if
Let's suppose I have a word in the rectangle of (x1, y1, x2, y2). If I call scale(1.5), then the new position of the rectangle will be (1.5 * x1, 1.5 * y1, 1.5 * x2, 1.5 * y2). This is very nice and simple, but I have a problem with this:
A word previously had a size of S1 and was situated on coordinates (x1, y1, x2, y2). If I want to scale it by r, then the new coordinates will be of (r * x1, r * y1, r * x2, r * y2). Question: If I know that the word will be r * bigger/smaller, then what is the value of S2 size which would be the new size of the word after scaling with a rate of r?