propane 3.3.1-java → 3.6.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -3
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +17 -5
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +16 -30
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +6 -4
  12. data/lib/propane/app.rb +20 -10
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +23 -24
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +21 -15
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +14 -6
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +28 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +6 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +7 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +4 -1
  37. data/mvnw +127 -51
  38. data/mvnw.cmd +182 -145
  39. data/pom.rb +53 -50
  40. data/pom.xml +17 -8
  41. data/propane.gemspec +13 -11
  42. data/src/main/java/monkstone/ColorUtil.java +13 -1
  43. data/src/main/java/monkstone/MathToolModule.java +253 -203
  44. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  45. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  46. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  47. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  48. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  53. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  54. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  55. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  56. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
  57. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  58. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  59. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  60. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  61. data/src/main/java/processing/awt/PGraphicsJava2D.java +2164 -1661
  62. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  63. data/src/main/java/processing/awt/PShapeJava2D.java +280 -268
  64. data/src/main/java/processing/awt/PSurfaceAWT.java +942 -829
  65. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  66. data/src/main/java/processing/core/PApplet.java +831 -824
  67. data/src/main/java/processing/core/PConstants.java +477 -447
  68. data/src/main/java/processing/core/PFont.java +914 -880
  69. data/src/main/java/processing/core/PGraphics.java +229 -213
  70. data/src/main/java/processing/core/PImage.java +620 -318
  71. data/src/main/java/processing/core/PMatrix.java +172 -159
  72. data/src/main/java/processing/core/PMatrix2D.java +478 -409
  73. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  74. data/src/main/java/processing/core/PShape.java +2888 -2652
  75. data/src/main/java/processing/core/PShapeOBJ.java +436 -415
  76. data/src/main/java/processing/core/PShapeSVG.java +1702 -1479
  77. data/src/main/java/processing/core/PStyle.java +40 -37
  78. data/src/main/java/processing/core/PSurface.java +139 -97
  79. data/src/main/java/processing/core/PSurfaceNone.java +296 -208
  80. data/src/main/java/processing/core/PVector.java +997 -965
  81. data/src/main/java/processing/core/ThinkDifferent.java +12 -17
  82. data/src/main/java/processing/data/DoubleDict.java +756 -710
  83. data/src/main/java/processing/data/DoubleList.java +749 -696
  84. data/src/main/java/processing/data/FloatDict.java +748 -702
  85. data/src/main/java/processing/data/FloatList.java +751 -697
  86. data/src/main/java/processing/data/IntDict.java +720 -673
  87. data/src/main/java/processing/data/IntList.java +699 -633
  88. data/src/main/java/processing/data/JSONArray.java +931 -873
  89. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  90. data/src/main/java/processing/data/JSONTokener.java +351 -341
  91. data/src/main/java/processing/data/LongDict.java +710 -663
  92. data/src/main/java/processing/data/LongList.java +701 -635
  93. data/src/main/java/processing/data/Sort.java +37 -41
  94. data/src/main/java/processing/data/StringDict.java +525 -486
  95. data/src/main/java/processing/data/StringList.java +626 -580
  96. data/src/main/java/processing/data/Table.java +3690 -3510
  97. data/src/main/java/processing/data/TableRow.java +182 -183
  98. data/src/main/java/processing/data/XML.java +957 -883
  99. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  100. data/src/main/java/processing/event/Event.java +87 -66
  101. data/src/main/java/processing/event/KeyEvent.java +48 -41
  102. data/src/main/java/processing/event/MouseEvent.java +88 -113
  103. data/src/main/java/processing/event/TouchEvent.java +10 -6
  104. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  105. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  106. data/src/main/java/processing/net/Client.java +744 -0
  107. data/src/main/java/processing/net/Server.java +388 -0
  108. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  109. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  110. data/src/main/java/processing/opengl/LinePath.java +547 -500
  111. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  112. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  113. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  114. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  115. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  116. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  117. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  118. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  119. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  120. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  121. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  122. data/test/create_test.rb +21 -20
  123. data/test/deglut_spec_test.rb +4 -2
  124. data/test/helper_methods_test.rb +49 -20
  125. data/test/math_tool_test.rb +39 -32
  126. data/test/native_folder.rb +47 -0
  127. data/test/respond_to_test.rb +3 -2
  128. data/test/sketches/key_event.rb +2 -2
  129. data/test/sketches/library/my_library/my_library.rb +3 -0
  130. data/test/test_helper.rb +2 -0
  131. data/test/vecmath_spec_test.rb +35 -22
  132. data/vendors/Rakefile +33 -62
  133. metadata +54 -45
  134. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  135. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  136. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  137. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  138. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  139. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  140. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  141. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  142. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  143. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  144. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  145. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  146. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  147. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  148. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  149. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  150. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  151. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  152. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  153. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  154. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  155. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  156. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  157. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,5 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'propane/version'
