I have the following data structure for storing meridians and parallels.
Each cartographic point stores:
A] geographic and spatial coordinates, cartographic distortions, etc.
B] pointer to north/south/east/west node.
It allows to store relationships between points, first of all their affiliation to the meridian/parallel...
class Node2DCart
{
protected:
//Coordinates of the point
double lat;
double lon;
double lattrans;
double lontrans;
double x;
double y;
.....
//Pointers to adjacent points in geographic network
Node2DCart *left;
Node2DCart *right;
Node2DCart *top;
Node2DCart *bottom;
.....
};
Data structure for meridian stores longitude of the meridian, start point and end point of the meridian and number of points.
class Meridian
{
private:
unsigned int points_count;
double longitude;
Node2DCart *start;
Node2DCart *end;
....
};
All points are stored in nodes list:
typedef std::vector<Node2DCart*> TNodes2DCartList;
class Node2DCartList
{
protected:
TNodes2DCartList nodes;
...
};
But there is a big problem writing copy constructor for Node2DList. There is a cyclic dependency between Meridian/Parallel and Node2Dlist.
Copy constructor uses std::map
and replaces old points and links with new, it is not an implementation problem... However pointers start/end from class Meridian point to points from old Node2DList... Node2DList copy constructor should have to notify all meridians pointed to old Node2DList points and change all pointers to new Node2DList points. This model does not allow it.
The possible solution would be adding two pointers pointing to meridian and parallel point belongs to:
class Node2DCart
{
protected:
//Coordinates of the point
double lat;
double lon;
double lattrans;
double lontrans;
double x;
double y;
.....
//Pointers to adjacent points in geographic network
Node2DCart *left;
Node2DCart *right;
Node2DCart *top;
Node2DCart *bottom;
.....
Meridian *m;
Parallel *p;
};
I am afraid that this proposed model is not good. There are still cycling references between two classes... Would someone help me to improve it? Thanks...