Changeset 232 for trunk/UGeometry.pas


Ignore:
Timestamp:
Sep 19, 2018, 2:34:06 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Adjusted center of Voronoi map to better place cells power text in center of polygons.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGeometry.pas

    r192 r232  
    9797    function GetRect: TGRect<T>;
    9898    function EdgeDistance(Polygon: TGPolygon<T>): Double;
     99    function GetCenter: T;
    99100    procedure AddPoint(const P: T);
    100101    procedure Clear;
     
    164165begin
    165166  Result := Points[Index];
     167end;
     168
     169function TGPolygon<T>.GetCenter: T;
     170var
     171  I: Integer;
     172begin
     173  Result := T.Create(0, 0);
     174  for I := 0 to Length(Points) - 1 do
     175    Result := Result + Points[I];
     176  Result.X := TypedRound(Result.X / Length(Points));
     177  Result.Y := TypedRound(Result.Y / Length(Points));
    166178end;
    167179
Note: See TracChangeset for help on using the changeset viewer.