5
6
 
@@ -8,14 +9,14 @@ Gem::Specification.new do |gem|
8
9
  gem.version = Propane::VERSION
9
10
  gem.authors = ['monkstone']
10
11
  gem.email = ['mamba2928@yahoo.co.uk']
11
- gem.licenses = %w(GPL-3.0 LGPL-2.0)
12
+ gem.licenses = %w[GPL-3.0 LGPL-2.0]
12
13
  gem.description = <<-EOS
13
14
  A batteries included version of processing in ruby targetting jdk11.
14
15
  EOS
15
- gem.summary = %q{ruby implementation of processing-4.0 on MacOS, linux and windows (64bit only)}
16
+ gem.summary = 'ruby implementation of processing-4.0 on MacOS, linux and windows (64bit only)'
16
17
  gem.homepage = 'https://ruby-processing.github.io/propane/'
17
- gem.files = `git ls-files`.split($/)
18
- gem.files << 'lib/propane-3.3.0.jar'
18
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
+ gem.files << "lib/propane-#{Propane::VERSION}.jar"
19
20
  gem.files << 'lib/gluegen-rt.jar'
20
21
  gem.files << 'lib/jogl-all.jar'
21
22
  gem.files << 'lib/gluegen-rt-natives-linux-amd64.jar'
@@ -24,12 +25,13 @@ Gem::Specification.new do |gem|
24
25
  gem.files << 'lib/jogl-all-natives-linux-amd64.jar'
25
26
  gem.files << 'lib/jogl-all-natives-macosx-universal.jar'
26
27
  gem.files << 'lib/jogl-all-natives-windows-amd64.jar'
27
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
28
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
28
29
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
29
- gem.add_development_dependency 'rake', '~> 12.3'
30
- gem.add_development_dependency 'minitest', '~> 5.10'
31
- gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.0'
30
+ gem.add_development_dependency 'jruby-openssl', '~> 0.1.0', '>=0.1.3'
31
+ gem.add_development_dependency 'minitest', '~> 5.14'
32
+ gem.add_runtime_dependency 'rake', '~> 12.3'
33
+ gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.2'
32
34
  gem.require_paths = ['lib']
33
35
  gem.platform = 'java'
34
- gem.requirements << 'java runtime >= 11.0.1+'
36
+ gem.requirements << 'java runtime >= 11.0.2+'
35
37
  end
@@ -3,7 +3,7 @@
3
3
  * in their sketches. Includes a method to efficiently convert an array of web
4
4
  * strings to an array of color int, and another to convert an array of color
5
5
  * int to a string that can be used in ruby code (to generate web color array).
6
- * Copyright (c) 2015-19 Martin Prout.
6
+ * Copyright (c) 2015-20 Martin Prout.
7
7
  * This utility is free software; you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Lesser General Public License as published by
