Skip to content

Commit 951fea2

Browse files
authored
Merge pull request #41 from ruby-processing/revert-40-jdk17
Revert "Jdk17"
2 parents ebb0f82 + 84a40f8 commit 951fea2

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

+1045
-1044
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-17+`
13+
- `jdk-11.0.11+`
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.6
91+
[Worked Examples](https://github.com/ruby-processing/propane-examples) more to follow, feel free to add your own, especially ruby-2.5
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' => '17')
64+
'release' => '11')
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>17</release>
142+
<release>11</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 >= 17+'
40+
gem.requirements << 'java runtime >= 11.0.11+'
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-21 Martin Prout.
6+
* Copyright (c) 2015-20 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: 55 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
2-
* Copyright (c) 2020-21 Martin Prout
3-
*/
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+
*/
46
package monkstone;
57

68
import monkstone.noise.OpenSimplex2F;
@@ -30,23 +32,6 @@ public static void createNoiseModule(Ruby runtime) {
3032
RubyModule noiseModule = runtime.defineModule("FastNoise");
3133
noiseModule.defineAnnotatedMethods(FastNoiseModuleJava.class);
3234
}
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-
}
5035

5136
/**
5237
*
@@ -57,36 +42,34 @@ private static double jvalue(IRubyObject obj) {
5742
*/
5843
@JRubyMethod(name = "tnoise", rest = true, module = true)
5944
public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
45+
double result = 0;
6046
double one;
6147
double two;
6248
double three;
6349
double four;
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");
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");
8971
}
72+
return RubyFloat.newFloat(context.runtime, result);
9073
}
9174

9275
/**
@@ -98,43 +81,39 @@ public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject re
9881
*/
9982
@JRubyMethod(name = "noise", rest = true, module = true)
10083
public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
84+
double result = 0;
10185
double one;
10286
double two;
10387
double three;
10488
double four;
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");
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");
134114
}
115+
return RubyFloat.newFloat(context.runtime, result);
135116
}
136-
}
137-
138117
// @JRubyMethod(name = "noise_seed", rest = true, module = true)
139118
// public static IRubyObject noiseSeedImpl(ThreadContext context, IRubyObject recv, IRubyObject arg) {
140119
// long seed;
@@ -145,4 +124,4 @@ public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRu
145124
// }
146125
// return RubyBoolean.newBoolean(context.runtime, false);
147126
// }
148-
//}
127+
}

src/main/java/monkstone/MathToolModule.java

Lines changed: 35 additions & 41 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-21 Martin Prout. This tool is free software; you can
5+
* Copyright (c) 2015-20 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,22 +37,6 @@ 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-
}
5640

5741
/**
5842
*
@@ -63,13 +47,18 @@ private static double jvalue(IRubyObject obj) {
6347
*/
6448
@JRubyMethod(name = "map1d", rest = true, module = true)
6549
public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
66-
double value = jvalue(args[0]);
50+
double value = args[0] instanceof RubyFloat
51+
? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
6752
RubyRange r1 = (RubyRange) args[1];
6853
RubyRange r2 = (RubyRange) args[2];
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));
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();
7362
return mapMt(context, value, first1, last1, first2, last2);
7463
}
7564

@@ -82,13 +71,17 @@ public static IRubyObject mapOneD(ThreadContext context, IRubyObject recv, IRuby
8271
*/
8372
@JRubyMethod(name = "constrained_map", rest = true, module = true)
8473
public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
85-
double value = jvalue(args[0]);
74+
double value = args[0] instanceof RubyFloat ? ((RubyFloat) args[0]).getValue() : ((RubyFixnum) args[0]).getDoubleValue();
8675
RubyRange r1 = (RubyRange) args[1];
8776
RubyRange r2 = (RubyRange) args[2];
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));
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();
9285
double max = Math.max(first1, last1);
9386
double min = Math.min(first1, last1);
9487
if (value < min) {
@@ -109,11 +102,11 @@ public static IRubyObject constrainedMap(ThreadContext context, IRubyObject recv
109102
*/
110103
@JRubyMethod(name = "p5map", rest = true, module = true)
111104
public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
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]);
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();
117110
return mapMt(context, value, first1, last1, first2, last2);
118111
}
119112

@@ -128,9 +121,9 @@ public static IRubyObject mapProcessing(ThreadContext context, IRubyObject recv,
128121
*/
129122
@JRubyMethod(name = "lerp", rest = true, module = true)
130123
public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
131-
double start = jvalue(args[0]);
132-
double stop = jvalue(args[1]);
133-
double amount = jvalue(args[2]);
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();
134127
if (amount <= 0) {
135128
return args[0];
136129
}
@@ -152,9 +145,9 @@ public static IRubyObject lerpP(ThreadContext context, IRubyObject recv, IRubyOb
152145
*/
153146
@JRubyMethod(name = "norm", rest = true, module = true)
154147
public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
155-
double value = jvalue(args[0]);
156-
double start = jvalue(args[1]);
157-
double stop = jvalue(args[2]);
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();
158151
return mapMt(context, value, start, stop, 0, 1.0);
159152
}
160153

@@ -169,9 +162,10 @@ public static IRubyObject normP(ThreadContext context, IRubyObject recv, IRubyOb
169162
*/
170163
@JRubyMethod(name = "norm_strict", rest = true, module = true)
171164
public static IRubyObject norm_strict(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
172-
double value = jvalue(args[0]);
173-
double start = jvalue(args[1]);
174-
double stop = jvalue(args[2]);
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();
175169
double max = Math.max(start, stop);
176170
double min = Math.min(start, stop);
177171
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-21 Martin Prout. This code is free software; you can
3+
* Copyright (C) 2015-20 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)