M
malcolm.mclean5
I've got a collection of lines, which intersect with each other. To avoid numerical problems and other nasty things, I want to store the intersectionsas intersections, rather than x,y coordinates.
Now each line means something to higher-level code. It could be an index ina polygon, part of a space invader, whatever. So it needs a arbitrary tag to retrieve and query it.
Now in C I'd write this something like the following.
struct line
{
double x1, y1, x2, y2;
void *tag;
int taglen;
int hash;
struct line **intersections;
int N_intersections;
} LINE;
Then you store the LINE objects in a hash table to retrieve them.
The interface is then
addline(x1, y1, x2, y2, tag, taglen);
LINE *getintersections(tag, taglen);
But the program contains C++, it would be nice to have a more C++ interfaceto it, so that the tags can contain embedded strings or whatever. Also maybe some sort of template so an int tag and a string tag which happens to be 4 bytes and the same bit pattern as the int doesn't evaluate to the same thing.
Now each line means something to higher-level code. It could be an index ina polygon, part of a space invader, whatever. So it needs a arbitrary tag to retrieve and query it.
Now in C I'd write this something like the following.
struct line
{
double x1, y1, x2, y2;
void *tag;
int taglen;
int hash;
struct line **intersections;
int N_intersections;
} LINE;
Then you store the LINE objects in a hash table to retrieve them.
The interface is then
addline(x1, y1, x2, y2, tag, taglen);
LINE *getintersections(tag, taglen);
But the program contains C++, it would be nice to have a more C++ interfaceto it, so that the tags can contain embedded strings or whatever. Also maybe some sort of template so an int tag and a string tag which happens to be 4 bytes and the same bit pattern as the int doesn't evaluate to the same thing.