propane 3.8.0-java → 4.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/maven-wrapper.properties +1 -1
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +7 -1
  6. data/README.md +7 -7
  7. data/Rakefile +6 -5
  8. data/lib/propane/app.rb +10 -17
  9. data/lib/propane/helper_methods.rb +6 -6
  10. data/lib/propane/version.rb +1 -1
  11. data/lib/propane-4.0.0.jar +0 -0
  12. data/library/pdf/itextpdf-5.5.13.2.jar +0 -0
  13. data/library/pdf/pdf.rb +7 -0
  14. data/library/slider/slider.rb +1 -1
  15. data/library/svg/batik-all-1.14.jar +0 -0
  16. data/library/svg/svg.rb +7 -0
  17. data/mvnw +3 -3
  18. data/mvnw.cmd +2 -2
  19. data/pom.rb +35 -8
  20. data/pom.xml +60 -9
  21. data/propane.gemspec +9 -7
  22. data/src/main/java/monkstone/ColorUtil.java +1 -1
  23. data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
  24. data/src/main/java/monkstone/MathToolModule.java +31 -31
  25. data/src/main/java/monkstone/PropaneLibrary.java +3 -1
  26. data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
  27. data/src/main/java/monkstone/fastmath/DegLutTables.java +25 -26
  28. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  29. data/src/main/java/monkstone/filechooser/Chooser.java +2 -2
  30. data/src/main/java/monkstone/noise/LICENSE +121 -0
  31. data/src/main/java/monkstone/noise/OpenSimplex2F.java +914 -0
  32. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
  33. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  34. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  35. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  36. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  37. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  38. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  39. data/src/main/java/monkstone/slider/WheelHandler.java +2 -2
  40. data/src/main/java/monkstone/vecmath/JRender.java +6 -6
  41. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  42. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +103 -83
  43. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +27 -41
  44. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  45. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  46. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  47. data/src/main/java/processing/awt/PGraphicsJava2D.java +11 -4
  48. data/src/main/java/processing/awt/PImageAWT.java +8 -8
  49. data/src/main/java/processing/core/PApplet.java +245 -254
  50. data/src/main/java/processing/core/PConstants.java +155 -163
  51. data/src/main/java/processing/core/PGraphics.java +116 -109
  52. data/src/main/java/processing/core/PImage.java +3025 -3047
  53. data/src/main/java/processing/core/PMatrix.java +5 -2
  54. data/src/main/java/processing/data/DoubleDict.java +72 -43
  55. data/src/main/java/processing/data/DoubleList.java +6 -2
  56. data/src/main/java/processing/data/FloatDict.java +744 -756
  57. data/src/main/java/processing/data/FloatList.java +68 -26
  58. data/src/main/java/processing/data/IntDict.java +72 -45
  59. data/src/main/java/processing/data/IntList.java +63 -26
  60. data/src/main/java/processing/data/JSONArray.java +892 -931
  61. data/src/main/java/processing/data/JSONObject.java +1169 -1262
  62. data/src/main/java/processing/data/JSONTokener.java +30 -49
  63. data/src/main/java/processing/data/LongDict.java +699 -712
  64. data/src/main/java/processing/data/LongList.java +676 -700
  65. data/src/main/java/processing/data/Sort.java +1 -0
  66. data/src/main/java/processing/data/Table.java +4040 -3661
  67. data/src/main/java/processing/data/TableRow.java +16 -0
  68. data/src/main/java/processing/data/XML.java +1041 -956
  69. data/src/main/java/processing/event/TouchEvent.java +1 -1
  70. data/src/main/java/processing/opengl/FontTexture.java +2 -2
  71. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +28 -31
  72. data/src/main/java/processing/opengl/PJOGL.java +8 -7
  73. data/src/main/java/processing/opengl/PShader.java +1 -6
  74. data/src/main/java/processing/opengl/PShapeOpenGL.java +23 -24
  75. data/src/main/java/processing/opengl/PSurfaceJOGL.java +6 -6
  76. data/src/main/java/processing/pdf/PGraphicsPDF.java +581 -0
  77. data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
  78. data/src/main/{java/processing/opengl → resources}/cursors/arrow.png +0 -0
  79. data/src/main/{java/processing/opengl → resources}/cursors/cross.png +0 -0
  80. data/src/main/{java/processing/opengl → resources}/cursors/hand.png +0 -0
  81. data/src/main/{java/processing/opengl → resources}/cursors/license.txt +0 -0
  82. data/src/main/{java/processing/opengl → resources}/cursors/move.png +0 -0
  83. data/src/main/{java/processing/opengl → resources}/cursors/text.png +0 -0
  84. data/src/main/{java/processing/opengl → resources}/cursors/wait.png +0 -0
  85. data/src/main/{java/processing/opengl → resources}/shaders/ColorFrag.glsl +0 -0
  86. data/src/main/{java/processing/opengl → resources}/shaders/ColorVert.glsl +0 -0
  87. data/src/main/{java/processing/opengl → resources}/shaders/LightFrag.glsl +0 -0
  88. data/src/main/{java/processing/opengl → resources}/shaders/LightVert.glsl +0 -0
  89. data/src/main/{java/processing/opengl → resources}/shaders/LineFrag.glsl +0 -0
  90. data/src/main/{java/processing/opengl → resources}/shaders/LineVert.glsl +0 -0
  91. data/src/main/{java/processing/opengl → resources}/shaders/MaskFrag.glsl +0 -0
  92. data/src/main/{java/processing/opengl → resources}/shaders/PointFrag.glsl +0 -0
  93. data/src/main/{java/processing/opengl → resources}/shaders/PointVert.glsl +0 -0
  94. data/src/main/{java/processing/opengl → resources}/shaders/TexFrag.glsl +0 -0
  95. data/src/main/{java/processing/opengl → resources}/shaders/TexLightFrag.glsl +0 -0
  96. data/src/main/{java/processing/opengl → resources}/shaders/TexLightVert.glsl +0 -0
  97. data/src/main/{java/processing/opengl → resources}/shaders/TexVert.glsl +0 -0
  98. data/test/test_helper.rb +1 -0
  99. data/test/vecmath_spec_test.rb +14 -3
  100. data/vendors/Rakefile +1 -1
  101. metadata +53 -53
  102. data/lib/propane-3.8.0.jar +0 -0
  103. data/src/main/java/monkstone/noise/Noise.java +0 -116
  104. data/src/main/java/monkstone/noise/NoiseGenerator.java +0 -63
  105. data/src/main/java/monkstone/noise/NoiseMode.java +0 -15
  106. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -470
  107. data/src/main/java/monkstone/noise/ValueNoise.java +0 -170
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-20 Martin Prout
2
+ * Copyright (c) 2015-22 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-20 Martin Prout
2
+ * Copyright (c) 2015-22 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-20 Martin Prout
2
+ * Copyright (c) 2015-22 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-20 Martin Prout
2
+ * Copyright (c) 2015-22 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-20 Martin Prout
2
+ * Copyright (c) 2015-22 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-20 Martin Prout
2
+ * Copyright (c) 2015-22 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-20 Martin Prout
2
+ * Copyright (c) 2015-22 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -31,5 +31,5 @@ public interface WheelHandler {
31
31
  *
32
32
  * @param amount int
33
33
  */
34
- public void handleWheel(final short amount);
34
+ void handleWheel(final short amount);
35
35
  }
