chipmunk 5.3.4.0-x86-mingw32 → 5.3.4.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/README +33 -13
  2. data/Rakefile +20 -7
  3. data/ext/chipmunk/extconf.rb +55 -12
  4. data/ext/chipmunk/rb_chipmunk.c +92 -98
  5. data/ext/chipmunk/rb_chipmunk.h +44 -34
  6. data/ext/chipmunk/rb_cpArbiter.c +135 -98
  7. data/ext/chipmunk/rb_cpBB.c +84 -101
  8. data/ext/chipmunk/rb_cpBody.c +219 -241
  9. data/ext/chipmunk/rb_cpConstraint.c +173 -185
  10. data/ext/chipmunk/rb_cpShape.c +347 -251
  11. data/ext/chipmunk/rb_cpSpace.c +376 -408
  12. data/ext/chipmunk/rb_cpVect.c +132 -170
  13. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk.h +163 -0
  14. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_ffi.h +59 -0
  15. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_private.h +49 -0
  16. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_types.h +151 -0
  17. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_unsafe.h +54 -0
  18. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpConstraint.h +105 -0
  19. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedRotarySpring.h +46 -0
  20. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedSpring.h +53 -0
  21. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGearJoint.h +41 -0
  22. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGrooveJoint.h +48 -0
  23. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPinJoint.h +43 -0
  24. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPivotJoint.h +42 -0
  25. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRatchetJoint.h +40 -0
  26. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRotaryLimitJoint.h +39 -0
  27. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSimpleMotor.h +37 -0
  28. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSlideJoint.h +44 -0
  29. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/util.h +134 -0
  30. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArbiter.h +188 -0
  31. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArray.h +49 -0
  32. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBB.h +74 -0
  33. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBody.h +219 -0
  34. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpCollision.h +28 -0
  35. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpHashSet.h +82 -0
  36. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpPolyShape.h +103 -0
  37. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpShape.h +177 -0
  38. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpace.h +206 -0
  39. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpaceHash.h +110 -0
  40. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpVect.h +207 -0
  41. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/chipmunk.c +151 -0
  42. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpConstraint.c +54 -0
  43. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedRotarySpring.c +105 -0
  44. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedSpring.c +115 -0
  45. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGearJoint.c +113 -0
  46. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGrooveJoint.c +161 -0
  47. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPinJoint.c +116 -0
  48. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPivotJoint.c +114 -0
  49. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRatchetJoint.c +126 -0
  50. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRotaryLimitJoint.c +120 -0
  51. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSimpleMotor.c +97 -0
  52. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSlideJoint.c +129 -0
  53. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArbiter.c +280 -0
  54. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArray.c +143 -0
  55. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBB.c +47 -0
  56. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBody.c +192 -0
  57. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpCollision.c +411 -0
  58. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpHashSet.c +253 -0
  59. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpPolyShape.c +240 -0
  60. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpShape.c +405 -0
  61. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpace.c +499 -0
  62. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceComponent.c +279 -0
  63. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceHash.c +534 -0
  64. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceQuery.c +246 -0
  65. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceStep.c +398 -0
  66. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpVect.c +71 -0
  67. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/prime.h +68 -0
  68. data/lib/1.9/chipmunk.so +0 -0
  69. data/lib/chipmunk.rb +19 -8
  70. metadata +84 -42
  71. data/lib/1.8/chipmunk.so +0 -0
