picrate 2.1.2-java → 2.4.2-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +3 -2
- data/Rakefile +2 -1
- data/docs/_includes/footer.html +1 -1
- data/docs/_layouts/post.html +1 -1
- data/docs/_methods/noise_mode.md +88 -0
- data/docs/_posts/2018-05-06-install_jruby.md +1 -1
- data/docs/_posts/2018-11-18-building-gem.md +3 -1
- data/docs/classes.md +2 -2
- data/docs/editors.md +2 -2
- data/docs/gems.md +3 -3
- data/docs/index.html +1 -1
- data/docs/libraries.md +2 -2
- data/docs/live.md +2 -2
- data/docs/magic.md +2 -2
- data/docs/methods.md +2 -2
- data/docs/modules.md +3 -3
- data/docs/objects.md +2 -2
- data/lib/picrate/app.rb +7 -6
- data/lib/picrate/native_folder.rb +1 -3
- data/lib/picrate/version.rb +1 -1
- data/library/pdf/pdf.rb +7 -0
- data/library/svg/svg.rb +7 -0
- data/picrate.gemspec +5 -3
- data/pom.rb +25 -4
- data/pom.xml +39 -4
- data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/PicrateLibrary.java +3 -1
- data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +41 -93
- data/src/main/java/monkstone/noise/OpenSimplex2F.java +914 -0
- data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/ShimAWT.java +260 -94
- data/src/main/java/processing/core/PApplet.java +14664 -13450
- data/src/main/java/processing/core/PConstants.java +5 -5
- data/src/main/java/processing/core/PFont.java +1 -1
- data/src/main/java/processing/core/PGraphics.java +200 -201
- data/src/main/java/processing/core/PImage.java +539 -549
- data/src/main/java/processing/core/PShape.java +18 -18
- data/src/main/java/processing/core/PVector.java +23 -23
- data/src/main/java/processing/data/Table.java +4 -4
- data/src/main/java/processing/net/Client.java +13 -13
- data/src/main/java/processing/net/Server.java +5 -5
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +4 -4
- data/src/main/java/processing/pdf/PGraphicsPDF.java +529 -0
- data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
- data/test/deglut_spec_test.rb +2 -2
- data/test/respond_to_test.rb +0 -2
- data/test/test_helper.rb +1 -1
- data/vendors/Rakefile +1 -1
- metadata +26 -15
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -465
data/pom.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
<!--
|
3
3
|
|
4
4
|
|
5
|
-
DO NOT
|
5
|
+
DO NOT MODIFY - GENERATED CODE
|
6
6
|
|
7
7
|
|
8
8
|
-->
|
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
|
|
11
11
|
<modelVersion>4.0.0</modelVersion>
|
12
12
|
<groupId>ruby-processing</groupId>
|
13
13
|
<artifactId>picrate</artifactId>
|
14
|
-
<version>2.
|
14
|
+
<version>2.4.2</version>
|
15
15
|
<name>picrate</name>
|
16
16
|
<description>An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.</description>
|
17
17
|
<url>http://maven.apache.org</url>
|
@@ -64,19 +64,21 @@ DO NOT MODIFIY - GENERATED CODE
|
|
64
64
|
<url>https://github.com/ruby-processing/PiCrate/issues</url>
|
65
65
|
</issueManagement>
|
66
66
|
<properties>
|
67
|
+
<batik.version>1.14</batik.version>
|
68
|
+
<itextpdf.version>5.5.13.2</itextpdf.version>
|
67
69
|
<jogl.version>2.3.2</jogl.version>
|
68
70
|
<jruby.api>http://jruby.org/apidocs/</jruby.api>
|
69
71
|
<picrate.basedir>${project.basedir}</picrate.basedir>
|
70
72
|
<polyglot.dump.pom>pom.xml</polyglot.dump.pom>
|
71
73
|
<processing.api>http://processing.github.io/processing-javadocs/core/</processing.api>
|
72
|
-
<project.build.sourceEncoding>
|
74
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
73
75
|
<source.directory>src</source.directory>
|
74
76
|
</properties>
|
75
77
|
<dependencies>
|
76
78
|
<dependency>
|
77
79
|
<groupId>org.jruby</groupId>
|
78
80
|
<artifactId>jruby</artifactId>
|
79
|
-
<version>9.2.
|
81
|
+
<version>9.2.19.0</version>
|
80
82
|
<type>pom</type>
|
81
83
|
</dependency>
|
82
84
|
<dependency>
|
@@ -94,6 +96,16 @@ DO NOT MODIFIY - GENERATED CODE
|
|
94
96
|
<artifactId>video</artifactId>
|
95
97
|
<version>3.0.2</version>
|
96
98
|
</dependency>
|
99
|
+
<dependency>
|
100
|
+
<groupId>org.apache.xmlgraphics</groupId>
|
101
|
+
<artifactId>batik-all</artifactId>
|
102
|
+
<version>${batik.version}</version>
|
103
|
+
</dependency>
|
104
|
+
<dependency>
|
105
|
+
<groupId>com.itextpdf</groupId>
|
106
|
+
<artifactId>itextpdf</artifactId>
|
107
|
+
<version>${itextpdf.version}</version>
|
108
|
+
</dependency>
|
97
109
|
</dependencies>
|
98
110
|
<build>
|
99
111
|
<resources>
|
@@ -124,6 +136,29 @@ DO NOT MODIFIY - GENERATED CODE
|
|
124
136
|
<plugin>
|
125
137
|
<artifactId>maven-dependency-plugin</artifactId>
|
126
138
|
<version>3.1.2</version>
|
139
|
+
<executions>
|
140
|
+
<execution>
|
141
|
+
<id>default-cli</id>
|
142
|
+
<configuration>
|
143
|
+
<artifactItems>
|
144
|
+
<artifactItem>
|
145
|
+
<groupId>com.itextpdf</groupId>
|
146
|
+
<artifactId>itextpdf</artifactId>
|
147
|
+
<version>${itextpdf.version}</version>
|
148
|
+
<type>jar</type>
|
149
|
+
<outputDirectory>${picrate.basedir}/library/pdf</outputDirectory>
|
150
|
+
</artifactItem>
|
151
|
+
<artifactItem>
|
152
|
+
<groupId>org.apache.xmlgraphics</groupId>
|
153
|
+
<artifactId>batik-all</artifactId>
|
154
|
+
<version>${batik.version}</version>
|
155
|
+
<type>jar</type>
|
156
|
+
<outputDirectory>${picrate.basedir}/library/svg</outputDirectory>
|
157
|
+
</artifactItem>
|
158
|
+
</artifactItems>
|
159
|
+
</configuration>
|
160
|
+
</execution>
|
161
|
+
</executions>
|
127
162
|
</plugin>
|
128
163
|
<plugin>
|
129
164
|
<artifactId>maven-compiler-plugin</artifactId>
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/*
|
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
|
+
*/
|
6
|
+
package monkstone;
|
7
|
+
|
8
|
+
import monkstone.noise.OpenSimplex2F;
|
9
|
+
import org.jruby.Ruby;
|
10
|
+
import org.jruby.RubyFixnum;
|
11
|
+
import org.jruby.RubyFloat;
|
12
|
+
import org.jruby.RubyModule;
|
13
|
+
import org.jruby.anno.JRubyMethod;
|
14
|
+
import org.jruby.anno.JRubyModule;
|
15
|
+
import org.jruby.runtime.ThreadContext;
|
16
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
17
|
+
|
18
|
+
/**
|
19
|
+
*
|
20
|
+
* @author Martin Prout
|
21
|
+
*/
|
22
|
+
@JRubyModule(name = "FastNoise")
|
23
|
+
public class FastNoiseModuleJava {
|
24
|
+
|
25
|
+
static OpenSimplex2F ng = new OpenSimplex2F(System.currentTimeMillis());
|
26
|
+
|
27
|
+
/**
|
28
|
+
*
|
29
|
+
* @param runtime Ruby
|
30
|
+
*/
|
31
|
+
public static void createNoiseModule(Ruby runtime) {
|
32
|
+
RubyModule noiseModule = runtime.defineModule("FastNoise");
|
33
|
+
noiseModule.defineAnnotatedMethods(FastNoiseModuleJava.class);
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
*
|
38
|
+
* @param context ThreadContext
|
39
|
+
* @param recv IRubyObject
|
40
|
+
* @param args array of numeric values
|
41
|
+
* @return mapped value RubyFloat
|
42
|
+
*/
|
43
|
+
@JRubyMethod(name = "tnoise", rest = true, module = true)
|
44
|
+
public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
45
|
+
double result = 0;
|
46
|
+
double one;
|
47
|
+
double two;
|
48
|
+
double three;
|
49
|
+
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");
|
71
|
+
}
|
72
|
+
return RubyFloat.newFloat(context.runtime, result);
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
*
|
77
|
+
* @param context ThreadContext
|
78
|
+
* @param recv IRubyObject
|
79
|
+
* @param args array of numeric values
|
80
|
+
* @return mapped value RubyFloat
|
81
|
+
*/
|
82
|
+
@JRubyMethod(name = "noise", rest = true, module = true)
|
83
|
+
public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
84
|
+
double result = 0;
|
85
|
+
double one;
|
86
|
+
double two;
|
87
|
+
double three;
|
88
|
+
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");
|
114
|
+
}
|
115
|
+
return RubyFloat.newFloat(context.runtime, result);
|
116
|
+
}
|
117
|
+
// @JRubyMethod(name = "noise_seed", rest = true, module = true)
|
118
|
+
// public static IRubyObject noiseSeedImpl(ThreadContext context, IRubyObject recv, IRubyObject arg) {
|
119
|
+
// long seed;
|
120
|
+
// if (arg instanceof RubyNumeric) {
|
121
|
+
// seed = ((RubyNumeric) arg).getLongValue();
|
122
|
+
// ng = new OpenSimplex2F(seed);
|
123
|
+
// return RubyBoolean.newBoolean(context.runtime, true);
|
124
|
+
// }
|
125
|
+
// return RubyBoolean.newBoolean(context.runtime, false);
|
126
|
+
// }
|
127
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* The purpose of this class is to load the MathTool into PiCrate runtime
|
3
|
-
* Copyright (C) 2018-
|
3
|
+
* Copyright (C) 2018-21 Martin Prout. This code is free software; you can
|
4
4
|
* redistribute it and/or modify it under the terms of the GNU Lesser General
|
5
5
|
* Public License as published by the Free Software Foundation; either version
|
6
6
|
* 2.1 of the License, or (at your option) any later version.
|
@@ -30,6 +30,8 @@ public class PicrateLibrary implements Library{
|
|
30
30
|
*/
|
31
31
|
public static void load(final Ruby runtime) {
|
32
32
|
MathToolModule.createMathToolModule(runtime);
|
33
|
+
FastNoiseModuleJava.createNoiseModule(runtime);
|
34
|
+
SmoothNoiseModuleJava.createNoiseModule(runtime);
|
33
35
|
Deglut.createDeglut(runtime);
|
34
36
|
Vec2.createVec2(runtime);
|
35
37
|
Vec3.createVec3(runtime);
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/*
|
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
|
+
*/
|
6
|
+
package monkstone;
|
7
|
+
|
8
|
+
import monkstone.noise.OpenSimplex2S;
|
9
|
+
import org.jruby.Ruby;
|
10
|
+
import org.jruby.RubyFixnum;
|
11
|
+
import org.jruby.RubyFloat;
|
12
|
+
import org.jruby.RubyModule;
|
13
|
+
import org.jruby.anno.JRubyMethod;
|
14
|
+
import org.jruby.anno.JRubyModule;
|
15
|
+
import org.jruby.runtime.ThreadContext;
|
16
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
17
|
+
|
18
|
+
/**
|
19
|
+
*
|
20
|
+
* @author Martin Prout
|
21
|
+
*/
|
22
|
+
@JRubyModule(name = "SmoothNoise")
|
23
|
+
public class SmoothNoiseModuleJava {
|
24
|
+
|
25
|
+
static OpenSimplex2S ng = new OpenSimplex2S(System.currentTimeMillis());
|
26
|
+
|
27
|
+
/**
|
28
|
+
*
|
29
|
+
* @param runtime Ruby
|
30
|
+
*/
|
31
|
+
public static void createNoiseModule(Ruby runtime) {
|
32
|
+
RubyModule noiseModule = runtime.defineModule("SmoothNoise");
|
33
|
+
noiseModule.defineAnnotatedMethods(SmoothNoiseModuleJava.class);
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
*
|
38
|
+
* @param context ThreadContext
|
39
|
+
* @param recv IRubyObject
|
40
|
+
* @param args array of numeric values
|
41
|
+
* @return mapped value RubyFloat
|
42
|
+
*/
|
43
|
+
@JRubyMethod(name = "tnoise", rest = true, module = true)
|
44
|
+
public static IRubyObject terrainNoiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
45
|
+
double result = 0;
|
46
|
+
double one;
|
47
|
+
double two;
|
48
|
+
double three;
|
49
|
+
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");
|
71
|
+
}
|
72
|
+
return RubyFloat.newFloat(context.runtime, result);
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
*
|
77
|
+
* @param context ThreadContext
|
78
|
+
* @param recv IRubyObject
|
79
|
+
* @param args array of numeric values
|
80
|
+
* @return mapped value RubyFloat
|
81
|
+
*/
|
82
|
+
@JRubyMethod(name = "noise", rest = true, module = true)
|
83
|
+
public static IRubyObject noiseImpl(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
|
84
|
+
double result = 0;
|
85
|
+
double one;
|
86
|
+
double two;
|
87
|
+
double three;
|
88
|
+
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");
|
114
|
+
}
|
115
|
+
return RubyFloat.newFloat(context.runtime, result);
|
116
|
+
}
|
117
|
+
// @JRubyMethod(name = "noise_seed", rest = true, module = true)
|
118
|
+
// public static IRubyObject noiseSeedImpl(ThreadContext context, IRubyObject recv, IRubyObject arg) {
|
119
|
+
// long seed;
|
120
|
+
// if (arg instanceof RubyNumeric) {
|
121
|
+
// seed = ((RubyNumeric) arg).getLongValue();
|
122
|
+
// ng = new OpenSimplex2S(seed);
|
123
|
+
// return RubyBoolean.newBoolean(context.runtime, true);
|
124
|
+
// }
|
125
|
+
// return RubyBoolean.newBoolean(context.runtime, false);
|
126
|
+
// }
|
127
|
+
}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2021 Martin Prout
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU Lesser General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* http://creativecommons.org/licenses/LGPL/2.1/
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
*/
|
20
|
+
package monkstone.fastmath;
|
21
|
+
|
22
|
+
public final class DegLutTables {
|
23
|
+
|
24
|
+
/**
|
25
|
+
*
|
26
|
+
*/
|
27
|
+
static public final float PI = 3.1415927f;
|
28
|
+
|
29
|
+
/**
|
30
|
+
*
|
31
|
+
*/
|
32
|
+
static public final float PI2 = PI * 2;
|
33
|
+
static private final int SIN_BITS = 15; // 16KB. Adjust for accuracy.
|
34
|
+
static private final int SIN_MASK = ~(-1 << SIN_BITS);
|
35
|
+
static private final int SIN_COUNT = SIN_MASK + 1;
|
36
|
+
|
37
|
+
static private final float RAD_FULL = PI * 2;
|
38
|
+
static private final float DEG_FULL = 360;
|
39
|
+
static private final float RAD_TO_INDEX = SIN_COUNT / RAD_FULL;
|
40
|
+
static private final float DEG_TO_INDEX = SIN_COUNT / DEG_FULL;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* multiply by this to convert from radians to degrees
|
44
|
+
*/
|
45
|
+
static public final float RADIANS_TO_DEGREES = 180f / PI;
|
46
|
+
|
47
|
+
/**
|
48
|
+
*
|
49
|
+
*/
|
50
|
+
static public final float RAD_DEG = RADIANS_TO_DEGREES;
|
51
|
+
/**
|
52
|
+
* multiply by this to convert from degrees to radians
|
53
|
+
*/
|
54
|
+
static public final float DEGREES_TO_RADIANS = PI / 180;
|
55
|
+
|
56
|
+
/**
|
57
|
+
*
|
58
|
+
*/
|
59
|
+
static public final float DEG_RAD = DEGREES_TO_RADIANS;
|
60
|
+
|
61
|
+
static private class Sin {
|
62
|
+
|
63
|
+
static final float[] table = new float[SIN_COUNT];
|
64
|
+
|
65
|
+
static {
|
66
|
+
for (int i = 0; i < SIN_COUNT; i++) {
|
67
|
+
table[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * RAD_FULL);
|
68
|
+
}
|
69
|
+
for (int i = 0; i < 360; i += 90) {
|
70
|
+
table[(int) (i * DEG_TO_INDEX) & SIN_MASK] = (float) Math.sin(i * DEGREES_TO_RADIANS);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Returns the sine in radians from a lookup table.
|
77
|
+
* @param radians
|
78
|
+
* @return
|
79
|
+
*/
|
80
|
+
static public final float sin(float radians) {
|
81
|
+
return Sin.table[(int) (radians * RAD_TO_INDEX) & SIN_MASK];
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Returns the cosine in radians from a lookup table.
|
86
|
+
* @param radians
|
87
|
+
* @return
|
88
|
+
*/
|
89
|
+
static public final float cos(float radians) {
|
90
|
+
return Sin.table[(int) ((radians + PI / 2) * RAD_TO_INDEX) & SIN_MASK];
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Returns the sine in radians from a lookup table.
|
95
|
+
* @param degrees
|
96
|
+
* @return
|
97
|
+
*/
|
98
|
+
static public final float sinDeg(float degrees) {
|
99
|
+
return Sin.table[(int) (degrees * DEG_TO_INDEX) & SIN_MASK];
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Returns the cosine in radians from a lookup table.
|
104
|
+
* @param degrees
|
105
|
+
* @return
|
106
|
+
*/
|
107
|
+
static public final float cosDeg(float degrees) {
|
108
|
+
return Sin.table[(int) ((degrees + 90) * DEG_TO_INDEX) & SIN_MASK];
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|