Changeset 172 for trunk/Packages


Ignore:
Timestamp:
Nov 24, 2017, 10:11:54 AM (7 years ago)
Author:
chronos
Message:
  • Fixed: Rectangle points were not normalized.
  • Fixed: Error in rect to polygon conversion.
File:
1 edited

Legend:

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

    r171 r172  
    66
    77uses
    8   Classes, SysUtils, Math, typinfo;
     8  Classes, SysUtils, Math;
    99
    1010type
     
    5151    function Center: T;
    5252    procedure SetEmpty;
     53    procedure Normalize;
    5354    class operator Equal(const A, B: TGRect<T>): Boolean;
    5455    constructor Create(const P1, P2: T);
     
    201202  Self.Points[0] := Rect.P1;
    202203  Self.Points[1] := T.Create(Rect.P2.X, Rect.P1.Y);
    203   Self.Points[2] := Rect.P1;
     204  Self.Points[2] := Rect.P2;
    204205  Self.Points[3] := T.Create(Rect.P1.X, Rect.P2.Y);
    205206end;
     
    320321function TGLine<T>.ToRect: TGRect<T>;
    321322begin
    322   Result.P1 := P1;
    323   Result.P2 := P2;
     323  Result := TGRect<T>.Create(P1, P2);
    324324end;
    325325
     
    461461end;
    462462
     463procedure TGRect<T>.Normalize;
     464var
     465  NewP1: T;
     466  NewP2: T;
     467begin
     468  NewP1 := P1.Min(P1, P2);
     469  NewP2 := P1.Max(P1, P2);
     470  P1 := NewP1;
     471  P2 := NewP2;
     472end;
     473
    463474function TGRect<T>.Center: T;
    464475begin
     
    481492  Self.P1 := P1;
    482493  Self.P2 := P2;
     494  Normalize;
    483495end;
    484496
Note: See TracChangeset for help on using the changeset viewer.