@@ -11,14 +11,14 @@ public interface JRender {
11
11
  * @param x double
12
12
  * @param y double
13
13
  */
14
- public void vertex(double x, double y);
14
+ void vertex(double x, double y);
15
15
 
16
16
  /**
17
17
  *
18
18
  * @param x double
19
19
  * @param y double
20
20
  */
21
- public void curveVertex(double x, double y);
21
+ void curveVertex(double x, double y);
22
22
 
23
23
  /**
24
24
  *
@@ -26,7 +26,7 @@ public interface JRender {
26
26
  * @param y double
27
27
  * @param z double
28
28
  */
29
- public void vertex(double x, double y, double z);
29
+ void vertex(double x, double y, double z);
30
30
 
31
31
  /**
32
32
  *
@@ -36,7 +36,7 @@ public interface JRender {
36
36
  * @param u double
37
37
  * @param v double
38
38
  */
39
- public void vertex(double x, double y, double z, double u, double v);
39
+ void vertex(double x, double y, double z, double u, double v);
40
40
 
41
41
  /**
42
42
  *
@@ -44,7 +44,7 @@ public interface JRender {
44
44
  * @param y double
45
45
  * @param z double
46
46
  */
47
- public void curveVertex(double x, double y, double z);
47
+ void curveVertex(double x, double y, double z);
48
48
 
49
49
  /**
50
50
  *
@@ -52,5 +52,5 @@ public interface JRender {
52
52
  * @param y double
53
53
  * @param z double
54
54
  */
55
- public void normal(double x, double y, double z);
55
+ void normal(double x, double y, double z);
56
56
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-20 Martin Prout
2
+ * Copyright (c) 2015-22 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -1,7 +1,7 @@
1
1
  package monkstone.vecmath.vec2;
2
2
 
3
3
  /*
4
- * Copyright (c) 2015-20 Martin Prout
4
+ * Copyright (c) 2015-22 Martin Prout
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
7
7
  * modify it under the terms of the GNU Lesser General Public
@@ -21,6 +21,7 @@ package monkstone.vecmath.vec2;
21
21
  *
22
22
  * fastAtan2 algorithm from https://github.com/libgdx/libgdx (Apache 2.0 license)
23
23
  */
24
+ import java.util.logging.Logger;
24
25
  import org.jruby.Ruby;
25
26
  import org.jruby.RubyArray;
26
27
  import org.jruby.RubyClass;
@@ -40,11 +41,10 @@ import monkstone.vecmath.JRender;
40
41
  * @author Martin Prout
41
42
  */
42
43
  @JRubyClass(name = "Vec2D")
43
- public class Vec2 extends RubyObject {
44
+ public final class Vec2 extends RubyObject {
44
45
 
45
46
  static final double EPSILON = 9.999999747378752e-05; // matches processing.org EPSILON
46
47
  private static final long serialVersionUID = -2950154560223211646L;
47
-
48
48
  private double jx = 0;
49
49
  private double jy = 0;
50
50
 
@@ -73,7 +73,7 @@ public class Vec2 extends RubyObject {
73
73
  * @return new Vec2 object (ruby)
74
74
  */
75
75
  @JRubyMethod(name = "new", meta = true, rest = true)
76
- public static final IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject... args) {
76
+ public static IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject... args) {
77
77
  Vec2 vec2 = (Vec2) ((RubyClass) klazz).allocate();
78
78
  vec2.init(context, args);
79
79
  return vec2;
@@ -91,17 +91,15 @@ public class Vec2 extends RubyObject {
91
91
  void init(ThreadContext context, IRubyObject... args) {
92
92
  int count = args.length;
93
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();
94
+ jx = jvalue(args[0]);
95
+ jy = jvalue(args[1]);
96
96
  } // allow ruby ducktyping in constructor
97
97
  if (count == 1) {
98
98
  if (!(args[0].respondsTo("x"))) {
99
99
  throw context.runtime.newTypeError(args[0].getType() + " doesn't respond_to :x & :y");
100
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();
101
+ jx = jvalue(args[0].callMethod(context, "x"));
102
+ jy = jvalue(args[0].callMethod(context, "y"));
105
103
  }
106
104
  }
107
105
 
@@ -137,13 +135,14 @@ public class Vec2 extends RubyObject {
137
135
 
138
136
  public IRubyObject aref(ThreadContext context, IRubyObject key) {
139
137
  Ruby runtime = context.runtime;
140
- if (key instanceof RubySymbol) {
141
- if (key == RubySymbol.newSymbol(runtime, "x")) {
138
+ if (key instanceof RubySymbol rubySymbol) {
139
+ if (rubySymbol.equals(RubySymbol.newSymbol(runtime, "x"))) {
142
140
  return runtime.newFloat(jx);
143
- } else if (key == RubySymbol.newSymbol(runtime, "y")) {
141
+ }
142
+ if (rubySymbol.equals(RubySymbol.newSymbol(runtime, "y"))) {
144
143
  return runtime.newFloat(jy);
145
144
  } else {
146
- throw runtime.newIndexError("invalid key");
145
+ throw runtime.newIndexError("unknown key");
147
146
  }
148
147
  } else {
149
148
  throw runtime.newIndexError("invalid key");
@@ -160,13 +159,13 @@ public class Vec2 extends RubyObject {
160
159
 
161
160
  public IRubyObject aset(ThreadContext context, IRubyObject key, IRubyObject value) {
162
161
  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();
162
+ if (key instanceof RubySymbol rubySymbol) {
163
+ if (rubySymbol.equals(RubySymbol.newSymbol(runtime, "x"))) {
164
+ jx = jvalue(value);
165
+ } else if (rubySymbol.equals(RubySymbol.newSymbol(runtime, "y"))) {
166
+ jy = jvalue(value);
167
+ } else {
168
+ throw runtime.newIndexError("unknown key");
170
169
  }
171
170
  } else {
172
171
  throw runtime.newIndexError("invalid key");
@@ -183,11 +182,7 @@ public class Vec2 extends RubyObject {
183
182
  @JRubyMethod(name = "x=")
184
183
 
185
184
  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
- }
185
+ jx = jvalue(other);
191
186
  return other;
192
187
  }
193
188
 
@@ -200,11 +195,7 @@ public class Vec2 extends RubyObject {
200
195
  @JRubyMethod(name = "y=")
201
196
 
202
197
  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
- }
198
+ jy = jvalue(other);
208
199
  return other;
209
200
  }
210
201
 
@@ -219,28 +210,36 @@ public class Vec2 extends RubyObject {
219
210
  public IRubyObject dist(ThreadContext context, IRubyObject other) {
220
211
  Vec2 b = null;
221
212
  Ruby runtime = context.runtime;
222
- if (other instanceof Vec2) {
223
- b = (Vec2) other.toJava(Vec2.class);
213
+ if (other instanceof Vec2 vec) {
214
+ b = vec.toJava(Vec2.class);
224
215
  } else {
225
216
  throw runtime.newTypeError("argument should be Vec2D");
226
217
  }
227
- double result = Math.hypot((jx - b.jx), (jy - b.jy));
218
+ double result = Math.hypot(jx - b.jx, jy - b.jy);
228
219
  return runtime.newFloat(result);
229
220
  }
221
+
222
+ @Deprecated
223
+ @JRubyMethod(name = "cross", required = 1)
224
+ public IRubyObject cross(ThreadContext context, IRubyObject other) {
225
+ Logger log = Logger.getGlobal();
226
+ log.warning("prefer ^ operator");
227
+ return op_wedge(context, other);
228
+ }
230
229
 
231
230
  /**
232
231
  *
233
232
  * @param context ThreadContext
234
233
  * @param other IRubyObject
235
- * @return cross product IRubyObject
234
+ * @return wedge product IRubyObject
236
235
  */
237
- @JRubyMethod(name = "cross", required = 1)
236
+ @JRubyMethod(name = "^", required = 1)
238
237
 
239
- public IRubyObject cross(ThreadContext context, IRubyObject other) {
238
+ public IRubyObject op_wedge(ThreadContext context, IRubyObject other) {
240
239
  Vec2 b = null;
241
240
  Ruby runtime = context.runtime;
242
- if (other instanceof Vec2) {
243
- b = (Vec2) other.toJava(Vec2.class);
241
+ if (other instanceof Vec2 vec) {
242
+ b = vec.toJava(Vec2.class);
244
243
  } else {
245
244
  throw runtime.newTypeError("argument should be Vec2D");
246
245
  }
@@ -258,8 +257,8 @@ public class Vec2 extends RubyObject {
258
257
  public IRubyObject dot(ThreadContext context, IRubyObject other) {
259
258
  Vec2 b = null;
260
259
  Ruby runtime = context.runtime;
261
- if (other instanceof Vec2) {
262
- b = (Vec2) other.toJava(Vec2.class);
260
+ if (other instanceof Vec2 vec) {
261
+ b = vec.toJava(Vec2.class);
263
262
  } else {
264
263
  throw runtime.newTypeError("argument should be Vec2D");
265
264
  }
@@ -277,8 +276,8 @@ public class Vec2 extends RubyObject {
277
276
  public IRubyObject op_plus(ThreadContext context, IRubyObject other) {
278
277
  Vec2 b = null;
279
278
  Ruby runtime = context.runtime;
280
- if (other instanceof Vec2) {
281
- b = (Vec2) other.toJava(Vec2.class);
279
+ if (other instanceof Vec2 vec) {
280
+ b = vec.toJava(Vec2.class);
282
281
  } else {
283
282
  throw runtime.newTypeError("argument should be Vec2D");
284
283
  }
@@ -298,8 +297,8 @@ public class Vec2 extends RubyObject {
298
297
  public IRubyObject op_minus(ThreadContext context, IRubyObject other) {
299
298
  Vec2 b = null;
300
299
  Ruby runtime = context.runtime;
301
- if (other instanceof Vec2) {
302
- b = (Vec2) other.toJava(Vec2.class);
300
+ if (other instanceof Vec2 vec) {
301
+ b = vec.toJava(Vec2.class);
303
302
  } else {
304
303
  throw runtime.newTypeError("argument should be Vec2D");
305
304
  }
@@ -308,6 +307,38 @@ public class Vec2 extends RubyObject {
308
307
  runtime.newFloat(jy - b.jy)});
309
308
  }
310
309
 
310
+ /**
311
+ * Utility method
312
+ *
313
+ * @param obj
314
+ * @return scalar value of object or unity (preempts poss division by zero)
315
+ */
316
+ private static double jscalar(IRubyObject obj) {
317
+ if (obj instanceof RubyFloat rubyFloat) {
318
+ return rubyFloat.getValue();
319
+ }
320
+ if (obj instanceof RubyFixnum rubyFixnum) {
321
+ return rubyFixnum.getDoubleValue();
322
+ }
323
+ return 1.0;
324
+ }
325
+
326
+ /**
327
+ * Utility method
328
+ *
329
+ * @param obj
330
+ * @return parse float value of object or zero
331
+ */
332
+ private static double jvalue(IRubyObject obj) {
333
+ if (obj instanceof RubyFloat rubyFloat) {
334
+ return rubyFloat.getValue();
335
+ }
336
+ if (obj instanceof RubyFixnum rubyFixnum) {
337
+ return rubyFixnum.getDoubleValue();
338
+ }
339
+ return 0;
340
+ }
341
+
311
342
  /**
312
343
  *
313
344
  * @param context ThreadContext
@@ -318,8 +349,7 @@ public class Vec2 extends RubyObject {
318
349
 
319
350
  public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
320
351
  Ruby runtime = context.runtime;
321
- double scalar = (other instanceof RubyFloat)
322
- ? ((RubyFloat) other).getValue() : ((RubyFixnum) other).getDoubleValue();
352
+ double scalar = jscalar(other);
323
353
  return Vec2.rbNew(context, this.getMetaClass(),
324
354
  new IRubyObject[]{runtime.newFloat(jx * scalar),
325
355
  runtime.newFloat(jy * scalar)});
@@ -335,8 +365,7 @@ public class Vec2 extends RubyObject {
335
365
 
336
366
  public IRubyObject op_div(ThreadContext context, IRubyObject other) {
337
367
  Ruby runtime = context.runtime;
338
- double scalar = (other instanceof RubyFloat)
339
- ? ((RubyFloat) other).getValue() : ((RubyFixnum) other).getDoubleValue();
368
+ double scalar = jscalar(other);
340
369
  if (Math.abs(scalar) < Vec2.EPSILON) {
341
370
  return this;
342
371
  }
@@ -400,10 +429,8 @@ public class Vec2 extends RubyObject {
400
429
 
401
430
  public IRubyObject set_mag(ThreadContext context, IRubyObject scalar, Block block) {
402
431
  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
- }
432
+ if (block.isGiven() && !block.yield(context, scalar).toJava(Boolean.class)) {
433
+ return this;
407
434
  }
408
435
  double current = 0;
409
436
  if (Math.abs(jx) > EPSILON && Math.abs(jy) > EPSILON) {
@@ -489,8 +516,7 @@ public class Vec2 extends RubyObject {
489
516
  @JRubyMethod(name = "from_angle", meta = true)
490
517
  public static IRubyObject from_angle(ThreadContext context, IRubyObject klazz, IRubyObject scalar) {
491
518
  Ruby runtime = context.runtime;
492
- double angle = (scalar instanceof RubyFloat)
493
- ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
519
+ double angle = jvalue(scalar);
494
520
  return Vec2.rbNew(context, klazz, new IRubyObject[]{
495
521
  runtime.newFloat(Math.cos(angle)),
496
522
  runtime.newFloat(Math.sin(angle))});
@@ -520,10 +546,9 @@ public class Vec2 extends RubyObject {
520
546
  */
521
547
  @JRubyMethod(name = "rotate!")
522
548
  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));
549
+ double theta = jvalue(scalar);
550
+ double x = jx * Math.cos(theta) - jy * Math.sin(theta);
551
+ double y = jx * Math.sin(theta) + jy * Math.cos(theta);
527
552
  jx = x;
528
553
  jy = y;
529
554
  return this;
@@ -538,8 +563,7 @@ public class Vec2 extends RubyObject {
538
563
  @JRubyMethod(name = "rotate")
539
564
  public IRubyObject rotate(ThreadContext context, IRubyObject scalar) {
540
565
  Ruby runtime = context.runtime;
541
- double theta = (scalar instanceof RubyFloat)
542
- ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
566
+ double theta = jvalue(scalar);
543
567
  IRubyObject[] ary = new IRubyObject[]{
544
568
  runtime.newFloat(jx * Math.cos(theta) - jy * Math.sin(theta)),
545
569
  runtime.newFloat(jx * Math.sin(theta) + jy * Math.cos(theta))};
@@ -559,9 +583,8 @@ public class Vec2 extends RubyObject {
559
583
  throw runtime.newSyntaxError("Check syntax");
560
584
  }
561
585
  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) :
586
+ double scalar = jvalue(args[1]);
587
+ assert scalar >= 0 && scalar < 1.0 :
565
588
  "Lerp value " + scalar + " out of range 0..1.0";
566
589
  return Vec2.rbNew(context, this.getMetaClass(), new IRubyObject[]{
567
590
  runtime.newFloat(jx + (vec.jx - jx) * scalar),
@@ -581,9 +604,8 @@ public class Vec2 extends RubyObject {
581
604
  throw runtime.newSyntaxError("Check syntax");
582
605
  }
583
606
  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) :
607
+ double scalar = jvalue(args[1]);
608
+ assert scalar >= 0 && scalar < 1.0 :
587
609
  "Lerp value " + scalar + " out of range 0..1.0";
588
610
  jx += (vec.jx - jx) * scalar;
589
611
  jy += (vec.jy - jy) * scalar;
@@ -601,8 +623,8 @@ public class Vec2 extends RubyObject {
601
623
  public IRubyObject angleBetween(ThreadContext context, IRubyObject other) {
602
624
  Vec2 vec = null;
603
625
  Ruby runtime = context.runtime;
604
- if (other instanceof Vec2) {
605
- vec = (Vec2) other.toJava(Vec2.class);
626
+ if (other instanceof Vec2 vector) {
627
+ vec = vector.toJava(Vec2.class);
606
628
  } else {
607
629
  throw runtime.newTypeError("argument should be Vec2D");
608
630
  }
@@ -620,8 +642,8 @@ public class Vec2 extends RubyObject {
620
642
  public IRubyObject fastAngleBetween(ThreadContext context, IRubyObject other) {
621
643
  Vec2 vec = null;
622
644
  Ruby runtime = context.runtime;
623
- if (other instanceof Vec2) {
624
- vec = (Vec2) other.toJava(Vec2.class);
645
+ if (other instanceof Vec2 vector) {
646
+ vec = vector.toJava(Vec2.class);
625
647
  } else {
626
648
  throw runtime.newTypeError("argument should be Vec2D");
627
649
  }
@@ -742,12 +764,10 @@ public class Vec2 extends RubyObject {
742
764
  if (obj == this) {
743
765
  return true;
744
766
  }
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
- }
767
+ if (obj instanceof Vec2 vec2) {
768
+ final Vec2 other = vec2;
769
+ return Double.compare(jx, (Double) other.jx) == 0
770
+ && Double.compare(jy, (Double) other.jy) == 0;
751
771
  }
752
772
  return false;
753
773
  }
@@ -764,10 +784,10 @@ public class Vec2 extends RubyObject {
764
784
  if (other == this) {
765
785
  return runtime.newBoolean(true);
766
786
  }
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)) {
787
+ if (other instanceof Vec2 vector) {
788
+ Vec2 v = vector.toJava(Vec2.class);
789
+ if (Double.compare(jx, (Double) v.jx) == 0
790
+ && Double.compare(jy, (Double) v.jy) == 0) {
771
791
  return runtime.newBoolean(true);
772
792
  }
773
793
  }
@@ -788,8 +808,8 @@ public class Vec2 extends RubyObject {
788
808
  if (other == this) {
789
809
  return runtime.newBoolean(true);
790
810
  }
791
- if (other instanceof Vec2) {
792
- Vec2 v = (Vec2) other.toJava(Vec2.class);
811
+ if (other instanceof Vec2 vector) {
812
+ Vec2 v = vector.toJava(Vec2.class);
793
813
  double diff = jx - v.jx;
794
814
  if ((diff < 0 ? -diff : diff) > Vec2.EPSILON) {
795
815
  return runtime.newBoolean(false);