Janilabo

Untitled

Apr 4th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.97 KB | None | 0 0
  1. function TPABounds2(TPA: TPointArray): TBox;
  2. var
  3.   h, i: Integer;
  4. begin
  5.   h := High(TPA);
  6.   case (h > -1) of
  7.     True:
  8.     begin
  9.       Result.X1 := TPA[0].X;
  10.       Result.Y1 := TPA[0].Y;
  11.       Result.X2 := TPA[0].X;
  12.       Result.Y2 := TPA[0].Y
  13.       if (h > 0) then
  14.         for i := 1 to h do
  15.         begin
  16.           if (Result.X1 > TPA[i].X) then
  17.             Result.X1 := TPA[i].X
  18.           else                    
  19.             if (Result.X2 < TPA[i].X) then
  20.               Result.X2 := TPA[i].X;
  21.           if (Result.Y1 > TPA[i].Y) then
  22.             Result.Y1 := TPA[i].Y
  23.           else
  24.             if (Result.Y2 < TPA[i].Y) then
  25.               Result.Y2 := TPA[i].Y;
  26.         end;
  27.     end;
  28.     False:
  29.     begin
  30.       Result.X1 := 0;
  31.       Result.Y1 := 0;
  32.       Result.X2 := 0;
  33.       Result.Y2 := 0;
  34.     end;
  35.   end;
  36. end;
  37.  
  38. var
  39.   TPA: TPointArray;
  40.  
  41. begin
  42.   TPA := [Point(5, 10), Point(4, 4), Point(8, 12)];
  43.   WriteLn(BoxToStr(TPABounds2(TPA)));
  44. end.
Advertisement
Add Comment
Please, Sign In to add comment