Proposal: Unify shape predicates

There are a few points now in the API where a unary function mapping from shapes to booleans is used/implied/would be useful. Such as
* Raycasting callback
* IsTouching from this patch
* b2World.Query

I was thinking we should arrange that these are all under the same system of overloaded function calls, including a few of:
* (No extra args) - All shapes selected.
* b2FilterData - Shapes with a corresponding filter data
* b2Shape - Shapes colliding with the given shape
* b2Body - shapes inside the given body
* C-style callback, i.e. a function pointer plus void* userData argument
* C++-style callback i.e. a object with a virtual method.
* Template style call back, i.e. an object with an () operator, and a templated argument.
* Box2D style callback i.e. a globally registered callback function, plus possibly a userData argument.


Basically, I just want to give everyone the ability to pass b2FilterData's to raycasting, without promotimg them to "first class" box2d citizens. The rest is just sugar.
This sounds good.

Ideally I would use a template style callback everywhere due to the improved performance.

I'm actually working on replacing SAP right now, so this is a good time to address this. The new broad-phase will support proper ray-casting.
Oh, ok! I had thought you'd reject templates to keep the API simpler (basically, OO C).

How about this, then: define the template concept ShapeCallback as any object with a method:
bool TestShape(Shape *);

b2FilterData (and possibly others), would be models of this concept, and functions like Raycast would have only two overloads - one for no extra argument, and one accepting models of ShapeCallback.

By not using the overloaded operator, but instead a named method, you avoid confusion as the classes are also used elsewhere.

Other language ports can make use of interfaces to replace this template style.

Will this really offer significant performance advantages?

(model and concept being the equivalent of instance and class for the templating system - I'm not sure how common this terminology is).
The performance benefit depends on whether the client code can be inlined. I use a template function for the GJK algorithm in b2Distance.cpp to avoid the virtual function hit. In that case it is a clear win.

I dislike using buffers for volume queries, so will implement a callback system where each shape/proxy is processed as it is found.

Original thread: https://box2d.org/forum/viewtopic.php?t=2877