- Timestamp:
- Nov 26, 2017, 11:35:25 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UGeometry.pas
r172 r174 95 95 constructor Create(const Rect: TGRect<T>); overload; 96 96 function GetRect: TGRect<T>; 97 function EdgeDistance(Polygon: TGPolygon<T>): Double; 97 98 procedure AddPoint(const P: T); 98 99 procedure Clear; … … 157 158 end; 158 159 159 { T Polygon }160 { TGPolygon } 160 161 161 162 function TGPolygon<T>.GetPoint(const Index: Integer): T; … … 282 283 end; 283 284 284 { TLine } 285 function TGPolygon<T>.EdgeDistance(Polygon: TGPolygon<T>): Double; 286 var 287 I, J: Integer; 288 Dist: Double; 289 begin 290 Result := Infinity; 291 for I := 0 to Length(Points) - 1 do 292 for J := 0 to Length(Polygon.Points) - 1 do begin 293 Dist := TGLine<T>.Create(Points[I], Polygon.Points[J]).Distance; 294 if Dist < Result then Result := Dist; 295 end; 296 end; 297 298 { TGLine } 285 299 286 300 function TGLine<T>.GetDistance: Double; -
trunk/UCore.pas
r170 r174 397 397 procedure TCore.DataModuleDestroy(Sender: TObject); 398 398 begin 399 StoredDimension.Free;;399 FreeAndNil(StoredDimension); 400 400 Game.SaveConfig(XMLConfig1, 'Game'); 401 401 SaveConfig; -
trunk/UMap.pas
r172 r174 259 259 CellDistance: TCellsDistance; 260 260 Cell: TCell; 261 Cell2: TCell; 261 262 L1, L2: TLine; 262 263 MP: TPoint; 263 264 LinkLine: TLine; 264 Polygon: TPolygon;265 //LeftLink: TCellsDistance;266 //CenterLink: TCellsDistance;267 //RightLink: TCellsDistance;268 265 LeftClosingLine1: TLine; 269 266 LeftClosingLine2: TLine; … … 283 280 LeftCellCommon: TCell; 284 281 RightCellCommon: TCell; 285 //LeftText: string; 286 //RightText: string; 287 NeighborCell: TCell; 282 const 283 CellGapWidth = 4; 288 284 begin 289 285 Clear; … … 306 302 // Calculate distance between all cells 307 303 CellsDistance := TFPGObjectList<TCellsDistance>.Create; 308 for I1 := 1to Cells.Count - 1 do304 for I1 := 0 to Cells.Count - 1 do 309 305 for I2 := I1 + 1 to Cells.Count - 1 do begin 310 306 NewCellDist := TCellsDistance.Create; … … 362 358 LeftCell := Cell.Neighbors[I]; 363 359 RightCell := Cell.Neighbors[(I + 1) mod Cell.Neighbors.Count]; 364 //LeftText := LeftCell.Neighbors.ToString;365 //RightText := RightCell.Neighbors.ToString;366 360 LeftIndex := LeftCell.Neighbors.IndexOf(Cell); 367 361 RightIndex := RightCell.Neighbors.IndexOf(Cell); … … 406 400 end; 407 401 408 // Compute polygon around cells with sequence sorted by link angle402 {// Compute polygon around cells with sequence sorted by link angle 409 403 for Cell in Cells do begin 410 404 // Use whole map first for cell polygon … … 414 408 for NeighborCell in Cell.Neighbors do begin 415 409 LinkLine := TLine.Create(Cell.PosPx, NeighborCell.PosPx); 416 LinkLine.Distance := LinkLine.Distance - 4;410 LinkLine.Distance := LinkLine.Distance - CellGapWidth; 417 411 MP := LinkLine.GetMiddle; 418 412 // Create half plane vector … … 424 418 Cell.Polygon := Polygon; 425 419 end else Cell.Polygon.Clear; 420 end;} 421 422 // Additional polygon by all other cells 423 for Cell in Cells do begin 424 Cell.Polygon := TPolygon.Create(TRect.Create(TPoint.Create(0, 0), 425 TPoint.Create(Size.X * DefaultCellSize.X, Size.Y * DefaultCellSize.Y))); 426 for Cell2 in Cells do 427 if Cell2 <> Cell then begin 428 LinkLine := TLine.Create(Cell.PosPx, Cell2.PosPx); 429 LinkLine.Distance := LinkLine.Distance - CellGapWidth; 430 MP := LinkLine.GetMiddle; 431 // Create half plane vector 432 L1 := TLine.Create(MP, TPoint.Create(MP.X + LinkLine.GetSize.X, 433 MP.Y + LinkLine.GetSize.Y)); 434 435 Cell.Polygon.CutLine(L1, Cell.PosPx); 436 end; 437 end; 438 439 // Remove all neighbor links for cell pairs with non-overlaping polygons 440 for Cell in Cells do begin 441 for I := Cell.Neighbors.Count - 1 downto 0 do begin 442 if Cell.Polygon.EdgeDistance(Cell.Neighbors[I].Polygon) > 2 * CellGapWidth then 443 Cell.Neighbors.Delete(I); 444 end; 426 445 end; 427 446 -
trunk/xtactics.lpr
r170 r174 11 11 CoolTranslator, TemplateGenerics, UFormPlayer 12 12 { you can add units after this }, 13 SysUtils, UFormMain, UFormMove, UFormNew, UFormCharts, UFormUnitMoves , UGeometryClasses;13 SysUtils, UFormMain, UFormMove, UFormNew, UFormCharts, UFormUnitMoves; 14 14 15 15 {$R *.res}
Note:
See TracChangeset
for help on using the changeset viewer.