Ignore:
Timestamp:
Jan 5, 2023, 11:03:33 PM (23 months ago)
Author:
chronos
Message:
  • Added: Snap package definition.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UGeometric.pas

    r54 r63  
    99  TPointArray = array of TPoint;
    1010
     11  { TVector }
     12
     13  TVector = record
     14    Position: TPoint;
     15    Direction: TPoint;
     16    function GetLength: Integer;
     17    function GetAngle: Double;
     18  end;
     19
    1120function Distance(P1, P2: TPoint): Integer;
    1221function Dot(const P1, P2: TPoint): Double;
    1322function AddPoint(const P1, P2: TPoint): TPoint;
    1423function SubPoint(const P1, P2: TPoint): TPoint;
    15 function PointToLineDistance(const P, V, W: TPoint): Integer;
     24function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer;
    1625function ComparePoint(P1, P2: TPoint): Boolean;
    1726function RotatePoint(Center, P: TPoint; Angle: Double): TPoint;
     
    5059end;
    5160
    52 function PointToLineDistance(const P, V, W: TPoint): Integer;
     61function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer;
    5362var
    5463  l2, t: Double;
     
    6877  if T < 0 then begin
    6978    Result := Distance(P, V);       // Beyond the 'v' end of the segment
    70     exit;
     79    Intersect := V;
     80    Exit;
    7181  end
    7282  else if T > 1 then begin
    7383    Result := Distance(P, W);  // Beyond the 'w' end of the segment
     84    Intersect := W;
    7485    Exit;
    7586  end;
     
    7788  TT.Y := Trunc(V.Y + T * (W.Y - V.Y));
    7889  Result := Distance(P, TT);
     90  Intersect := TT;
    7991end;
    8092
     
    162174end;
    163175
     176{ TVector }
     177
     178function TVector.GetLength: Integer;
     179begin
     180  Result := Trunc(Sqrt(Sqr(Direction.X) + Sqr(Direction.Y)));
     181end;
     182
     183function TVector.GetAngle: Double;
     184begin
     185  Result := ArcTan2(Direction.Y, Direction.X);
     186end;
    164187
    165188end.
Note: See TracChangeset for help on using the changeset viewer.