| 73 | } |
| 74 | |
| 75 | cpShape * |
| 76 | cpSpacePointQueryNearest(cpSpace *space, cpVect point, cpFloat maxDistance, cpShapeFilter filter, cpPointQueryInfo *out) |
| 77 | { |
| 78 | cpPointQueryInfo info = {NULL, cpvzero, maxDistance, cpvzero}; |
| 79 | if(out){ |
| 80 | (*out) = info; |
| 81 | } else { |
| 82 | out = &info; |
| 83 | } |
| 84 | |
| 85 | struct PointQueryContext context = { |
| 86 | point, maxDistance, |
| 87 | filter, |
| 88 | NULL |
| 89 | }; |
| 90 | |
| 91 | cpBB bb = cpBBNewForCircle(point, cpfmax(maxDistance, 0.0f)); |
| 92 | cpSpatialIndexQuery(space->dynamicShapes, &context, bb, (cpSpatialIndexQueryFunc)NearestPointQueryNearest, out); |
| 93 | cpSpatialIndexQuery(space->staticShapes, &context, bb, (cpSpatialIndexQueryFunc)NearestPointQueryNearest, out); |
| 94 | |
| 95 | return (cpShape *)out->shape; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | //MARK: Segment Query Functions |