propane 3.10.0-java → 3.11.0-java

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