hedgewars/uLandOutline.pas
changeset 6990 40e5af28d026
parent 6580 6155187bf599
child 8145 6408c0ba4ba1
equal deleted inserted replaced
6989:4c35e9cf6057 6990:40e5af28d026
   218 
   218 
   219 
   219 
   220 function CheckIntersect(V1, V2, V3, V4: TPoint): boolean;
   220 function CheckIntersect(V1, V2, V3, V4: TPoint): boolean;
   221 var c1, c2, dm: LongInt;
   221 var c1, c2, dm: LongInt;
   222 begin
   222 begin
       
   223     CheckIntersect:= false;
   223     dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y);
   224     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     c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x);
   225     if dm = 0 then
   226     if dm = 0 then
   226             exit(false);
   227         exit;
   227 
   228 
       
   229     CheckIntersect:= true;
   228     c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x);
   230     c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x);
   229     if dm > 0 then
   231     if dm > 0 then
   230         begin
   232     begin
   231         if (c1 < 0) or (c1 > dm) then
   233         if (c1 < 0) or (c1 > dm) then
   232             exit(false);
   234             CheckIntersect:= false
   233         if (c2 < 0) or (c2 > dm) then
   235         else if (c2 < 0) or (c2 > dm) then
   234             exit(false)
   236             CheckIntersect:= false;
   235         end 
   237     end 
   236     else
   238     else
   237         begin
   239     begin
   238         if (c1 > 0) or (c1 < dm) then
   240         if (c1 > 0) or (c1 < dm) then
   239             exit(false);
   241             CheckIntersect:= false
   240         if (c2 > 0) or (c2 < dm) then
   242         else if (c2 > 0) or (c2 < dm) then
   241             exit(false)
   243             CheckIntersect:= false;
   242         end;
   244     end;
   243 
   245 
   244     //AddFileLog('1  (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')');
   246     //AddFileLog('1  (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')');
   245     //AddFileLog('2  (' + inttostr(V3.x) + ',' + inttostr(V3.y) + ')x(' + inttostr(V4.x) + ',' + inttostr(V4.y) + ')');
   247     //AddFileLog('2  (' + inttostr(V3.x) + ',' + inttostr(V3.y) + ')x(' + inttostr(V4.x) + ',' + inttostr(V4.y) + ')');
   246     CheckIntersect:= true
       
   247 end;
   248 end;
   248 
   249 
   249 
   250 
   250 function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean;
   251 function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean;
   251 var i: Longword;
   252 var i: Longword;
   252 begin
   253 begin
       
   254     CheckSelfIntersect:= false;
   253     if (ind <= 0) or (ind >= Pred(pa.Count)) then
   255     if (ind <= 0) or (ind >= Pred(pa.Count)) then
   254                 exit(false);
   256         exit;
       
   257 
       
   258     CheckSelfIntersect:= true;
   255     for i:= 1 to pa.Count - 3 do
   259     for i:= 1 to pa.Count - 3 do
   256         if (i <= ind - 1) or (i >= ind + 2) then
   260         if (i <= ind - 1) or (i >= ind + 2) then
   257         begin
   261         begin
   258         if (i <> ind - 1) and
   262             if (i <> ind - 1) and CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then
   259             CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then
   263                 exit;
   260                 exit(true);
   264             if (i <> ind + 2) and CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then
   261         if (i <> ind + 2) and
   265                 exit;
   262             CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then
       
   263                 exit(true);
       
   264         end;
   266         end;
   265     CheckSelfIntersect:= false
   267     CheckSelfIntersect:= false
   266 end;
   268 end;
   267 
   269 
   268 procedure RandomizePoints(var pa: TPixAr);
   270 procedure RandomizePoints(var pa: TPixAr);