picrate 2.1.0-java → 2.4.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
- data/.mvn/wrapper/maven-wrapper.properties +2 -2
- data/CHANGELOG.md +10 -0
- data/README.md +6 -3
- data/Rakefile +2 -1
- data/docs/_includes/footer.html +1 -1
- data/docs/_layouts/post.html +1 -1
- data/docs/_methods/alternative_methods.md +2 -1
- data/docs/_methods/noise_mode.md +88 -0
- data/docs/_posts/2018-05-06-install_jruby.md +3 -3
- data/docs/_posts/2018-11-18-building-gem.md +3 -1
- data/docs/_posts/2020-03-09-auto_install_picrate.md +2 -3
- data/docs/_posts/2020-05-11-getting_started_manjaro.md +19 -7
- 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.rb +2 -1
- data/lib/picrate/app.rb +3 -2
- data/lib/picrate/helper_methods.rb +1 -1
- data/lib/picrate/native_folder.rb +1 -3
- data/lib/picrate/runner.rb +4 -4
- data/lib/picrate/version.rb +1 -1
- data/library/jcomplex/jcomplex.rb +1 -0
- data/library/pdf/pdf.rb +7 -0
- data/library/svg/svg.rb +7 -0
- data/mvnw +2 -2
- data/mvnw.cmd +2 -2
- data/picrate.gemspec +5 -3
- data/pom.rb +31 -9
- data/pom.xml +41 -6
- 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/complex/JComplex.java +252 -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 +813 -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/vendors/Rakefile +31 -22
- data/vendors/geany.rb +3 -3
- metadata +26 -13
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -465
@@ -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,252 @@
|
|
1
|
+
package monkstone.complex;
|
2
|
+
|
3
|
+
import java.util.Objects;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* The purpose of this class is to to make Complex operations more efficient
|
7
|
+
* than JRuby RubyComplex, by having a simpler interface, only modest
|
8
|
+
* improvements were obtained (but this is better than nothing on RaspberryPI).
|
9
|
+
*/
|
10
|
+
public final class JComplex {
|
11
|
+
|
12
|
+
private final double re; // the real part
|
13
|
+
private final double im; // the imaginary part
|
14
|
+
private final static JComplex ZERO = new JComplex(0, 0);
|
15
|
+
private final static JComplex NAN = new JComplex(Double.NaN, Double.NaN);
|
16
|
+
|
17
|
+
/**
|
18
|
+
* create a new object with the given real and imaginary parts
|
19
|
+
*
|
20
|
+
* @param real
|
21
|
+
* @param imag
|
22
|
+
*/
|
23
|
+
public JComplex(double real, double imag) {
|
24
|
+
re = real;
|
25
|
+
im = imag;
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @return a string representation of the invoking Complex object
|
30
|
+
*/
|
31
|
+
@Override
|
32
|
+
public String toString() {
|
33
|
+
return "JComplex(" + re + ", " + im + "i)";
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
*
|
38
|
+
* @return abs/modulus/magnitude
|
39
|
+
*/
|
40
|
+
public final double abs() {
|
41
|
+
return Math.hypot(re, im);
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
*
|
46
|
+
* @return square of abs/modulus/magnitude
|
47
|
+
*/
|
48
|
+
public final double abs2() {
|
49
|
+
return re * re + im * im;
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
*
|
54
|
+
* @return angle/phase/argument, normalized to be between -pi and pi
|
55
|
+
*/
|
56
|
+
public final double phase() {
|
57
|
+
return Math.atan2(im, re);
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
*
|
62
|
+
* @param b
|
63
|
+
* @return a new Complex object whose value is (this + b)
|
64
|
+
*/
|
65
|
+
public final JComplex add(JComplex b) {
|
66
|
+
JComplex a = this; // invoking object
|
67
|
+
double real = a.re + b.re;
|
68
|
+
double imag = a.im + b.im;
|
69
|
+
return new JComplex(real, imag);
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
*
|
74
|
+
* @param scalar
|
75
|
+
* @return a new Complex object whose value is (this + scalar)
|
76
|
+
*/
|
77
|
+
public final JComplex add(double scalar) {
|
78
|
+
return new JComplex(re + scalar, im);
|
79
|
+
}
|
80
|
+
|
81
|
+
public final boolean zero() {
|
82
|
+
return this.equals(ZERO);
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
*
|
87
|
+
* @param b
|
88
|
+
* @return a new Complex object whose value is (this - b)
|
89
|
+
*/
|
90
|
+
public final JComplex sub(JComplex b) {
|
91
|
+
JComplex a = this;
|
92
|
+
double real = a.re - b.re;
|
93
|
+
double imag = a.im - b.im;
|
94
|
+
return new JComplex(real, imag);
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
*
|
99
|
+
* @param scalar
|
100
|
+
* @return a new Complex object whose value is (this - scalar)
|
101
|
+
*/
|
102
|
+
public final JComplex sub(double scalar) {
|
103
|
+
return new JComplex(re - scalar, im);
|
104
|
+
}
|
105
|
+
|
106
|
+
/**
|
107
|
+
*
|
108
|
+
* @param b
|
109
|
+
* @return a new Complex object whose value is (this * b)
|
110
|
+
*/
|
111
|
+
public final JComplex mul(JComplex b) {
|
112
|
+
JComplex a = this;
|
113
|
+
double real = a.re * b.re - a.im * b.im;
|
114
|
+
double imag = a.re * b.im + a.im * b.re;
|
115
|
+
return new JComplex(real, imag);
|
116
|
+
}
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Also known as scale
|
120
|
+
*
|
121
|
+
* @param b
|
122
|
+
* @return a new Complex object whose value is (this * b)
|
123
|
+
*/
|
124
|
+
public final JComplex mul(double b) {
|
125
|
+
return new JComplex(re * b, im * b);
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
*
|
130
|
+
* @return a new Complex object whose value is the conjugate of this
|
131
|
+
*/
|
132
|
+
public final JComplex conjugate() {
|
133
|
+
return new JComplex(re, -im);
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
*
|
138
|
+
* @return a new Complex object whose value is the reciprocal of this
|
139
|
+
*/
|
140
|
+
private JComplex reciprocal() {
|
141
|
+
double scale = re * re + im * im; // self dot product
|
142
|
+
return new JComplex(re / scale, -im / scale);
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
*
|
147
|
+
* @param other
|
148
|
+
* @return this^other
|
149
|
+
*/
|
150
|
+
public final JComplex pow(JComplex other) {
|
151
|
+
if (this.zero()) {
|
152
|
+
if (other.zero()) {
|
153
|
+
return ZERO;
|
154
|
+
}
|
155
|
+
return NAN;
|
156
|
+
}
|
157
|
+
return (this).log().mul(other).exp();
|
158
|
+
}
|
159
|
+
|
160
|
+
/**
|
161
|
+
*
|
162
|
+
* @param scalar
|
163
|
+
* @return this^scalar
|
164
|
+
*/
|
165
|
+
public final JComplex pow(double scalar) {
|
166
|
+
if (this.zero()) {
|
167
|
+
if (scalar == 0) {
|
168
|
+
return ZERO;
|
169
|
+
}
|
170
|
+
return NAN;
|
171
|
+
}
|
172
|
+
return (this).log().mul(scalar).exp();
|
173
|
+
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
*
|
177
|
+
* @return log
|
178
|
+
*/
|
179
|
+
private JComplex log() {
|
180
|
+
return new JComplex(Math.log(abs()), Math.atan2(im, re));
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
*
|
185
|
+
* @return real part
|
186
|
+
*/
|
187
|
+
public final double re() {
|
188
|
+
return re;
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
*
|
193
|
+
* @return imaginary part
|
194
|
+
*/
|
195
|
+
public final double im() {
|
196
|
+
return im;
|
197
|
+
}
|
198
|
+
|
199
|
+
/**
|
200
|
+
*
|
201
|
+
* @param b
|
202
|
+
* @return a / b
|
203
|
+
*/
|
204
|
+
public final JComplex div(JComplex b) {
|
205
|
+
JComplex a = this;
|
206
|
+
return a.mul(b.reciprocal());
|
207
|
+
}
|
208
|
+
|
209
|
+
/**
|
210
|
+
*
|
211
|
+
* @param b
|
212
|
+
* @return a / b
|
213
|
+
*/
|
214
|
+
public final JComplex div(double b) {
|
215
|
+
if (b == 0) {
|
216
|
+
return NAN;
|
217
|
+
}
|
218
|
+
return new JComplex(re / b, im / b);
|
219
|
+
}
|
220
|
+
|
221
|
+
/**
|
222
|
+
*
|
223
|
+
* @return a new Complex object whose value is the complex exponential of
|
224
|
+
* this
|
225
|
+
*/
|
226
|
+
public final JComplex exp() {
|
227
|
+
return new JComplex(Math.exp(re) * Math.cos(im), Math.exp(re) * Math.sin(im));
|
228
|
+
}
|
229
|
+
|
230
|
+
@Override
|
231
|
+
public final int hashCode() {
|
232
|
+
return Objects.hash(re, im);
|
233
|
+
}
|
234
|
+
|
235
|
+
@Override
|
236
|
+
public final boolean equals(Object obj) {
|
237
|
+
if (this == obj) {
|
238
|
+
return true;
|
239
|
+
}
|
240
|
+
if (obj == null) {
|
241
|
+
return false;
|
242
|
+
}
|
243
|
+
if (getClass() != obj.getClass()) {
|
244
|
+
return false;
|
245
|
+
}
|
246
|
+
final JComplex other = (JComplex) obj;
|
247
|
+
if (Double.doubleToLongBits(this.re) != Double.doubleToLongBits(other.re)) {
|
248
|
+
return false;
|
249
|
+
}
|
250
|
+
return Double.doubleToLongBits(this.im) == Double.doubleToLongBits(other.im);
|
251
|
+
}
|
252
|
+
}
|
@@ -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
|
+
|