Delphi XE5에서 삼각형 메쉬 구조를 만들고 싶습니다.Delphi에서 메쉬 클래스 구조를위한 가장 좋은 방법은 무엇입니까?
주요 TMyMesh 클래스는, 정점의 목록을 유지하는 일반적인 TObjectLists이있다면 등
이의 내가 메쉬의 모든 얼굴을 위해 뭔가를해야만 계산할 수 있다고 가정 해 봅시다. 나는 ListOfVertices에 TMyTriangleFace 클래스 액세스 권한을 부여 할 필요가
TMyVertex=class(TComponent)
Vertex: TPoint3D;
//other fields and methods
end;
TMyTriangleFace=class(TComponent)
Vertices: Array [0..2] of Integer;
procedure DoSomethingWithTheFace;
//other fields and methods
end;
TMyMesh=class(TComponent)
ListOfVertices: TObjectList<TMyVertex>;
ListOfTriangleFaces: TObjectList<TMyTriangleFace>;
procedure CreateListOfTriangleFaces;
procedure DoSomethingWithAllFaces;
end;
procedure TMyTriangleFace.DoSomethingWithTheFace;
begin
AVertex:=TMyMesh(Owner).ListOfVertices[Vertices[0]];
//do something
end;
procedure TMyMesh.CreateListOfTriangleFaces;
begin
for i := 0 to NumberOfTriangleFaces-1 do
begin
ListOfTriangleFaces.Add(TMyTraingleFace.Add(Self));
end;
end;
procedure TMyMesh.DoSomethingWithAllFaces;
begin
for i := 0 to ListOfFaces.Count-1 do
begin
ListOfTriangleFaces[i].DoSomethingWithTheFace;
end;
end;
이 경우 :이의 TMyMesh 클래스 관리 보자 수 :
TMyVertex=class(TComponent)
Vertex: TPoint3D;
//other fields and methods
end;
TMyTriangleFace=class(TComponent)
Vertices: Array [0..2] of Integer;
//other fields and methods
end;
TMyMesh=class(TComponent)
ListOfVertices: TObjectList<TMyVertex>;
ListOfTriangleFaces: TObjectList<TMyTriangleFace>;
procedure CreateListOfTriangleFaces;
procedure DoSomethingWithTheFace(const FaceNumber: Integer);
procedure DoSomethingWithAllFaces;
end;
procedure TMyMesh.CreateListOfTriangleFaces;
begin
for i := 0 to NumberOfTriangleFaces-1 do
begin
ListOfTriangleFaces.Add(TMyTraingleFace.Add(nil));
end;
end;
procedure TMyMesh.DoSomethingWithTheFace(const AFaceNumber: Integer);
begin
AVertex:=ListOfVertices[ListOfFaces[AFaceNumber].Vertices[0]];
//do something
end;
procedure TMyMesh.DoSomethingWithAllFaces;
begin
for i := 0 to ListOfFaces.Count-1 do
begin
DoSomethingWithTheFace(i);
end;
end;
을 또는 내가 TMyTriangleFace 클래스에 위임 할 수있다 . CreateListOfTriangleFaces 프로 시저에서 TMyMesh를 소유자로 전달하여이 작업을 수행 할 수 있습니다.
제 2 부분은 더 나은 코드 (Demeter의 법칙)이어야합니다. 그러나 TMyMesh를 소유자로 전달하는 것은 그렇게 좋지 않을 수 있습니다.
이 작업을 수행 할 수있는 가장 좋은 방법은 무엇입니까? 어쩌면 두 가지 해결책이 잘못된 방향으로 가고 있으며 훨씬 좋은 해결책이 있습니까?
대단히 감사합니다!
가능한 한 값을 사용하고 싶습니다. 모든 것을 구성 요소로 만들면 위력이 저하됩니다. –
이 질문은 코드 검토를 요구하기 때문에 주제가 아닌 것으로 보입니다. 이 질문은 코드 검토 스택 교환 사이트에서 요청하는 것이 좋습니다. –
나에게 코드 검토처럼 보이지 않습니다. 물론 큰 코드 샘플이 있지만 본질적으로 OOP 접근과 데이터 저장에 관한 것입니다. OOP가 세밀하거나 간단한 접근 방법이 유익해야합니다. – Kromster