So, ich bin auf das hier gekommen:
Delphi-Quellcode:
TGridPoint = class(TObject)
private
FPos: TVector;
FAbove,
FUnder,
FLeft,
FRight: TGridPoint;
constructor CreateOnNil;
public
constructor Create(aPosX, aPosY: Single; aAbove, aUnder, aLeft, aRight: TGridPoint);
property Position : TVector read FPos write FPos;
property PointAbove: TGridPoint read FAbove write FAbove;
property PointUnder: TGridPoint read FUnder write FUnder;
property PointLeft : TGridPoint read FLeft write FLeft;
property PointRight: TGridPoint read FRight write FRight;
function Replicate: TGridPoint;
end;
{ TGridPoint }
function TGridPoint.Replicate: TGridPoint;
type
TCloneGridPoint = record
Point,
FGridPoint: TGridPoint;
end;
var
Cells: array of TCloneGridPoint;
function CellsIndex(Point: TGridPoint): Integer;
var i: Integer;
begin
Result := -1;
for i := 0 to High(Cells) do
if Cells[i].FGridPoint = Point then
begin
Result := i;
Exit;
end;
end;
function CellsContain(Point: TGridPoint): Boolean;
begin
Result := CellsIndex(Point) <> -1;
end;
function CloneSingleCell(Cell: TGridPoint): TGridPoint;
begin
if Cell = nil then
begin
Result := nil;
Exit;
end;
if not CellsContain(Cell) then
begin
Result := TGridPoint.CreateOnNil;
Result.Position := Cell.Position;
SetLength(Cells, Length(Cells)+1);
Cells[High(Cells)].Point := Result;
Cells[High(Cells)].FGridPoint := Cell;
Result.PointAbove := CloneSingleCell(Cell.PointAbove);
Result.PointUnder := CloneSingleCell(Cell.PointUnder);
Result.PointLeft := CloneSingleCell(Cell.PointLeft);
Result.PointRight := CloneSingleCell(Cell.PointRight);
end
else
Result := Cells[CellsIndex(Cell)].Point;
end;
begin
Result := CloneSingleCell(Self);
end;
constructor TGridPoint.Create(aPosX, aPosY: Single; aAbove, aUnder, aLeft,
aRight: TGridPoint);
begin
FAbove := aAbove;
FUnder := aUnder;
FLeft := aLeft;
FRight := aRight;
FPos.x := aPosX;
FPos.y := aPosY;
end;
constructor TGridPoint.CreateOnNil;
begin
end;
dizzy, bitte mal austesten