@@ -0,0 +1,74 @@
1
+ /* Copyright (c) 2007 Scott Lembcke
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
+ typedef struct cpBB{
23
+ cpFloat l, b, r ,t;
24
+ } cpBB;
25
+
26
+ static inline cpBB
27
+ cpBBNew(const cpFloat l, const cpFloat b,
28
+ const cpFloat r, const cpFloat t)
29
+ {
30
+ cpBB bb = {l, b, r, t};
31
+ return bb;
32
+ }
33
+
34
+ static inline cpBool
35
+ cpBBintersects(const cpBB a, const cpBB b)
36
+ {
37
+ return (a.l<=b.r && b.l<=a.r && a.b<=b.t && b.b<=a.t);
38
+ }
39
+
40
+ static inline cpBool
41
+ cpBBcontainsBB(const cpBB bb, const cpBB other)
42
+ {
43
+ return (bb.l < other.l && bb.r > other.r && bb.b < other.b && bb.t > other.t);
44
+ }
45
+
46
+ static inline cpBool
47
+ cpBBcontainsVect(const cpBB bb, const cpVect v)
48
+ {
49
+ return (bb.l < v.x && bb.r > v.x && bb.b < v.y && bb.t > v.y);
50
+ }
51
+
52
+ static inline cpBB
53
+ cpBBmerge(const cpBB a, const cpBB b){
54
+ return cpBBNew(
55
+ cpfmin(a.l, b.l),
56
+ cpfmin(a.b, b.b),
57
+ cpfmax(a.r, b.r),
58
+ cpfmax(a.t, b.t)
59
+ );
60
+ }
61
+
62
+ static inline cpBB
63
+ cpBBexpand(const cpBB bb, const cpVect v){
64
+ return cpBBNew(
65
+ cpfmin(bb.l, v.x),
66
+ cpfmin(bb.b, v.y),
67
+ cpfmax(bb.r, v.x),
68
+ cpfmax(bb.t, v.y)
69
+ );
70
+ }
71
+
72
+ cpVect cpBBClampVect(const cpBB bb, const cpVect v); // clamps the vector to lie within the bbox
73
+ // TODO edge case issue
74
+ cpVect cpBBWrapVect(const cpBB bb, const cpVect v); // wrap a vector to a bbox
@@ -0,0 +1,219 @@
1
+ /* Copyright (c) 2007 Scott Lembcke
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
+ struct cpBody;
23
+ struct cpShape;
24
+ struct cpSpace;
25
+
26
+ typedef void (*cpBodyVelocityFunc)(struct cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
27
+ typedef void (*cpBodyPositionFunc)(struct cpBody *body, cpFloat dt);
28
+
29
+ extern cpBodyVelocityFunc cpBodyUpdateVelocityDefault;
30
+ extern cpBodyPositionFunc cpBodyUpdatePositionDefault;
31
+
32
+ // Structure to hold information about the contact graph components
33
+ // when putting groups of objects to sleep.
34
+ // No interesting user accessible fields.
35
+ typedef struct cpComponentNode {
36
+ struct cpBody *parent;
37
+ struct cpBody *next;
38
+ int rank;
39
+ cpFloat idleTime;
40
+ } cpComponentNode;
41
+
42
+ typedef struct cpBody{
43
+ // *** Integration Functions.
44
+
45
+ // Function that is called to integrate the body's velocity. (Defaults to cpBodyUpdateVelocity)
46
+ cpBodyVelocityFunc velocity_func;
47
+
48
+ // Function that is called to integrate the body's position. (Defaults to cpBodyUpdatePosition)
49
+ cpBodyPositionFunc position_func;
50
+
51
+ // *** Mass Properties
52
+
53
+ // Mass and it's inverse.
54
+ // Always use cpBodySetMass() whenever changing the mass as these values must agree.
55
+ cpFloat m, m_inv;
56
+
57
+ // Moment of inertia and it's inverse.
58
+ // Always use cpBodySetMoment() whenever changing the moment as these values must agree.
59
+ cpFloat i, i_inv;
60
+
61
+ // *** Positional Properties
62
+
63
+ // Linear components of motion (position, velocity, and force)
64
+ cpVect p, v, f;
65
+
66
+ // Angular components of motion (angle, angular velocity, and torque)
67
+ // Always use cpBodySetAngle() to set the angle of the body as a and rot must agree.
68
+ cpFloat a, w, t;
69
+
70
+ // Cached unit length vector representing the angle of the body.
71
+ // Used for fast vector rotation using cpvrotate().
72
+ cpVect rot;
73
+
74
+ // *** User Definable Fields
75
+
76
+ // User defined data pointer.
77
+ cpDataPointer data;
78
+
79
+ // *** Other Fields
80
+
81
+ // Maximum velocities this body can move at after integrating velocity
82
+ cpFloat v_limit, w_limit;
83
+
84
+ // *** Internally Used Fields
85
+
86
+ // Velocity bias values used when solving penetrations and correcting constraints.
87
+ CP_PRIVATE(cpVect v_bias);
88
+ CP_PRIVATE(cpFloat w_bias);
89
+
90
+ // Space this body has been added to
91
+ CP_PRIVATE(struct cpSpace *space);
92
+
93
+ // Pointer to the shape list.
94
+ // Shapes form a linked list using cpShape.next when added to a space.
95
+ CP_PRIVATE(struct cpShape *shapesList);
96
+
97
+ // Used by cpSpaceStep() to store contact graph information.
98
+ CP_PRIVATE(cpComponentNode node);
99
+ } cpBody;
100
+
101
+ // Basic allocation/destruction functions
102
+ cpBody *cpBodyAlloc(void);
103
+ cpBody *cpBodyInit(cpBody *body, cpFloat m, cpFloat i);
104
+ cpBody *cpBodyNew(cpFloat m, cpFloat i);
105
+
106
+ cpBody *cpBodyInitStatic(cpBody *body);
107
+ cpBody *cpBodyNewStatic();
108
+
109
+ void cpBodyDestroy(cpBody *body);
110
+ void cpBodyFree(cpBody *body);
111
+
112
+ // Wake up a sleeping or idle body. (defined in cpSpace.c)
113
+ void cpBodyActivate(cpBody *body);
114
+
115
+ // Force a body to sleep;
116
+ // defined in cpSpaceComponent.c
117
+ void cpBodySleep(cpBody *body);
118
+ void cpBodySleepWithGroup(cpBody *body, cpBody *group);
119
+
120
+ static inline cpBool
121
+ cpBodyIsSleeping(const cpBody *body)
122
+ {
123
+ return (CP_PRIVATE(body->node).next != ((cpBody*)0));
124
+ }
125
+
126
+ static inline cpBool
127
+ cpBodyIsStatic(const cpBody *body)
128
+ {
129
+ return CP_PRIVATE(body->node).idleTime == INFINITY;
130
+ }
131
+
132
+ static inline cpBool
133
+ cpBodyIsRogue(const cpBody *body)
134
+ {
135
+ return (body->CP_PRIVATE(space) == ((struct cpSpace*)0));
136
+ }
137
+
138
+
139
+ #define CP_DefineBodyGetter(type, member, name) \
140
+ static inline type cpBodyGet##name(const cpBody *body){return body->member;}
141
+
142
+ #define CP_DefineBodySetter(type, member, name) \
143
+ static inline void \
144
+ cpBodySet##name(cpBody *body, const type value){ \
145
+ cpBodyActivate(body); \
146
+ body->member = value; \
147
+ } \
148
+
149
+ #define CP_DefineBodyProperty(type, member, name) \
150
+ CP_DefineBodyGetter(type, member, name) \
151
+ CP_DefineBodySetter(type, member, name)
152
+
153
+
154
+ // Accessors for cpBody struct members
155
+ CP_DefineBodyGetter(cpFloat, m, Mass);
156
+ void cpBodySetMass(cpBody *body, cpFloat m);
157
+
158
+ CP_DefineBodyGetter(cpFloat, i, Moment);
159
+ void cpBodySetMoment(cpBody *body, cpFloat i);
160
+
161
+
162
+ CP_DefineBodyProperty(cpVect, p, Pos);
163
+ CP_DefineBodyProperty(cpVect, v, Vel);
164
+ CP_DefineBodyProperty(cpVect, f, Force);
165
+ CP_DefineBodyGetter(cpFloat, a, Angle);
166
+ void cpBodySetAngle(cpBody *body, cpFloat a);
167
+ CP_DefineBodyProperty(cpFloat, w, AngVel);
168
+ CP_DefineBodyProperty(cpFloat, t, Torque);
169
+ CP_DefineBodyGetter(cpVect, rot, Rot);
170
+ CP_DefineBodyProperty(cpFloat, v_limit, VelLimit);
171
+ CP_DefineBodyProperty(cpFloat, w_limit, AngVelLimit);
172
+
173
+ // Modify the velocity of the body so that it will move to the specified absolute coordinates in the next timestep.
174
+ // Intended for objects that are moved manually with a custom velocity integration function.
175
+ void cpBodySlew(cpBody *body, cpVect pos, cpFloat dt);
176
+
177
+ // Default Integration functions.
178
+ void cpBodyUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
179
+ void cpBodyUpdatePosition(cpBody *body, cpFloat dt);
180
+
181
+ // Convert body local to world coordinates
182
+ static inline cpVect
183
+ cpBodyLocal2World(const cpBody *body, const cpVect v)
184
+ {
185
+ return cpvadd(body->p, cpvrotate(v, body->rot));
186
+ }
187
+
188
+ // Convert world to body local coordinates
189
+ static inline cpVect
190
+ cpBodyWorld2Local(const cpBody *body, const cpVect v)
191
+ {
192
+ return cpvunrotate(cpvsub(v, body->p), body->rot);
193
+ }
194
+
195
+ // Apply an impulse (in world coordinates) to the body at a point relative to the center of gravity (also in world coordinates).
196
+ static inline void
197
+ cpBodyApplyImpulse(cpBody *body, const cpVect j, const cpVect r)
198
+ {
199
+ body->v = cpvadd(body->v, cpvmult(j, body->m_inv));
200
+ body->w += body->i_inv*cpvcross(r, j);
201
+ }
202
+
203
+ // Zero the forces on a body.
204
+ void cpBodyResetForces(cpBody *body);
205
+ // Apply a force (in world coordinates) to a body at a point relative to the center of gravity (also in world coordinates).
206
+ void cpBodyApplyForce(cpBody *body, const cpVect f, const cpVect r);
207
+
208
+ static inline cpFloat
209
+ cpBodyKineticEnergy(const cpBody *body)
210
+ {
211
+ // Need to do some fudging to avoid NaNs
212
+ cpFloat vsq = cpvdot(body->v, body->v);
213
+ cpFloat wsq = body->w*body->w;
214
+ return (vsq ? vsq*body->m : 0.0f) + (wsq ? wsq*body->i : 0.0f);
215
+ }
216
+
217
+ // Apply a damped spring force between two bodies.
218
+ // Warning: Large damping values can be unstable. Use a cpDampedSpring constraint for this instead.
219
+ void cpApplyDampedSpring(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt);
@@ -0,0 +1,28 @@
1
+ /* Copyright (c) 2007 Scott Lembcke
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
+ //TODO delete this header?
23
+
24
+ // Collides two cpShape structures.
25
+ // Returns the number of contact points added to arr
26
+ // which should be at least CP_MAX_CONTACTS_PER_ARBITER in length.
27
+ // This function is very lonely in this header :(
28
+ int cpCollideShapes(const cpShape *a, const cpShape *b, cpContact *arr);
@@ -0,0 +1,82 @@
1
+ /* Copyright (c) 2007 Scott Lembcke
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
+ // cpHashSet uses a chained hashtable implementation.
23
+ // Other than the transformation functions, there is nothing fancy going on.
24
+
25
+ // cpHashSetBin's form the linked lists in the chained hash table.
26
+ typedef struct cpHashSetBin {
27
+ // Pointer to the element.
28
+ CP_PRIVATE(void *elt);
29
+ // Hash value of the element.
30
+ CP_PRIVATE(cpHashValue hash);
31
+ // Next element in the chain.
32
+ CP_PRIVATE(struct cpHashSetBin *next);
33
+ } cpHashSetBin;
34
+
35
+ // Equality function. Returns true if ptr is equal to elt.
36
+ typedef cpBool (*cpHashSetEqlFunc)(void *ptr, void *elt);
37
+ // Used by cpHashSetInsert(). Called to transform the ptr into an element.
38
+ typedef void *(*cpHashSetTransFunc)(void *ptr, void *data);
39
+
40
+ typedef struct cpHashSet {
41
+ // Number of elements stored in the table.
42
+ CP_PRIVATE(int entries);
43
+ // Number of cells in the table.
44
+ CP_PRIVATE(int size);
45
+
46
+ CP_PRIVATE(cpHashSetEqlFunc eql);
47
+ CP_PRIVATE(cpHashSetTransFunc trans);
48
+
49
+ // Default value returned by cpHashSetFind() when no element is found.
50
+ // Defaults to NULL.
51
+ CP_PRIVATE(void *default_value);
52
+
53
+ // The table and recycled bins
54
+ CP_PRIVATE(cpHashSetBin **table);
55
+ CP_PRIVATE(cpHashSetBin *pooledBins);
56
+
57
+ CP_PRIVATE(cpArray *allocatedBuffers);
58
+ } cpHashSet;
59
+
60
+ // Basic allocation/destruction functions.
61
+ void cpHashSetDestroy(cpHashSet *set);
62
+ void cpHashSetFree(cpHashSet *set);
63
+
64
+ cpHashSet *cpHashSetAlloc(void);
65
+ cpHashSet *cpHashSetInit(cpHashSet *set, int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans);
66
+ cpHashSet *cpHashSetNew(int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans);
67
+
68
+ // Insert an element into the set, returns the element.
69
+ // If it doesn't already exist, the transformation function is applied.
70
+ void *cpHashSetInsert(cpHashSet *set, cpHashValue hash, void *ptr, void *data);
71
+ // Remove and return an element from the set.
72
+ void *cpHashSetRemove(cpHashSet *set, cpHashValue hash, void *ptr);
73
+ // Find an element in the set. Returns the default value if the element isn't found.
74
+ void *cpHashSetFind(cpHashSet *set, cpHashValue hash, void *ptr);
75
+
76
+ // Iterate over a hashset.
77
+ typedef void (*cpHashSetIterFunc)(void *elt, void *data);
78
+ void cpHashSetEach(cpHashSet *set, cpHashSetIterFunc func, void *data);
79
+
80
+ // Iterate over a hashset, drop the element if the func returns false.
81
+ typedef cpBool (*cpHashSetFilterFunc)(void *elt, void *data);
82
+ void cpHashSetFilter(cpHashSet *set, cpHashSetFilterFunc func, void *data);
@@ -0,0 +1,103 @@
1
+ /* Copyright (c) 2007 Scott Lembcke
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
+ // Axis structure used by cpPolyShape.
23
+ typedef struct cpPolyShapeAxis{
24
+ // normal
25
+ cpVect n;
26
+ // distance from origin
27
+ cpFloat d;
28
+ } cpPolyShapeAxis;
29
+
30
+ // Convex polygon shape structure.
31
+ typedef struct cpPolyShape{
32
+ CP_PRIVATE(cpShape shape);
33
+
34
+ // Vertex and axis lists.
35
+ CP_PRIVATE(int numVerts);
36
+ CP_PRIVATE(cpVect *verts);
37
+ CP_PRIVATE(cpPolyShapeAxis *axes);
38
+
39
+ // Transformed vertex and axis lists.
40
+ CP_PRIVATE(cpVect *tVerts);
41
+ CP_PRIVATE(cpPolyShapeAxis *tAxes);
42
+ } cpPolyShape;
43
+
44
+ // Basic allocation functions.
45
+ cpPolyShape *cpPolyShapeAlloc(void);
46
+ cpPolyShape *cpPolyShapeInit(cpPolyShape *poly, cpBody *body, int numVerts, cpVect *verts, cpVect offset);
47
+ cpShape *cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset);
48
+
49
+ cpPolyShape *cpBoxShapeInit(cpPolyShape *poly, cpBody *body, cpFloat width, cpFloat height);
50
+ cpShape *cpBoxShapeNew(cpBody *body, cpFloat width, cpFloat height);
51
+
52
+ // Check that a set of vertexes has a correct winding and that they are convex
53
+ cpBool cpPolyValidate(const cpVect *verts, const int numVerts);
54
+
55
+ int cpPolyShapeGetNumVerts(cpShape *shape);
56
+ cpVect cpPolyShapeGetVert(cpShape *shape, int idx);
57
+
58
+ // *** inlined utility functions
59
+
60
+ // Returns the minimum distance of the polygon to the axis.
61
+ static inline cpFloat
62
+ cpPolyShapeValueOnAxis(const cpPolyShape *poly, const cpVect n, const cpFloat d)
63
+ {
64
+ cpVect *verts = poly->CP_PRIVATE(tVerts);
65
+ cpFloat min = cpvdot(n, verts[0]);
66
+
67
+ int i;
68
+ for(i=1; i<poly->CP_PRIVATE(numVerts); i++)
69
+ min = cpfmin(min, cpvdot(n, verts[i]));
70
+
71
+ return min - d;
72
+ }
73
+
74
+ // Returns true if the polygon contains the vertex.
75
+ static inline cpBool
76
+ cpPolyShapeContainsVert(const cpPolyShape *poly, const cpVect v)
77
+ {
78
+ cpPolyShapeAxis *axes = poly->CP_PRIVATE(tAxes);
79
+
80
+ int i;
81
+ for(i=0; i<poly->CP_PRIVATE(numVerts); i++){
82
+ cpFloat dist = cpvdot(axes[i].n, v) - axes[i].d;
83
+ if(dist > 0.0f) return cpFalse;
84
+ }
85
+
86
+ return cpTrue;
87
+ }
88
+
89
+ // Same as cpPolyShapeContainsVert() but ignores faces pointing away from the normal.
90
+ static inline cpBool
91
+ cpPolyShapeContainsVertPartial(const cpPolyShape *poly, const cpVect v, const cpVect n)
92
+ {
93
+ cpPolyShapeAxis *axes = poly->CP_PRIVATE(tAxes);
94
+
95
+ int i;
96
+ for(i=0; i<poly->CP_PRIVATE(numVerts); i++){
97
+ if(cpvdot(axes[i].n, n) < 0.0f) continue;
98
+ cpFloat dist = cpvdot(axes[i].n, v) - axes[i].d;
99
+ if(dist > 0.0f) return cpFalse;
100
+ }
101
+
102
+ return cpTrue;
103
+ }