Changeset 105 for trunk/Packages


Ignore:
Timestamp:
Oct 4, 2022, 11:25:28 AM (2 years ago)
Author:
chronos
Message:
  • Modified: Improved trains placement behavior by mouse drag and drop.
File:
1 edited

Legend:

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

    r93 r105  
    2222function AddPoint(const P1, P2: TPoint): TPoint;
    2323function SubPoint(const P1, P2: TPoint): TPoint;
    24 function PointToLineDistance(const P, V, W: TPoint): Integer;
     24function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer;
    2525function ComparePoint(P1, P2: TPoint): Boolean;
    2626function RotatePoint(Center, P: TPoint; Angle: Double): TPoint;
     
    5959end;
    6060
    61 function PointToLineDistance(const P, V, W: TPoint): Integer;
     61function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer;
    6262var
    6363  l2, t: Double;
     
    7777  if T < 0 then begin
    7878    Result := Distance(P, V);       // Beyond the 'v' end of the segment
    79     exit;
     79    Intersect := V;
     80    Exit;
    8081  end
    8182  else if T > 1 then begin
    8283    Result := Distance(P, W);  // Beyond the 'w' end of the segment
     84    Intersect := W;
    8385    Exit;
    8486  end;
     
    8688  TT.Y := Trunc(V.Y + T * (W.Y - V.Y));
    8789  Result := Distance(P, TT);
     90  Intersect := TT;
    8891end;
    8992
Note: See TracChangeset for help on using the changeset viewer.