9
9
  * the Free Software Foundation; either version 2.1 of the License, or (at
@@ -13,6 +13,7 @@
13
13
  */
14
14
  package monkstone;
15
15
 
16
+ import java.util.Random;
16
17
  /**
17
18
  *
18
19
  * @author Martin Prout
@@ -102,6 +103,17 @@ public class ColorUtil {
102
103
  return (float) hex;
103
104
  }
104
105
 
106
+ static public int[] shuffle(int[] cols) {
107
+ Random rgen = new Random(); // Random number generator
108
+ for (int i = 0; i < cols.length; i++) {
109
+ int randomPosition = rgen.nextInt(cols.length);
110
+ int temp = cols[i];
111
+ cols[i] = cols[randomPosition];
112
+ cols[randomPosition] = temp;
113
+ }
114
+ return cols;
115
+ }
116
+
105
117
  /**
106
118
  *
107
119
  * @param hue
@@ -1,13 +1,14 @@
1
1
  /**
2
- * The purpose of this tool is to allow propane users to use an alternative
3
- * to processing.org map, lerp and norm methods in their sketches
4
- * Copyright (c) 2015-19 Martin Prout. This tool is free software; you can
5
- * redistribute it and/or modify it under the terms of the GNU Lesser General
6
- * Public License as published by the Free Software Foundation; either version
7
- * 2.1 of the License, or (at your option) any later version.
8
- *
9
- * Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html
10
- */
2
+ * The purpose of this tool is to allow JRubyArt users to use an alternative
3
+ * to processing.org map, lerp and norm methods in their sketches and to implement
4
+ * JRubyArt convenenience method grid(width, height, stepW, stepH) { |x, y| do stuff }
5
+ * Copyright (c) 2015-20 Martin Prout. This tool is free software; you can
6
+ * redistribute it and/or modify it under the terms of the GNU Lesser General
7
+ * Public License as published by the Free Software Foundation; either version
8
+ * 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * Obtain a copy of the license at http://www.gnu.org/licenses/lgpl-2.1.html
11
+ */
11
12
  package monkstone;
12
13
 
13
14
  import org.jruby.Ruby;
@@ -22,216 +23,265 @@ import org.jruby.runtime.ThreadContext;
22
23
  import org.jruby.runtime.builtin.IRubyObject;
23
24
 
24
25
  /**
25
- *
26
- * @author Martin Prout
27
- */
26
+ *
27
+ * @author Martin Prout
28
+ */
28
29
  @JRubyModule(name = "MathTool")
29
30
  public class MathToolModule {
30
31
 
31
- /**
32
- *
33
- * @param runtime Ruby
34
- */
35
- public static void createMathToolModule(Ruby runtime) {
36
- RubyModule mtModule = runtime.defineModule("MathTool");
37
- mtModule.defineAnnotatedMethods(MathToolModule.class);
38
- }
32
+ /**
33
+ *
34
+ * @param runtime Ruby
35
+ */
36
+ public static void createMathToolModule(Ruby runtime) {
37
+ RubyModule mtModule = runtime.defineModule("MathTool");
38
+ mtModule.defineAnnotatedMethods(MathToolModule.class);
39
+ }
39
40
 
40
- /**
41
- *
42
- * @param context ThreadContext
43
- * @param recv IRubyObject
44
- * @param args array of RubyRange (must be be numeric)
45
- * @return mapped value RubyFloat
46
- */
47
- @JRubyMethod(name = "map1d", rest = true, module = true)
48
- public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
49
- double value = (args[0] instanceof RubyFloat)
50
- ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
51
- RubyRange r1 = (RubyRange) args[1];
52
- RubyRange r2 = (RubyRange) args[2];
53
- double first1 = (r1.first(context) instanceof RubyFloat)
54
- ? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
55
- double first2 = (r2.first(context) instanceof RubyFloat)
56
- ? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
57
- double last1 = (r1.last(context) instanceof RubyFloat)
58
- ? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
59
- double last2 = (r2.last(context) instanceof RubyFloat)
60
- ? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
61
- return mapMt(context, value, first1, last1, first2, last2);
62
- }
41
+ /**
42
+ *
43
+ * @param context ThreadContext
44
+ * @param recv IRubyObject
45
+ * @param args array of RubyRange (must be be numeric)
46
+ * @return mapped value RubyFloat
47
+ */
48
+ @JRubyMethod(name = "map1d", rest = true, module = true)
49
+ public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
50
+ double value = (args[0] instanceof RubyFloat)
51
+ ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
52
+ RubyRange r1 = (RubyRange) args[1];
53
+ RubyRange r2 = (RubyRange) args[2];
54
+ double first1 = (r1.first(context) instanceof RubyFloat)
55
+ ? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
56
+ double first2 = (r2.first(context) instanceof RubyFloat)
57
+ ? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
58
+ double last1 = (r1.last(context) instanceof RubyFloat)
59
+ ? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
60
+ double last2 = (r2.last(context) instanceof RubyFloat)
61
+ ? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
62
+ return mapMt(context, value, first1, last1, first2, last2);
63
+ }
63
64
 
