copyToXYFromRect: simplify my math (so that it actually, you know, works...)
authorsheepluva
Sun, 04 Dec 2016 01:07:36 +0100
changeset 12101 2e70ef81e281
parent 12100 166725555e57
child 12102 51596d30a724
copyToXYFromRect: simplify my math (so that it actually, you know, works...)
hedgewars/uRenderUtils.pas
--- a/hedgewars/uRenderUtils.pas	Sat Dec 03 17:45:32 2016 +0100
+++ b/hedgewars/uRenderUtils.pas	Sun Dec 04 01:07:36 2016 +0100
@@ -164,8 +164,10 @@
     dY:= destY - srcY;
 
     // let's figure out where the rectangle we can actually copy ends
-    lX:= ( min( min(srcX + srcW, src^.w), min(destX + srcW, dest^.w) - dx ) ) - 1;
-    lY:= ( min( min(srcY + srcH, src^.h), min(destY + srcH, dest^.h) - dY ) ) - 1;
+    lX:= min(srcX + srcW, src^.w) - 1;
+    if lX + dx >= dest^.w then lX:= dest^.w - dx - 1;
+    lY:= min(srcY + srcH, src^.h) - 1;
+    if lY + dy >= dest^.h then lY:= dest^.h - dy - 1;
 
     for iX:= srcX to lX do
     for iY:= srcY to lY do