Skip to content

Commit ebb0f82

Browse files
authored
Merge pull request #40 from ruby-processing/jdk17
Jdk17
2 parents af0d237 + 21ac4f3 commit ebb0f82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1044
-1045
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ adjust above for your OS/distro setup.
1010

1111
Tested with OpenJDK11 and OpenJDK17.
1212

13-
- `jdk-11.0.11+`
13+
- `jdk-17+`
1414
- `jruby-9.3.1.0`
1515

1616
## Building and testing
@@ -88,7 +88,7 @@ See [gh-pages][gh-pages] for more detailed instructions and much more.
8888

8989
## Examples
9090

91-
[Worked Examples](https://github.com/ruby-processing/propane-examples) more to follow, feel free to add your own, especially ruby-2.5
91+
[Worked Examples](https://github.com/ruby-processing/propane-examples) more to follow, feel free to add your own, especially ruby-2.6
9292
+ syntax now we can. To install the samples. The samples get copied to `~/propane_samples`. Depends on wget.
9393
```bash
9494
propane --install samples

pom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
plugin('org.codehaus.mojo:versions-maven-plugin:2.7',
6262
'generateBackupPoms' => 'false')
6363
plugin(:compiler, '3.8.1',
64-
'release' => '11')
64+
'release' => '17')
6565
plugin :dependency, '3.1.2' do
6666
execute_goals( id: 'default-cli',
6767
artifactItems:[

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ DO NOT MODIFY - GENERATED CODE
139139
<artifactId>maven-compiler-plugin</artifactId>
140140
<version>3.8.1</version>
141141
<configuration>
142-
<release>11</release>
142+
<release>17</release>
143143
</configuration>
144144
</plugin>
145145
<plugin>

propane.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ Gem::Specification.new do |gem|
3737
gem.add_runtime_dependency 'arcball', '~> 1.2'
3838
gem.require_paths = ['lib']
3939
gem.platform = 'java'
40-
gem.requirements << 'java runtime >= 11.0.11+'
40+
gem.requirements << 'java runtime >= 17+'
4141
end

src/main/java/monkstone/ColorUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* in their sketches. Includes a method to efficiently convert an array of web
44
* strings to an array of color int, and another to convert an array of color
55
* int to a string that can be used in ruby code (to generate web color array).
6-
* Copyright (c) 2015-20 Martin Prout.
6+
* Copyright (c) 2015-21 Martin Prout.
77
* This utility is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as published by
99
* the Free Software Foundation; either version 2.1 of the License, or (at
Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
2+
* Copyright (c) 2020-21 Martin Prout
3+
*/
64
package monkstone;
75

86
import monkstone.noise.OpenSimplex2F;
@@ -32,6 +30,23 @@ public static void createNoiseModule(Ruby runtime) {
3230
RubyModule noiseModule = runtime.defineModule("FastNoise");
3331
noiseModule.defineAnnotatedMethods(FastNoiseModuleJava.class);
3432
}
33+
34+
35+
/**
36+
* Utility method
37+
*
38+
* @param obj
39+
* @return parse float value of object or zero
40+
*/
41+
private static double jvalue(IRubyObject obj) {
42+
if (obj instanceof RubyFloat rubyFloat) {
43+
return rubyFloat.getValue();
44+
}
45+
if (obj instanceof RubyFixnum rubyFixnum) {
46+
return rubyFixnum.getDoubleValue();
47+
}
48+
return 0;
49+
}
3550

3651
/**
3752
*
@@ -42,34 +57,36 @@ public static void createNoiseModule(Ruby runtime) {
4257
*/
4358
@JRubyMethod(name = "tnoise", rest = true, module = true)
4459
public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
45-
double result = 0;
4660
double one;
4761
double two;
4862
double three;
4963
double four;
50-
switch (args.length) {
51-
case 2:
52-
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
53-
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
54-
result = ng.noise2_XBeforeY(one, two);
55-
break;
56-
case 3:
57-
three = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
58-
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
59-
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
60-
result = ng.noise3_XYBeforeZ(one, two, three);
61-
break;
62-
case 4:
63-
four = args[3] instanceof RubyFloat ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
64-
three = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
65-
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
66-
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
67-
result = ng.noise4_XYBeforeZW(one, two, three, four);
68-
break;
69-
default:
70-
throw new RuntimeException("Min 2D Max 4D Noise");
64+
double result = switch (args.length) {
65+
case 2 -> {
66+
two = jvalue(args[1]);
67+
one = jvalue(args[0]);
68+
yield ng.noise2_XBeforeY(one, two);
69+
}
70+
case 3 -> {
71+
three = jvalue(args[2]);
72+
two = jvalue(args[1]);
73+
one = jvalue(args[0]);
74+
yield ng.noise3_XYBeforeZ(one, two, three);
75+
}
76+
case 4 -> {
77+
four = jvalue(args[3]);
78+
three = jvalue(args[2]);
79+
two = jvalue(args[1]);
80+
one = jvalue(args[0]);
81+
yield ng.noise4_XYBeforeZW(one, two, three, four);
82+
}
83+
default -> { yield 2; } // yield an invalid value for noise
84+
};
85+
if (result != 2) {
86+
return RubyFloat.newFloat(context.runtime, result);
87+
} else {
88+
throw new RuntimeException("Min 2D Max 4D Noise");
7189
}
72-
return RubyFloat.newFloat(context.runtime, result);
7390
}
7491

7592
/**
@@ -81,39 +98,43 @@ public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject re
8198
*/
8299
@JRubyMethod(name = "noise", rest = true, module = true)
83100
public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
84-
double result = 0;
85101
double one;
86102
double two;
87103
double three;
88104
double four;
89-
switch (args.length) {
90-
case 1:
91-
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
92-
result = ng.noise2(one, 0);
93-
break;
94-
case 2:
95-
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
96-
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
97-
result = ng.noise2(one, two);
98-
break;
99-
case 3:
100-
three = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
101-
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
102-
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
103-
result = ng.noise3_Classic(one, two, three);
104-
break;
105-
case 4:
106-
four = args[3] instanceof RubyFloat ? ((RubyFloat) args[3]).getValue() : ((RubyFixnum) args[3]).getDoubleValue();
107-
three = args[2] instanceof RubyFloat ? ((RubyFloat) args[2]).getValue() : ((RubyFixnum) args[2]).getDoubleValue();
108-
two = args[1] instanceof RubyFloat ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
109-
one = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
110-
result = ng.noise4_Classic(one, two, three, four);
111-
break;
112-
default:
113-
throw new RuntimeException("Maximum of 4D Noise");
105+
double result = switch (args.length) {
106+
case 1 -> {
107+
one = jvalue(args[0]);
108+
yield ng.noise2(one, 0);
109+
}
110+
case 2 -> {
111+
two = jvalue(args[1]);
112+
one = jvalue(args[0]);
113+
yield ng.noise2(one, two);
114+
}
115+
case 3 -> {
116+
three = jvalue(args[2]);
117+
two = jvalue(args[1]);
118+
one = jvalue(args[0]);
119+
yield ng.noise3_Classic(one, two, three);
120+
}
121+
case 4 -> {
122+
four = jvalue(args[3]);
123+
three = jvalue(args[2]);
124+
two = jvalue(args[1]);
125+
one = jvalue(args[0]);
126+
yield ng.noise4_Classic(one, two, three, four);
127+
}
128+
default -> { yield 2; } // yield an invalid value for noise
129+
};
130+
if (result != 2) {
131+
return RubyFloat.newFloat(context.runtime, result);
132+
} else {
133+
throw new RuntimeException("Min 2D Max 4D Noise");
114134
}
115-
return RubyFloat.newFloat(context.runtime, result);
116135
}
136+
}
137+
117138
// @JRubyMethod(name = "noise_seed", rest = true, module = true)
118139
// public static IRubyObject noiseSeedImpl(ThreadContext context, IRubyObject recv, IRubyObject arg) {
119140
// long seed;
@@ -124,4 +145,4 @@ public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRu
124145
// }
125146
// return RubyBoolean.newBoolean(context.runtime, false);
126147
// }
127-
}
148+
//}

src/main/java/monkstone/MathToolModule.java

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The purpose of this tool is to allow JRubyArt users to use an alternative
33
* to processing.org map, lerp and norm methods in their sketches and to implement
44
* 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
5+
* Copyright (c) 2015-21 Martin Prout. This tool is free software; you can
66
* redistribute it and/or modify it under the terms of the GNU Lesser General
77
* Public License as published by the Free Software Foundation; either version
88
* 2.1 of the License, or (at your option) any later version.
@@ -37,6 +37,22 @@ public static void createMathToolModule(Ruby runtime) {
3737
RubyModule mtModule = runtime.defineModule("MathTool");
3838
mtModule.defineAnnotatedMethods(MathToolModule.class);
3939
}
40+
41+
/**
42+
* Utility method
43+
*
44+
* @param obj
45+
* @return parse float value of object or zero
46+
*/
47+
private static double jvalue(IRubyObject obj) {
48+
if (obj instanceof RubyFloat rubyFloat) {
49+
return rubyFloat.getValue();
50+
}
51+
if (obj instanceof RubyFixnum rubyFixnum) {
52+
return rubyFixnum.getDoubleValue();
53+
}
54+
return 0;
55+
}
4056

4157
/**
4258
*
@@ -47,18 +63,13 @@ public static void createMathToolModule(Ruby runtime) {
4763
*/
4864
@JRubyMethod(name = "map1d", rest = true, module = true)
4965
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();
66+
double value = jvalue(args[0]);
5267
RubyRange r1 = (RubyRange) args[1];
5368
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();
69+
double first1 = jvalue(r1.first(context));
70+
double first2 = jvalue(r2.first(context));
71+
double last1 = jvalue(r1.last(context));
72+
double last2 = jvalue(r2.last(context));
6273
return mapMt(context, value, first1, last1, first2, last2);
6374
}
6475

@@ -71,17 +82,13 @@ public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRuby
7182
*/
7283
@JRubyMethod(name = "constrained_map", rest = true, module = true)
7384
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();
85+
double value = jvalue(args[0]);
7586
RubyRange r1 = (RubyRange) args[1];
7687
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();
88+
double first1 = jvalue(r1.first(context));
89+
double first2 = jvalue(r2.first(context));
90+
double last1 = jvalue(r1.last(context));
91+
double last2 = jvalue(r2.last(context));
8592
double max = Math.max(first1, last1);
8693
double min = Math.min(first1, last1);
8794
if (value < min) {
@@ -102,11 +109,11 @@ public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv
102109
*/
103110
@JRubyMethod(name = "p5map", rest = true, module = true)
104111
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();
112+
double value = jvalue(args[0]);
113+
double first1 = jvalue(args[1]);
114+
double first2 = jvalue(args[3]);
115+
double last1 = jvalue(args[2]);
116+
double last2 = jvalue(args[4]);
110117
return mapMt(context, value, first1, last1, first2, last2);
111118
}
112119

@@ -121,9 +128,9 @@ public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv,
121128
*/
122129
@JRubyMethod(name = "lerp", rest = true, module = true)
123130
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();
131+
double start = jvalue(args[0]);
132+
double stop = jvalue(args[1]);
133+
double amount = jvalue(args[2]);
127134
if (amount <= 0) {
128135
return args[0];
129136
}
@@ -145,9 +152,9 @@ public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyOb
145152
*/
146153
@JRubyMethod(name = "norm", rest = true, module = true)
147154
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();
155+
double value = jvalue(args[0]);
156+
double start = jvalue(args[1]);
157+
double stop = jvalue(args[2]);
151158
return mapMt(context, value, start, stop, 0, 1.0);
152159
}
153160

@@ -162,10 +169,9 @@ public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyOb
162169
*/
163170
@JRubyMethod(name = "norm_strict", rest = true, module = true)
164171
public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
165-
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();
172+
double value = jvalue(args[0]);
173+
double start = jvalue(args[1]);
174+
double stop = jvalue(args[2]);
169175
double max = Math.max(start, stop);
170176
double min = Math.min(start, stop);
171177
if (value < min) {

src/main/java/monkstone/PropaneLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* The purpose of this class is to load the MathTool into ruby-processing runtime
3-
* Copyright (C) 2015-20 Martin Prout. This code is free software; you can
3+
* Copyright (C) 2015-21 Martin Prout. This code is free software; you can
44
* redistribute it and/or modify it under the terms of the GNU Lesser General
55
* Public License as published by the Free Software Foundation; either version
66
* 2.1 of the License, or (at your option) any later version.

0 commit comments

Comments
 (0)