I would like to have a generic KDTree implementation in C++ that can hold any kind of positionable object. Such objects have a 2D position.
Unfortunately. Positionable classes could have different ways of getting the position.
- Getters
getX()andgetY() - std::pair<double, double>
- sf::Vector2f
- ...
What would be the proper way to wrap such classes into my KDTree?
My Tree is composed of nodes such as:
template <typename T>
struct Node {
int id;
T element;
Node *left, *right;
Node(T element) : element(element), left(NULL), right(NULL)
{
static int id = 0;
this->id = id++;
}
};
Somehow I would like to have a generic getter to the position of T element.
One possible solution is to define a positionable interface:
struct KDTreeElement {
virtual getX() = 0;
virtual getY() = 0;
}
The con of this method is that the positionable element must know the KDTree library
What are the alternatives?