propane 3.4.0-java → 3.4.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.travis.yml +2 -2
  4. data/CHANGELOG.md +2 -0
  5. data/README.md +12 -7
  6. data/Rakefile +2 -2
  7. data/lib/propane.rb +2 -2
  8. data/lib/propane/app.rb +18 -9
  9. data/lib/propane/helper_methods.rb +1 -1
  10. data/lib/propane/runner.rb +1 -1
  11. data/lib/propane/version.rb +1 -1
  12. data/library/color_group/color_group.rb +26 -0
  13. data/library/dxf/dxf.rb +4 -0
  14. data/library/net/net.rb +5 -0
  15. data/library/video_event/video_event.rb +2 -1
  16. data/pom.rb +3 -3
  17. data/pom.xml +3 -3
  18. data/propane.gemspec +1 -1
  19. data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
  20. data/src/main/java/monkstone/ColorUtil.java +14 -0
  21. data/src/main/java/monkstone/MathToolModule.java +243 -194
  22. data/src/main/java/monkstone/filechooser/Chooser.java +1 -0
  23. data/src/main/java/monkstone/slider/WheelHandler.java +6 -5
  24. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -2
  25. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  26. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +10 -26
  27. data/src/main/java/processing/awt/PSurfaceAWT.java +1 -1
  28. data/src/main/java/processing/core/PApplet.java +1236 -599
  29. data/src/main/java/processing/core/PGraphics.java +59 -59
  30. data/src/main/java/processing/core/PImage.java +528 -129
  31. data/src/main/java/processing/core/PShape.java +10 -10
  32. data/src/main/java/processing/core/PVector.java +2 -2
  33. data/src/main/java/processing/core/ThinkDifferent.java +5 -7
  34. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  35. data/src/main/java/processing/net/Client.java +744 -0
  36. data/src/main/java/processing/net/Server.java +388 -0
  37. data/src/main/java/processing/opengl/FontTexture.java +19 -20
  38. data/src/main/java/processing/opengl/FrameBuffer.java +27 -17
  39. data/src/main/java/processing/opengl/LinePath.java +512 -508
  40. data/src/main/java/processing/opengl/PGL.java +3106 -3066
  41. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +4 -4
  42. data/src/main/java/processing/opengl/PShader.java +1442 -1341
  43. data/vendors/Rakefile +3 -27
  44. metadata +12 -25
  45. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  46. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  47. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  48. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  49. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  50. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  51. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  52. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  53. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  54. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  55. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  56. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  57. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  58. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  59. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  60. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  61. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  62. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  63. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  64. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a17549b4cc5bcc10bb764cca572641ea1cc26e03f3634e6ca6765566d74e31a
4
- data.tar.gz: 365bcb651c4a64e0218c35c21ee08b7e62c7dd55523d4fc6d1a4552bd8bbc636
3
+ metadata.gz: f88b5c1c3e6afb699ccabb96cd98d9b60aa9d8ec0614d59a601a3e8df074946b
4
+ data.tar.gz: 6943a2c007f56b01faf2ce1e3636f407d53dbf80c36458c27598e4365da46b48
5
5
  SHA512:
6
- metadata.gz: 6cfc69cad0fe6d1d3a2e663ae267bb8057c4552702133554febb911aec0495cfbe231801489419e2b1d85ce1d4e55e87c2e66d69d3606d1d864a5fc074fa84c5
7
- data.tar.gz: 298859b0bf5f3ac80796b85d306fb0f1f20b99c28857c469a0bd7ae896abb81d96d74b4a8c3105a7ccd26345ca4569659d695c22322bcfa07b90c880147e138b
6
+ metadata.gz: 0162ff22dcdda3764363e5fc2c1c07c9619a3f97e209837faa125a8d4fd6412e6077cd3ba3a436efbd33db7371a68adcbb166e46d324846aecff155ef4690c44
7
+ data.tar.gz: c4fad0d7f20ca7b4b9fb5f840caf63da4d8f9f21805029e46fa024ce6c2b5d8cb7263df9ddba95932d2825d9510bd6bbd47884a478ce55aa135bcee2df4ab06d
data/.mvn/extensions.xml CHANGED
@@ -3,7 +3,6 @@
3
3
  <extension>
