Ignore:
Timestamp:
Mar 26, 2024, 10:57:56 PM (8 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 moved

Legend:

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

    r73 r74  
    1 unit UGeometric;
     1unit Geometric;
    22
    33interface
     
    1414    Position: TPoint;
    1515    Direction: TPoint;
    16     function GetLength: Integer;
     16    function GetLength: Double;
    1717    function GetAngle: Double;
     18    procedure SetLength(Value: Double);
     19    class function Create(P1, P2: TPoint): TVector; static;
    1820  end;
    1921
     
    176178{ TVector }
    177179
    178 function TVector.GetLength: Integer;
    179 begin
    180   Result := Trunc(Sqrt(Sqr(Direction.X) + Sqr(Direction.Y)));
     180function TVector.GetLength: Double;
     181begin
     182  Result := Sqrt(Sqr(Direction.X) + Sqr(Direction.Y));
    181183end;
    182184
     
    186188end;
    187189
     190procedure TVector.SetLength(Value: Double);
     191var
     192  Angle: Double;
     193begin
     194  Angle := GetAngle;
     195  Direction := Point(Round(Cos(Angle) * Value),
     196    Round(Sin(Angle) * Value));
     197end;
     198
     199class function TVector.Create(P1, P2: TPoint): TVector;
     200begin
     201  Result.Position := P1;
     202  Result.Direction := Point(P2.X - P1.X, P2.Y - P1.Y);
     203end;
     204
    188205end.
    189 
Note: See TracChangeset for help on using the changeset viewer.