const eRectangle &bounds = eWallRim::GetBounds(); double lx = bounds.GetLow().x - border, hx = bounds.GetHigh().x + border; double ly = bounds.GetLow().y - border, hy = bounds.GetHigh().y + border; double mw = hx - lx, mh = hy - ly; double xpos, ypos, xscale, yscale; double xrat = (rw * mh) / (rh * mw); double yrat = (rh * mw) / (rw * mh); if(xrat > yrat) { xscale = (w * rh) / (mh * rw); yscale = h / mh; xpos = x + ix * (w - w * yrat); ypos = y; } else { xscale = w / mw; yscale = (h * rw) / (mw * rh); xpos = x; ypos = y + iy * (h - h * xrat); } xpos -= lx * xscale; ypos -= ly * yscale;