4
4
  <groupId>io.takari.polyglot</groupId>
5
5
  <artifactId>polyglot-ruby</artifactId>
6
- <version>0.4.0</version>
6
+ <version>0.4.4</version>
7
7
  </extension>
8
8
  </extensions>
9
-
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: java
2
- dist: trusty
2
+ dist: bionic
3
3
 
4
4
  rvm:
5
- - jruby-9.2.7.0
5
+ - jruby-9.2.9.0
6
6
  jdk:
7
7
  - openjdk11
8
8
  os:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ **v3.4.1** Update to JRuby-9.2.9.0
2
+
1
3
  **v3.4.0** Experimental refactoring of ThinkDifferent, and some other processing classes
2
4
 
3
5
  **v3.3.1** Reflection makes refactoring a nightmare DesktopHandler => ThinkDifferent
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Propane ![Travis CI](https://travis-ci.org/ruby-processing/propane.svg)
1
+ # Propane [![Gem Version](https://badge.fury.io/rb/propane.svg)](https://badge.fury.io/rb/propane) ![Travis CI](https://travis-ci.org/ruby-processing/propane.svg)
2
2
 
3
- This version is intended to work with openjdk11+, @sampottinger is currently working on [vanilla processing][vanilla] which will enable JRubyArt to catch up. Unfortunately there is a cockup in debian distributions, and it is currently safer to use the Oracle version on debian (Archlinux openjdk version is fine).
3
+ This version is intended to work with openjdk11+, @sampottinger is currently working on [vanilla processing][vanilla] which will enable JRubyArt to catch up.
4
4
 
5
5
  A slim layer to communicate with Processing from JRuby, features maven build. We have created a configuration free version of ruby processing, for processing-4.0+, where we include a modified processing core (`public runPropane()` to replace `protected runSketch()`. These jars are small enough to include in a gem distribution, and hence we do not require configuration. This has created a scriptable version, ie files get run direct from jruby. Currently JavaFX is unsupported again @sampottinger is currently working on [vanilla processing][vanilla] to use OpenJFX. It would be nice make use of java modules, but I think we should let jruby project do that first (unless processing.org beat them to it).
6
6
 
@@ -8,9 +8,12 @@ adjust above for your OS/distro setup.
8
8
 
9
9
  ## Requirements
10
10
 
11
- - `jdk-11.0.2+`
12
- - `jruby-9.2.7.0`
13
- - `mvn-3.5.4+`
11
+ There may be a linker issue with P2D or P3D sketches with stock openjdk with some linux distros, in which case you might find [Adopt open jdk binaries][adopt] will work for you.
12
+
13
+ - `jdk-11.0.3+`
14
+ - `jruby-9.2.9.0`
15
+
16
+ Currently you can ignore `illegal reflective access` warnings, see [here how to suppress them][warning].
14
17
 
15
18
  ## Building and testing
16
19
 
@@ -24,10 +27,10 @@ rake javadoc
24
27
 
25
28
  ```bash
26
29
  jgem install propane # from rubygems
27
- jgem install propane-3.3.0-java.gem # local install
30
+ jgem install propane-3.4.1-java.gem # local install
28
31
  # Alternative
29
32
  jruby -S gem install propane # from rubygems
30
- jruby -S gem install propane-3.3.0-java.gem # local install
33
+ jruby -S gem install propane-3.4.1-java.gem # local install
31
34
  ```
32
35
 
33
36
  ## Check Install
@@ -95,6 +98,8 @@ propane --install samples
95
98
  ```
96
99
  please move existing `propane_samples` if you wish to keep them. The current release features several PixelFlow glsl library examples, including a few shadertoy demos as sketches.
97
100
 
101
+ [adopt]: https://adoptopenjdk.net/
98
102
  [building]:http://ruby-processing.github.io/building/building/
99
103
  [gh-pages]:https://ruby-processing.github.io/propane/
100
104
  [vanilla]:https://github.com/processing/processing/pull/5753
105
+ [warning]: https://monkstone.github.io/jruby_art/update/2019/09/10/Reflective_Access.html
data/Rakefile CHANGED
@@ -28,12 +28,12 @@ end
28
28
 
29
29
  desc 'Document'
30
30
  task :javadoc do
31
- sh 'mvn javadoc:javadoc'
31
+ sh './mvnw javadoc:javadoc'
32
32
  end
33
33
 
34
34
  desc 'Compile'
35
35
  task :compile do
36
- sh 'mvn package'
36
+ sh './mvnw package'
37
37
  end
38
38
 
39
39
  desc 'JRuby-Complete'
data/lib/propane.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  require 'java'
3
3
  unless defined? PROPANE_ROOT
4
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
5
- PROPANE_ROOT = File.absolute_path(File.dirname(__dir__))
4
+ $LOAD_PATH << File.dirname(__dir__)
5
+ PROPANE_ROOT = File.dirname(__dir__)
6
6
  end
7
7
  Dir["#{PROPANE_ROOT}/lib/*.jar"].each do |jar|
8
8
  require jar
data/lib/propane/app.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  require_relative 'helper_methods'
3
4
  require_relative 'library_loader'
4
5
 
@@ -8,7 +9,7 @@ module Propane
8
9
  # Load vecmath, fastmath and mathtool modules
9
10
  Java::Monkstone::PropaneLibrary.load(JRuby.runtime)
10
11
  SKETCH_ROOT = File.absolute_path('.')
11
-
12
+ # import custom Vecmath renderers
12
13
  module Render
13
14
  java_import 'monkstone.vecmath.GfxRender'
14
15
  java_import 'monkstone.vecmath.ShapeRender'
@@ -49,13 +50,15 @@ module Propane
49
50
 
50
51
  # All sketches extend this class
51
52
  class App < PApplet
52
- include Math, MathTool, HelperMethods, Render
53
+ include HelperMethods
54
+ include Math
55
+ include MathTool
56
+ include Render
53
57
  # Alias some methods for familiarity for Shoes coders.
54
58
  alias oval ellipse
55
59
  alias stroke_width stroke_weight
56
60
  alias rgb color
57
61
  alias gray color
58
- field_reader :surface
59
62
 
60
63
  def sketch_class
61
64
  self.class.sketch_class
@@ -75,8 +78,8 @@ module Propane
75
78
  #
76
79
  class << self
77
80
  # Handy getters and setters on the class go here:
78
- attr_accessor :sketch_class, :library_loader, :title, :arguments, :options
79
-
81
+ attr_accessor :sketch_class, :library_loader, :arguments, :options
82
+ attr_reader :surface
80
83
  def load_libraries(*args)
81
84
  library_loader ||= LibraryLoader.new
82
85
  library_loader.load_library(*args)
@@ -99,6 +102,7 @@ module Propane
99
102
  # Processing call them by their expected Java names.
100
103
  def method_added(method_name) #:nodoc:
101
104
  return unless METHODS_TO_ALIAS.key?(method_name)
105
+
102
106
  alias_method METHODS_TO_ALIAS[method_name], method_name
103
107
  end
104
108
  end
@@ -112,12 +116,14 @@ module Propane
112
116
  proxy_java_fields
113
117
  raise TypeError unless options.is_a? Hash
114
118
  raise TypeError unless arguments.is_a? Array
119
+
115
120
  # Set up the sketch.
116
121
  super()
117
122
  post_initialize(options)
118
123
  Propane.app = self
119
124
  @arguments = arguments
120
125
  @options = options
126
+ @surface = get_surface
121
127
  run_propane
122
128
  end
123
129
 
@@ -130,8 +136,7 @@ module Propane
130
136
  super(*args)
131
137
  end
132
138
 
133
- def post_initialize(_args)
134
- end
139
+ def post_initialize(_args); end
135
140
 
136
141
  def sketch_title(title)
137
142
  surface.set_title(title)
@@ -164,6 +169,7 @@ module Propane
164
169
  # Processing call them by their expected Java names.
165
170
  def method_added(method_name) #:nodoc:
166
171
  return unless METHODS_TO_ALIAS.key?(method_name)
172
+
167
173
  alias_method METHODS_TO_ALIAS[method_name], method_name
168
174
  end
169
175
  end
@@ -181,7 +187,10 @@ module Propane
181
187
 
182
188
  def method_missing(name, *args, &block)
183
189
  return Propane.app.send(name, *args) if Propane.app.respond_to? name
190
+
184
191
  super
185
192
  end
186
- end # Processing::Proxy
187
- end # Propane
193
+ end
194
+ # end Processing::Proxy
195
+ end
196
+ # end Propane
@@ -56,7 +56,7 @@ module Propane
56
56
  end
57
57
 
58
58
  def web_to_color_array(web)
59
- Java::Monkstone::ColorUtil.webArray(web)
59
+ Java::Monkstone::ColorUtil.webArray(web.to_java(:string))
60
60
  end
61
61
 
62
62
  def int_to_ruby_colors(hex)
@@ -40,7 +40,7 @@ module Propane
40
40
  end
41
41
 
42
42
  options[:install] = false
43
- message = '<Samples><GLVideo><Video><Sound> Install samples or library'
43
+ message = '<Samples><Video><Sound> Install samples or library'
44
44
  opts.on('-i', '--install', message) do
45
45
  options[:install] = true
46
46
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Propane
3
- VERSION = '3.4.0'
3
+ VERSION = '3.4.1'
4
4
  end
@@ -0,0 +1,26 @@
1
+ java_import Java::Monkstone::ColorUtil
2
+
3
+ # class wraps a java color array, supports shuffle!, last and ruby_string
4
+ # as well as ability to initialize with an array of "web" color string
5
+ class ColorGroup
6
+ attr_reader :colors
7
+ def initialize(p5cols)
8
+ @colors = p5cols
9
+ end
10
+
11
+ def self.from_web_array(web)
12
+ ColorGroup.new(ColorUtil.web_array(web.to_java(:string)))
13
+ end
14
+
15
+ def shuffle!
16
+ @colors = ColorUtil.shuffle(colors)
17
+ end
18
+
19
+ def ruby_string
20
+ ColorUtil.rubyString(colors)
21
+ end
22
+
23
+ def last
24
+ colors[0]
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ # @TODO usage
2
+ class Propane::App
3
+ java_import Java::ProcessingDxf::RawDXF
4
+ end
@@ -0,0 +1,5 @@
1
+ # @TODO usage
2
+ class Propane::App
3
+ java_import Java::ProcessingNet::Client
4
+ java_import Java::ProcessingNet::Server
5
+ end
@@ -1,3 +1,4 @@
1
1
  class Propane::App
2
- include Java::MonkstoneVideoevent::VideoInterface
2
+ include Java::MonkstoneVideoevent::CaptureEvent
3
+ include Java::MonkstoneVideoevent::MovieEvent
3
4
  end
data/pom.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  project 'propane', 'https://github.com/monkstone/propane' do
2
2
 
3
3
  model_version '4.0.0'
4
- id 'propane:propane:3.4.0'
4
+ id 'propane:propane:3.4.1'
5
5
  packaging 'jar'
6
6
 
7
7
  description 'An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.'
@@ -45,8 +45,8 @@ project 'propane', 'https://github.com/monkstone/propane' do
45
45
  'jogl.version' => '2.3.2',
46
46
  'jruby.api' => 'http://jruby.org/apidocs/' )
47
47
 
48
- pom 'org.jruby:jruby:9.2.8.0'
49
- jar 'org.processing:video:3.2.3'
48
+ pom 'org.jruby:jruby:9.2.9.0'
49
+ jar 'org.processing:video:3.3.7'
50
50
  jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
51
51
  jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
52
52
 
data/pom.xml CHANGED
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
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.4.1</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.9.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>
data/propane.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.summary = %q{ruby implementation of processing-4.0 on MacOS, linux and windows (64bit only)}
16
16
  gem.homepage = 'https://ruby-processing.github.io/propane/'
17
17
  gem.files = `git ls-files`.split($/)
18
- gem.files << 'lib/propane-3.4.0.jar'
18
+ gem.files << 'lib/propane-3.4.1.jar'
19
19
  gem.files << 'lib/gluegen-rt.jar'
20
20
  gem.files << 'lib/jogl-all.jar'
21
21
  gem.files << 'lib/gluegen-rt-natives-linux-amd64.jar'
@@ -19,8 +19,9 @@
19
19
  */
20
20
  package japplemenubar;
21
21
 
22
- import java.io.*;
23
-
22
+ import java.io.File;
23
+ import java.io.IOException;
24
+ import java.io.InputStream;
24
25
  import processing.core.PApplet;
25
26
 
26
27
 
@@ -58,7 +59,6 @@ public class JAppleMenuBar {
58
59
  }
59
60
  } catch (IOException e) {
60
61
  sadness("Unknown error, here's the stack trace.");
61
- e.printStackTrace();
62
62
  }
63
63
  }
64
64
 
@@ -13,6 +13,9 @@
13
13
  */
14
14
  package monkstone;
15
15
 
16
+ import java.util.ArrayList;
17
+ import java.util.List;
18
+ import java.util.Random;
16
19
  /**
17
20
  *
18
21
  * @author Martin Prout
@@ -102,6 +105,17 @@ public class ColorUtil {
102
105
  return (float) hex;
103
106
  }
104
107
 
108
+ static public int[] shuffle(int[] cols) {
109
+ Random rgen = new Random(); // Random number generator
110
+ for (int i = 0; i < cols.length; i++) {
111
+ int randomPosition = rgen.nextInt(cols.length);
112
+ int temp = cols[i];
113
+ cols[i] = cols[randomPosition];
114
+ cols[randomPosition] = temp;
115
+ }
116
+ return cols;
117
+ }
118
+
105
119
  /**
106
120
  *
107
121
  * @param hue
@@ -22,216 +22,265 @@ import org.jruby.runtime.ThreadContext;
22
22
  import org.jruby.runtime.builtin.IRubyObject;
23
23
 
24
24
  /**
25
- *
26
- * @author Martin Prout
27
- */
25
+ *
26
+ * @author Martin Prout
27
+ */
28
28
  @JRubyModule(name = "MathTool")
29
29
  public class MathToolModule {
30
30
 
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
- }
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
+ }
39
39
 
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
- }
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
+ }
63
63
 
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);
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);
93
88
  }
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);
89
+ if (value > max) {
90
+ return mapMt(context, max, first1, last1, first2, last2);
110
91
  }
92
+ return mapMt(context, value, first1, last1, first2, last2);
93
+ }
111
94
 
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
- }
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);
110
+ }
134
111
 
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);
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];
151
128
  }
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);
129
+ if (amount >= 1.0) {
130
+ return args[1];
177
131
  }
178
- // start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
132
+ return context.runtime.newFloat((1 - amount) * start + (stop * amount));
133
+ }
134
+
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);
151
+ }
179
152
 
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);
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
+
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);
183
175
  }
176
+ return mapMt(context, value, start, stop, 0, 1.0);
177
+ }
178
+ // start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
179
+ static final RubyFloat mapMt(ThreadContext context, double value, double first1, double last1, double first2, double last2) {
180
+ Ruby ruby = context.runtime;
181
+ double result = first2 + (last2 - first2) * ((value - first1) / (last1 - first1));
182
+ return ruby.newFloat(result);
183
+ }
184
184
 
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
- }
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];
205
204
  }
205
+ }
206
206
 
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
- }
207
+ /**
208
+ * Provides JRubyArt grid method as a ruby module method behaves like:-
209
+ * def grid(dx, dy, sx = 1, sy = 1)
210
+ * (0...dx).step(sx) do |x|
211
+ * (0...dy).step(sy) do |y|
212
+ * yield(x, y)
213
+ * end
214
+ * end
215
+ * end
216
+ * @param context ThreadContext
217
+ * @param recv IRubyObject
218
+ * @param args array of args should be Fixnum
219
+ * @param block { |x, y| `do something` }
220
+ * @return nil
221
+ */
222
+ @JRubyMethod(name = "grid", rest = true, module = true)
223
+ public static IRubyObject createGrid(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
224
+ Ruby ruby = context.runtime;
225
+ int row = (int) args[0].toJava(Integer.class);
226
+ int column = (int) args[1].toJava(Integer.class);
227
+ int rowStep = 1;
228
+ int colStep = 1;
229
+ if (args.length == 4){
230
+ rowStep = (int) args[2].toJava(Integer.class);
231
+ colStep = (int) args[3].toJava(Integer.class);
232
+ }
233
+ if (block.isGiven()) {
234
+ int tempRow = row / rowStep;
235
+ int tempColumn = column /colStep;
236
+ for (int z = 0; z < (tempRow * tempColumn); z++){
237
+ int y = z % tempColumn;
238
+ int x = z / tempColumn;
239
+ block.yieldSpecific(context, ruby.newFixnum(x * rowStep), ruby.newFixnum(y * colStep));
240
+ }
241
+ }
242
+ return context.nil;
243
+ }
244
+ /**
245
+ * Provides JRubyArt mesh_grid method as a ruby module method
246
+ * def grid(dx, dy, dz, sx = 1, sy = 1, sz = 1)
247
+ * (0...dx).step(sx) do |x|
248
+ * (0...dy).step(sy) do |y|
249
+ * (0...dz).step(sy) do |z|
250
+ * yield(x, y, z)
251
+ * end
252
+ * end
253
+ * end
254
+ * end
255
+ *
256
+ * @param context ThreadContext
257
+ * @param recv IRubyObject
258
+ * @param args array of args should be Fixnum
259
+ * @param block { |x, y, z| `do something` }
260
+ * @return nil
261
+ */
262
+ @JRubyMethod(name = "mesh_grid", rest = true, module = true)
263
+ public static IRubyObject createGrid3D(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
264
+ Ruby ruby = context.runtime;
265
+ int xDim = (int) args[0].toJava(Integer.class);
266
+ int yDim = (int) args[1].toJava(Integer.class);
267
+ int zDim = (int) args[2].toJava(Integer.class);
268
+ int xStep = (args.length > 3) ? (int) args[3].toJava(Integer.class) : 1;
269
+ int yStep = (args.length > 4) ? (int) args[4].toJava(Integer.class) : 1;
270
+ int zStep = (args.length == 6) ? (int) args[5].toJava(Integer.class) : 1;
271
+ int dimX = xDim / xStep;
272
+ int dimY = yDim / yStep;
273
+ int dimZ = zDim / zStep;
274
+ if (block.isGiven()) {
275
+ int count = dimX * dimY * dimZ;
276
+ for (int x = 0; x < xDim; x += xStep){
277
+ for (int j = 0; j < (dimZ * dimY); j++){
278
+ int z = j % dimZ;
279
+ int y = j / dimZ;
280
+ block.yieldSpecific(context, ruby.newFixnum(x), ruby.newFixnum(y * yStep), ruby.newFixnum(z * zStep));
233
281
  }
234
- return context.nil;
235
-
282
+ }
236
283
  }
284
+ return context.nil;
285
+ }
237
286
  }