propane 3.4.0-java → 3.7.0.pre-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +2 -2
  6. data/CHANGELOG.md +12 -0
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +10 -11
  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 +10 -9
  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/pom.rb +37 -36
  38. data/pom.xml +7 -7
  39. data/propane.gemspec +16 -12
  40. data/src/main/java/monkstone/ColorUtil.java +13 -1
  41. data/src/main/java/monkstone/MathToolModule.java +253 -203
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  44. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  45. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  46. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  47. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  51. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  52. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  53. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  54. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  55. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -3
  56. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  57. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  58. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  59. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  60. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  61. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  62. data/src/main/java/processing/awt/PSurfaceAWT.java +309 -209
  63. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  64. data/src/main/java/processing/core/PApplet.java +4510 -4503
  65. data/src/main/java/processing/core/PConstants.java +477 -447
  66. data/src/main/java/processing/core/PFont.java +914 -880
  67. data/src/main/java/processing/core/PGraphics.java +193 -177
  68. data/src/main/java/processing/core/PImage.java +611 -309
  69. data/src/main/java/processing/core/PMatrix.java +172 -159
  70. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  71. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  72. data/src/main/java/processing/core/PShape.java +2888 -2652
  73. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  74. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  75. data/src/main/java/processing/core/PStyle.java +40 -37
  76. data/src/main/java/processing/core/PSurface.java +139 -97
  77. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  78. data/src/main/java/processing/core/PVector.java +997 -965
  79. data/src/main/java/processing/core/ThinkDifferent.java +15 -13
  80. data/src/main/java/processing/data/DoubleDict.java +756 -710
  81. data/src/main/java/processing/data/DoubleList.java +749 -696
  82. data/src/main/java/processing/data/FloatDict.java +748 -702
  83. data/src/main/java/processing/data/FloatList.java +751 -697
  84. data/src/main/java/processing/data/IntDict.java +720 -673
  85. data/src/main/java/processing/data/IntList.java +699 -633
  86. data/src/main/java/processing/data/JSONArray.java +931 -873
  87. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  88. data/src/main/java/processing/data/JSONTokener.java +351 -341
  89. data/src/main/java/processing/data/LongDict.java +710 -663
  90. data/src/main/java/processing/data/LongList.java +701 -635
  91. data/src/main/java/processing/data/Sort.java +37 -41
  92. data/src/main/java/processing/data/StringDict.java +525 -486
  93. data/src/main/java/processing/data/StringList.java +626 -580
  94. data/src/main/java/processing/data/Table.java +3690 -3510
  95. data/src/main/java/processing/data/TableRow.java +182 -183
  96. data/src/main/java/processing/data/XML.java +957 -883
  97. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  98. data/src/main/java/processing/event/Event.java +87 -67
  99. data/src/main/java/processing/event/KeyEvent.java +48 -41
  100. data/src/main/java/processing/event/MouseEvent.java +88 -113
  101. data/src/main/java/processing/event/TouchEvent.java +10 -6
  102. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  103. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  104. data/src/main/java/processing/net/Client.java +744 -0
  105. data/src/main/java/processing/net/Server.java +388 -0
  106. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  107. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  108. data/src/main/java/processing/opengl/LinePath.java +547 -500
  109. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  110. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  111. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  112. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  113. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  114. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  115. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  116. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  117. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  118. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  119. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  120. data/test/create_test.rb +21 -20
  121. data/test/deglut_spec_test.rb +4 -2
  122. data/test/helper_methods_test.rb +49 -20
  123. data/test/math_tool_test.rb +39 -32
  124. data/test/native_folder.rb +47 -0
  125. data/test/respond_to_test.rb +3 -2
  126. data/test/sketches/key_event.rb +2 -2
  127. data/test/sketches/library/my_library/my_library.rb +3 -0
  128. data/test/test_helper.rb +2 -0
  129. data/test/vecmath_spec_test.rb +35 -22
  130. data/vendors/Rakefile +33 -62
  131. metadata +56 -48
  132. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  133. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  134. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  135. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  136. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  137. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  138. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  139. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  140. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  141. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  142. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  143. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  144. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  145. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  146. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  147. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  148. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  149. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  150. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  151. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  152. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  153. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  154. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  155. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Here's a little library for quickly hooking up in sketch sliders.
3
- # Copyright (c) 2016-19 Martin Prout.
4
+ # Copyright (c) 2015-20 Martin Prout.
4
5
 
5
6
  java_import 'monkstone.slider.CustomHorizontalSlider'
6
7
  java_import 'monkstone.slider.CustomVerticalSlider'
@@ -9,27 +10,27 @@ java_import 'monkstone.slider.CustomVerticalSlider'
9
10
  module Slider
10
11
  def self.slider(app:, x:, y:, name:, **opts)
11
12
  options = default.merge opts
