Debian Codegraph @

src/cpPolyShape.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 #include "chipmunk/chipmunk_unsafe.h"cxx . . $ `<file>/include/chipmunk/chipmunk_unsafe.h`/
24
25 cpPolyShapecxx . . $ cpPolyShape# *
26 cpPolyShapeAlloccxx . . $ cpPolyShapeAlloc(3ef3cc9382c7ba3b).(void)
27 {
28 return (cpPolyShapecxx . . $ cpPolyShape# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, sizeof(cpPolyShapecxx . . $ cpPolyShape#));
29 }
30
31 static void
32 cpPolyShapeDestroycxx . . $ cpPolyShapeDestroy(9e5954eb97ba7ffd).(cpPolyShapecxx . . $ cpPolyShape# *poly)
33 {
34 if(poly->countcxx . . $ cpPolyShape#count. > CP_POLY_SHAPE_INLINE_ALLOCcxx . . $ `include/chipmunk/chipmunk_structs.h:223:9`!){
35 cpfreecxx . . $ `include/chipmunk/chipmunk.h:82:10`!(poly->planescxx . . $ cpPolyShape#planes.);
36 }
37 }
38
39 static cpBBcxx . . $ cpBB#
40 cpPolyShapeCacheDatacxx . . $ cpPolyShapeCacheData(5448ad0e02f7dd7b).(cpPolyShapecxx . . $ cpPolyShape# *poly, cpTransformcxx . . $ cpTransform# transform)
41 {
42 int count = poly->countcxx . . $ cpPolyShape#count.;
43 struct cpSplittingPlanecxx . . $ cpSplittingPlane# *dst = poly->planescxx . . $ cpPolyShape#planes.;
44 struct cpSplittingPlanecxx . . $ cpSplittingPlane# *src = dst + count;
45
46 cpFloatcxx . . $ cpFloat# l = (cpFloatcxx . . $ cpFloat#)INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!, r = -(cpFloatcxx . . $ cpFloat#)INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!;
47 cpFloatcxx . . $ cpFloat# b = (cpFloatcxx . . $ cpFloat#)INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!, t = -(cpFloatcxx . . $ cpFloat#)INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!;
48
49 for(int i=0; i<count; i++){
50 cpVectcxx . . $ cpVect# v = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(transform, src[i].v0cxx . . $ cpSplittingPlane#v0.);
51 cpVectcxx . . $ cpVect# n = cpTransformVectcxx . . $ cpTransformVect(7fc9e234cc6e750a).(transform, src[i].ncxx . . $ cpSplittingPlane#n.);
52
53 dst[i].v0cxx . . $ cpSplittingPlane#v0. = v;
54 dst[i].ncxx . . $ cpSplittingPlane#n. = n;
55
56 l = cpfmincxx . . $ cpfmin(d8e7e0733fa41c87).(l, v.xcxx . . $ cpVect#x.);
57 r = cpfmaxcxx . . $ cpfmax(d8e7e0733fa41c87).(r, v.xcxx . . $ cpVect#x.);
58 b = cpfmincxx . . $ cpfmin(d8e7e0733fa41c87).(b, v.ycxx . . $ cpVect#y.);
59 t = cpfmaxcxx . . $ cpfmax(d8e7e0733fa41c87).(t, v.ycxx . . $ cpVect#y.);
60 }
61
62 cpFloatcxx . . $ cpFloat# radius = poly->rcxx . . $ cpPolyShape#r.;
63 return (poly->shapecxx . . $ cpPolyShape#shape..bbcxx . . $ cpShape#bb. = cpBBNewcxx . . $ cpBBNew(f05aa3203068e6d3).(l - radius, b - radius, r + radius, t + radius));
64 }
65
66 static void
67 cpPolyShapePointQuerycxx . . $ cpPolyShapePointQuery(6788d1f7090e90fb).(cpPolyShapecxx . . $ cpPolyShape# *poly, cpVectcxx . . $ cpVect# p, cpPointQueryInfocxx . . $ cpPointQueryInfo# *info){
68 int count = poly->countcxx . . $ cpPolyShape#count.;
69 struct cpSplittingPlanecxx . . $ cpSplittingPlane# *planes = poly->planescxx . . $ cpPolyShape#planes.;
70 cpFloatcxx . . $ cpFloat# r = poly->rcxx . . $ cpPolyShape#r.;
71
72 cpVectcxx . . $ cpVect# v0 = planes[count - 1].v0cxx . . $ cpSplittingPlane#v0.;
73 cpFloatcxx . . $ cpFloat# minDist = INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!;
74 cpVectcxx . . $ cpVect# closestPoint = cpvzerocxx . . $ cpvzero.;
75 cpVectcxx . . $ cpVect# closestNormal = cpvzerocxx . . $ cpvzero.;
76 cpBoolcxx . . $ cpBool# outside = cpFalsecxx . . $ `include/chipmunk/chipmunk_types.h:188:10`!;
77
78 for(int i=0; i<count; i++){
79 cpVectcxx . . $ cpVect# v1 = planes[i].v0cxx . . $ cpSplittingPlane#v0.;
80 outside = outside || (cpvdotcxx . . $ cpvdot(7d57c1c4dd559d53).(planes[i].ncxx . . $ cpSplittingPlane#n., cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(p,v1)) > 0.0f);
81
82 cpVectcxx . . $ cpVect# closest = cpClosetPointOnSegmentcxx . . $ cpClosetPointOnSegment(7c4544d786004357).(p, v0, v1);
83
84 cpFloatcxx . . $ cpFloat# dist = cpvdistcxx . . $ cpvdist(7d57c1c4dd559d53).(p, closest);
85 if(dist < minDist){
86 minDist = dist;
87 closestPoint = closest;
88 closestNormal = planes[i].ncxx . . $ cpSplittingPlane#n.;
89 }
90
91 v0 = v1;
92 }
93
94 cpFloatcxx . . $ cpFloat# dist = (outside ? minDist : -minDist);
95 cpVectcxx . . $ cpVect# g = cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(p, closestPoint), 1.0f/dist);
96
97 info->shapecxx . . $ cpPointQueryInfo#shape. = (cpShapecxx . . $ cpShape# *)poly;
98 info->pointcxx . . $ cpPointQueryInfo#point. = cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(closestPoint, cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(g, r));
99 info->distancecxx . . $ cpPointQueryInfo#distance. = dist - r;
100
101 // Use the normal of the closest segment if the distance is small.
102 info->gradientcxx . . $ cpPointQueryInfo#gradient. = (minDist > MAGIC_EPSILONcxx . . $ `include/chipmunk/chipmunk_private.h:32:9`! ? g : closestNormal);
103 }
104
105 static void
106 cpPolyShapeSegmentQuerycxx . . $ cpPolyShapeSegmentQuery(107e9a6a08f603a9).(cpPolyShapecxx . . $ cpPolyShape# *poly, cpVectcxx . . $ cpVect# a, cpVectcxx . . $ cpVect# b, cpFloatcxx . . $ cpFloat# r2, cpSegmentQueryInfocxx . . $ cpSegmentQueryInfo# *info)
107 {
108 struct cpSplittingPlanecxx . . $ cpSplittingPlane# *planes = poly->planescxx . . $ cpPolyShape#planes.;
109 int count = poly->countcxx . . $ cpPolyShape#count.;
110 cpFloatcxx . . $ cpFloat# r = poly->rcxx . . $ cpPolyShape#r.;
111 cpFloatcxx . . $ cpFloat# rsum = r + r2;
112
113 for(int i=0; i<count; i++){
114 cpVectcxx . . $ cpVect# n = planes[i].ncxx . . $ cpSplittingPlane#n.;
115 cpFloatcxx . . $ cpFloat# an = cpvdotcxx . . $ cpvdot(7d57c1c4dd559d53).(a, n);
116 cpFloatcxx . . $ cpFloat# d = an - cpvdotcxx . . $ cpvdot(7d57c1c4dd559d53).(planes[i].v0cxx . . $ cpSplittingPlane#v0., n) - rsum;
117 if(d < 0.0f) continue;
118
119 cpFloatcxx . . $ cpFloat# bn = cpvdotcxx . . $ cpvdot(7d57c1c4dd559d53).(b, n);
120 cpFloatcxx . . $ cpFloat# t = d/(an - bn);
121 if(t < 0.0f || 1.0f < t) continue;
122
123 cpVectcxx . . $ cpVect# point = cpvlerpcxx . . $ cpvlerp(12b05c0b9acd6d4b).(a, b, t);
124 cpFloatcxx . . $ cpFloat# dt = cpvcrosscxx . . $ cpvcross(7d57c1c4dd559d53).(n, point);
125 cpFloatcxx . . $ cpFloat# dtMin = cpvcrosscxx . . $ cpvcross(7d57c1c4dd559d53).(n, planes[(i - 1 + count)%count].v0cxx . . $ cpSplittingPlane#v0.);
126 cpFloatcxx . . $ cpFloat# dtMax = cpvcrosscxx . . $ cpvcross(7d57c1c4dd559d53).(n, planes[i].v0cxx . . $ cpSplittingPlane#v0.);
127
128 if(dtMin <= dt && dt <= dtMax){
129 info->shapecxx . . $ cpSegmentQueryInfo#shape. = (cpShapecxx . . $ cpShape# *)poly;
130 info->pointcxx . . $ cpSegmentQueryInfo#point. = cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(cpvlerpcxx . . $ cpvlerp(12b05c0b9acd6d4b).(a, b, t), cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(n, r2));
131 info->normalcxx . . $ cpSegmentQueryInfo#normal. = n;
132 info->alphacxx . . $ cpSegmentQueryInfo#alpha. = t;
133 }
134 }
135
136 // Also check against the beveled vertexes.
137 if(rsum > 0.0f){
138 for(int i=0; i<count; i++){
139 cpSegmentQueryInfocxx . . $ cpSegmentQueryInfo# circle_info = {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, b, cpvzerocxx . . $ cpvzero., 1.0f};
140 CircleSegmentQuerycxx . . $ CircleSegmentQuery(bf928cae3d166851).(&poly->shapecxx . . $ cpPolyShape#shape., planes[i].v0cxx . . $ cpSplittingPlane#v0., r, a, b, r2, &circle_info);
141 if(circle_info.alphacxx . . $ cpSegmentQueryInfo#alpha. < info->alphacxx . . $ cpSegmentQueryInfo#alpha.) (*info) = circle_info;
142 }
143 }
144 }
145
146 static void
147 SetVertscxx . . $ SetVerts(81a89784553bd105).(cpPolyShapecxx . . $ cpPolyShape# *poly, int count, const cpVectcxx . . $ cpVect# *verts)
148 {
149 poly->countcxx . . $ cpPolyShape#count. = count;
150 if(count <= CP_POLY_SHAPE_INLINE_ALLOCcxx . . $ `include/chipmunk/chipmunk_structs.h:223:9`!){
151 poly->planescxx . . $ cpPolyShape#planes. = poly->_planescxx . . $ cpPolyShape#_planes.;
152 } else {
153 poly->planescxx . . $ cpPolyShape#planes. = (struct cpSplittingPlanecxx . . $ cpSplittingPlane# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(2*count, sizeof(struct cpSplittingPlanecxx . . $ cpSplittingPlane#));
154 }
155
156 for(int i=0; i<count; i++){
157 cpVectcxx . . $ cpVect# a = verts[(i - 1 + count)%count];
158 cpVectcxx . . $ cpVect# b = verts[i];
159 cpVectcxx . . $ cpVect# n = cpvnormalizecxx . . $ cpvnormalize(e06142a62109ae08).(cpvrperpcxx . . $ cpvrperp(e06142a62109ae08).(cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(b, a)));
160
161 poly->planescxx . . $ cpPolyShape#planes.[i + count].v0cxx . . $ cpSplittingPlane#v0. = b;
162 poly->planescxx . . $ cpPolyShape#planes.[i + count].ncxx . . $ cpSplittingPlane#n. = n;
163 }
164 }
165
166 static struct cpShapeMassInfocxx . . $ cpShapeMassInfo#
167 cpPolyShapeMassInfocxx . . $ cpPolyShapeMassInfo(da09f97bbd04a176).(cpFloatcxx . . $ cpFloat# mass, int count, const cpVectcxx . . $ cpVect# *verts, cpFloatcxx . . $ cpFloat# radius)
168 {
169 // TODO moment is approximate due to radius.
170
171 cpVectcxx . . $ cpVect# centroid = cpCentroidForPolycxx . . $ cpCentroidForPoly(740f059a8e4cff9d).(count, verts);
172 struct cpShapeMassInfocxx . . $ cpShapeMassInfo# info = {
173 mass, cpMomentForPolycxx . . $ cpMomentForPoly(89d843ff16ae6b28).(1.0f, count, verts, cpvnegcxx . . $ cpvneg(e06142a62109ae08).(centroid), radius),
174 centroid,
175 cpAreaForPolycxx . . $ cpAreaForPoly(c1e6bc8c2660eac5).(count, verts, radius),
176 };
177
178 return info;
179 }
180
181 static const cpShapeClasscxx . . $ cpShapeClass# polyClasscxx . . $ polyClass. = {
182 CP_POLY_SHAPEcxx . . $ CP_POLY_SHAPE.,
183 (cpShapeCacheDataImplcxx . . $ cpShapeCacheDataImpl#)cpPolyShapeCacheDatacxx . . $ cpPolyShapeCacheData(5448ad0e02f7dd7b).,
184 (cpShapeDestroyImplcxx . . $ cpShapeDestroyImpl#)cpPolyShapeDestroycxx . . $ cpPolyShapeDestroy(9e5954eb97ba7ffd).,
185 (cpShapePointQueryImplcxx . . $ cpShapePointQueryImpl#)cpPolyShapePointQuerycxx . . $ cpPolyShapePointQuery(6788d1f7090e90fb).,
186 (cpShapeSegmentQueryImplcxx . . $ cpShapeSegmentQueryImpl#)cpPolyShapeSegmentQuerycxx . . $ cpPolyShapeSegmentQuery(107e9a6a08f603a9).,
187 };
188
189 cpPolyShapecxx . . $ cpPolyShape# *
190 cpPolyShapeInitcxx . . $ cpPolyShapeInit(489c25036f1c8ccc).(cpPolyShapecxx . . $ cpPolyShape# *poly, cpBodycxx . . $ cpBody# *body, int count, const cpVectcxx . . $ cpVect# *verts, cpTransformcxx . . $ cpTransform# transform, cpFloatcxx . . $ cpFloat# radius)
191 {
192 cpVectcxx . . $ cpVect# *hullVerts = (cpVectcxx . . $ cpVect# *)allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(count*sizeof(cpVect));
193
194 // Transform the verts before building the hull in case of a negative scale.
195 for(int i=0; i<count; i++) hullVerts[i] = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(transform, verts[i]);
196
197 unsigned int hullCount = cpConvexHullcxx . . $ cpConvexHull(ca3a36ade7aeec92).(count, hullVerts, hullVerts, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0.0);
198 return cpPolyShapeInitRawcxx . . $ cpPolyShapeInitRaw(88e951e0bb760581).(poly, body, hullCount, hullVerts, radius);
199 }
200
201 cpPolyShapecxx . . $ cpPolyShape# *
202 cpPolyShapeInitRawcxx . . $ cpPolyShapeInitRaw(88e951e0bb760581).(cpPolyShapecxx . . $ cpPolyShape# *poly, cpBodycxx . . $ cpBody# *body, int count, const cpVectcxx . . $ cpVect# *verts, cpFloatcxx . . $ cpFloat# radius)
203 {
204 cpShapeInitcxx . . $ cpShapeInit(fe460fb3c2ea2ff0).((cpShapecxx . . $ cpShape# *)poly, &polyClasscxx . . $ polyClass., body, cpPolyShapeMassInfocxx . . $ cpPolyShapeMassInfo(da09f97bbd04a176).(0.0f, count, verts, radius));
205
206 SetVertscxx . . $ SetVerts(81a89784553bd105).(poly, count, verts);
207 poly->rcxx . . $ cpPolyShape#r. = radius;
208
209 return poly;
210 }
211
212 cpShapecxx . . $ cpShape# *
213 cpPolyShapeNewcxx . . $ cpPolyShapeNew(119891a3da20e8eb).(cpBodycxx . . $ cpBody# *body, int count, const cpVectcxx . . $ cpVect# *verts, cpTransformcxx . . $ cpTransform# transform, cpFloatcxx . . $ cpFloat# radius)
214 {
215 return (cpShapecxx . . $ cpShape# *)cpPolyShapeInitcxx . . $ cpPolyShapeInit(489c25036f1c8ccc).(cpPolyShapeAlloccxx . . $ cpPolyShapeAlloc(3ef3cc9382c7ba3b).(), body, count, verts, transform, radius);
216 }
217
218 cpShapecxx . . $ cpShape# *
219 cpPolyShapeNewRawcxx . . $ cpPolyShapeNewRaw(1ee7eca64f2711ec).(cpBodycxx . . $ cpBody# *body, int count, const cpVectcxx . . $ cpVect# *verts, cpFloatcxx . . $ cpFloat# radius)
220 {
221 return (cpShapecxx . . $ cpShape# *)cpPolyShapeInitRawcxx . . $ cpPolyShapeInitRaw(88e951e0bb760581).(cpPolyShapeAlloccxx . . $ cpPolyShapeAlloc(3ef3cc9382c7ba3b).(), body, count, verts, radius);
222 }
223
224 cpPolyShapecxx . . $ cpPolyShape# *
225 cpBoxShapeInitcxx . . $ cpBoxShapeInit(3e272c6816b6cddc).(cpPolyShapecxx . . $ cpPolyShape# *poly, cpBodycxx . . $ cpBody# *body, cpFloatcxx . . $ cpFloat# width, cpFloatcxx . . $ cpFloat# height, cpFloatcxx . . $ cpFloat# radius)
226 {
227 cpFloatcxx . . $ cpFloat# hw = width/2.0f;
228 cpFloatcxx . . $ cpFloat# hh = height/2.0f;
229
230 return cpBoxShapeInit2cxx . . $ cpBoxShapeInit2(d8ad8bdc0a5a2669).(poly, body, cpBBNewcxx . . $ cpBBNew(f05aa3203068e6d3).(-hw, -hh, hw, hh), radius);
231 }
232
233 cpPolyShapecxx . . $ cpPolyShape# *
234 cpBoxShapeInit2cxx . . $ cpBoxShapeInit2(d8ad8bdc0a5a2669).(cpPolyShapecxx . . $ cpPolyShape# *poly, cpBodycxx . . $ cpBody# *body, cpBBcxx . . $ cpBB# box, cpFloatcxx . . $ cpFloat# radius)
235 {
236 cpVectcxx . . $ cpVect# verts[] = {
237 cpvcxx . . $ cpv(3142d57d978b2176).(box.rcxx . . $ cpBB#r., box.bcxx . . $ cpBB#b.),
238 cpvcxx . . $ cpv(3142d57d978b2176).(box.rcxx . . $ cpBB#r., box.tcxx . . $ cpBB#t.),
239 cpvcxx . . $ cpv(3142d57d978b2176).(box.lcxx . . $ cpBB#l., box.tcxx . . $ cpBB#t.),
240 cpvcxx . . $ cpv(3142d57d978b2176).(box.lcxx . . $ cpBB#l., box.bcxx . . $ cpBB#b.),
241 };
242
243 return cpPolyShapeInitRawcxx . . $ cpPolyShapeInitRaw(88e951e0bb760581).(poly, body, 4, verts, radius);
244 }
245
246 cpShapecxx . . $ cpShape# *
247 cpBoxShapeNewcxx . . $ cpBoxShapeNew(94c4f8982441e75a).(cpBodycxx . . $ cpBody# *body, cpFloatcxx . . $ cpFloat# width, cpFloatcxx . . $ cpFloat# height, cpFloatcxx . . $ cpFloat# radius)
248 {
249 return (cpShapecxx . . $ cpShape# *)cpBoxShapeInitcxx . . $ cpBoxShapeInit(3e272c6816b6cddc).(cpPolyShapeAlloccxx . . $ cpPolyShapeAlloc(3ef3cc9382c7ba3b).(), body, width, height, radius);
250 }
251
252 cpShapecxx . . $ cpShape# *
253 cpBoxShapeNew2cxx . . $ cpBoxShapeNew2(ac0258d00568be32).(cpBodycxx . . $ cpBody# *body, cpBBcxx . . $ cpBB# box, cpFloatcxx . . $ cpFloat# radius)
254 {
255 return (cpShapecxx . . $ cpShape# *)cpBoxShapeInit2cxx . . $ cpBoxShapeInit2(d8ad8bdc0a5a2669).(cpPolyShapeAlloccxx . . $ cpPolyShapeAlloc(3ef3cc9382c7ba3b).(), body, box, radius);
256 }
257
258 int
259 cpPolyShapeGetCountcxx . . $ cpPolyShapeGetCount(46d926dc73b3f622).(const cpShapecxx . . $ cpShape# *shape)
260 {
261 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(shape->klass == &polyClass, "Shape is not a poly shape.");
262 return ((cpPolyShapecxx . . $ cpPolyShape# *)shape)->countcxx . . $ cpPolyShape#count.;
263 }
264
265 cpVectcxx . . $ cpVect#
266 cpPolyShapeGetVertcxx . . $ cpPolyShapeGetVert(9392d0fc785db450).(const cpShapecxx . . $ cpShape# *shape, int i)
267 {
268 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(shape->klass == &polyClass, "Shape is not a poly shape.");
269
270 int count = cpPolyShapeGetCountcxx . . $ cpPolyShapeGetCount(46d926dc73b3f622).(shape);
271 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(0 <= i && i < count, "Index out of range.");
272
273 return ((cpPolyShapecxx . . $ cpPolyShape# *)shape)->planescxx . . $ cpPolyShape#planes.[i + count].v0cxx . . $ cpSplittingPlane#v0.;
274 }
275
276 cpFloatcxx . . $ cpFloat#
277 cpPolyShapeGetRadiuscxx . . $ cpPolyShapeGetRadius(1bf41e75729c6179).(const cpShapecxx . . $ cpShape# *shape)
278 {
279 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(shape->klass == &polyClass, "Shape is not a poly shape.");
280 return ((cpPolyShapecxx . . $ cpPolyShape# *)shape)->rcxx . . $ cpPolyShape#r.;
281 }
282
283 // Unsafe API (chipmunk_unsafe.h)
284
285 void
286 cpPolyShapeSetVertscxx . . $ cpPolyShapeSetVerts(1d0447bf15bf2ec5).(cpShapecxx . . $ cpShape# *shape, int count, cpVectcxx . . $ cpVect# *verts, cpTransformcxx . . $ cpTransform# transform)
287 {
288 cpVectcxx . . $ cpVect# *hullVerts = (cpVectcxx . . $ cpVect# *)allocacxx . . $ `<external>/11612401604547820122/alloca.h:35:10`!(count*sizeof(cpVect));
289
290 // Transform the verts before building the hull in case of a negative scale.
291 for(int i=0; i<count; i++) hullVerts[i] = cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(transform, verts[i]);
292
293 unsigned int hullCount = cpConvexHullcxx . . $ cpConvexHull(ca3a36ade7aeec92).(count, hullVerts, hullVerts, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0.0);
294 cpPolyShapeSetVertsRawcxx . . $ cpPolyShapeSetVertsRaw(36af62e8b0f08eb2).(shape, hullCount, hullVerts);
295 }
296
297 void
298 cpPolyShapeSetVertsRawcxx . . $ cpPolyShapeSetVertsRaw(36af62e8b0f08eb2).(cpShapecxx . . $ cpShape# *shape, int count, cpVectcxx . . $ cpVect# *verts)
299 {
300 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(shape->klass == &polyClass, "Shape is not a poly shape.");
301 cpPolyShapecxx . . $ cpPolyShape# *poly = (cpPolyShapecxx . . $ cpPolyShape# *)shape;
302 cpPolyShapeDestroycxx . . $ cpPolyShapeDestroy(9e5954eb97ba7ffd).(poly);
303
304 SetVertscxx . . $ SetVerts(81a89784553bd105).(poly, count, verts);
305
306 cpFloatcxx . . $ cpFloat# mass = shape->massInfocxx . . $ cpShape#massInfo..mcxx . . $ cpShapeMassInfo#m.;
307 shape->massInfocxx . . $ cpShape#massInfo. = cpPolyShapeMassInfocxx . . $ cpPolyShapeMassInfo(da09f97bbd04a176).(shape->massInfocxx . . $ cpShape#massInfo..mcxx . . $ cpShapeMassInfo#m., count, verts, poly->rcxx . . $ cpPolyShape#r.);
308 if(mass > 0.0f) cpBodyAccumulateMassFromShapescxx . . $ cpBodyAccumulateMassFromShapes(92943d3541b63e72).(shape->bodycxx . . $ cpShape#body.);
309 }
310
311 void
312 cpPolyShapeSetRadiuscxx . . $ cpPolyShapeSetRadius(2eca2465ee202d41).(cpShapecxx . . $ cpShape# *shape, cpFloatcxx . . $ cpFloat# radius)
313 {
314 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(shape->klass == &polyClass, "Shape is not a poly shape.");
315 cpPolyShapecxx . . $ cpPolyShape# *poly = (cpPolyShapecxx . . $ cpPolyShape# *)shape;
316 poly->rcxx . . $ cpPolyShape#r. = radius;
317
318
319 // TODO radius is not handled by moment/area
320 // cpFloat mass = shape->massInfo.m;
321 // shape->massInfo = cpPolyShapeMassInfo(shape->massInfo.m, poly->count, poly->verts, poly->r);
322 // if(mass > 0.0f) cpBodyAccumulateMassFromShapes(shape->body);
323 }