[Request] Better world query

I wouldn't mind using the colliders. It's just that you have to switch on shape types to use them, and construct a manifold. That would have doubled the size of the snippet I posted! I was really just suggesting a wrapper for that, (or maybe b2Distance); it's too much effort to write fractionally more efficient boolean tests, when in most efficiency cases, you'd be better off with a sensor.

In general, shapes are now a user type, so we can "talk about" them, but there is very little vocabulary to do so. I'd like to see the following general purpose additions so that next time someone asks why Box2D doesn't give an API for such and such, I can always fire off a quick snippet.

  • shape_cast<b2CircleShape*>, like dynamic_cast, except using shape GetType().
  • Either virtual or templated unary/binary shape dispatch (e.g. exposing something like the contact register (virtual style) or taking a vistor object (see boost::variant for apply_visitor)
  • More basic geometry queries, e.g. Support, b2Mul, Nearest. If you want even more: Flip, Scale, Furthest, AngularSupport, Bisect, Shrink, MinkowskiSum.

But now I'm just making demands again. But I've actually written the first two, and a bit of the third, before templates were really introduced to the C++.

Templated visitors are particularly neat, you can avoid the heap allocation usually required by polymorphism, which is otherwise a massive API problem considering Box2D doesn't return heap allocated values ever. But it seems that the API is still template free, even if they are used internally.
I've been using switch statements for 20 years and they have always switched correctly.

My grandfather invented switch statements. What do you have against switch statements?

🙂
Erin Catto wrote:
What do you have against switch statements?


I've heard rumors that they're slower than if statements.
Rumors are useless here. 🙂
The only way to get the correct information about something is to test it.
Anyway, even if they're slower, they're much easier to use - if you don't like switch, you would have to use "do{ .. }while(false);" with many ifs and gotos in it. 😀
snake5 wrote:
Rumors are useless here. 🙂
The only way to get the correct information about something is to test it.
Anyway, even if they're slower, they're much easier to use - if you don't like switch, you would have to use "do{ .. }while(false);" with many ifs and gotos in it. 😀


Wha? Now we're completely off topic, but why on earth would you need a do-while loop, are you just screwing with me now?

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