12
- if options[:vertical]
13
- slider = CustomVerticalSlider.new(
14
- app,
15
- x,
16
- y,
17
- options[:length],
18
- options[:range].first,
19
- options[:range].last,
20
- name
21
- )
22
- else
23
- slider = CustomHorizontalSlider.new(
24
- app,
25
- x,
26
- y,
27
- options[:length],
28
- options[:range].first,
29
- options[:range].last,
30
- name
31
- )
32
- end
13
+ slider = if options[:vertical]
14
+ CustomVerticalSlider.new(
15
+ app,
16
+ x,
17
+ y,
18
+ options[:length],
19
+ options[:range].first,
20
+ options[:range].last,
21
+ name
22
+ )
23
+ else
24
+ CustomHorizontalSlider.new(
25
+ app,
26
+ x,
27
+ y,
28
+ options[:length],
29
+ options[:range].first,
30
+ options[:range].last,
31
+ name
32
+ )
33
+ end
33
34
  unless opts.empty?
34
35
  slider.bar_width(opts.fetch(:bar_width, 10))
35
36
  slider.set_value(opts.fetch(:initial_value, 0))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  PHI ||= (1 + Math.sqrt(5)) / 2 # golden ratio
2
4
  GA = PHI * 2 * Math::PI # golden angle
3
5
 
@@ -48,6 +50,7 @@ module VectorUtil
48
50
  def self.cartesian_to_polar(vec:)
49
51
  res = Vec3D.new(vec.mag, 0, 0)
50
52
  return Vec3D.new unless res.x > 0
53
+
51
54
  res.y = -Math.atan2(vec.z, vec.x)
52
55
  res.z = Math.asin(vec.y / res.x)
53
56
  res
@@ -64,6 +67,7 @@ module VectorUtil
64
67
 
65
68
  def self.polar_to_cartesian(vec:)
66
69
  return Vec3D.new if vec.mag <= 0
70
+
67
71
  Vec3D.new(Math.asin(vec.y / vec.mag), vec.mag, -Math.atan2(vec.z, vec.x))
68
72
  end
69
73
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Propane::App
2
- include Java::MonkstoneVideoevent::VideoInterface
4
+ include Java::MonkstoneVideoevent::CaptureEvent
5
+ include Java::MonkstoneVideoevent::MovieEvent
3
6
  end
data/pom.rb CHANGED
@@ -1,7 +1,8 @@
1
- project 'propane', 'https://github.com/monkstone/propane' do
1
+ # frozen_string_literal: true
2
2
 
3
+ project 'propane', 'https://github.com/monkstone/propane' do
3
4
  model_version '4.0.0'
4
- id 'propane:propane:3.4.0'
5
+ id 'propane:propane:3.7.0.pre'
5
6
  packaging 'jar'
6
7
 
7
8
  description 'An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.'
@@ -33,49 +34,49 @@ project 'propane', 'https://github.com/monkstone/propane' do
33
34
 
34
35
  issue_management 'https://github.com/ruby-processing/propane/issues', 'Github'
35
36
 
36
- source_control( :url => 'https://github.com/ruby-processing/propane',
37
- :connection => 'scm:git:git://github.com/ruby-processing/propane.git',
38
- :developer_connection => 'scm:git:git@github.com/ruby-processing/propane.git' )
37
+ source_control(url: 'https://github.com/ruby-processing/propane',
38
+ connection: 'scm:git:git://github.com/ruby-processing/propane.git',
39
+ developer_connection: 'scm:git:git@github.com/ruby-processing/propane.git')
39
40
 
40
- properties( 'propane.basedir' => '${project.basedir}',
41
+ properties('propane.basedir' => '${project.basedir}',
41
42
  'processing.api' => 'http://processing.github.io/processing-javadocs/core/',
42
43
  'source.directory' => 'src',
43
44
  'polyglot.dump.pom' => 'pom.xml',
44
45
  'project.build.sourceEncoding' => 'utf-8',
45
- 'jogl.version' => '2.3.2',
46
- 'jruby.api' => 'http://jruby.org/apidocs/' )
46
+ 'jogl.version' => '2.3.2', # for compiling actual included 2.4.0-rc
47
+ 'jruby.api' => 'http://jruby.org/apidocs/')
47
48
 
48
- pom 'org.jruby:jruby:9.2.8.0'
49
- jar 'org.processing:video:3.2.3'
49
+ pom 'org.jruby:jruby:9.2.14.0'
50
+ jar 'org.processing:video:3.3.7' # only for compiling
50
51
  jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
51
52
  jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
52
53
 
53
54
  overrides do
