# HG changeset patch
# User sheepluva
# Date 1480810056 -3600
# Node ID 2e70ef81e281f2a707a02b6a0b514720d0d16a99
# Parent  166725555e5715221be0a55dd244fda969604d54
copyToXYFromRect: simplify my math (so that it actually, you know, works...)

diff -r 166725555e57 -r 2e70ef81e281 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