64
- /**
65
- *
66
- * @param context ThreadContext
67
- * @param recv IRubyObject
68
- * @param args array of RubyRange (must be be numeric)
69
- * @return mapped value RubyFloat
70
- */
71
- @JRubyMethod(name = "constrained_map", rest = true, module = true)
72
- public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
73
- double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
74
- RubyRange r1 = (RubyRange) args[1];
75
- RubyRange r2 = (RubyRange) args[2];
76
- double first1 = (r1.first(context) instanceof RubyFloat)
77
- ? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
78
- double first2 = (r2.first(context) instanceof RubyFloat)
79
- ? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
80
- double last1 = (r1.last(context) instanceof RubyFloat)
81
- ? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
82
- double last2 = (r2.last(context) instanceof RubyFloat)
83
- ? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
84
- double max = Math.max(first1, last1);
85
- double min = Math.min(first1, last1);
86
- if (value < min) {
87
- return mapMt(context, min, first1, last1, first2, last2);
88
- }
89
- if (value > max) {
90
- return mapMt(context, max, first1, last1, first2, last2);
91
- }
92
- return mapMt(context, value, first1, last1, first2, last2);
65
+ /**
66
+ *
67
+ * @param context ThreadContext
68
+ * @param recv IRubyObject
69
+ * @param args array of RubyRange (must be be numeric)
70
+ * @return mapped value RubyFloat
71
+ */
72
+ @JRubyMethod(name = "constrained_map", rest = true, module = true)
73
+ public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
74
+ double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
75
+ RubyRange r1 = (RubyRange) args[1];
76
+ RubyRange r2 = (RubyRange) args[2];
77
+ double first1 = (r1.first(context) instanceof RubyFloat)
78
+ ? ((RubyFloat) r1.first(context)).getValue() : ((RubyFixnum) r1.first(context)).getDoubleValue();
79
+ double first2 = (r2.first(context) instanceof RubyFloat)
80
+ ? ((RubyFloat) r2.first(context)).getValue() : ((RubyFixnum) r2.first(context)).getDoubleValue();
81
+ double last1 = (r1.last(context) instanceof RubyFloat)
82
+ ? ((RubyFloat) r1.last(context)).getValue() : ((RubyFixnum) r1.last(context)).getDoubleValue();
83
+ double last2 = (r2.last(context) instanceof RubyFloat)
84
+ ? ((RubyFloat) r2.last(context)).getValue() : ((RubyFixnum) r2.last(context)).getDoubleValue();
85
+ double max = Math.max(first1, last1);
86
+ double min = Math.min(first1, last1);
87
+ if (value < min) {
88
+ return mapMt(context, min, first1, last1, first2, last2);
93
89
  }
94
-
95
- /**
96
- *
97
- * @param context ThreadContext
98
- * @param recv self IRubyObject
99
- * @param args floats as in processing map function
100
- * @return mapped value RubyFloat
101
- */
102
- @JRubyMethod(name = "p5map", rest = true, module = true)
103
- public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
104
- double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
105
- double first1 = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
106
- double first2 = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
107
- double last1 = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
108
- double last2 = (args[4] instanceof RubyFloat) ? ((RubyFloat) args[4]).getValue() : ((RubyFixnum) args[4]).getDoubleValue();
109
- return mapMt(context, value, first1, last1, first2, last2);
90
+ if (value > max) {
91
+ return mapMt(context, max, first1, last1, first2, last2);
110
92
  }
93
+ return mapMt(context, value, first1, last1, first2, last2);
94
+ }
111
95
 
