hedgewars/uLandOutline.pas
changeset 6990 40e5af28d026
parent 6580 6155187bf599
child 8145 6408c0ba4ba1
--- a/hedgewars/uLandOutline.pas	Wed May 02 11:28:38 2012 +0200
+++ b/hedgewars/uLandOutline.pas	Wed May 02 10:53:13 2012 +0100
@@ -220,47 +220,49 @@
 function CheckIntersect(V1, V2, V3, V4: TPoint): boolean;
 var c1, c2, dm: LongInt;
 begin
+    CheckIntersect:= false;
     dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y);
     c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x);
     if dm = 0 then
-            exit(false);
+        exit;
 
+    CheckIntersect:= true;
     c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x);
     if dm > 0 then
-        begin
+    begin
         if (c1 < 0) or (c1 > dm) then
-            exit(false);
-        if (c2 < 0) or (c2 > dm) then
-            exit(false)
-        end 
+            CheckIntersect:= false
+        else if (c2 < 0) or (c2 > dm) then
+            CheckIntersect:= false;
+    end 
     else
-        begin
+    begin
         if (c1 > 0) or (c1 < dm) then
-            exit(false);
-        if (c2 > 0) or (c2 < dm) then
-            exit(false)
-        end;
+            CheckIntersect:= false
+        else if (c2 > 0) or (c2 < dm) then
+            CheckIntersect:= false;
+    end;
 
     //AddFileLog('1  (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')');
     //AddFileLog('2  (' + inttostr(V3.x) + ',' + inttostr(V3.y) + ')x(' + inttostr(V4.x) + ',' + inttostr(V4.y) + ')');
-    CheckIntersect:= true
 end;
 
 
 function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean;
 var i: Longword;
 begin
+    CheckSelfIntersect:= false;
     if (ind <= 0) or (ind >= Pred(pa.Count)) then
-                exit(false);
+        exit;
+
+    CheckSelfIntersect:= true;
     for i:= 1 to pa.Count - 3 do
         if (i <= ind - 1) or (i >= ind + 2) then
         begin
-        if (i <> ind - 1) and
-            CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then
-                exit(true);
-        if (i <> ind + 2) and
-            CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then
-                exit(true);
+            if (i <> ind - 1) and CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then
+                exit;
+            if (i <> ind + 2) and CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then
+                exit;
         end;
     CheckSelfIntersect:= false
 end;