Debian Codegraph @

src/cpSpaceQuery.c

raw symbols SCIP
1 /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 * SOFTWARE.
20 */
21
22 #include "chipmunk/chipmunk_private.h"cxx . . $ `<file>/include/chipmunk/chipmunk_private.h`/
23
24 //MARK: Nearest Point Query Functions
25
26 struct PointQueryContextcxx . . $ PointQueryContext# {
27 cpVectcxx . . $ cpVect# pointcxx . . $ PointQueryContext#point.;
28 cpFloatcxx . . $ cpFloat# maxDistancecxx . . $ PointQueryContext#maxDistance.;
29 cpShapeFiltercxx . . $ cpShapeFilter# filtercxx . . $ PointQueryContext#filter.;
30 cpSpacePointQueryFunccxx . . $ cpSpacePointQueryFunc# funccxx . . $ PointQueryContext#func.;
31 };
32
33 static cpCollisionIDcxx . . $ cpCollisionID#
34 NearestPointQuerycxx . . $ NearestPointQuery(d7826b5d12ce6bbc).(struct PointQueryContextcxx . . $ PointQueryContext# *context, cpShapecxx . . $ cpShape# *shape, cpCollisionIDcxx . . $ cpCollisionID# id, void *data)
35 {
36 if(
37 !cpShapeFilterRejectcxx . . $ cpShapeFilterReject(ceeed05db6a03aa5).(shape->filtercxx . . $ cpShape#filter., context->filtercxx . . $ PointQueryContext#filter.)
38 ){
39 cpPointQueryInfocxx . . $ cpPointQueryInfo# info;
40 cpShapePointQuerycxx . . $ cpShapePointQuery(fba695676919fb41).(shape, context->pointcxx . . $ PointQueryContext#point., &info);
41
42 if(info.shapecxx . . $ cpPointQueryInfo#shape. && info.distancecxx . . $ cpPointQueryInfo#distance. < context->maxDistancecxx . . $ PointQueryContext#maxDistance.) context->funccxx . . $ PointQueryContext#func.(shape, info.pointcxx . . $ cpPointQueryInfo#point., info.distancecxx . . $ cpPointQueryInfo#distance., info.gradientcxx . . $ cpPointQueryInfo#gradient., data);
43 }
44
45 return id;
46 }
47
48 void
49 cpSpacePointQuerycxx . . $ cpSpacePointQuery(f29d3a38a73ac9fd).(cpSpacecxx . . $ cpSpace# *space, cpVectcxx . . $ cpVect# point, cpFloatcxx . . $ cpFloat# maxDistance, cpShapeFiltercxx . . $ cpShapeFilter# filter, cpSpacePointQueryFunccxx . . $ cpSpacePointQueryFunc# func, void *data)
50 {
51 struct PointQueryContextcxx . . $ PointQueryContext# context = {point, maxDistance, filter, func};
52 cpBBcxx . . $ cpBB# bb = cpBBNewForCirclecxx . . $ cpBBNewForCircle(3659726deb36ce15).(point, cpfmaxcxx . . $ cpfmax(d8e7e0733fa41c87).(maxDistance, 0.0f));
53
54 cpSpaceLockcxx . . $ cpSpaceLock(728b9c9a69722ef8).(space); {
55 cpSpatialIndexQuerycxx . . $ cpSpatialIndexQuery(98cec8d8ff387e12).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., &context, bb, (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)NearestPointQuerycxx . . $ NearestPointQuery(d7826b5d12ce6bbc)., data);
56 cpSpatialIndexQuerycxx . . $ cpSpatialIndexQuery(98cec8d8ff387e12).(space->staticShapescxx . . $ cpSpace#staticShapes., &context, bb, (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)NearestPointQuerycxx . . $ NearestPointQuery(d7826b5d12ce6bbc)., data);
57 } cpSpaceUnlockcxx . . $ cpSpaceUnlock(67df6f6b25fde2).(space, cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!);
58 }
59
60 static cpCollisionIDcxx . . $ cpCollisionID#
61 NearestPointQueryNearestcxx . . $ NearestPointQueryNearest(b0d0e68889762f6b).(struct PointQueryContextcxx . . $ PointQueryContext# *context, cpShapecxx . . $ cpShape# *shape, cpCollisionIDcxx . . $ cpCollisionID# id, cpPointQueryInfocxx . . $ cpPointQueryInfo# *out)
62 {
63 if(
64 !cpShapeFilterRejectcxx . . $ cpShapeFilterReject(ceeed05db6a03aa5).(shape->filtercxx . . $ cpShape#filter., context->filtercxx . . $ PointQueryContext#filter.) && !shape->sensorcxx . . $ cpShape#sensor.
65 ){
66 cpPointQueryInfocxx . . $ cpPointQueryInfo# info;
67 cpShapePointQuerycxx . . $ cpShapePointQuery(fba695676919fb41).(shape, context->pointcxx . . $ PointQueryContext#point., &info);
68
69 if(info.distancecxx . . $ cpPointQueryInfo#distance. < out->distancecxx . . $ cpPointQueryInfo#distance.) (*out) = info;
70 }
71
72 return id;
73 }
74
75 cpShapecxx . . $ cpShape# *
76 cpSpacePointQueryNearestcxx . . $ cpSpacePointQueryNearest(b0e549d484789d).(cpSpacecxx . . $ cpSpace# *space, cpVectcxx . . $ cpVect# point, cpFloatcxx . . $ cpFloat# maxDistance, cpShapeFiltercxx . . $ cpShapeFilter# filter, cpPointQueryInfocxx . . $ cpPointQueryInfo# *out)
77 {
78 cpPointQueryInfocxx . . $ cpPointQueryInfo# info = {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, cpvzerocxx . . $ cpvzero., maxDistance, cpvzerocxx . . $ cpvzero.};
79 if(out){
80 (*out) = info;
81 } else {
82 out = &info;
83 }
84
85 struct PointQueryContextcxx . . $ PointQueryContext# context = {
86 point, maxDistance,
87 filter,
88 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!
89 };
90
91 cpBBcxx . . $ cpBB# bb = cpBBNewForCirclecxx . . $ cpBBNewForCircle(3659726deb36ce15).(point, cpfmaxcxx . . $ cpfmax(d8e7e0733fa41c87).(maxDistance, 0.0f));
92 cpSpatialIndexQuerycxx . . $ cpSpatialIndexQuery(98cec8d8ff387e12).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., &context, bb, (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)NearestPointQueryNearestcxx . . $ NearestPointQueryNearest(b0d0e68889762f6b)., out);
93 cpSpatialIndexQuerycxx . . $ cpSpatialIndexQuery(98cec8d8ff387e12).(space->staticShapescxx . . $ cpSpace#staticShapes., &context, bb, (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)NearestPointQueryNearestcxx . . $ NearestPointQueryNearest(b0d0e68889762f6b)., out);
94
95 return (cpShapecxx . . $ cpShape# *)out->shapecxx . . $ cpPointQueryInfo#shape.;
96 }
97
98
99 //MARK: Segment Query Functions
100
101 struct SegmentQueryContextcxx . . $ SegmentQueryContext# {
102 cpVectcxx . . $ cpVect# startcxx . . $ SegmentQueryContext#start., endcxx . . $ SegmentQueryContext#end.;
103 cpFloatcxx . . $ cpFloat# radiuscxx . . $ SegmentQueryContext#radius.;
104 cpShapeFiltercxx . . $ cpShapeFilter# filtercxx . . $ SegmentQueryContext#filter.;
105 cpSpaceSegmentQueryFunccxx . . $ cpSpaceSegmentQueryFunc# funccxx . . $ SegmentQueryContext#func.;
106 };
107
108 static cpFloatcxx . . $ cpFloat#
109 SegmentQuerycxx . . $ SegmentQuery(333b94703fabc924).(struct SegmentQueryContextcxx . . $ SegmentQueryContext# *context, cpShapecxx . . $ cpShape# *shape, void *data)
110 {
111 cpSegmentQueryInfocxx . . $ cpSegmentQueryInfo# info;
112
113 if(
114 !cpShapeFilterRejectcxx . . $ cpShapeFilterReject(ceeed05db6a03aa5).(shape->filtercxx . . $ cpShape#filter., context->filtercxx . . $ SegmentQueryContext#filter.) &&
115 cpShapeSegmentQuerycxx . . $ cpShapeSegmentQuery(b386381aae6390da).(shape, context->startcxx . . $ SegmentQueryContext#start., context->endcxx . . $ SegmentQueryContext#end., context->radiuscxx . . $ SegmentQueryContext#radius., &info)
116 ){
117 context->funccxx . . $ SegmentQueryContext#func.(shape, info.pointcxx . . $ cpSegmentQueryInfo#point., info.normalcxx . . $ cpSegmentQueryInfo#normal., info.alphacxx . . $ cpSegmentQueryInfo#alpha., data);
118 }
119
120 return 1.0f;
121 }
122
123 void
124 cpSpaceSegmentQuerycxx . . $ cpSpaceSegmentQuery(f0c0ce39a75d406e).(cpSpacecxx . . $ cpSpace# *space, cpVectcxx . . $ cpVect# start, cpVectcxx . . $ cpVect# end, cpFloatcxx . . $ cpFloat# radius, cpShapeFiltercxx . . $ cpShapeFilter# filter, cpSpaceSegmentQueryFunccxx . . $ cpSpaceSegmentQueryFunc# func, void *data)
125 {
126 struct SegmentQueryContextcxx . . $ SegmentQueryContext# context = {
127 start, end,
128 radius,
129 filter,
130 func,
131 };
132
133 cpSpaceLockcxx . . $ cpSpaceLock(728b9c9a69722ef8).(space); {
134 cpSpatialIndexSegmentQuerycxx . . $ cpSpatialIndexSegmentQuery(df419dda02f85b8f).(space->staticShapescxx . . $ cpSpace#staticShapes., &context, start, end, 1.0f, (cpSpatialIndexSegmentQueryFunccxx . . $ cpSpatialIndexSegmentQueryFunc#)SegmentQuerycxx . . $ SegmentQuery(333b94703fabc924)., data);
135 cpSpatialIndexSegmentQuerycxx . . $ cpSpatialIndexSegmentQuery(df419dda02f85b8f).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., &context, start, end, 1.0f, (cpSpatialIndexSegmentQueryFunccxx . . $ cpSpatialIndexSegmentQueryFunc#)SegmentQuerycxx . . $ SegmentQuery(333b94703fabc924)., data);
136 } cpSpaceUnlockcxx . . $ cpSpaceUnlock(67df6f6b25fde2).(space, cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!);
137 }
138
139 static cpFloatcxx . . $ cpFloat#
140 SegmentQueryFirstcxx . . $ SegmentQueryFirst(92263a2544a6c10c).(struct SegmentQueryContextcxx . . $ SegmentQueryContext# *context, cpShapecxx . . $ cpShape# *shape, cpSegmentQueryInfocxx . . $ cpSegmentQueryInfo# *out)
141 {
142 cpSegmentQueryInfocxx . . $ cpSegmentQueryInfo# info;
143
144 if(
145 !cpShapeFilterRejectcxx . . $ cpShapeFilterReject(ceeed05db6a03aa5).(shape->filtercxx . . $ cpShape#filter., context->filtercxx . . $ SegmentQueryContext#filter.) && !shape->sensorcxx . . $ cpShape#sensor. &&
146 cpShapeSegmentQuerycxx . . $ cpShapeSegmentQuery(b386381aae6390da).(shape, context->startcxx . . $ SegmentQueryContext#start., context->endcxx . . $ SegmentQueryContext#end., context->radiuscxx . . $ SegmentQueryContext#radius., &info) &&
147 info.alphacxx . . $ cpSegmentQueryInfo#alpha. < out->alphacxx . . $ cpSegmentQueryInfo#alpha.
148 ){
149 (*out) = info;
150 }
151
152 return out->alphacxx . . $ cpSegmentQueryInfo#alpha.;
153 }
154
155 cpShapecxx . . $ cpShape# *
156 cpSpaceSegmentQueryFirstcxx . . $ cpSpaceSegmentQueryFirst(e8de41ced5effca2).(cpSpacecxx . . $ cpSpace# *space, cpVectcxx . . $ cpVect# start, cpVectcxx . . $ cpVect# end, cpFloatcxx . . $ cpFloat# radius, cpShapeFiltercxx . . $ cpShapeFilter# filter, cpSegmentQueryInfocxx . . $ cpSegmentQueryInfo# *out)
157 {
158 cpSegmentQueryInfocxx . . $ cpSegmentQueryInfo# info = {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, end, cpvzerocxx . . $ cpvzero., 1.0f};
159 if(out){
160 (*out) = info;
161 } else {
162 out = &info;
163 }
164
165 struct SegmentQueryContextcxx . . $ SegmentQueryContext# context = {
166 start, end,
167 radius,
168 filter,
169 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!
170 };
171
172 cpSpatialIndexSegmentQuerycxx . . $ cpSpatialIndexSegmentQuery(df419dda02f85b8f).(space->staticShapescxx . . $ cpSpace#staticShapes., &context, start, end, 1.0f, (cpSpatialIndexSegmentQueryFunccxx . . $ cpSpatialIndexSegmentQueryFunc#)SegmentQueryFirstcxx . . $ SegmentQueryFirst(92263a2544a6c10c)., out);
173 cpSpatialIndexSegmentQuerycxx . . $ cpSpatialIndexSegmentQuery(df419dda02f85b8f).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., &context, start, end, out->alphacxx . . $ cpSegmentQueryInfo#alpha., (cpSpatialIndexSegmentQueryFunccxx . . $ cpSpatialIndexSegmentQueryFunc#)SegmentQueryFirstcxx . . $ SegmentQueryFirst(92263a2544a6c10c)., out);
174
175 return (cpShapecxx . . $ cpShape# *)out->shapecxx . . $ cpSegmentQueryInfo#shape.;
176 }
177
178 //MARK: BB Query Functions
179
180 struct BBQueryContextcxx . . $ BBQueryContext# {
181 cpBBcxx . . $ cpBB# bbcxx . . $ BBQueryContext#bb.;
182 cpShapeFiltercxx . . $ cpShapeFilter# filtercxx . . $ BBQueryContext#filter.;
183 cpSpaceBBQueryFunccxx . . $ cpSpaceBBQueryFunc# funccxx . . $ BBQueryContext#func.;
184 };
185
186 static cpCollisionIDcxx . . $ cpCollisionID#
187 BBQuerycxx . . $ BBQuery(3dd4aa54e1e2988e).(struct BBQueryContextcxx . . $ BBQueryContext# *context, cpShapecxx . . $ cpShape# *shape, cpCollisionIDcxx . . $ cpCollisionID# id, void *data)
188 {
189 if(
190 !cpShapeFilterRejectcxx . . $ cpShapeFilterReject(ceeed05db6a03aa5).(shape->filtercxx . . $ cpShape#filter., context->filtercxx . . $ BBQueryContext#filter.) &&
191 cpBBIntersectscxx . . $ cpBBIntersects(aa08641fa2db23dc).(context->bbcxx . . $ BBQueryContext#bb., shape->bbcxx . . $ cpShape#bb.)
192 ){
193 context->funccxx . . $ BBQueryContext#func.(shape, data);
194 }
195
196 return id;
197 }
198
199 void
200 cpSpaceBBQuerycxx . . $ cpSpaceBBQuery(edce504918bdb151).(cpSpacecxx . . $ cpSpace# *space, cpBBcxx . . $ cpBB# bb, cpShapeFiltercxx . . $ cpShapeFilter# filter, cpSpaceBBQueryFunccxx . . $ cpSpaceBBQueryFunc# func, void *data)
201 {
202 struct BBQueryContextcxx . . $ BBQueryContext# context = {bb, filter, func};
203
204 cpSpaceLockcxx . . $ cpSpaceLock(728b9c9a69722ef8).(space); {
205 cpSpatialIndexQuerycxx . . $ cpSpatialIndexQuery(98cec8d8ff387e12).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., &context, bb, (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)BBQuerycxx . . $ BBQuery(3dd4aa54e1e2988e)., data);
206 cpSpatialIndexQuerycxx . . $ cpSpatialIndexQuery(98cec8d8ff387e12).(space->staticShapescxx . . $ cpSpace#staticShapes., &context, bb, (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)BBQuerycxx . . $ BBQuery(3dd4aa54e1e2988e)., data);
207 } cpSpaceUnlockcxx . . $ cpSpaceUnlock(67df6f6b25fde2).(space, cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!);
208 }
209
210 //MARK: Shape Query Functions
211
212 struct ShapeQueryContextcxx . . $ ShapeQueryContext# {
213 cpSpaceShapeQueryFunccxx . . $ cpSpaceShapeQueryFunc# funccxx . . $ ShapeQueryContext#func.;
214 void *datacxx . . $ ShapeQueryContext#data.;
215 cpBoolcxx . . $ cpBool# anyCollisioncxx . . $ ShapeQueryContext#anyCollision.;
216 };
217
218 // Callback from the spatial hash.
219 static cpCollisionIDcxx . . $ cpCollisionID#
220 ShapeQuerycxx . . $ ShapeQuery(46f202055f9a7f86).(cpShapecxx . . $ cpShape# *a, cpShapecxx . . $ cpShape# *b, cpCollisionIDcxx . . $ cpCollisionID# id, struct ShapeQueryContextcxx . . $ ShapeQueryContext# *context)
221 {
222 if(cpShapeFilterRejectcxx . . $ cpShapeFilterReject(ceeed05db6a03aa5).(a->filtercxx . . $ cpShape#filter., b->filtercxx . . $ cpShape#filter.) || a == b) return id;
223
224 cpContactPointSetcxx . . $ cpContactPointSet# set = cpShapesCollidecxx . . $ cpShapesCollide(f75c4ecc6571f5c9).(a, b);
225 if(set.countcxx . . $ cpContactPointSet#count.){
226 if(context->funccxx . . $ ShapeQueryContext#func.) context->funccxx . . $ ShapeQueryContext#func.(b, &set, context->datacxx . . $ ShapeQueryContext#data.);
227 context->anyCollisioncxx . . $ ShapeQueryContext#anyCollision. = !(a->sensorcxx . . $ cpShape#sensor. || b->sensorcxx . . $ cpShape#sensor.);
228 }
229
230 return id;
231 }
232
233 cpBoolcxx . . $ cpBool#
234 cpSpaceShapeQuerycxx . . $ cpSpaceShapeQuery(3c0ac7bdb14b7ab7).(cpSpacecxx . . $ cpSpace# *space, cpShapecxx . . $ cpShape# *shape, cpSpaceShapeQueryFunccxx . . $ cpSpaceShapeQueryFunc# func, void *data)
235 {
236 cpBodycxx . . $ cpBody# *body = shape->bodycxx . . $ cpShape#body.;
237 cpBBcxx . . $ cpBB# bb = (body ? cpShapeUpdatecxx . . $ cpShapeUpdate(67a5b3d30c6115fd).(shape, body->transformcxx . . $ cpBody#transform.) : shape->bbcxx . . $ cpShape#bb.);
238 struct ShapeQueryContextcxx . . $ ShapeQueryContext# context = {func, data, cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!};
239
240 cpSpaceLockcxx . . $ cpSpaceLock(728b9c9a69722ef8).(space); {
241 cpSpatialIndexQuerycxx . . $ cpSpatialIndexQuery(98cec8d8ff387e12).(space->dynamicShapescxx . . $ cpSpace#dynamicShapes., shape, bb, (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)ShapeQuerycxx . . $ ShapeQuery(46f202055f9a7f86)., &context);
242 cpSpatialIndexQuerycxx . . $ cpSpatialIndexQuery(98cec8d8ff387e12).(space->staticShapescxx . . $ cpSpace#staticShapes., shape, bb, (cpSpatialIndexQueryFunccxx . . $ cpSpatialIndexQueryFunc#)ShapeQuerycxx . . $ ShapeQuery(46f202055f9a7f86)., &context);
243 } cpSpaceUnlockcxx . . $ cpSpaceUnlock(67df6f6b25fde2).(space, cpTruecxx . . $ `include/chipmunk/chipmunk_types.h:183:10`!);
244
245 return context.anyCollisioncxx . . $ ShapeQueryContext#anyCollision.;
246 }