- Timestamp:
- Sep 21, 2018, 1:34:58 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UMap.pas
r238 r242 267 267 begin 268 268 Result := TCellLink.Create; 269 Cell1. Neighbors.Add(Cell2);269 Cell1.ConnectTo(Cell2); 270 270 Cell1.Links.Add(Result); 271 Cell2.Neighbors.Add(Cell1);272 271 Cell2.Links.Add(Result); 273 272 SetLength(Result.Points, 2); -
trunk/UMapType.pas
r235 r242 100 100 PX, PY: Double; 101 101 P: TPoint; 102 Cell: TCell; 102 103 begin 103 104 Clear; … … 126 127 for X := 0 to Size.X - 1 do 127 128 with Cells[Y * Size.X + X] do begin 129 Cell := Cells[Y * Size.X + X]; 128 130 if Cyclic then begin 129 131 P := TPoint.Create(X + 0 + (Y mod 2), Y + 1); 130 132 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 131 Neighbors.Add(Cells[P.Y * Size.X + P.X]);133 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 132 134 P := TPoint.Create(X - 1 + (Y mod 2), Y + 1); 133 135 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 134 Neighbors.Add(Cells[P.Y * Size.X + P.X]);136 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 135 137 P := TPoint.Create(X + 0 + (Y mod 2), Y - 1); 136 138 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 137 Neighbors.Add(Cells[P.Y * Size.X + P.X]);139 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 138 140 P := TPoint.Create(X - 1 + (Y mod 2), Y - 1); 139 141 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 140 Neighbors.Add(Cells[P.Y * Size.X + P.X]);142 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 141 143 end else begin 142 144 P := TPoint.Create(X + 0 + (Y mod 2), Y + 1); 143 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);145 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 144 146 P := TPoint.Create(X - 1 + (Y mod 2), Y + 1); 145 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);147 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 146 148 P := TPoint.Create(X + 0 + (Y mod 2), Y - 1); 147 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);149 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 148 150 P := TPoint.Create(X - 1 + (Y mod 2), Y - 1); 149 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);151 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 150 152 end; 151 153 end; … … 312 314 NewCell: TCell; 313 315 P: TPoint; 316 Cell: TCell; 314 317 begin 315 318 Clear; … … 332 335 for X := 0 to Size.X - 1 do 333 336 with Cells[Y * Size.X + X] do begin 337 Cell := Cells[Y * Size.X + X]; 334 338 if Cyclic then begin 335 339 P := TPoint.Create(X + 1, Y + 0); 336 340 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 337 Neighbors.Add(Cells[P.Y * Size.X + P.X]);341 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 338 342 P := TPoint.Create(X + 0, Y + 1); 339 343 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 340 Neighbors.Add(Cells[P.Y * Size.X + P.X]);344 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 341 345 P := TPoint.Create(X - 1, Y + 0); 342 346 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 343 Neighbors.Add(Cells[P.Y * Size.X + P.X]);347 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 344 348 P := TPoint.Create(X + 0, Y - 1); 345 349 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 346 Neighbors.Add(Cells[P.Y * Size.X + P.X]);350 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 347 351 end else begin 348 352 P := TPoint.Create(X + 1, Y + 0); 349 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);353 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 350 354 P := TPoint.Create(X + 0, Y + 1); 351 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);355 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 352 356 P := TPoint.Create(X - 1, Y + 0); 353 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);357 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 354 358 P := TPoint.Create(X + 0, Y - 1); 355 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);359 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 356 360 end; 357 361 end; … … 481 485 NewCell: TCell; 482 486 P: TPoint; 487 Cell: TCell; 483 488 begin 484 489 Clear; … … 504 509 for X := 0 to Size.X - 1 do 505 510 with Cells[Y * Size.X + X] do begin 511 Cell := Cells[Y * Size.X + X]; 506 512 if Boolean(X mod 2) xor Boolean(Y mod 2) then Rev := -1 507 513 else Rev := 1; … … 509 515 P := TPoint.Create(X + 1, Y + 0); 510 516 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 511 Neighbors.Add(Cells[P.Y * Size.X + P.X]);517 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 512 518 P := TPoint.Create(X + 0, Y - 1 * Rev); 513 519 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 514 Neighbors.Add(Cells[P.Y * Size.X + P.X]);520 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 515 521 P := TPoint.Create(X - 1, Y + 0); 516 522 P := TPoint.Create((P.X + Size.X) mod Size.X, (P.Y + Size.Y) mod Size.Y); 517 Neighbors.Add(Cells[P.Y * Size.X + P.X]);523 Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 518 524 end else begin 519 525 P := TPoint.Create(X + 1, Y + 0); 520 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);526 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 521 527 P := TPoint.Create(X + 0, Y - 1 * Rev); 522 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);528 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 523 529 P := TPoint.Create(X - 1, Y + 0); 524 if IsValidIndex(P) then Neighbors.Add(Cells[P.Y * Size.X + P.X]);530 if IsValidIndex(P) then Cell.ConnectTo(Cells[P.Y * Size.X + P.X]); 525 531 end; 526 532 end;
Note:
See TracChangeset
for help on using the changeset viewer.