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,802 +0,0 @@
1
- package monkstone.vecmath.vec2;
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
- * fastAtan2 algorithm from https://github.com/libgdx/libgdx (Apache 2.0 license)
23
- */
24
- import org.jruby.Ruby;
25
- import org.jruby.RubyArray;
26
- import org.jruby.RubyClass;
27
- import org.jruby.RubyFixnum;
28
- import org.jruby.RubyFloat;
29
- import org.jruby.RubyObject;
30
- import org.jruby.RubySymbol;
31
- import org.jruby.anno.JRubyClass;
32
- import org.jruby.anno.JRubyMethod;
33
- import org.jruby.runtime.Block;
34
- import org.jruby.runtime.ThreadContext;
35
- import org.jruby.runtime.builtin.IRubyObject;
36
- import monkstone.vecmath.JRender;
37
-
38
- /**
39
- *
40
- * @author Martin Prout
41
- */
42
- @JRubyClass(name = "Vec2D")
43
- public class Vec2 extends RubyObject {
44
-
45
- static final double EPSILON = 9.999999747378752e-05; // matches processing.org EPSILON
46
- private static final long serialVersionUID = -2950154560223211646L;
47
-
48
- private double jx = 0;
49
- private double jy = 0;
50
-
51
- /**
52
- *
53
- * @param runtime ThreadContext
54
- */
55
- public static void createVec2(final Ruby runtime) {
56
- RubyClass vec2Cls = runtime.defineClass("Vec2D", runtime.getObject(), (Ruby runtime1, RubyClass rubyClass) -> new Vec2(runtime1, rubyClass));
57
- vec2Cls.defineAnnotatedMethods(Vec2.class);
58
- }
59
-
60
- public double javax() {
61
- return jx;
62
- }
63
-
64
- public double javay() {
65
- return jy;
66
- }
67
-
68
- /**
69
- *
70
- * @param context ThreadContext
71
- * @param klazz IRubyObject
72
- * @param args optional (no args jx = 0, jy = 0)
73
- * @return new Vec2 object (ruby)
74
- */
75
- @JRubyMethod(name = "new", meta = true, rest = true)
76
- public static final IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject... args) {
77
- Vec2 vec2 = (Vec2) ((RubyClass) klazz).allocate();
78
- vec2.init(context, args);
79
- return vec2;
80
- }
81
-
82
- /**
83
- *
84
- * @param runtime Ruby
85
- * @param klass RubyClass
86
- */
87
- public Vec2(Ruby runtime, RubyClass klass) {
88
- super(runtime, klass);
89
- }
90
-
91
- void init(ThreadContext context, IRubyObject... args) {
92
- int count = args.length;
93
- if (count == 2) {
94
- jx = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
95
- jy = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
96
- } // allow ruby ducktyping in constructor
97
- if (count == 1) {
98
- if (!(args[0].respondsTo("x"))) {
99
- throw context.runtime.newTypeError(args[0].getType() + " doesn't respond_to :x & :y");
100
- }
101
- jx = ((args[0].callMethod(context, "x")) instanceof RubyFloat)
102
- ? ((RubyFloat) args[0].callMethod(context, "x")).getValue() : ((RubyFixnum) args[0].callMethod(context, "x")).getDoubleValue();
103
- jy = ((args[0].callMethod(context, "y")) instanceof RubyFloat)
104
- ? ((RubyFloat) args[0].callMethod(context, "y")).getValue() : ((RubyFixnum) args[0].callMethod(context, "y")).getDoubleValue();
105
- }
106
- }
107
-
108
- /**
109
- *
110
- * @param context ThreadContext
111
- * @return x IRubyObject
112
- */
113
- @JRubyMethod(name = "x")
114
-
115
- public IRubyObject getX(ThreadContext context) {
116
- return context.runtime.newFloat(jx);
117
- }
118
-
119
- /**
120
- *
121
- * @param context ThreadContext
122
- * @return y IRubyObject
123
- */
124
- @JRubyMethod(name = "y")
125
-
126
- public IRubyObject getY(ThreadContext context) {
127
- return context.runtime.newFloat(jy);
128
- }
129
-
130
- /**
131
- *
132
- * @param context ThreadContext
133
- * @param key as symbol
134
- * @return value float
135
- */
136
- @JRubyMethod(name = "[]", required = 1)
137
-
138
- public IRubyObject aref(ThreadContext context, IRubyObject key) {
139
- Ruby runtime = context.runtime;
140
- if (key instanceof RubySymbol) {
141
- if (key == RubySymbol.newSymbol(runtime, "x")) {
142
- return runtime.newFloat(jx);
143
- } else if (key == RubySymbol.newSymbol(runtime, "y")) {
144
- return runtime.newFloat(jy);
145
- } else {
146
- throw runtime.newIndexError("invalid key");
147
- }
148
- } else {
149
- throw runtime.newIndexError("invalid key");
150
- }
151
- }
152
-
153
- /**
154
- * @param context ThreadContext
155
- * @param key as symbol
156
- * @param value as float
157
- * @return value float
158
- */
159
- @JRubyMethod(name = "[]=")
160
-
161
- public IRubyObject aset(ThreadContext context, IRubyObject key, IRubyObject value) {
162
- Ruby runtime = context.runtime;
163
- if (key instanceof RubySymbol) {
164
- if (key == RubySymbol.newSymbol(runtime, "x")) {
165
- jx = (value instanceof RubyFloat)
166
- ? ((RubyFloat) value).getValue() : ((RubyFixnum) value).getDoubleValue();
167
- } else if (key == RubySymbol.newSymbol(runtime, "y")) {
168
- jy = (value instanceof RubyFloat)
169
- ? ((RubyFloat) value).getValue() : ((RubyFixnum) value).getDoubleValue();
170
- }
171
- } else {
172
- throw runtime.newIndexError("invalid key");
173
- }
174
- return value;
175
- }
176
-
177
- /**
178
- *
179
- * @param context ThreadContext
180
- * @param other IRubyObject
181
- * @return x IRubyObject
182
- */
183
- @JRubyMethod(name = "x=")
184
-
185
- public IRubyObject setX(ThreadContext context, IRubyObject other) {
186
- if (other instanceof RubyFloat) {
187
- jx = ((RubyFloat) other).getValue();
188
- } else {
189
- jx = ((RubyFixnum) other).getDoubleValue();
190
- }
191
- return other;
192
- }
193
-
194
- /**
195
- *
196
- * @param context ThreadContext
197
- * @param other IRubyObject
198
- * @return y IRubyObject
199
- */
200
- @JRubyMethod(name = "y=")
201
-
202
- public IRubyObject setY(ThreadContext context, IRubyObject other) {
203
- if (other instanceof RubyFloat) {
204
- jy = ((RubyFloat) other).getValue();
205
- } else {
206
- jy = ((RubyFixnum) other).getDoubleValue();
207
- }
208
- return other;
209
- }
210
-
211
- /**
212
- *
213
- * @param context ThreadContext
214
- * @param other IRubyObject
215
- * @return distance float
216
- */
217
- @JRubyMethod(name = "dist", required = 1)
218
-
219
- public IRubyObject dist(ThreadContext context, IRubyObject other) {
220
- Vec2 b = null;
221
- Ruby runtime = context.runtime;
222
- if (other instanceof Vec2) {
223
- b = (Vec2) other.toJava(Vec2.class);
224
- } else {
225
- throw runtime.newTypeError("argument should be Vec2D");
226
- }
227
- double result = Math.hypot((jx - b.jx), (jy - b.jy));
228
- return runtime.newFloat(result);
229
- }
230
-
231
- /**
232
- *
233
- * @param context ThreadContext
234
- * @param other IRubyObject
235
- * @return cross product IRubyObject
236
- */
237
- @JRubyMethod(name = "cross", required = 1)
238
-
239
- public IRubyObject cross(ThreadContext context, IRubyObject other) {
240
- Vec2 b = null;
241
- Ruby runtime = context.runtime;
242
- if (other instanceof Vec2) {
243
- b = (Vec2) other.toJava(Vec2.class);
244
- } else {
245
- throw runtime.newTypeError("argument should be Vec2D");
246
- }
247
- return runtime.newFloat(jx * b.jy - jy * b.jx);
248
- }
249
-
250
- /**
251
- *
252
- * @param context ThreadContext
253
- * @param other IRubyObject
254
- * @return dot product IRubyObject
255
- */
256
- @JRubyMethod(name = "dot", required = 1)
257
-
258
- public IRubyObject dot(ThreadContext context, IRubyObject other) {
259
- Vec2 b = null;
260
- Ruby runtime = context.runtime;
261
- if (other instanceof Vec2) {
262
- b = (Vec2) other.toJava(Vec2.class);
263
- } else {
264
- throw runtime.newTypeError("argument should be Vec2D");
265
- }
266
- return runtime.newFloat(jx * b.jx + jy * b.jy);
267
- }
268
-
269
- /**
270
- *
271
- * @param context ThreadContext
272
- * @param other IRubyObject
273
- * @return new Vec2D object (ruby)
274
- */
275
- @JRubyMethod(name = "+", required = 1)
276
-
277
- public IRubyObject op_plus(ThreadContext context, IRubyObject other) {
278
- Vec2 b = null;
279
- Ruby runtime = context.runtime;
280
- if (other instanceof Vec2) {
281
- b = (Vec2) other.toJava(Vec2.class);
282
- } else {
283
- throw runtime.newTypeError("argument should be Vec2D");
284
- }
285
- return Vec2.rbNew(context, other.getMetaClass(), new IRubyObject[]{
286
- runtime.newFloat(jx + b.jx),
287
- runtime.newFloat(jy + b.jy)});
288
- }
289
-
290
- /**
291
- *
292
- * @param context ThreadContext
293
- * @param other IRubyObject
294
- * @return new Vec2D object (ruby)
295
- */
296
- @JRubyMethod(name = "-", required = 1)
297
-
298
- public IRubyObject op_minus(ThreadContext context, IRubyObject other) {
299
- Vec2 b = null;
300
- Ruby runtime = context.runtime;
301
- if (other instanceof Vec2) {
302
- b = (Vec2) other.toJava(Vec2.class);
303
- } else {
304
- throw runtime.newTypeError("argument should be Vec2D");
305
- }
306
- return Vec2.rbNew(context, other.getMetaClass(), new IRubyObject[]{
307
- runtime.newFloat(jx - b.jx),
308
- runtime.newFloat(jy - b.jy)});
309
- }
310
-
311
- /**
312
- *
313
- * @param context ThreadContext
314
- * @param other IRubyObject scalar
315
- * @return new Vec2D object (ruby)
316
- */
317
- @JRubyMethod(name = "*")
318
-
319
- public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
320
- Ruby runtime = context.runtime;
321
- double scalar = (other instanceof RubyFloat)
322
- ? ((RubyFloat) other).getValue() : ((RubyFixnum) other).getDoubleValue();
323
- return Vec2.rbNew(context, this.getMetaClass(),
324
- new IRubyObject[]{runtime.newFloat(jx * scalar),
325
- runtime.newFloat(jy * scalar)});
326
- }
327
-
328
- /**
329
- *
330
- * @param context ThreadContext
331
- * @param other IRubyObject scalar
332
- * @return new Vec2D object (ruby)
333
- */
334
- @JRubyMethod(name = "/", required = 1)
335
-
336
- public IRubyObject op_div(ThreadContext context, IRubyObject other) {
337
- Ruby runtime = context.runtime;
338
- double scalar = (other instanceof RubyFloat)
339
- ? ((RubyFloat) other).getValue() : ((RubyFixnum) other).getDoubleValue();
340
- if (Math.abs(scalar) < Vec2.EPSILON) {
341
- return this;
342
- }
343
- return Vec2.rbNew(context, this.getMetaClass(), new IRubyObject[]{
344
- runtime.newFloat(jx / scalar),
345
- runtime.newFloat(jy / scalar)});
346
- }
347
-
348
- /**
349
- *
350
- * @param context ThreadContext
351
- * @return heading IRubyObject radians
352
- */
353
- @JRubyMethod(name = "heading")
354
- public IRubyObject heading(ThreadContext context) {
355
- return context.runtime.newFloat(Math.atan2(jy, jx));
356
- }
357
-
358
- /**
359
- *
360
- * @param context ThreadContext
361
- * @return heading IRubyObject radians
362
- */
363
- @JRubyMethod(name = "fast_heading")
364
- public IRubyObject fastHeading(ThreadContext context) {
365
- return context.runtime.newFloat(fastAtan2(jy, jx));
366
- }
367
-
368
- /**
369
- *
370
- * @param context ThreadContext
371
- * @return magnitude IRubyObject
372
- */
373
- @JRubyMethod(name = "mag")
374
-
375
- public IRubyObject mag(ThreadContext context) {
376
- double result = 0;
377
- if (Math.abs(jx) > EPSILON && Math.abs(jy) > EPSILON) {
378
- result = Math.hypot(jx, jy);
379
- } else {
380
- if (Math.abs(jy) > EPSILON) {
381
- result = Math.abs(jy);
382
- }
383
- if (Math.abs(jx) > EPSILON) {
384
- result = Math.abs(jx);
385
- }
386
- }
387
- return context.runtime.newFloat(result);
388
- }
389
-
390
- /**
391
- * Call yield if block given, do nothing if yield == false else set_mag to
392
- * given scalar
393
- *
394
- * @param context ThreadContext
395
- * @param scalar double value to set
396
- * @param block should return a boolean (optional)
397
- * @return magnitude IRubyObject
398
- */
399
- @JRubyMethod(name = "set_mag")
400
-
401
- public IRubyObject set_mag(ThreadContext context, IRubyObject scalar, Block block) {
402
- double new_mag = scalar.toJava(Double.class);
403
- if (block.isGiven()) {
404
- if (!(boolean) block.yield(context, scalar).toJava(Boolean.class)) {
405
- return this;
406
- }
407
- }
408
- double current = 0;
409
- if (Math.abs(jx) > EPSILON && Math.abs(jy) > EPSILON) {
410
- current = Math.hypot(jx, jy);
411
- } else {
412
- if (Math.abs(jy) > EPSILON) {
413
- current = Math.abs(jy);
414
- }
415
- if (Math.abs(jx) > EPSILON) {
416
- current = Math.abs(jx);
417
- }
418
- }
419
- if (current > 0) {
420
- jx *= new_mag / current;
421
- jy *= new_mag / current;
422
- }
423
- return this;
424
- }
425
-
426
- /**
427
- *
428
- * @param context ThreadContext
429
- * @return this as a ruby object
430
- */
431
- @JRubyMethod(name = "normalize!")
432
-
433
- public IRubyObject normalize_bang(ThreadContext context) {
434
- double mag = 0;
435
- if (Math.abs(jx) > EPSILON && Math.abs(jy) > EPSILON) {
436
- mag = Math.hypot(jx, jy);
437
- } else {
438
- if (Math.abs(jx) > EPSILON) {
439
- mag = Math.abs(jx);
440
- }
441
- if (Math.abs(jy) > EPSILON) {
442
- mag = Math.abs(jy);
443
- }
444
- }
445
- if (mag > 0) {
446
- jx /= mag;
447
- jy /= mag;
448
- }
449
- return this;
450
- }
451
-
452
- /**
453
- *
454
- * @param context ThreadContext
455
- * @return new normalized Vec2D object (ruby)
456
- */
457
- @JRubyMethod(name = "normalize")
458
-
459
- public IRubyObject normalize(ThreadContext context) {
460
- double mag = 0;
461
- Ruby runtime = context.runtime;
462
- if (Math.abs(jx) > EPSILON && Math.abs(jy) > EPSILON) {
463
- mag = Math.hypot(jx, jy);
464
- } else {
465
- if (Math.abs(jx) > EPSILON) {
466
- mag = jx;
467
- }
468
- if (Math.abs(jy) > EPSILON) {
469
- mag = jy;
470
- }
471
- }
472
- if (mag < EPSILON) {
473
- mag = 1.0;
474
- }
475
- return Vec2.rbNew(context, this.getMetaClass(), new IRubyObject[]{
476
- runtime.newFloat(jx / mag),
477
- runtime.newFloat(jy / mag)});
478
- }
479
-
480
- /**
481
- * Example of a regular ruby class method Use Math rather than RadLut
482
- * here!!!
483
- *
484
- * @param context ThreadContext
485
- * @param klazz IRubyObject
486
- * @param scalar input angle in radians
487
- * @return new Vec2 object (ruby)
488
- */
489
- @JRubyMethod(name = "from_angle", meta = true)
490
- public static IRubyObject from_angle(ThreadContext context, IRubyObject klazz, IRubyObject scalar) {
491
- Ruby runtime = context.runtime;
492
- double angle = (scalar instanceof RubyFloat)
493
- ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
494
- return Vec2.rbNew(context, klazz, new IRubyObject[]{
495
- runtime.newFloat(Math.cos(angle)),
496
- runtime.newFloat(Math.sin(angle))});
497
- }
498
-
499
- /**
500
- * Example of a regular ruby class method
501
- *
502
- * @param context ThreadContext
503
- * @param klazz IRubyObject
504
- * @return new Vec2 object (ruby)
505
- */
506
- @JRubyMethod(name = "random", meta = true)
507
- public static IRubyObject random_direction(ThreadContext context, IRubyObject klazz) {
508
- Ruby runtime = context.runtime;
509
- double angle = Math.random() * Math.PI * 2;
510
- return Vec2.rbNew(context, klazz, new IRubyObject[]{
511
- runtime.newFloat(Math.cos(angle)),
512
- runtime.newFloat(Math.sin(angle))});
513
- }
514
-
515
- /**
516
- *
517
- * @param context ThreadContext
518
- * @param scalar IRubyObject
519
- * @return this Vec2 object rotated
520
- */
521
- @JRubyMethod(name = "rotate!")
522
- public IRubyObject rotate_bang(ThreadContext context, IRubyObject scalar) {
523
- double theta = (scalar instanceof RubyFloat)
524
- ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
525
- double x = (jx * Math.cos(theta) - jy * Math.sin(theta));
526
- double y = (jx * Math.sin(theta) + jy * Math.cos(theta));
527
- jx = x;
528
- jy = y;
529
- return this;
530
- }
531
-
532
- /**
533
- *
534
- * @param context ThreadContext
535
- * @param scalar IRubyObject
536
- * @return a new Vec2 object rotated
537
- */
538
- @JRubyMethod(name = "rotate")
539
- public IRubyObject rotate(ThreadContext context, IRubyObject scalar) {
540
- Ruby runtime = context.runtime;
541
- double theta = (scalar instanceof RubyFloat)
542
- ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
543
- IRubyObject[] ary = new IRubyObject[]{
544
- runtime.newFloat(jx * Math.cos(theta) - jy * Math.sin(theta)),
545
- runtime.newFloat(jx * Math.sin(theta) + jy * Math.cos(theta))};
546
- return Vec2.rbNew(context, this.getMetaClass(), ary);
547
- }
548
-
549
- /**
550
- *
551
- * @param context ThreadContext
552
- * @param args IRubyObject[]
553
- * @return as a new Vec2 object (ruby)
554
- */
555
- @JRubyMethod(name = "lerp", rest = true)
556
- public IRubyObject lerp(ThreadContext context, IRubyObject[] args) {
557
- Ruby runtime = context.runtime;
558
- if (args.length != 2) {
559
- throw runtime.newSyntaxError("Check syntax");
560
- }
561
- Vec2 vec = (Vec2) args[0].toJava(Vec2.class);
562
- double scalar = (args[1] instanceof RubyFloat)
563
- ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
564
- assert (scalar >= 0 && scalar < 1.0) :
565
- "Lerp value " + scalar + " out of range 0..1.0";
566
- return Vec2.rbNew(context, this.getMetaClass(), new IRubyObject[]{
567
- runtime.newFloat(jx + (vec.jx - jx) * scalar),
568
- runtime.newFloat(jy + (vec.jy - jy) * scalar)});
569
- }
570
-
571
- /**
572
- *
573
- * @param context ThreadContext
574
- * @param args IRubyObject[]
575
- * @return this IRubyObject
576
- */
577
- @JRubyMethod(name = "lerp!", rest = true)
578
- public IRubyObject lerp_bang(ThreadContext context, IRubyObject[] args) {
579
- Ruby runtime = context.runtime;
580
- if (args.length != 2) {
581
- throw runtime.newSyntaxError("Check syntax");
582
- }
583
- Vec2 vec = (Vec2) args[0].toJava(Vec2.class);
584
- double scalar = (args[1] instanceof RubyFloat)
585
- ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
586
- assert (scalar >= 0 && scalar < 1.0) :
587
- "Lerp value " + scalar + " out of range 0..1.0";
588
- jx += (vec.jx - jx) * scalar;
589
- jy += (vec.jy - jy) * scalar;
590
- return this;
591
- }
592
-
593
- /**
594
- *
595
- * @param context ThreadContext
596
- * @param other IRubyObject another Vec2D
597
- * @return angle IRubyObject in radians
598
- */
599
- @JRubyMethod(name = "angle_between")
600
-
601
- public IRubyObject angleBetween(ThreadContext context, IRubyObject other) {
602
- Vec2 vec = null;
603
- Ruby runtime = context.runtime;
604
- if (other instanceof Vec2) {
605
- vec = (Vec2) other.toJava(Vec2.class);
606
- } else {
607
- throw runtime.newTypeError("argument should be Vec2D");
608
- }
609
- return runtime.newFloat(Math.atan2(jx - vec.jx, jy - vec.jy));
610
- }
611
-
612
- /**
613
- *
614
- * @param context ThreadContext
615
- * @param other IRubyObject another Vec2D
616
- * @return angle IRubyObject in radians
617
- */
618
- @JRubyMethod(name = "fast_angle_between")
619
-
620
- public IRubyObject fastAngleBetween(ThreadContext context, IRubyObject other) {
621
- Vec2 vec = null;
622
- Ruby runtime = context.runtime;
623
- if (other instanceof Vec2) {
624
- vec = (Vec2) other.toJava(Vec2.class);
625
- } else {
626
- throw runtime.newTypeError("argument should be Vec2D");
627
- }
628
- return runtime.newFloat(fastAtan2(jx - vec.jx, jy - vec.jy));
629
- }
630
-
631
- /**
632
- *
633
- * @param context ThreadContext
634
- * @return IRubyObject copy
635
- */
636
- @JRubyMethod(name = {"copy", "dup"})
637
-
638
- public IRubyObject copy(ThreadContext context) {
639
- Ruby runtime = context.runtime;
640
- return Vec2.rbNew(context, this.getMetaClass(), new IRubyObject[]{
641
- runtime.newFloat(jx),
642
- runtime.newFloat(jy)});
643
- }
644
-
645
- /**
646
- *
647
- * @param context ThreadContext
648
- * @return IRubyObject array of float
649
- */
650
- @JRubyMethod(name = "to_a")
651
-
652
- public IRubyObject toArray(ThreadContext context) {
653
- Ruby runtime = context.runtime;
654
- return RubyArray.newArray(runtime, new IRubyObject[]{
655
- runtime.newFloat(jx),
656
- runtime.newFloat(jy)});
657
- }
658
-
659
- /**
660
- *
661
- * To vertex
662
- *
663
- * @param context ThreadContext
664
- * @param object IRubyObject vertex renderer
665
- */
666
- @JRubyMethod(name = "to_vertex")
667
-
668
- public void toVertex(ThreadContext context, IRubyObject object) {
669
- JRender renderer = (JRender) object.toJava(JRender.class);
670
- renderer.vertex(jx, jy);
671
- }
672
-
673
- /**
674
- *
675
- * To curve vertex
676
- *
677
- * @param context ThreadContext
678
- * @param object IRubyObject vertex renderer
679
- */
680
- @JRubyMethod(name = "to_curve_vertex")
681
-
682
- public void toCurveVertex(ThreadContext context, IRubyObject object) {
683
- JRender renderer = (JRender) object.toJava(JRender.class);
684
- renderer.curveVertex(jx, jy);
685
- }
686
-
687
- /**
688
- * For jruby-9000 we alias to inspect
689
- *
690
- * @param context ThreadContext
691
- * @return IRubyObject to_s
692
- */
693
- @JRubyMethod(name = {"to_s", "inspect"})
694
-
695
- public IRubyObject to_s(ThreadContext context) {
696
- return context.runtime.newString(String.format("Vec2D(x = %4.4f, y = %4.4f)", jx, jy));
697
- }
698
-
699
- private double fastAtan2(double y, double x) {
700
- if (x == 0) {
701
- if (y > 0) {
702
- return Math.PI / 2;
703
- }
704
- if (y == 0) {
705
- return 0;
706
- }
707
- return -Math.PI / 2;
708
- }
709
- final double atan, z = y / x;
710
- if (Math.abs(z) < 1) {
711
- atan = z / (1 + 0.28 * z * z);
712
- if (x < 0) {
713
- return atan + (y < 0 ? -Math.PI : Math.PI);
714
- }
715
- return atan;
716
- }
717
- atan = Math.PI / 2 - z / (z * z + 0.28);
718
- return y < 0 ? atan - Math.PI : atan;
719
- }
720
-
721
- /**
722
- *
723
- * @return hash int
724
- */
725
- @Override
726
- public int hashCode() {
727
- int hash = 5;
728
- hash = 53 * hash + (int) (Double.doubleToLongBits(this.jx) ^ (Double.doubleToLongBits(this.jx) >>> 32));
729
- hash = 53 * hash + (int) (Double.doubleToLongBits(this.jy) ^ (Double.doubleToLongBits(this.jy) >>> 32));
730
- return hash;
731
- }
732
-
733
- /**
734
- *
735
- * Java Equals
736
- *
737
- * @param obj Object
738
- * @return result boolean
739
- */
740
- @Override
741
- public boolean equals(Object obj) {
742
- if (obj == this) {
743
- return true;
744
- }
745
- if (obj instanceof Vec2) {
746
- final Vec2 other = (Vec2) obj;
747
- if ((Double.compare(jx, (Double) other.jx) == 0)
748
- && (Double.compare(jy, (Double) other.jy) == 0)) {
749
- return true;
750
- }
751
- }
752
- return false;
753
- }
754
-
755
- /**
756
- *
757
- * @param context ThreadContext
758
- * @param other IRubyObject
759
- * @return result IRubyObject as boolean
760
- */
761
- @JRubyMethod(name = "eql?", required = 1)
762
- public IRubyObject eql_p(ThreadContext context, IRubyObject other) {
763
- Ruby runtime = context.runtime;
764
- if (other == this) {
765
- return runtime.newBoolean(true);
766
- }
767
- if (other instanceof Vec2) {
768
- Vec2 v = (Vec2) other.toJava(Vec2.class);
769
- if ((Double.compare(jx, (Double) v.jx) == 0)
770
- && (Double.compare(jy, (Double) v.jy) == 0)) {
771
- return runtime.newBoolean(true);
772
- }
773
- }
774
- return runtime.newBoolean(false);
775
- }
776
-
777
- /**
778
- *
779
- * @param context ThreadContext
780
- * @param other IRubyObject
781
- * @return result IRubyObject as boolean
782
- */
783
- @JRubyMethod(name = "==", required = 1)
784
-
785
- @Override
786
- public IRubyObject op_equal(ThreadContext context, IRubyObject other) {
787
- Ruby runtime = context.runtime;
788
- if (other == this) {
789
- return runtime.newBoolean(true);
790
- }
791
- if (other instanceof Vec2) {
792
- Vec2 v = (Vec2) other.toJava(Vec2.class);
793
- double diff = jx - v.jx;
794
- if ((diff < 0 ? -diff : diff) > Vec2.EPSILON) {
795
- return runtime.newBoolean(false);
796
- }
797
- diff = jy - v.jy;
798
- return runtime.newBoolean((diff < 0 ? -diff : diff) < Vec2.EPSILON);
799
- }
800
- return runtime.newBoolean(false);
801
- }
802
- }