Janilabo

Untitled

Jul 5th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.18 KB | None | 0 0
  1. procedure TPAUnique(var TPA: TPointArray);
  2. var
  3.   h, h2, i, i2, i3, d: Integer;
  4. begin
  5.   h := High(TPA);
  6.   if (h < 1) then
  7.     Exit;
  8.   for i := (h - d) downto 1 do
  9.     for i2 := (i - 1) downto 0 do
  10.       if ((TPA[i].X = TPA[i2].X) and (TPA[i].Y = TPA[i2].Y)) then
  11.       begin
  12.         h2 := High(TPA);
  13.         for i3 := i to (h2 - 1) do
  14.           TPA[i3] := TPA[(i3 + 1)];
  15.         SetLength(TPA, h2);
  16.         Inc(d);
  17.         Break;
  18.       end;
  19. end;
  20.  
  21. function TPAUniqueIDs(TPA: TPointArray): TIntegerArray;
  22. var
  23.   h, r, x, y: Integer;
  24. begin
  25.   h := High(TPA);
  26.   SetLength(Result, (h + 1));
  27.   if (h > -1) then
  28.   case (h = 0) of
  29.     False:
  30.     begin
  31.       for x := 0 to h do
  32.       begin
  33.         for y := 0 to h do
  34.           if (y <> x) then
  35.             if ((TPA[x].X = TPA[y].X) and (TPA[x].Y = TPA[y].Y)) then
  36.               Break;
  37.         if (y > h) then
  38.         begin
  39.           Result[r] := x;
  40.           Inc(r);
  41.         end;
  42.       end;
  43.       SetLength(Result, r);
  44.     end;
  45.     True: Result[0] := 0;
  46.   end;
  47. end;
  48.  
  49. function TPADensity(TPA: TPointArray): Extended;
  50. var
  51.   h, l, i, r, d, x, y: Integer;
  52.   b: TBox;
  53. begin
  54.   h := High(TPA);
  55.   case (h > -1) of
  56.     True:
  57.     begin
  58.       if (h > 0) then
  59.       for i := (h - d) downto 1 do
  60.         for x := (i - 1) downto 0 do
  61.           if ((TPA[i].X = TPA[x].X) and (TPA[i].Y = TPA[x].Y)) then
  62.           begin
  63.             l := High(TPA);
  64.             for y := i to (l - 1) do
  65.               TPA[y] := TPA[(y + 1)];
  66.             SetLength(TPA, l);
  67.             Inc(d);
  68.             Break;
  69.           end;
  70.       b := GetTPABounds(TPA);
  71.       Result := (Extended(Length(TPA)) / (((b.X2 - b.X1) + 1) * ((b.Y2 - b.Y1) + 1)));
  72.     end;
  73.     False: Result := 0;
  74.   end;
  75. end;
  76.  
  77. procedure TPAReplace(var TPA: TPointArray; oldPoint, newPoint: TPoint);
  78. var
  79.   h, i: Integer;
  80. begin
  81.   if ((oldPoint.X <> newPoint.X) and (oldPoint.Y <> newPoint.Y)) then
  82.   begin
  83.     h := High(TPA);
  84.     for i := 0 to h do
  85.       if ((TPA[i].X = oldPoint.X) and (TPA[i].Y = oldPoint.Y)) then
  86.         TPA[i] := TPoint(newPoint);
  87.   end;
  88. end;
  89.  
  90. procedure TPAReplaceEx(var TPA: TPointArray; oldPoints: TPointArray; newPoint: TPoint);
  91. var
  92.   h, i: Integer;
  93. begin
  94.   if (High(oldPoints) > -1) then
  95.   begin
  96.     h := High(TPA);
  97.     for i := 0 to h do
  98.       if PointInTPA(TPA[i], oldPoints) then
  99.         TPA[i] := TPoint(newPoint);
  100.   end;
  101. end;
  102.  
  103. procedure TPAFill(var TPA: TPointArray; pt: TPoint);
  104. var
  105.   h, i: Integer;
  106. begin
  107.   h := High(TPA);
  108.   for i := 0 to h do
  109.     TPA[i] := TPoint(pt);
  110. end;
  111.  
  112. procedure TPAFillIDs(var TPA: TPointArray; IDs: TIntegerArray; pt: TPoint);
  113. var
  114.   h, l, i: Integer;
  115. begin
  116.   l := Length(TPA);
  117.   h := High(IDs);
  118.   if ((l > 0) and (h > -1)) then
  119.   for i := 0 to h do
  120.     if ((IDs[i] < l) and (IDs[i] > -1)) then
  121.       TPA[IDs[i]] := TPoint(pt);
  122. end;
  123.  
  124. var
  125.   TPA: TPointArray;
  126.  
  127. begin
  128.   TPA := [Point(10, 10), Point(15, 15), Point(12, 12), Point(18, 20), Point(25, 20), Point(12, 12)];
  129.   WriteLn('TPA BEFORE: ' + ToStr(TPA));
  130.   TPAFillIDs(TPA, [1, 2, 3], Point(6, 9));
  131.   WriteLn('TPA AFTER: ' + ToStr(TPA));
  132.   WriteLn(ToStr(TPAUniqueIDs(TPA)));
  133.   WriteLn(FloatToStr(TPADensity(TPA)));
  134.   WriteLn(FloatToStr(0.1 * 0.01));
  135. end.
Advertisement
Add Comment
Please, Sign In to add comment