hedgewars/uLandOutline.pas
changeset 14025 bb2f4636787f
parent 13907 c36aaa30be98
child 15900 128ace913837
equal deleted inserted replaced
14024:03a5d9f0bcc9 14025:bb2f4636787f
   213         pa.ar[pa.Count].Y:= 0;
   213         pa.ar[pa.Count].Y:= 0;
   214         inc(pa.Count);
   214         inc(pa.Count);
   215         end else inc(i)
   215         end else inc(i)
   216 end;
   216 end;
   217 
   217 
   218 
       
   219 function CheckIntersect(V1, V2, V3, V4: TPoint): boolean;
       
   220 var c1, c2, dm: LongInt;
       
   221 begin
       
   222     CheckIntersect:= false;
       
   223     dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y);
       
   224     c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x);
       
   225     if dm = 0 then
       
   226         exit;
       
   227 
       
   228     CheckIntersect:= true;
       
   229     c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x);
       
   230     if dm > 0 then
       
   231     begin
       
   232         if (c1 < 0) or (c1 > dm) then
       
   233             CheckIntersect:= false
       
   234         else if (c2 < 0) or (c2 > dm) then
       
   235             CheckIntersect:= false;
       
   236     end
       
   237     else
       
   238     begin
       
   239         if (c1 > 0) or (c1 < dm) then
       
   240             CheckIntersect:= false
       
   241         else if (c2 > 0) or (c2 < dm) then
       
   242             CheckIntersect:= false;
       
   243     end;
       
   244 
       
   245     //AddFileLog('1  (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')');
       
   246     //AddFileLog('2  (' + inttostr(V3.x) + ',' + inttostr(V3.y) + ')x(' + inttostr(V4.x) + ',' + inttostr(V4.y) + ')');
       
   247 end;
       
   248 
       
   249 
       
   250 function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean;
       
   251 var i: Longword;
       
   252 begin
       
   253     CheckSelfIntersect:= false;
       
   254     if (ind <= 0) or (LongInt(ind) >= Pred(pa.Count)) then
       
   255         exit;
       
   256 
       
   257     CheckSelfIntersect:= true;
       
   258     for i:= 1 to pa.Count - 3 do
       
   259         if (i <= ind - 1) or (i >= ind + 2) then
       
   260         begin
       
   261             if (i <> ind - 1) and CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then
       
   262                 exit;
       
   263             if (i <> ind + 2) and CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then
       
   264                 exit;
       
   265         end;
       
   266     CheckSelfIntersect:= false
       
   267 end;
       
   268 
       
   269 end.
   218 end.