Advertisement
mixster

FilterPointsLine improv

Apr 17th, 2012
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.78 KB | None | 0 0
  1. program new;
  2.  
  3. procedure FilterPointsLine2(var Points: TPointArray; Radial: Extended; Radius, MX, MY: Integer);
  4. var
  5.   I, Hi, Ind, y, j, LX, LY, OX, OY: Integer;
  6.   P: TPointArray;
  7.   Box: TBox;
  8.   B: Array of Array of Boolean;
  9.   SinAngle,CosAngle : Extended;
  10. begin
  11.   if Length(Points) < 1 then
  12.     Exit;
  13.   Ind := 0;
  14.   Box:= GetTPABounds(Points);
  15.   SinAngle := sin(Radial);
  16.   CosAngle := -cos(Radial);
  17.   LX := Min(Box.x1, Floor(SinAngle * Radius) + MX);
  18.   LY := Min(Box.y1, Floor(CosAngle * Radius) + MY);
  19.   SetLength(B, max(Box.x2, Ceil(SinAngle * Radius) + MX) + 2 - LX);
  20.   y:= max(Box.x2, Ceil(CosAngle * Radius) + MY) + 2 - LY;
  21.   for I:= 0 to High(B) do
  22.     SetLength(B[I], y);
  23.  
  24.   Hi:= High(Points);
  25.   for I:= 0 to Hi do
  26.   begin
  27.     B[Points[I].x - LX][Points[I].y - LY]:= True;
  28.     Writeln(Point(Points[I].x - LX, Points[I].y - LY));
  29.   end;
  30.   SetLength(P, Hi + 1);
  31.   OX := MX - LX;
  32.   OY := MY - LY;
  33.   for I:= 0 to Radius do
  34.   begin
  35.     Writeln(Point(Round(SinAngle * I) + OX, Round(CosAngle * I) + OY));
  36.     if(B[Round(SinAngle * I) + OX][Round(CosAngle * I) + OY])then
  37.     begin
  38.       P[Ind].X := Round(SinAngle * I) + MX;
  39.       P[Ind].Y := Round(CosAngle * I) + MY;
  40.       Inc(Ind);
  41.     end;
  42.   end;
  43.   SetLength(P, Ind);
  44.   Points:= P;
  45. end;
  46.  
  47. var
  48.   tpa, clone: TPointArray;
  49.   r: extended;
  50.   i: Integer;
  51. begin
  52.   tpa := [Point(0, 1), Point(1, 1), Point(1, 0), Point(1, -1), Point(0, -1), Point(-1, -1),
  53.     Point(-1, 0), Point(-1, 1)];
  54.   r := -pi;
  55.   clone := tpa;
  56.   FilterPointsLine2(tpa, r, 10, 0, 0);
  57.   WriteLn(tpa);
  58.   for i := 0 to High(clone) do
  59.     clone[i] := Point(clone[i].x + 100, clone[i].y + 100);
  60.   FilterPointsLine(clone, r, 10, 100, 100);
  61.   for i := 0 to High(clone) do
  62.     clone[i] := Point(clone[i].x - 100, clone[i].y - 100);
  63.   Writeln(clone);
  64. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement