Function S2Shape.userData

Virtual methods that return pointers of your choice.

const(void*) userData() const;

These methods are intended to help with the problem of attaching additional data to S2Shape objects. For example, you could return a pointer to a source object, or a pointer to a bundle of additional data allocated with the S2Shape. Because this method exists in all S2Shapes, you can override it in each type of shape you have and call it without knowing the concrete subtype. For example, if you have polyline and polygon shapes, you can do this:

class MyPolyline : S2Polyline.Shape {
public:
  void* mutableUserData() { return &_myData; }
private:
  MyData _myData;
}
class MyPolygon : S2Polygon.Shape {
public:
  void* mutableUserData() { return &_myData; }
private:
  MyData _myData;
};
...
S2Shape* shape = index.shape(id);
const(MyData)* data = cast(const(MyData)*)(shape.userData());

This is not the only way to map from an S2Shape back to your source data. Other reasonable techniques include:

- Every shape has an id() assigned by S2ShapeIndex. Ids are assigned sequentially starting from 0 in the order the shapes are added to the index. You can use this id to look up arbitrary data stored in your own vector.

- If all of your shapes are the same type, then you can create your own subclass of some existing S2Shape type (such as S2Polyline::Shape) and add your own methods and fields. You can access this data by downcasting the S2Shape pointers returned by S2ShapeIndex methods.