112
- /**
113
- * A more correct version than processing.org version
114
- *
115
- * @param context ThreadContext
116
- * @param recv self IRubyObject
117
- * @param args args[2] should be between 0 and 1.0 if not returns start or
118
- * stop
119
- * @return lerped value RubyFloat
120
- */
121
- @JRubyMethod(name = "lerp", rest = true, module = true)
122
- public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
123
- double start = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
124
- double stop = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
125
- double amount = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
126
- if (amount <= 0) {
127
- return args[0];
128
- }
129
- if (amount >= 1.0) {
130
- return args[1];
131
- }
132
- return context.runtime.newFloat((1 - amount) * start + (stop * amount));
133
- }
96
+ /**
97
+ *
98
+ * @param context ThreadContext
99
+ * @param recv self IRubyObject
100
+ * @param args floats as in processing map function
101
+ * @return mapped value RubyFloat
102
+ */
103
+ @JRubyMethod(name = "p5map", rest = true, module = true)
104
+ public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
105
+ double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
106
+ double first1 = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
107
+ double first2 = (args[3] instanceof RubyFloat) ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
108
+ double last1 = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
109
+ double last2 = (args[4] instanceof RubyFloat) ? ((RubyFloat) args[4]).getValue() : ((RubyFixnum) args[4]).getDoubleValue();
110
+ return mapMt(context, value, first1, last1, first2, last2);
111
+ }
134
112
 
135
- /**
136
- * Identical to p5map(value, low, high, 0, 1). Numbers outside of the range
137
- * are not clamped to 0 and 1, because out-of-range values are often
138
- * intentional and useful.
139
- *
140
- * @param context ThreadContext
141
- * @param recv IRubyObject
142
- * @param args array of args must be be numeric
143
- * @return mapped value RubyFloat
144
- */
145
- @JRubyMethod(name = "norm", rest = true, module = true)
146
- public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
147
- double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
148
- double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
149
- double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
150
- return mapMt(context, value, start, stop, 0, 1.0);
113
+ /**
114
+ * A more correct version than processing.org version
115
+ *
116
+ * @param context ThreadContext
117
+ * @param recv self IRubyObject
118
+ * @param args args[2] should be between 0 and 1.0 if not returns start or
119
+ * stop
120
+ * @return lerped value RubyFloat
121
+ */
122
+ @JRubyMethod(name = "lerp", rest = true, module = true)
123
+ public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
124
+ double start = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
125
+ double stop = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
126
+ double amount = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
127
+ if (amount <= 0) {
128
+ return args[0];
151
129
  }
152
-
153
- /**
154
- * Identical to p5map(value, low, high, 0, 1) but 'clamped'. Numbers outside
155
- * of the range are clamped to 0 and 1,
156
- *
157
- * @param context ThreadContext
158
- * @param recv IRubyObject
159
- * @param args array of args must be be numeric
160
- * @return mapped value RubyFloat
161
- */
162
- @JRubyMethod(name = "norm_strict", rest = true, module = true)
163
- public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
164
- Ruby ruby = context.runtime;
165
- double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
166
- double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
167
- double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
168
- double max = Math.max(start, stop);
169
- double min = Math.min(start, stop);
170
- if (value < min) {
171
- return mapMt(context, min, start, stop, 0, 1.0);
172
- }
173
- if (value > max) {
174
- return mapMt(context, max, start, stop, 0, 1.0);
175
- }
176
- return mapMt(context, value, start, stop, 0, 1.0);
130
+ if (amount >= 1.0) {
131
+ return args[1];
177
132
  }
