slembcke/Chipmunk2D

Segment query returns incorrect point at alpha=0

Troid92 opened this issue · 0 comments

If you do a segment query from point A to point B, and there is a shape covering point A that the query intersects, it will call for that shape at point B instead of point A.
Here's the simplest reproduction I could come up with in C:

#include <chipmunk/chipmunk.h>
void foundShape(cpShape*, cpVect point, cpVect, cpFloat alpha, void*) {
    printf("Found shape at (%g,%g) with alpha=%g",point.x,point.y,alpha);
}
int main() {
    cpSpace* space = nmGetPhysicsWorld();
    cpBody* body = cpSpaceGetStaticBody(space);
    cpSpaceAddShape(space, cpCircleShapeNew(body, 1.0, cpvzero));
    cpSpaceSegmentQuery(space,cpv(0.0,0.0),cpv(5.0,5.0), 0.0, CP_SHAPE_FILTER_ALL, &foundShape, NULL);
    return 0;
}

The output is Found shape at (5,5) with alpha=0.
It should be Found shape at (0,0) with alpha=0.
Might be worth checking other query types for similar edge cases.