54
- plugin( 'org.codehaus.mojo:versions-maven-plugin:2.7',
55
- 'generateBackupPoms' => 'false' )
56
- plugin( :compiler, '3.8.1',
57
- 'release' => '11' )
58
- plugin( :javadoc, '3.1.1',
59
- 'detectOfflineLinks' => 'false',
60
- 'links' => [ '${jruby.api}',
61
- '${processing.api}' ] )
62
- plugin(
63
- :jar, '3.1.2',
55
+ plugin('org.codehaus.mojo:versions-maven-plugin:2.7',
56
+ 'generateBackupPoms' => 'false')
57
+ plugin(:compiler, '3.8.1',
58
+ 'release' => '11')
59
+ plugin(:javadoc, '3.2.0',
60
+ 'detectOfflineLinks' => 'false',
61
+ 'links' => ['${jruby.api}',
62
+ '${processing.api}'])
63
+ plugin(:jar, '3.2.0',
64
64
  'archive' => {
65
- 'manifestEntries' => { 'Class-Path' => 'gluegen-rt.jar jog-all.jar' }
66
- }
67
- )
68
- end
69
- build do
70
- resource do
71
- directory '${source.directory}/main/java'
72
- includes '**/**/*.glsl', '**/*.jnilib'
73
- excludes '**/**/*.java'
74
- end
75
- resource do
76
- directory '${source.directory}/main/resources'
77
- includes '**/*.png', '*.txt'
78
- excludes
65
+ 'manifestEntries' => {
66
+ 'Automatic-Module-Name' => 'processing.core'
67
+ }
68
+ })
69
+ end
70
+ build do
71
+ resource do
72
+ directory '${source.directory}/main/java'
73
+ includes '**/**/*.glsl', '**/*.jnilib'
74
+ excludes '**/**/*.java'
75
+ end
76
+ resource do
77
+ directory '${source.directory}/main/resources'
78
+ includes '**/*.png', '*.txt'
79
+ excludes
80
+ end
81
+ end
79
82
  end
80
- end
81
- end
data/pom.xml CHANGED
@@ -6,12 +6,12 @@ DO NOT MODIFIY - GENERATED CODE
6
6
 
7
7
 
8
8
  -->
9
- <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
9
+ <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
10
10
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
11
11
  <modelVersion>4.0.0</modelVersion>
12
12
  <groupId>propane</groupId>
13
13
  <artifactId>propane</artifactId>
14
- <version>3.4.0</version>
14
+ <version>3.7.0.pre</version>
15
15
  <name>propane</name>
16
16
  <description>An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.</description>
17
17
  <url>https://github.com/monkstone/propane</url>
@@ -74,13 +74,13 @@ DO NOT MODIFIY - GENERATED CODE
74
74
  <dependency>
75
75
  <groupId>org.jruby</groupId>
76
76
  <artifactId>jruby</artifactId>
77
- <version>9.2.8.0</version>
77
+ <version>9.2.14.0</version>
78
78
  <type>pom</type>
79
79
  </dependency>
80
80
  <dependency>
81
81
  <groupId>org.processing</groupId>
82
82
  <artifactId>video</artifactId>
83
- <version>3.2.3</version>
83
+ <version>3.3.7</version>
84
84
  </dependency>
85
85
  <dependency>
86
86
  <groupId>org.jogamp.jogl</groupId>
@@ -132,7 +132,7 @@ DO NOT MODIFIY - GENERATED CODE
132
132
  </plugin>
133
133
  <plugin>
134
134
  <artifactId>maven-javadoc-plugin</artifactId>
135
- <version>3.1.1</version>
135
+ <version>3.2.0</version>
136
136
  <configuration>
137
137
  <detectOfflineLinks>false</detectOfflineLinks>
138
138
  <links>
@@ -143,11 +143,11 @@ DO NOT MODIFIY - GENERATED CODE
143
143
  </plugin>
144
144
  <plugin>
145
145
  <artifactId>maven-jar-plugin</artifactId>
146
- <version>3.1.2</version>
146
+ <version>3.2.0</version>
147
147
  <configuration>
148
148
  <archive>
149
149
  <manifestEntries>
150
- <Class-Path>gluegen-rt.jar jog-all.jar</Class-Path>
150
+ <Automatic-Module-Name>processing.core</Automatic-Module-Name>
151
151
  </manifestEntries>
152
152
  </archive>
153
153
  </configuration>
@@ -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,28 +9,31 @@ 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.4.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'
22
23
  gem.files << 'lib/gluegen-rt-natives-macosx-universal.jar'
24
+ gem.files << 'lib/gluegen-rt-natives-ios-arm64.jar'
23
25
  gem.files << 'lib/gluegen-rt-natives-windows-amd64.jar'
24
26
  gem.files << 'lib/jogl-all-natives-linux-amd64.jar'
25
- gem.files << 'lib/jogl-all-natives-macosx-universal.jar'
27
+ gem.files << 'lib/gluegen-rt-natives-macosx-universal.jar'
28
+ gem.files << 'lib/jogl-all-natives-ios-arm64.jar'
26
29
  gem.files << 'lib/jogl-all-natives-windows-amd64.jar'
27
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
30
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
28
31
  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.11'
31
- gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.0'
32
+ gem.add_development_dependency 'jruby-openssl', '~> 0.1.0', '>=0.1.3'
33
+ gem.add_development_dependency 'minitest', '~> 5.14'
34
+ gem.add_runtime_dependency 'rake', '~> 12.3'
35
+ gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.2'
32
36
  gem.require_paths = ['lib']
33
37
  gem.platform = 'java'
34
- gem.requirements << 'java runtime >= 11.0.2+'
38
+ gem.requirements << 'java runtime >= 11.0.7+'
35
39
  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
  }