178
- // start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
133
+ return context.runtime.newFloat((1 - amount) * start + (stop * amount));
134
+ }
135
+
136
+ /**
137
+ * Identical to p5map(value, low, high, 0, 1). Numbers outside of the range
138
+ * are not clamped to 0 and 1, because out-of-range values are often
139
+ * intentional and useful.
140
+ *
141
+ * @param context ThreadContext
142
+ * @param recv IRubyObject
143
+ * @param args array of args must be be numeric
144
+ * @return mapped value RubyFloat
145
+ */
146
+ @JRubyMethod(name = "norm", rest = true, module = true)
147
+ public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
148
+ double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
149
+ double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
150
+ double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
151
+ return mapMt(context, value, start, stop, 0, 1.0);
152
+ }
153
+
154
+ /**
155
+ * Identical to p5map(value, low, high, 0, 1) but 'clamped'. Numbers outside
156
+ * of the range are clamped to 0 and 1,
157
+ *
158
+ * @param context ThreadContext
159
+ * @param recv IRubyObject
160
+ * @param args array of args must be be numeric
161
+ * @return mapped value RubyFloat
162
+ */
163
+ @JRubyMethod(name = "norm_strict", rest = true, module = true)
164
+ public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
179
165
 
180
- static final RubyFloat mapMt(ThreadContext context, double value, double first1, double last1, double first2, double last2) {
181
- double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
182
- return context.runtime.newFloat(result);
166
+ double value = (args[0] instanceof RubyFloat) ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
167
+ double start = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
168
+ double stop = (args[2] instanceof RubyFloat) ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
169
+ double max = Math.max(start, stop);
170
+ double min = Math.min(start, stop);
171
+ if (value < min) {
172
+ return mapMt(context, min, start, stop, 0, 1.0);
183
173
  }
174
+ if (value > max) {
175
+ return mapMt(context, max, start, stop, 0, 1.0);
176
+ }
177
+ return mapMt(context, value, start, stop, 0, 1.0);
178
+ }
179
+ // start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
180
+ static final RubyFloat mapMt(ThreadContext context, double value, double first1, double last1, double first2, double last2) {
181
+ Ruby ruby = context.runtime;
182
+ double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
183
+ return ruby.newFloat(result);
184
+ }
184
185
 
