I have a problem with two classes that were once nicely separated, but now they want to put together.
Without delving into the specifics of the problem, here it is:
I had a Triangle class that contained 3 vertices of spatial position.
class Triangle { Vertex a,b,c ;
There were many instances of Triangle in the program, so each of them saved its own copy of its vertices. Member functions, such as getArea() , getCentroid() , etc., were written in the Triangle class, and since each Triangle instance had copies of the vertices a, b, and c, the search for a region or centroid was independent of other classes. As it should be!
Then I wanted to go into the vertex array / index buffer style representation for other reasons. This means that all vertices are stored in one array located in the Scene object, and each Triangle stores only the LINKS of the vertices in the Scene , and not copies of the vertices themselves. At first I tried disabling pointers:
class Scene { std::vector<Vertex> masterVertexList ; } ; class Triangle { Vertex *a,*b,*c ;
(If you are wondering about the benefits, I did this for reasons mainly related to the triangles that separate the vertices. If * a moves, all the triangles that use this vertex are updated automatically).
That would be a really good solution! But it did not work reliably because std :: vector invalidates pointers , and I used std :: vector to list the main vertices in the Scene class.
So I had to use integers:
class Triangle { int a,b,c ;
But now I have this new communication problem: in order to find its own area or center, the Triangle class needs access to the class Scene , where it had not been before. It seems that I have something, but really.
WWYD?