propane 0.6.0-java → 0.7.0-java
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.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/.travis.yml +12 -4
- data/CHANGELOG.md +1 -0
- data/Rakefile +1 -1
- data/examples/complete/landscape.rb +1 -1
- data/examples/regular/colors_two.rb +1 -3
- data/examples/regular/tree.rb +0 -1
- data/examples/regular/vector_math.rb +4 -3
- data/lib/propane/app.rb +1 -4
- data/lib/propane/helpers/numeric.rb +2 -2
- data/lib/propane/runner.rb +32 -8
- data/lib/propane/version.rb +1 -1
- data/pom.rb +5 -5
- data/pom.xml +6 -6
- data/propane.gemspec +1 -1
- data/src/monkstone/CodeListener.java +7 -0
- data/src/monkstone/{MathTool.java → MathToolModule.java} +59 -68
- data/src/monkstone/PropaneLibrary.java +1 -1
- data/src/monkstone/WatchSketchDir.java +190 -0
- data/src/monkstone/fastmath/Deglut.java +47 -38
- data/src/monkstone/fastmath/package-info.java +6 -0
- data/src/monkstone/vecmath/AppRender.java +19 -20
- data/src/monkstone/vecmath/JRender.java +19 -19
- data/src/monkstone/vecmath/ShapeRender.java +19 -19
- data/src/monkstone/vecmath/package-info.java +20 -0
- data/src/monkstone/vecmath/vec2/Vec2.java +694 -624
- data/src/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/monkstone/vecmath/vec3/Vec3.java +704 -669
- data/src/monkstone/vecmath/vec3/package-info.java +6 -0
- data/vendors/Rakefile +2 -2
- metadata +11 -5
@@ -1,31 +1,31 @@
|
|
1
1
|
package monkstone.vecmath.vec3;
|
2
|
-
|
2
|
+
|
3
|
+
/*
|
3
4
|
* Copyright (c) 2015-16 Martin Prout
|
4
|
-
*
|
5
|
+
*
|
5
6
|
* This library is free software; you can redistribute it and/or
|
6
7
|
* modify it under the terms of the GNU Lesser General Public
|
7
8
|
* License as published by the Free Software Foundation; either
|
8
9
|
* version 2.1 of the License, or (at your option) any later version.
|
9
|
-
*
|
10
|
+
*
|
10
11
|
* http://creativecommons.org/licenses/LGPL/2.1/
|
11
|
-
*
|
12
|
+
*
|
12
13
|
* This library is distributed in the hope that it will be useful,
|
13
14
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
15
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
16
|
* Lesser General Public License for more details.
|
16
|
-
*
|
17
|
+
*
|
17
18
|
* You should have received a copy of the GNU Lesser General Public
|
18
19
|
* License along with this library; if not, write to the Free Software
|
19
20
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
-
*/
|
21
|
-
|
21
|
+
*/
|
22
22
|
import org.jruby.Ruby;
|
23
23
|
import org.jruby.RubyArray;
|
24
|
-
import org.jruby.RubyBoolean;
|
25
24
|
import org.jruby.RubyClass;
|
25
|
+
import org.jruby.RubyFixnum;
|
26
|
+
import org.jruby.RubyFloat;
|
26
27
|
import org.jruby.RubyObject;
|
27
28
|
import org.jruby.RubySymbol;
|
28
|
-
import org.jruby.runtime.ObjectAllocator;
|
29
29
|
import org.jruby.anno.JRubyClass;
|
30
30
|
import org.jruby.anno.JRubyMethod;
|
31
31
|
import org.jruby.runtime.Arity;
|
@@ -36,668 +36,703 @@ import monkstone.vecmath.JRender;
|
|
36
36
|
import monkstone.vecmath.vec2.Vec2;
|
37
37
|
|
38
38
|
/**
|
39
|
-
*
|
40
|
-
* @author Martin Prout
|
41
|
-
*/
|
39
|
+
*
|
40
|
+
* @author Martin Prout
|
41
|
+
*/
|
42
42
|
@JRubyClass(name = "Vec3D")
|
43
43
|
public final class Vec3 extends RubyObject {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
return
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
}
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
44
|
+
|
45
|
+
private static final long serialVersionUID = 4563517343762009867L;
|
46
|
+
|
47
|
+
/**
|
48
|
+
*
|
49
|
+
* @param runtime Ruby
|
50
|
+
*/
|
51
|
+
public static void createVec3(final Ruby runtime) {
|
52
|
+
RubyClass vec3Cls = runtime.defineClass("Vec3D", runtime.getObject(), (Ruby runtime1, RubyClass rubyClass) -> new Vec3(runtime1, rubyClass));
|
53
|
+
vec3Cls.defineAnnotatedMethods(Vec3.class);
|
54
|
+
}
|
55
|
+
|
56
|
+
static final double EPSILON = 9.999999747378752e-05; // matches processing.org EPSILON
|
57
|
+
double jx = 0;
|
58
|
+
double jy = 0;
|
59
|
+
double jz = 0;
|
60
|
+
|
61
|
+
/**
|
62
|
+
*
|
63
|
+
* @param context ThreadContext
|
64
|
+
* @param klazz IRubyObject
|
65
|
+
* @param args optional (no args jx = 0, jy = 0, jz = 0) (2 args jz = 0)
|
66
|
+
* @return new Vec3 object (ruby)
|
67
|
+
*/
|
68
|
+
@JRubyMethod(name = "new", meta = true, rest = true)
|
69
|
+
public final static IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
|
70
|
+
Vec3 vec = (Vec3) ((RubyClass) klazz).allocate();
|
71
|
+
vec.init(context, args);
|
72
|
+
return vec;
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
*
|
77
|
+
* @param runtime Ruby
|
78
|
+
* @param klass RubyClass
|
79
|
+
*/
|
80
|
+
public Vec3(Ruby runtime, RubyClass klass) {
|
81
|
+
super(runtime, klass);
|
82
|
+
}
|
83
|
+
|
84
|
+
void init(ThreadContext context, IRubyObject[] args) {
|
85
|
+
int count = Arity.checkArgumentCount(context.runtime, args, Arity.OPTIONAL.getValue(), 3);
|
86
|
+
if (count >= 2) {
|
87
|
+
jx = (args[0] instanceof RubyFloat)
|
88
|
+
? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
|
89
|
+
jy = (args[1] instanceof RubyFloat)
|
90
|
+
? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
91
|
+
}
|
92
|
+
if (count == 3) {
|
93
|
+
jz = (args[2] instanceof RubyFloat)
|
94
|
+
? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
*
|
100
|
+
* @param context ThreadContext
|
101
|
+
* @return x IRubyObject
|
102
|
+
*/
|
103
|
+
@JRubyMethod(name = "x")
|
104
|
+
|
105
|
+
public IRubyObject getX(ThreadContext context) {
|
106
|
+
return context.runtime.newFloat(jx);
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
*
|
111
|
+
* @param context ThreadContext
|
112
|
+
* @return y IRubyObject
|
113
|
+
*/
|
114
|
+
@JRubyMethod(name = "y")
|
115
|
+
|
116
|
+
public IRubyObject getY(ThreadContext context) {
|
117
|
+
return context.runtime.newFloat(jy);
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
*
|
122
|
+
* @param context ThreadContext
|
123
|
+
* @return z IRubyObject
|
124
|
+
*/
|
125
|
+
@JRubyMethod(name = "z")
|
126
|
+
public IRubyObject getZ(ThreadContext context) {
|
127
|
+
return context.runtime.newFloat(jz);
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
*
|
132
|
+
* @param context ThreadContext
|
133
|
+
* @param other IRubyObject
|
134
|
+
* @return x IRubyObject
|
135
|
+
*/
|
136
|
+
@JRubyMethod(name = "x=")
|
137
|
+
|
138
|
+
public IRubyObject setX(ThreadContext context, IRubyObject other) {
|
139
|
+
if (other instanceof RubyFloat) {
|
140
|
+
jx = ((RubyFloat) other).getValue();
|
141
|
+
} else {
|
142
|
+
jx = ((RubyFixnum) other).getDoubleValue();
|
143
|
+
}
|
144
|
+
return other;
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
*
|
149
|
+
* @param context ThreadContext
|
150
|
+
* @param other IRubyObject
|
151
|
+
* @return y IRubyObject
|
152
|
+
*/
|
153
|
+
@JRubyMethod(name = "y=")
|
154
|
+
|
155
|
+
public IRubyObject setY(ThreadContext context, IRubyObject other) {
|
156
|
+
if (other instanceof RubyFloat) {
|
157
|
+
jy = ((RubyFloat) other).getValue();
|
158
|
+
} else {
|
159
|
+
jy = ((RubyFixnum) other).getDoubleValue();
|
160
|
+
}
|
161
|
+
return other;
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
*
|
166
|
+
* @param context ThreadContext
|
167
|
+
* @param other IRubyObject
|
168
|
+
* @return z IRubyObject
|
169
|
+
*/
|
170
|
+
@JRubyMethod(name = "z=")
|
171
|
+
public IRubyObject setZ(ThreadContext context, IRubyObject other) {
|
172
|
+
if (other instanceof RubyFloat) {
|
173
|
+
jz = ((RubyFloat) other).getValue();
|
174
|
+
} else {
|
175
|
+
jz = ((RubyFixnum) other).getDoubleValue();
|
176
|
+
}
|
177
|
+
return other;
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
*
|
182
|
+
* @param context ThreadContext
|
183
|
+
* @param key as symbol
|
184
|
+
* @return value float
|
185
|
+
*/
|
186
|
+
@JRubyMethod(name = "[]", required = 1)
|
187
|
+
|
188
|
+
public IRubyObject aref(ThreadContext context, IRubyObject key) {
|
189
|
+
Ruby runtime = context.runtime;
|
190
|
+
if (key instanceof RubySymbol) {
|
191
|
+
if (key == RubySymbol.newSymbol(runtime, "x")) {
|
192
|
+
return runtime.newFloat(jx);
|
193
|
+
} else if (key == RubySymbol.newSymbol(runtime, "y")) {
|
194
|
+
return runtime.newFloat(jy);
|
195
|
+
} else if (key == RubySymbol.newSymbol(runtime, "z")) {
|
196
|
+
return runtime.newFloat(jz);
|
197
|
+
} else {
|
198
|
+
throw runtime.newIndexError("invalid key");
|
199
|
+
}
|
200
|
+
} else {
|
201
|
+
throw runtime.newIndexError("invalid key");
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* @param context ThreadContext
|
207
|
+
* @param key as symbol
|
208
|
+
* @param value as float
|
209
|
+
* @return value float
|
210
|
+
*/
|
211
|
+
@JRubyMethod(name = "[]=")
|
212
|
+
|
213
|
+
public IRubyObject aset(ThreadContext context, IRubyObject key, IRubyObject value) {
|
214
|
+
Ruby runtime = context.runtime;
|
215
|
+
if (key instanceof RubySymbol) {
|
216
|
+
if (key == RubySymbol.newSymbol(runtime, "x")) {
|
217
|
+
jx = (value instanceof RubyFloat)
|
218
|
+
? ((RubyFloat) value).getValue() : ((RubyFixnum) value).getDoubleValue();
|
219
|
+
} else if (key == RubySymbol.newSymbol(runtime, "y")) {
|
220
|
+
jy = (value instanceof RubyFloat)
|
221
|
+
? ((RubyFloat) value).getValue() : ((RubyFixnum) value).getDoubleValue();
|
222
|
+
} else if (key == RubySymbol.newSymbol(runtime, "z")) {
|
223
|
+
jz = (value instanceof RubyFloat)
|
224
|
+
? ((RubyFloat) value).getValue() : ((RubyFixnum) value).getDoubleValue();
|
225
|
+
} else {
|
226
|
+
throw runtime.newIndexError("invalid key");
|
227
|
+
}
|
228
|
+
} else {
|
229
|
+
throw runtime.newIndexError("invalid key");
|
230
|
+
}
|
231
|
+
return value;
|
232
|
+
}
|
233
|
+
|
234
|
+
/**
|
235
|
+
*
|
236
|
+
* @param context ThreadContext
|
237
|
+
* @param other IRubyObject
|
238
|
+
* @return distance float
|
239
|
+
*/
|
240
|
+
@JRubyMethod(name = "dist", required = 1)
|
241
|
+
|
242
|
+
public IRubyObject dist(ThreadContext context, IRubyObject other) {
|
243
|
+
Vec3 b = null;
|
244
|
+
if (other instanceof Vec3) {
|
245
|
+
b = (Vec3) other.toJava(Vec3.class);
|
246
|
+
} else {
|
247
|
+
throw context.runtime.newTypeError("argument should be Vec3D");
|
248
|
+
}
|
249
|
+
double result = Math.sqrt((jx - b.jx) * (jx - b.jx) + (jy - b.jy) * (jy - b.jy) + (jz - b.jz) * (jz - b.jz));
|
250
|
+
return context.runtime.newFloat(result);
|
251
|
+
}
|
252
|
+
|
253
|
+
/**
|
254
|
+
*
|
255
|
+
* @param context ThreadContext
|
256
|
+
* @param other IRubyObject
|
257
|
+
* @return distance squared float
|
258
|
+
*/
|
259
|
+
@JRubyMethod(name = "dist_squared", required = 1)
|
260
|
+
|
261
|
+
public IRubyObject dist_squared(ThreadContext context, IRubyObject other) {
|
262
|
+
Vec3 b = null;
|
263
|
+
if (other instanceof Vec3) {
|
264
|
+
b = (Vec3) other.toJava(Vec3.class);
|
265
|
+
} else {
|
266
|
+
throw context.runtime.newTypeError("argument should be Vec3D");
|
267
|
+
}
|
268
|
+
double result = (jx - b.jx) * (jx - b.jx) + (jy - b.jy) * (jy - b.jy) + (jz - b.jz) * (jz - b.jz);
|
269
|
+
return context.runtime.newFloat(result);
|
270
|
+
}
|
271
|
+
|
272
|
+
/**
|
273
|
+
*
|
274
|
+
*
|
275
|
+
* @param context ThreadContext
|
276
|
+
* @param other IRubyObject
|
277
|
+
* @return cross product IRubyObject
|
278
|
+
*/
|
279
|
+
@JRubyMethod(name = "cross", required = 1)
|
280
|
+
|
281
|
+
public IRubyObject cross(ThreadContext context, IRubyObject other) {
|
282
|
+
Ruby runtime = context.runtime;
|
283
|
+
Vec3 vec = null;
|
284
|
+
if (other instanceof Vec3) {
|
285
|
+
vec = (Vec3) other.toJava(Vec3.class);
|
286
|
+
} else {
|
287
|
+
throw runtime.newTypeError("argument should be Vec3D");
|
288
|
+
}
|
289
|
+
return Vec3.rbNew(context, other.getMetaClass(), new IRubyObject[]{
|
290
|
+
runtime.newFloat(jy * vec.jz - jz * vec.jy),
|
291
|
+
runtime.newFloat(jz * vec.jx - jx * vec.jz),
|
292
|
+
runtime.newFloat(jx * vec.jy - jy * vec.jx)
|
293
|
+
}
|
294
|
+
);
|
295
|
+
}
|
296
|
+
|
297
|
+
/**
|
298
|
+
*
|
299
|
+
* @param context ThreadContext
|
300
|
+
* @param other IRubyObject
|
301
|
+
* @return dot product IRubyObject
|
302
|
+
*/
|
303
|
+
@JRubyMethod(name = "dot", required = 1)
|
304
|
+
|
305
|
+
public IRubyObject dot(ThreadContext context, IRubyObject other) {
|
306
|
+
Ruby runtime = context.runtime;
|
307
|
+
Vec3 b = null;
|
308
|
+
if (other instanceof Vec3) {
|
309
|
+
b = (Vec3) other.toJava(Vec3.class);
|
310
|
+
} else {
|
311
|
+
throw runtime.newTypeError("argument should be Vec3D");
|
312
|
+
}
|
313
|
+
return runtime.newFloat(jx * b.jx + jy * b.jy + jz * b.jz);
|
314
|
+
}
|
315
|
+
|
316
|
+
/**
|
317
|
+
*
|
318
|
+
* @param context ThreadContext
|
319
|
+
* @param other IRubyObject
|
320
|
+
* @return new Vec3 object (ruby)
|
321
|
+
*/
|
322
|
+
@JRubyMethod(name = "+", required = 1)
|
323
|
+
|
324
|
+
public IRubyObject op_add(ThreadContext context, IRubyObject other) {
|
325
|
+
Ruby runtime = context.runtime;
|
326
|
+
Vec3 b = (Vec3) other.toJava(Vec3.class);
|
327
|
+
return Vec3.rbNew(context, other.getMetaClass(), new IRubyObject[]{
|
328
|
+
runtime.newFloat(jx + b.jx),
|
329
|
+
runtime.newFloat(jy + b.jy),
|
330
|
+
runtime.newFloat(jz + b.jz)});
|
331
|
+
}
|
332
|
+
|
333
|
+
/**
|
334
|
+
*
|
335
|
+
* @param context ThreadContext
|
336
|
+
* @param other IRubyObject
|
337
|
+
* @return new Vec3 object (ruby)
|
338
|
+
*/
|
339
|
+
@JRubyMethod(name = "-")
|
340
|
+
|
341
|
+
public IRubyObject op_sub(ThreadContext context, IRubyObject other) {
|
342
|
+
Ruby runtime = context.runtime;
|
343
|
+
Vec3 b = null;
|
344
|
+
if (other instanceof Vec3) {
|
345
|
+
b = (Vec3) other.toJava(Vec3.class);
|
346
|
+
} else {
|
347
|
+
throw runtime.newTypeError("argument should be Vec3D");
|
348
|
+
}
|
349
|
+
return Vec3.rbNew(context, other.getMetaClass(), new IRubyObject[]{
|
350
|
+
runtime.newFloat(jx - b.jx),
|
351
|
+
runtime.newFloat(jy - b.jy),
|
352
|
+
runtime.newFloat(jz - b.jz)});
|
353
|
+
}
|
354
|
+
|
355
|
+
/**
|
356
|
+
*
|
357
|
+
* @param context ThreadContext
|
358
|
+
* @param scalar IRubyObject
|
359
|
+
* @return new Vec3 object (ruby)
|
360
|
+
*/
|
361
|
+
@JRubyMethod(name = "*", required = 1)
|
362
|
+
|
363
|
+
public IRubyObject op_mul(ThreadContext context, IRubyObject scalar) {
|
364
|
+
Ruby runtime = context.runtime;
|
365
|
+
double multi = (scalar instanceof RubyFloat)
|
366
|
+
? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
|
367
|
+
return Vec3.rbNew(context, this.getMetaClass(), new IRubyObject[]{
|
368
|
+
runtime.newFloat(jx * multi),
|
369
|
+
runtime.newFloat(jy * multi),
|
370
|
+
runtime.newFloat(jz * multi)});
|
371
|
+
}
|
372
|
+
|
373
|
+
/**
|
374
|
+
*
|
375
|
+
* @param context ThreadContext
|
376
|
+
* @param scalar IRubyObject
|
377
|
+
* @return new Vec3 object (ruby)
|
378
|
+
*/
|
379
|
+
@JRubyMethod(name = "/", required = 1)
|
380
|
+
|
381
|
+
public IRubyObject op_div(ThreadContext context, IRubyObject scalar) {
|
382
|
+
Ruby runtime = context.runtime;
|
383
|
+
double divisor = (scalar instanceof RubyFloat)
|
384
|
+
? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
|
385
|
+
if (Math.abs(divisor) < Vec3.EPSILON) {
|
386
|
+
return this;
|
387
|
+
}
|
388
|
+
return Vec3.rbNew(context, this.getMetaClass(), new IRubyObject[]{
|
389
|
+
runtime.newFloat(jx / divisor),
|
390
|
+
runtime.newFloat(jy / divisor),
|
391
|
+
runtime.newFloat(jz / divisor)});
|
392
|
+
}
|
393
|
+
|
394
|
+
/**
|
395
|
+
*
|
396
|
+
* @param context ThreadContext
|
397
|
+
* @return magnitude squared IRubyObject
|
398
|
+
*/
|
399
|
+
@JRubyMethod(name = "mag_squared")
|
400
|
+
|
401
|
+
public IRubyObject mag_squared(ThreadContext context) {
|
402
|
+
return context.runtime.newFloat(jx * jx + jy * jy + jz * jz);
|
403
|
+
}
|
404
|
+
|
405
|
+
/**
|
406
|
+
*
|
407
|
+
* @param context ThreadContext
|
408
|
+
* @return magnitude IRubyObject
|
409
|
+
*/
|
410
|
+
@JRubyMethod(name = "mag")
|
411
|
+
|
412
|
+
public IRubyObject mag(ThreadContext context) {
|
413
|
+
return context.runtime.newFloat(Math.sqrt(jx * jx + jy * jy + jz * jz));
|
414
|
+
}
|
415
|
+
|
416
|
+
/**
|
417
|
+
* Call yield if block given, do nothing if yield == false else set_mag to
|
418
|
+
* given scalar
|
419
|
+
*
|
420
|
+
* @param context ThreadContext
|
421
|
+
* @param scalar double value to set
|
422
|
+
* @param block should return a boolean (optional)
|
423
|
+
* @return magnitude IRubyObject
|
424
|
+
*/
|
425
|
+
@JRubyMethod(name = "set_mag")
|
426
|
+
|
427
|
+
public IRubyObject set_mag(ThreadContext context, IRubyObject scalar, Block block) {
|
428
|
+
if (block.isGiven()) {
|
429
|
+
if (!(boolean) block.yield(context, scalar).toJava(Boolean.class)) {
|
430
|
+
return this;
|
431
|
+
}
|
432
|
+
}
|
433
|
+
double new_mag = (scalar instanceof RubyFloat)
|
434
|
+
? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
|
435
|
+
double current = Math.sqrt(jx * jx + jy * jy + jz * jz);
|
436
|
+
if (current > EPSILON) {
|
437
|
+
jx *= new_mag / current;
|
438
|
+
jy *= new_mag / current;
|
439
|
+
jz *= new_mag / current;
|
440
|
+
}
|
411
441
|
return this;
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
442
|
+
}
|
443
|
+
|
444
|
+
/**
|
445
|
+
*
|
446
|
+
* @param context ThreadContext
|
447
|
+
* @return this as a ruby object
|
448
|
+
*/
|
449
|
+
@JRubyMethod(name = "normalize!")
|
450
|
+
|
451
|
+
public IRubyObject normalize_bang(ThreadContext context) {
|
452
|
+
if (Math.abs(jx) < EPSILON && Math.abs(jy) < EPSILON && Math.abs(jz) < EPSILON) {
|
453
|
+
return this;
|
454
|
+
}
|
455
|
+
double mag = Math.sqrt(jx * jx + jy * jy + jz * jz);
|
456
|
+
jx /= mag;
|
457
|
+
jy /= mag;
|
458
|
+
jz /= mag;
|
459
|
+
return this;
|
460
|
+
}
|
461
|
+
|
462
|
+
/**
|
463
|
+
*
|
464
|
+
* @param context ThreadContext
|
465
|
+
* @return new normalized Vec3D object (ruby)
|
466
|
+
*/
|
467
|
+
@JRubyMethod(name = "normalize")
|
468
|
+
|
469
|
+
public IRubyObject normalize(ThreadContext context) {
|
470
|
+
Ruby runtime = context.runtime;
|
471
|
+
double mag = Math.sqrt(jx * jx + jy * jy + jz * jz);
|
472
|
+
if (mag < EPSILON) {
|
473
|
+
return Vec3.rbNew(context, this.getMetaClass(), new IRubyObject[]{
|
474
|
+
runtime.newFloat(jx),
|
475
|
+
runtime.newFloat(jy),
|
476
|
+
runtime.newFloat(jz)});
|
477
|
+
}
|
478
|
+
return Vec3.rbNew(context, this.getMetaClass(), new IRubyObject[]{
|
479
|
+
runtime.newFloat(jx / mag),
|
480
|
+
runtime.newFloat(jy / mag),
|
481
|
+
runtime.newFloat(jz / mag)});
|
482
|
+
}
|
483
|
+
|
484
|
+
/**
|
485
|
+
* Example of a regular ruby class method
|
486
|
+
*
|
487
|
+
* @param context ThreadContext
|
488
|
+
* @param klazz IRubyObject
|
489
|
+
* @return new random Vec3D object (ruby)
|
490
|
+
*/
|
491
|
+
@JRubyMethod(name = "random", meta = true)
|
492
|
+
|
493
|
+
public static IRubyObject random_direction(ThreadContext context, IRubyObject klazz) {
|
494
|
+
Ruby runtime = context.runtime;
|
495
|
+
double angle = Math.random() * Math.PI * 2;
|
496
|
+
double vz = Math.random() * 2 - 1;
|
497
|
+
double vx = Math.sqrt(1 - vz * vz) * Math.cos(angle);
|
498
|
+
double vy = Math.sqrt(1 - vz * vz) * Math.sin(angle);
|
499
|
+
|
500
|
+
return Vec3.rbNew(context, klazz, new IRubyObject[]{
|
501
|
+
runtime.newFloat(vx),
|
502
|
+
runtime.newFloat(vy),
|
503
|
+
runtime.newFloat(vz)});
|
504
|
+
}
|
505
|
+
|
506
|
+
/**
|
507
|
+
*
|
508
|
+
* @param context ThreadContext
|
509
|
+
* @param other IRubyObject another Vec3D
|
510
|
+
* @return angle IRubyObject in radians
|
511
|
+
*/
|
512
|
+
@JRubyMethod(name = "angle_between")
|
513
|
+
|
514
|
+
public IRubyObject angleBetween(ThreadContext context, IRubyObject other) {
|
515
|
+
Ruby runtime = context.runtime;
|
516
|
+
Vec3 vec = (Vec3) other.toJava(Vec3.class);
|
517
|
+
// We get NaN if we pass in a zero vector which can cause problems
|
518
|
+
// Zero seems like a reasonable angle between a (0,0,0) vector and something else
|
519
|
+
if (jx == 0 && jy == 0 && jz == 0) {
|
520
|
+
return runtime.newFloat(0.0);
|
521
|
+
}
|
522
|
+
if (vec.jx == 0 && vec.jy == 0 && vec.jz == 0) {
|
523
|
+
return runtime.newFloat(0.0);
|
524
|
+
}
|
525
|
+
|
526
|
+
double dot = jx * vec.jx + jy * vec.jy + jz * vec.jz;
|
527
|
+
double v1mag = Math.sqrt(jx * jx + jy * jy + jz * jz);
|
528
|
+
double v2mag = Math.sqrt(vec.jx * vec.jx + vec.jy * vec.jy + vec.jz * vec.jz);
|
529
|
+
// This should be a number between -1 and 1, since it's "normalized"
|
530
|
+
double amt = dot / (v1mag * v2mag);
|
531
|
+
if (amt <= -1) {
|
532
|
+
return runtime.newFloat(Math.PI);
|
533
|
+
} else if (amt >= 1) {
|
534
|
+
return runtime.newFloat(0.0);
|
535
|
+
}
|
536
|
+
return runtime.newFloat(Math.acos(amt));
|
537
|
+
}
|
538
|
+
|
539
|
+
/**
|
540
|
+
*
|
541
|
+
* @param context ThreadContext
|
542
|
+
* @return IRubyObject copy
|
543
|
+
*/
|
544
|
+
@JRubyMethod(name = {"copy", "dup"})
|
545
|
+
|
546
|
+
public IRubyObject copy(ThreadContext context) {
|
547
|
+
Ruby runtime = context.runtime;
|
548
|
+
return Vec3.rbNew(context, this.getMetaClass(), new IRubyObject[]{
|
549
|
+
runtime.newFloat(jx),
|
550
|
+
runtime.newFloat(jy),
|
551
|
+
runtime.newFloat(jz)});
|
552
|
+
}
|
553
|
+
|
554
|
+
/**
|
555
|
+
*
|
556
|
+
* @param context ThreadContext
|
557
|
+
* @return IRubyObject array of float
|
558
|
+
*/
|
559
|
+
@JRubyMethod(name = "to_a")
|
560
|
+
|
561
|
+
public IRubyObject toArray(ThreadContext context) {
|
562
|
+
Ruby runtime = context.runtime;
|
563
|
+
return RubyArray.newArray(context.runtime, new IRubyObject[]{
|
564
|
+
runtime.newFloat(jx),
|
565
|
+
runtime.newFloat(jy),
|
566
|
+
runtime.newFloat(jz)});
|
567
|
+
}
|
568
|
+
|
569
|
+
/**
|
570
|
+
* To vertex
|
571
|
+
*
|
572
|
+
* @param context ThreadContext
|
573
|
+
* @param object IRubyObject vertex renderer
|
574
|
+
*/
|
575
|
+
@JRubyMethod(name = "to_vertex")
|
576
|
+
|
577
|
+
public void toVertex(ThreadContext context, IRubyObject object) {
|
578
|
+
JRender renderer = (JRender) object.toJava(JRender.class);
|
579
|
+
renderer.vertex(jx, jy, jz);
|
580
|
+
}
|
581
|
+
|
582
|
+
/**
|
583
|
+
* To curve vertex
|
584
|
+
*
|
585
|
+
* @param context ThreadContext
|
586
|
+
* @param object IRubyObject vertex renderer
|
587
|
+
*/
|
588
|
+
@JRubyMethod(name = "to_curve_vertex")
|
589
|
+
|
590
|
+
public void toCurveVertex(ThreadContext context, IRubyObject object) {
|
591
|
+
JRender renderer = (JRender) object.toJava(JRender.class);
|
592
|
+
renderer.curveVertex(jx, jy, jz);
|
593
|
+
}
|
594
|
+
|
595
|
+
/**
|
596
|
+
* Sends this Vec3D as a processing vertex uv
|
597
|
+
*
|
598
|
+
* @param context ThreadContext
|
599
|
+
* @param args IRubyObject[]
|
600
|
+
*/
|
601
|
+
@JRubyMethod(name = "to_vertex_uv", rest = true)
|
602
|
+
|
603
|
+
public void toVertexUV(ThreadContext context, IRubyObject[] args) {
|
604
|
+
int count = Arity.checkArgumentCount(context.runtime, args, Arity.OPTIONAL.getValue(), 3);
|
605
|
+
double u = 0;
|
606
|
+
double v = 0;
|
607
|
+
if (count == 3) {
|
608
|
+
u = (args[1] instanceof RubyFloat)
|
609
|
+
? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
|
610
|
+
v = (args[2] instanceof RubyFloat)
|
611
|
+
? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
|
612
|
+
}
|
613
|
+
if (count == 2) {
|
614
|
+
Vec2 texture = (Vec2) args[1].toJava(Vec2.class);
|
615
|
+
u = texture.javax();
|
616
|
+
v = texture.javay();
|
617
|
+
}
|
618
|
+
JRender renderer = (JRender) args[0].toJava(JRender.class);
|
619
|
+
renderer.vertex(jx, jy, jz, u, v);
|
620
|
+
}
|
621
|
+
|
622
|
+
/**
|
623
|
+
* Sends this Vec3D as a processing normal
|
624
|
+
*
|
625
|
+
* @param context ThreadContext
|
626
|
+
* @param object IRubyObject vertex renderer
|
627
|
+
*/
|
628
|
+
@JRubyMethod(name = "to_normal")
|
629
|
+
|
630
|
+
public void toNormal(ThreadContext context, IRubyObject object) {
|
631
|
+
JRender renderer = (JRender) object.toJava(JRender.class);
|
632
|
+
renderer.normal(jx, jy, jz);
|
633
|
+
}
|
634
|
+
|
635
|
+
/**
|
636
|
+
* For jruby-9000 we alias to inspect
|
637
|
+
*
|
638
|
+
* @param context ThreadContext
|
639
|
+
* @return IRubyObject to_s
|
640
|
+
*/
|
641
|
+
@JRubyMethod(name = {"to_s", "inspect"})
|
642
|
+
|
643
|
+
public IRubyObject to_s(ThreadContext context) {
|
644
|
+
return context.runtime.newString(String.format("Vec3D(x = %4.4f, y = %4.4f, z = %4.4f)", jx, jy, jz));
|
645
|
+
}
|
646
|
+
|
647
|
+
/**
|
648
|
+
* Java hash
|
649
|
+
*
|
650
|
+
* @return hash int
|
651
|
+
*/
|
652
|
+
@Override
|
653
|
+
public int hashCode() {
|
654
|
+
int hash = 7;
|
655
|
+
hash = 97 * hash + (int) (Double.doubleToLongBits(this.jx) ^ (Double.doubleToLongBits(this.jx) >>> 32));
|
656
|
+
hash = 97 * hash + (int) (Double.doubleToLongBits(this.jy) ^ (Double.doubleToLongBits(this.jy) >>> 32));
|
657
|
+
hash = 97 * hash + (int) (Double.doubleToLongBits(this.jz) ^ (Double.doubleToLongBits(this.jz) >>> 32));
|
658
|
+
return hash;
|
659
|
+
}
|
660
|
+
|
661
|
+
/**
|
662
|
+
* Java Equals
|
663
|
+
*
|
664
|
+
* @param obj Object
|
665
|
+
* @return result boolean
|
666
|
+
*/
|
667
|
+
@Override
|
668
|
+
public boolean equals(Object obj) {
|
669
|
+
if (obj == this) {
|
670
|
+
return true;
|
671
|
+
}
|
672
|
+
if (obj instanceof Vec3) {
|
673
|
+
final Vec3 other = (Vec3) obj;
|
674
|
+
if ((Double.compare(jx, (Double) other.jx) == 0)
|
675
|
+
&& (Double.compare(jy, (Double) other.jy) == 0)
|
676
|
+
&& (Double.compare(jz, (Double) other.jz) == 0)) {
|
677
|
+
return true;
|
678
|
+
}
|
679
|
+
|
680
|
+
}
|
648
681
|
return false;
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
682
|
+
}
|
683
|
+
|
684
|
+
/**
|
685
|
+
*
|
686
|
+
* @param context ThreadContext
|
687
|
+
* @param other IRubyObject
|
688
|
+
* @return result IRubyObject as boolean
|
689
|
+
*/
|
690
|
+
@JRubyMethod(name = "eql?", required = 1)
|
691
|
+
|
692
|
+
public IRubyObject eql_p(ThreadContext context, IRubyObject other) {
|
693
|
+
Ruby runtime = context.runtime;
|
694
|
+
if (other == this) {
|
695
|
+
return runtime.newBoolean(true);
|
696
|
+
}
|
697
|
+
if (other instanceof Vec3) {
|
698
|
+
Vec3 v = (Vec3) other.toJava(Vec3.class);
|
699
|
+
if ((Double.compare(jx, (Double) v.jx) == 0)
|
700
|
+
&& (Double.compare(jy, (Double) v.jy) == 0)
|
701
|
+
&& (Double.compare(jz, (Double) v.jz) == 0)) {
|
702
|
+
return runtime.newBoolean(true);
|
703
|
+
}
|
704
|
+
|
705
|
+
}
|
706
|
+
return runtime.newBoolean(false);
|
707
|
+
}
|
708
|
+
|
709
|
+
/**
|
710
|
+
*
|
711
|
+
* @param context ThreadContext
|
712
|
+
* @param other IRubyObject
|
713
|
+
* @return result IRubyObject as boolean
|
714
|
+
*/
|
715
|
+
@JRubyMethod(name = "==", required = 1)
|
716
|
+
|
717
|
+
@Override
|
718
|
+
public IRubyObject op_equal(ThreadContext context, IRubyObject other) {
|
719
|
+
Ruby runtime = context.runtime;
|
720
|
+
if (other == this) {
|
721
|
+
return runtime.newBoolean(true);
|
722
|
+
}
|
723
|
+
if (other instanceof Vec3) {
|
724
|
+
Vec3 v = (Vec3) other.toJava(Vec3.class);
|
725
|
+
double diff = jx - v.jx;
|
726
|
+
if ((diff < 0 ? -diff : diff) > Vec3.EPSILON) {
|
727
|
+
return runtime.newBoolean(false);
|
728
|
+
}
|
729
|
+
diff = jy - v.jy;
|
730
|
+
if ((diff < 0 ? -diff : diff) > Vec3.EPSILON) {
|
731
|
+
return runtime.newBoolean(false);
|
732
|
+
}
|
733
|
+
diff = jz - v.jz;
|
734
|
+
return runtime.newBoolean((diff < 0 ? -diff : diff) < Vec3.EPSILON);
|
735
|
+
}
|
736
|
+
return runtime.newBoolean(false);
|
737
|
+
}
|
703
738
|
}
|