Convex Cast

I created a patch to do convex casts: ray-casts that cast a convex shape over a path instead of a ray. There's lots of room for optimization, but it seems to perform reasonably well. I'm posting here for suggestions on API improvements and for help with a bug.

The ConvexCast function is added to b2World.h:
Code:
void ConvexCast(b2ConvexCastCallback* callback,
    const b2Shape* shape,
    const b2Transform& xf1,
    const b2Transform& xf2) const;

And the callback is in b2WorldCallbacks.h:
Code:
virtual float32 ReportFixture(
    b2Fixture* fixture, const b2Shape* shape,
    const b2Transform& xf, const b2Vec2& point,
    const b2Vec2& normal, float32 fraction) = 0;



I've run into a bug that may be related to the use of b2TimeOfImpact. I get a lot of false positives for collisions. When a fixture should be detected by the cast, it reports the intersection correctly, but it will also report a hit way off on the sides (much larger than radii). I only report a hit when I see e_touching, so I find this behavior odd.

Should b2TimeOfImpact show lots of error over larger distances? Perhaps it assumes overlap at t=1?
Yes, convex casting is possible using b2World::QueryAABB and b2TimeOfImpact.

If you find an incorrect result with b2TimeOfImpact, please file an issue with enough data to reproduce the problem:
http://code.google.com/p/box2d/issues/list
OK, it turns out it was a problem with using b2TimeOfImpact over large distances. Once this issue is resolved, the patch will work 100%.
I was thinking about this myself, but along different lines from either of you. Like raycasts are done loosely against the broadphase, and then accurately, wouldn't it make sense to provided AABB-casts for loose queries, and then b2TimeOfImpact for the accurate part.

Because AABB casts are sort of a generalization of QueryAABB and Raycast.
Yes, an AABB cast in the dynamic tree would speed up long shape casts. In my experience shape casts are usually short, so the gain would be for a niche case. Nevertheless, if shape casts become a bottleneck for someone, they should file an issue.

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