Unless it is trivial it is forbidden to use embarcadero code. Work always from the interface.
I understand not using Embarcadero's code, but it is also trival and a person with experience could come up with the same solution without looking at Embarcadero code.
Are all of these suggestion too trivial to be added to FPC ? With {$MODE DELPHI} available in FPC, it would seem beneficial and maybe even expected. I know I expected it to work without writing my own in FPC.
In this case I suggest to use the generic swap, which may be even faster than the usually expensive modulo on some platforms.
In this case I suggest to use the generic swap, which may be even faster than the usually expensive modulo on some platforms.
Could you please elaborate ? I am guessing the 'NormalizedRect' will be quicker that the 'Normalize' procedure I posted above
void NormalizeRect() _ALWAYS_INLINE {
int i;
if (left > right)
{
i = left;
left = right;
right = i;
}
if (top > bottom)
{
i = top;
top = bottom;
bottom = i;
}
}
CenteredRect Procedure :
function centeredRect(const ARect: TRect; const bRect: TRect): TRect;
//@TODO check if this even works correctly
var
outerSize, innerSize: TSize;
xNew, yNew: longint;
begin
xNew := 0;
yNew := 0;
outerSize := ARect.Size;
innerSize := bRect.Size;
if innerSize.cx > outerSize.cx then
innerSize.cx := outerSize.cx;
if innerSize.cy > outerSize.cy then
innerSize.cy := outerSize.cy;
Result := bounds(xNew, yNew, innerSize.cx, innerSize.cy);
end;
You were posting as I was replying... I added the CenteredRect procedure to your code so it would compile .The output of your example , so others can see :