185
- /**
186
- * Provides processing constrain method as a ruby module method
187
- *
188
- * @param context ThreadContext
189
- * @param recv IRubyObject
190
- * @param args array of args must be be numeric
191
- * @return original or limit values
192
- */
193
- @JRubyMethod(name = "constrain", rest = true, module = true)
194
- public static IRubyObject constrainValue(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
195
- RubyFloat value = args[0].convertToFloat();
196
- RubyFloat start = args[1].convertToFloat();
197
- RubyFloat stop = args[2].convertToFloat();
198
- if (value.op_ge(context, start).isTrue() && value.op_le(context, stop).isTrue()) {
199
- return args[0];
200
- } else if (value.op_ge(context, start).isTrue()) {
201
- return args[2];
202
- } else {
203
- return args[1];
204
- }
186
+ /**
187
+ * Provides processing constrain method as a ruby module method
188
+ *
189
+ * @param context ThreadContext
190
+ * @param recv IRubyObject
191
+ * @param args array of args must be be numeric
192
+ * @return original or limit values
193
+ */
194
+ @JRubyMethod(name = "constrain", rest = true, module = true)
195
+ public static IRubyObject constrainValue(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
196
+ RubyFloat value = args[0].convertToFloat();
197
+ RubyFloat start = args[1].convertToFloat();
198
+ RubyFloat stop = args[2].convertToFloat();
199
+ if (value.op_ge(context, start).isTrue() && value.op_le(context, stop).isTrue()) {
200
+ return args[0];
201
+ } else if (value.op_ge(context, start).isTrue()) {
202
+ return args[2];
203
+ } else {
204
+ return args[1];
205
205
  }
206
+ }
206
207
 
207
- /**
208
- * Provides propane grid method as a ruby module method
209
- *
210
- * @param context ThreadContext
211
- * @param recv IRubyObject
212
- * @param args array of args should be Fixnum
213
- * @param block { |x, y| `do something` }
214
- * @return nil
215
- */
216
- @JRubyMethod(name = "grid", rest = true, module = true)
217
- public static IRubyObject createGrid(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
218
- int row = (int) args[0].toJava(Integer.class);
219
- int column = (int) args[1].toJava(Integer.class);
220
- int rowStep = 1;
221
- int colStep = 1;
222
- if (args.length == 4) {
223
- rowStep = (int) args[2].toJava(Integer.class);
224
- colStep = (int) args[3].toJava(Integer.class);
225
- }
226
- if (block.isGiven()) {
227
- int tempRow = row / rowStep;
228
- for (int z = 0; z < (tempRow * (column / colStep)); z++) {
229
- int x = z % tempRow;
230
- int y = z / tempRow;
231
- block.yieldSpecific(context, context.runtime.newFixnum(x * rowStep), context.runtime.newFixnum(y * colStep));
232
- }
208
+ /**
209
+ * Provides JRubyArt grid method as a ruby module method behaves like:-
210
+ * def grid(dx, dy, sx = 1, sy = 1)
211
+ * (0...dx).step(sx) do |x|
212
+ * (0...dy).step(sy) do |y|
213
+ * yield(x, y)
214
+ * end
215
+ * end
216
+ * end
217
+ * @param context ThreadContext
218
+ * @param recv IRubyObject
219
+ * @param args array of args should be Fixnum
220
+ * @param block { |x, y| `do something` }
221
+ * @return nil
222
+ */
223
+ @JRubyMethod(name = "grid", rest = true, module = true)
224
+ public static IRubyObject createGrid(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
225
+ Ruby ruby = context.runtime;
226
+ int row = (int) args[0].toJava(Integer.class);
227
+ int column = (int) args[1].toJava(Integer.class);
228
+ int rowStep = 1;
229
+ int colStep = 1;
230
+ if (args.length == 4){
231
+ rowStep = (int) args[2].toJava(Integer.class);
232
+ colStep = (int) args[3].toJava(Integer.class);
233
+ }
234
+ if (block.isGiven()) {
235
+ int tempRow = row / rowStep;
236
+ int tempColumn = column /colStep;
237
+ for (int z = 0; z < (tempRow * tempColumn); z++){
238
+ int y = z % tempColumn;
239
+ int x = z / tempColumn;
240
+ block.yieldSpecific(context, ruby.newFixnum(x * rowStep), ruby.newFixnum(y * colStep));
241
+ }
242
+ }
243
+ return context.nil;
244
+ }
245
+ /**
246
+ * Provides JRubyArt mesh_grid method as a ruby module method
247
+ * def grid(dx, dy, dz, sx = 1, sy = 1, sz = 1)
248
+ * (0...dx).step(sx) do |x|
249
+ * (0...dy).step(sy) do |y|
250
+ * (0...dz).step(sy) do |z|
251
+ * yield(x, y, z)
252
+ * end
253
+ * end
254
+ * end
255
+ * end
256
+ *
257
+ * @param context ThreadContext
258
+ * @param recv IRubyObject
259
+ * @param args array of args should be Fixnum
260
+ * @param block { |x, y, z| `do something` }
261
+ * @return nil
262
+ */
263
+ @JRubyMethod(name = "mesh_grid", rest = true, module = true)
264
+ public static IRubyObject createGrid3D(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
265
+ Ruby ruby = context.runtime;
266
+ int xDim = (int) args[0].toJava(Integer.class);
267
+ int yDim = (int) args[1].toJava(Integer.class);
268
+ int zDim = (int) args[2].toJava(Integer.class);
269
+ int xStep = (args.length > 3) ? (int) args[3].toJava(Integer.class) : 1;
270
+ int yStep = (args.length > 4) ? (int) args[4].toJava(Integer.class) : 1;
271
+ int zStep = (args.length == 6) ? (int) args[5].toJava(Integer.class) : 1;
272
+ int dimX = xDim / xStep;
273
+ int dimY = yDim / yStep;
274
+ int dimZ = zDim / zStep;
275
+ if (block.isGiven()) {
276
+ int count = dimX * dimY * dimZ;
277
+ for (int x = 0; x < xDim; x += xStep){
278
+ for (int j = 0; j < (dimZ * dimY); j++){
279
+ int z = j % dimZ;
280
+ int y = j / dimZ;
281
+ block.yieldSpecific(context, ruby.newFixnum(x), ruby.newFixnum(y * yStep), ruby.newFixnum(z * zStep));
233
282
  }
234
- return context.nil;
235
-
283
+ }
236
284
  }
285
+ return context.nil;
286
+ }
237
287
  }