chipmunk 5.3.4.0-x86-mingw32 → 5.3.4.2-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +33 -13
- data/Rakefile +20 -7
- data/ext/chipmunk/extconf.rb +55 -12
- data/ext/chipmunk/rb_chipmunk.c +92 -98
- data/ext/chipmunk/rb_chipmunk.h +44 -34
- data/ext/chipmunk/rb_cpArbiter.c +135 -98
- data/ext/chipmunk/rb_cpBB.c +84 -101
- data/ext/chipmunk/rb_cpBody.c +219 -241
- data/ext/chipmunk/rb_cpConstraint.c +173 -185
- data/ext/chipmunk/rb_cpShape.c +347 -251
- data/ext/chipmunk/rb_cpSpace.c +376 -408
- data/ext/chipmunk/rb_cpVect.c +132 -170
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk.h +163 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_ffi.h +59 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_private.h +49 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_types.h +151 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_unsafe.h +54 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpConstraint.h +105 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedRotarySpring.h +46 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedSpring.h +53 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGearJoint.h +41 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGrooveJoint.h +48 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPinJoint.h +43 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPivotJoint.h +42 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRatchetJoint.h +40 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRotaryLimitJoint.h +39 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSimpleMotor.h +37 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSlideJoint.h +44 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/util.h +134 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArbiter.h +188 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArray.h +49 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBB.h +74 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBody.h +219 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpCollision.h +28 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpHashSet.h +82 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpPolyShape.h +103 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpShape.h +177 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpace.h +206 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpaceHash.h +110 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpVect.h +207 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/chipmunk.c +151 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpConstraint.c +54 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedRotarySpring.c +105 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedSpring.c +115 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGearJoint.c +113 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGrooveJoint.c +161 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPinJoint.c +116 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPivotJoint.c +114 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRatchetJoint.c +126 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRotaryLimitJoint.c +120 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSimpleMotor.c +97 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSlideJoint.c +129 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArbiter.c +280 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArray.c +143 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBB.c +47 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBody.c +192 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpCollision.c +411 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpHashSet.c +253 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpPolyShape.c +240 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpShape.c +405 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpace.c +499 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceComponent.c +279 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceHash.c +534 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceQuery.c +246 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceStep.c +398 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpVect.c +71 -0
- data/ext/chipmunk/vendor/chipmunk-5.3.4/src/prime.h +68 -0
- data/lib/1.9/chipmunk.so +0 -0
- data/lib/chipmunk.rb +19 -8
- metadata +84 -42
- data/lib/1.8/chipmunk.so +0 -0
data/ext/chipmunk/rb_cpVect.c
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
/* Copyright (c) 2007 Scott Lembcke
|
2
|
-
*
|
2
|
+
*
|
3
3
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
* of this software and associated documentation files (the "Software"), to deal
|
5
5
|
* in the Software without restriction, including without limitation the rights
|
6
6
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
7
|
* copies of the Software, and to permit persons to whom the Software is
|
8
8
|
* furnished to do so, subject to the following conditions:
|
9
|
-
*
|
9
|
+
*
|
10
10
|
* The above copyright notice and this permission notice shall be included in
|
11
11
|
* all copies or substantial portions of the Software.
|
12
|
-
*
|
12
|
+
*
|
13
13
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
14
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
15
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
@@ -18,7 +18,7 @@
|
|
18
18
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
19
|
* SOFTWARE.
|
20
20
|
*/
|
21
|
-
|
21
|
+
|
22
22
|
#include <stdlib.h>
|
23
23
|
#include "chipmunk.h"
|
24
24
|
|
@@ -28,319 +28,281 @@
|
|
28
28
|
VALUE c_cpVect;
|
29
29
|
|
30
30
|
static VALUE
|
31
|
-
rb_cpVectForAngle(VALUE self, VALUE angle)
|
32
|
-
|
33
|
-
return VNEW(cpvforangle(NUM2DBL(angle)));
|
31
|
+
rb_cpVectForAngle(VALUE self, VALUE angle) {
|
32
|
+
return VNEW(cpvforangle(NUM2DBL(angle)));
|
34
33
|
}
|
35
34
|
|
36
35
|
static VALUE
|
37
|
-
rb_cpVectAlloc(VALUE klass)
|
38
|
-
|
39
|
-
|
40
|
-
return Data_Wrap_Struct(klass, NULL, free, v);
|
36
|
+
rb_cpVectAlloc(VALUE klass) {
|
37
|
+
cpVect *v = malloc(sizeof(cpVect));
|
38
|
+
return Data_Wrap_Struct(klass, NULL, free, v);
|
41
39
|
}
|
42
40
|
|
43
41
|
static VALUE
|
44
|
-
rb_cpVectInitialize(VALUE self, VALUE x, VALUE y)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
return self;
|
42
|
+
rb_cpVectInitialize(VALUE self, VALUE x, VALUE y) {
|
43
|
+
cpVect *v = VGET(self);
|
44
|
+
v->x = NUM2DBL(x);
|
45
|
+
v->y = NUM2DBL(y);
|
46
|
+
|
47
|
+
return self;
|
51
48
|
}
|
52
49
|
|
53
50
|
static VALUE
|
54
|
-
rb_cpVectGetX(VALUE self)
|
55
|
-
|
56
|
-
return rb_float_new(VGET(self)->x);
|
51
|
+
rb_cpVectGetX(VALUE self) {
|
52
|
+
return rb_float_new(VGET(self)->x);
|
57
53
|
}
|
58
54
|
|
59
55
|
static VALUE
|
60
|
-
rb_cpVectGetY(VALUE self)
|
61
|
-
|
62
|
-
return rb_float_new(VGET(self)->y);
|
56
|
+
rb_cpVectGetY(VALUE self) {
|
57
|
+
return rb_float_new(VGET(self)->y);
|
63
58
|
}
|
64
59
|
|
65
60
|
static VALUE
|
66
|
-
rb_cpVectSetX(VALUE self, VALUE x)
|
67
|
-
|
68
|
-
|
69
|
-
return self;
|
61
|
+
rb_cpVectSetX(VALUE self, VALUE x) {
|
62
|
+
VGET(self)->x = NUM2DBL(x);
|
63
|
+
return self;
|
70
64
|
}
|
71
65
|
|
72
66
|
static VALUE
|
73
|
-
rb_cpVectSetY(VALUE self, VALUE y)
|
74
|
-
|
75
|
-
|
76
|
-
return self;
|
67
|
+
rb_cpVectSetY(VALUE self, VALUE y) {
|
68
|
+
VGET(self)->y = NUM2DBL(y);
|
69
|
+
return self;
|
77
70
|
}
|
78
71
|
|
79
72
|
static VALUE
|
80
|
-
rb_cpVectToString(VALUE self)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
return rb_str_new2(str);
|
73
|
+
rb_cpVectToString(VALUE self) {
|
74
|
+
char str[256];
|
75
|
+
cpVect *v = VGET(self);
|
76
|
+
|
77
|
+
sprintf(str, "(% .3f, % .3f)", v->x, v->y);
|
78
|
+
|
79
|
+
return rb_str_new2(str);
|
88
80
|
}
|
89
81
|
|
90
82
|
static VALUE
|
91
|
-
rb_cpVectToArray(VALUE self)
|
92
|
-
|
93
|
-
|
94
|
-
return rb_ary_new3(2, rb_float_new(v->x), rb_float_new(v->y));
|
83
|
+
rb_cpVectToArray(VALUE self) {
|
84
|
+
cpVect *v = VGET(self);
|
85
|
+
return rb_ary_new3(2, rb_float_new(v->x), rb_float_new(v->y));
|
95
86
|
}
|
96
87
|
|
97
88
|
static VALUE
|
98
|
-
rb_cpVectToAngle(VALUE self)
|
99
|
-
|
100
|
-
return rb_float_new(cpvtoangle(*VGET(self)));
|
89
|
+
rb_cpVectToAngle(VALUE self) {
|
90
|
+
return rb_float_new(cpvtoangle(*VGET(self)));
|
101
91
|
}
|
102
|
-
|
92
|
+
|
103
93
|
|
104
94
|
static VALUE
|
105
|
-
rb_cpVectNegate(VALUE self)
|
106
|
-
|
107
|
-
return VNEW(cpvneg(*VGET(self)));
|
95
|
+
rb_cpVectNegate(VALUE self) {
|
96
|
+
return VNEW(cpvneg(*VGET(self)));
|
108
97
|
}
|
109
98
|
|
110
99
|
static VALUE
|
111
|
-
rb_cpVectAdd(VALUE self, VALUE v)
|
112
|
-
|
113
|
-
return VNEW(cpvadd(*VGET(self), *VGET(v)));
|
100
|
+
rb_cpVectAdd(VALUE self, VALUE v) {
|
101
|
+
return VNEW(cpvadd(*VGET(self), *VGET(v)));
|
114
102
|
}
|
115
103
|
|
116
104
|
static VALUE
|
117
|
-
rb_cpVectSub(VALUE self, VALUE v)
|
118
|
-
|
119
|
-
return VNEW(cpvsub(*VGET(self), *VGET(v)));
|
105
|
+
rb_cpVectSub(VALUE self, VALUE v) {
|
106
|
+
return VNEW(cpvsub(*VGET(self), *VGET(v)));
|
120
107
|
}
|
121
108
|
|
122
109
|
static VALUE
|
123
|
-
rb_cpVectSMult(VALUE self, VALUE s)
|
124
|
-
|
125
|
-
return VNEW(cpvmult(*VGET(self), NUM2DBL(s)));
|
110
|
+
rb_cpVectSMult(VALUE self, VALUE s) {
|
111
|
+
return VNEW(cpvmult(*VGET(self), NUM2DBL(s)));
|
126
112
|
}
|
127
113
|
|
128
114
|
static VALUE
|
129
|
-
rb_cpVectSDiv(VALUE self, VALUE s)
|
130
|
-
|
131
|
-
|
132
|
-
return VNEW(cpvmult(*VGET(self), factor));
|
115
|
+
rb_cpVectSDiv(VALUE self, VALUE s) {
|
116
|
+
cpFloat factor = 1.0f / (float)NUM2DBL(s);
|
117
|
+
return VNEW(cpvmult(*VGET(self), factor));
|
133
118
|
}
|
134
119
|
|
135
120
|
static VALUE
|
136
|
-
rb_cpVectDot(VALUE self, VALUE v)
|
137
|
-
|
138
|
-
return rb_float_new(cpvdot(*VGET(self), *VGET(v)));
|
121
|
+
rb_cpVectDot(VALUE self, VALUE v) {
|
122
|
+
return rb_float_new(cpvdot(*VGET(self), *VGET(v)));
|
139
123
|
}
|
140
124
|
|
141
125
|
static VALUE
|
142
|
-
rb_cpVectCross(VALUE self, VALUE v)
|
143
|
-
|
144
|
-
return rb_float_new(cpvcross(*VGET(self), *VGET(v)));
|
126
|
+
rb_cpVectCross(VALUE self, VALUE v) {
|
127
|
+
return rb_float_new(cpvcross(*VGET(self), *VGET(v)));
|
145
128
|
}
|
146
129
|
|
147
130
|
static VALUE
|
148
|
-
rb_cpVectLength(VALUE self)
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
return rb_float_new(cpvlength(*v));
|
131
|
+
rb_cpVectLength(VALUE self) {
|
132
|
+
cpVect *v;
|
133
|
+
Data_Get_Struct(self, cpVect, v);
|
134
|
+
return rb_float_new(cpvlength(*v));
|
153
135
|
}
|
154
136
|
|
155
137
|
static VALUE
|
156
|
-
rb_cpVectLengthsq(VALUE self)
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
return rb_float_new(cpvlengthsq(*v));
|
138
|
+
rb_cpVectLengthsq(VALUE self) {
|
139
|
+
cpVect *v;
|
140
|
+
Data_Get_Struct(self, cpVect, v);
|
141
|
+
return rb_float_new(cpvlengthsq(*v));
|
161
142
|
}
|
162
143
|
|
163
144
|
static VALUE
|
164
|
-
rb_cpVectNorm(VALUE self)
|
165
|
-
|
166
|
-
return VNEW(cpvnormalize(*VGET(self)));
|
145
|
+
rb_cpVectNorm(VALUE self) {
|
146
|
+
return VNEW(cpvnormalize(*VGET(self)));
|
167
147
|
}
|
168
148
|
|
169
149
|
static VALUE
|
170
|
-
rb_cpVectNormBang(VALUE self)
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
return self;
|
150
|
+
rb_cpVectNormBang(VALUE self) {
|
151
|
+
cpVect *v = VGET(self);
|
152
|
+
*v = cpvnormalize(*v);
|
153
|
+
return self;
|
175
154
|
}
|
176
155
|
|
177
156
|
static VALUE
|
178
|
-
rb_cpVectNormSafe(VALUE self)
|
179
|
-
{
|
157
|
+
rb_cpVectNormSafe(VALUE self) {
|
180
158
|
return VNEW(cpvnormalize_safe(*VGET(self)));
|
181
159
|
}
|
182
160
|
|
183
161
|
static VALUE
|
184
|
-
rb_cpVectNormSafeBang(VALUE self)
|
185
|
-
{
|
162
|
+
rb_cpVectNormSafeBang(VALUE self) {
|
186
163
|
cpVect *v = VGET(self);
|
187
164
|
*v = cpvnormalize_safe(*v);
|
188
165
|
return self;
|
189
166
|
}
|
190
167
|
|
191
168
|
static VALUE
|
192
|
-
rb_cpVectPerp(VALUE self)
|
193
|
-
|
194
|
-
return VNEW(cpvperp(*VGET(self)));
|
169
|
+
rb_cpVectPerp(VALUE self) {
|
170
|
+
return VNEW(cpvperp(*VGET(self)));
|
195
171
|
}
|
196
172
|
|
197
173
|
static VALUE
|
198
|
-
rb_cpVectRperp(VALUE self)
|
199
|
-
{
|
174
|
+
rb_cpVectRperp(VALUE self) {
|
200
175
|
return VNEW(cpvrperp(*VGET(self)));
|
201
176
|
}
|
202
177
|
|
203
178
|
static VALUE
|
204
|
-
rb_cpVectLerp(VALUE self, VALUE v, VALUE d)
|
205
|
-
{
|
179
|
+
rb_cpVectLerp(VALUE self, VALUE v, VALUE d) {
|
206
180
|
cpFloat df = NUM2DBL(d);
|
207
181
|
return VNEW(cpvlerp(*VGET(self), *VGET(v), df));
|
208
182
|
}
|
209
183
|
|
210
184
|
static VALUE
|
211
|
-
rb_cpVectLerpconst(VALUE self, VALUE v, VALUE d)
|
212
|
-
{
|
185
|
+
rb_cpVectLerpconst(VALUE self, VALUE v, VALUE d) {
|
213
186
|
cpFloat df = (cpFloat) NUM2DBL(d);
|
214
187
|
return VNEW(cpvlerpconst(*VGET(self), *VGET(v), df));
|
215
188
|
}
|
216
189
|
|
217
190
|
static VALUE
|
218
|
-
rb_cpVectSlerp(VALUE self, VALUE v, VALUE d)
|
219
|
-
{
|
191
|
+
rb_cpVectSlerp(VALUE self, VALUE v, VALUE d) {
|
220
192
|
cpFloat df = (cpFloat) NUM2DBL(d);
|
221
193
|
return VNEW(cpvslerp(*VGET(self), *VGET(v), df));
|
222
194
|
}
|
223
195
|
|
224
196
|
static VALUE
|
225
|
-
rb_cpVectSlerpconst(VALUE self, VALUE v, VALUE d)
|
226
|
-
{
|
197
|
+
rb_cpVectSlerpconst(VALUE self, VALUE v, VALUE d) {
|
227
198
|
cpFloat df = (cpFloat) NUM2DBL(d);
|
228
199
|
return VNEW(cpvslerpconst(*VGET(self), *VGET(v), df));
|
229
200
|
}
|
230
201
|
|
231
202
|
static VALUE
|
232
|
-
rb_cpVectProject(VALUE self, VALUE v)
|
233
|
-
|
234
|
-
return VNEW(cpvproject(*VGET(self), *VGET(v)));
|
203
|
+
rb_cpVectProject(VALUE self, VALUE v) {
|
204
|
+
return VNEW(cpvproject(*VGET(self), *VGET(v)));
|
235
205
|
}
|
236
206
|
|
237
207
|
static VALUE
|
238
|
-
rb_cpVectRotate(VALUE self, VALUE v)
|
239
|
-
|
240
|
-
return VNEW(cpvrotate(*VGET(self), *VGET(v)));
|
208
|
+
rb_cpVectRotate(VALUE self, VALUE v) {
|
209
|
+
return VNEW(cpvrotate(*VGET(self), *VGET(v)));
|
241
210
|
}
|
242
211
|
|
243
212
|
static VALUE
|
244
|
-
rb_cpVectUnRotate(VALUE self, VALUE v)
|
245
|
-
|
246
|
-
return VNEW(cpvunrotate(*VGET(self), *VGET(v)));
|
213
|
+
rb_cpVectUnRotate(VALUE self, VALUE v) {
|
214
|
+
return VNEW(cpvunrotate(*VGET(self), *VGET(v)));
|
247
215
|
}
|
248
216
|
|
249
217
|
static VALUE
|
250
|
-
rb_cpVectDist(VALUE self, VALUE v)
|
251
|
-
{
|
218
|
+
rb_cpVectDist(VALUE self, VALUE v) {
|
252
219
|
return rb_float_new(cpvdist(*VGET(self), *VGET(v)));
|
253
220
|
}
|
254
221
|
|
255
222
|
static VALUE
|
256
|
-
rb_cpVectDistsq(VALUE self, VALUE v)
|
257
|
-
{
|
223
|
+
rb_cpVectDistsq(VALUE self, VALUE v) {
|
258
224
|
return rb_float_new(cpvdistsq(*VGET(self), *VGET(v)));
|
259
225
|
}
|
260
226
|
|
261
227
|
static VALUE
|
262
|
-
rb_cpVectClamp(VALUE self, VALUE len)
|
263
|
-
{
|
228
|
+
rb_cpVectClamp(VALUE self, VALUE len) {
|
264
229
|
return VNEW(cpvclamp(*VGET(self), NUM2DBL(len)));
|
265
230
|
}
|
266
231
|
|
267
232
|
|
268
233
|
static VALUE
|
269
|
-
rb_cpVectNear(VALUE self, VALUE v, VALUE d)
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
return (cpvdot(delta, delta) <= dist*dist) ? Qtrue : Qfalse;
|
234
|
+
rb_cpVectNear(VALUE self, VALUE v, VALUE d) {
|
235
|
+
cpFloat dist = NUM2DBL(d);
|
236
|
+
cpVect delta = cpvsub(*VGET(self), *VGET(v));
|
237
|
+
return (cpvdot(delta, delta) <= dist * dist) ? Qtrue : Qfalse;
|
274
238
|
}
|
275
239
|
|
276
240
|
static VALUE
|
277
|
-
rb_cpVectEql(VALUE self, VALUE other)
|
278
|
-
{
|
241
|
+
rb_cpVectEql(VALUE self, VALUE other) {
|
279
242
|
return cpveql(*VGET(self), *VGET(other)) ? Qtrue : Qfalse;
|
280
243
|
}
|
281
244
|
|
282
245
|
// the usefulness of unary plus is debatable, but I'll include it for consistency.
|
283
|
-
static VALUE
|
246
|
+
static VALUE
|
247
|
+
rb_cpVectUnaryplus(VALUE self) {
|
284
248
|
return self;
|
285
249
|
}
|
286
250
|
|
287
251
|
|
288
252
|
static VALUE
|
289
|
-
rb_vec2(VALUE self, VALUE x, VALUE y)
|
290
|
-
|
291
|
-
return VNEW(cpv(NUM2DBL(x), NUM2DBL(y)));
|
253
|
+
rb_vec2(VALUE self, VALUE x, VALUE y) {
|
254
|
+
return VNEW(cpv(NUM2DBL(x), NUM2DBL(y)));
|
292
255
|
}
|
293
256
|
|
294
257
|
void
|
295
|
-
Init_cpVect(void)
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
rb_define_method(c_cpVect, "-@", rb_cpVectNegate, 0);
|
258
|
+
Init_cpVect(void) {
|
259
|
+
c_cpVect = rb_define_class_under(m_Chipmunk, "Vec2", rb_cObject);
|
260
|
+
rb_define_singleton_method(c_cpVect, "for_angle", rb_cpVectForAngle, 1);
|
261
|
+
|
262
|
+
rb_define_alloc_func(c_cpVect, rb_cpVectAlloc);
|
263
|
+
rb_define_method(c_cpVect, "initialize", rb_cpVectInitialize, 2);
|
264
|
+
|
265
|
+
rb_define_method(c_cpVect, "x", rb_cpVectGetX, 0);
|
266
|
+
rb_define_method(c_cpVect, "y", rb_cpVectGetY, 0);
|
267
|
+
rb_define_method(c_cpVect, "x=", rb_cpVectSetX, 1);
|
268
|
+
rb_define_method(c_cpVect, "y=", rb_cpVectSetY, 1);
|
269
|
+
|
270
|
+
rb_define_method(c_cpVect, "to_s", rb_cpVectToString, 0);
|
271
|
+
rb_define_method(c_cpVect, "to_a", rb_cpVectToArray, 0);
|
272
|
+
rb_define_method(c_cpVect, "to_angle", rb_cpVectToAngle, 0);
|
273
|
+
|
274
|
+
rb_define_method(c_cpVect, "-@", rb_cpVectNegate, 0);
|
313
275
|
rb_define_method(c_cpVect, "+@", rb_cpVectUnaryplus, 0);
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
276
|
+
rb_define_method(c_cpVect, "+", rb_cpVectAdd, 1);
|
277
|
+
rb_define_method(c_cpVect, "-", rb_cpVectSub, 1);
|
278
|
+
rb_define_method(c_cpVect, "*", rb_cpVectSMult, 1);
|
279
|
+
rb_define_method(c_cpVect, "/", rb_cpVectSDiv, 1);
|
280
|
+
rb_define_method(c_cpVect, "dot", rb_cpVectDot, 1);
|
281
|
+
rb_define_method(c_cpVect, "cross", rb_cpVectCross, 1);
|
282
|
+
rb_define_method(c_cpVect, "length", rb_cpVectLength, 0);
|
283
|
+
rb_define_method(c_cpVect, "lengthsq", rb_cpVectLengthsq, 0);
|
284
|
+
rb_define_method(c_cpVect, "normalize", rb_cpVectNorm, 0);
|
285
|
+
rb_define_method(c_cpVect, "normalize!", rb_cpVectNormBang, 0);
|
324
286
|
rb_define_method(c_cpVect, "normalize_safe", rb_cpVectNormSafe, 0);
|
325
|
-
rb_define_method(c_cpVect, "normalize_safe!", rb_cpVectNormSafeBang, 0);
|
326
|
-
|
287
|
+
rb_define_method(c_cpVect, "normalize_safe!", rb_cpVectNormSafeBang, 0);
|
288
|
+
rb_define_method(c_cpVect, "perp", rb_cpVectPerp, 0);
|
327
289
|
rb_define_method(c_cpVect, "rperp", rb_cpVectRperp, 0);
|
328
290
|
rb_define_method(c_cpVect, "lerp", rb_cpVectLerp, 2);
|
329
291
|
rb_define_method(c_cpVect, "lerpconst", rb_cpVectLerpconst, 2);
|
330
292
|
rb_define_method(c_cpVect, "slerp", rb_cpVectSlerp, 2);
|
331
293
|
rb_define_method(c_cpVect, "slerpconst", rb_cpVectSlerpconst, 2);
|
332
294
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
295
|
+
rb_define_method(c_cpVect, "project", rb_cpVectProject, 1);
|
296
|
+
rb_define_method(c_cpVect, "rotate", rb_cpVectRotate, 1);
|
297
|
+
rb_define_method(c_cpVect, "unrotate", rb_cpVectUnRotate, 1);
|
298
|
+
rb_define_method(c_cpVect, "near?", rb_cpVectNear, 2);
|
299
|
+
|
338
300
|
rb_define_method(c_cpVect, "dist", rb_cpVectDist, 1);
|
339
301
|
rb_define_method(c_cpVect, "distsq", rb_cpVectDistsq, 1);
|
340
|
-
|
302
|
+
|
341
303
|
rb_define_method(c_cpVect, "==", rb_cpVectEql, 1);
|
342
304
|
rb_define_method(c_cpVect, "clamp", rb_cpVectClamp, 1);
|
343
|
-
|
344
|
-
|
345
|
-
|
305
|
+
|
306
|
+
|
307
|
+
rb_define_global_function("vec2", rb_vec2, 2);
|
346
308
|
}
|