Changeset 232


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.
Location:
trunk
Files:
2 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
  • trunk/UMapType.pas

    r231 r232  
    405405  end;
    406406
     407  // Adjust polygon centers
     408  for I := 0 to Cells.Count - 1 do begin
     409    Cells[I].PosPx := Cells[I].Polygon.GetCenter;
     410  end;
     411
    407412  FPixelRect := CalculatePixelRect;
    408413end;
Note: See TracChangeset for help on using the changeset viewer.