propane 0.6.0-java → 0.7.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/.travis.yml +12 -4
- data/CHANGELOG.md +1 -0
- data/Rakefile +1 -1
- data/examples/complete/landscape.rb +1 -1
- data/examples/regular/colors_two.rb +1 -3
- data/examples/regular/tree.rb +0 -1
- data/examples/regular/vector_math.rb +4 -3
- data/lib/propane/app.rb +1 -4
- data/lib/propane/helpers/numeric.rb +2 -2
- data/lib/propane/runner.rb +32 -8
- data/lib/propane/version.rb +1 -1
- data/pom.rb +5 -5
- data/pom.xml +6 -6
- data/propane.gemspec +1 -1
- data/src/monkstone/CodeListener.java +7 -0
- data/src/monkstone/{MathTool.java → MathToolModule.java} +59 -68
- data/src/monkstone/PropaneLibrary.java +1 -1
- data/src/monkstone/WatchSketchDir.java +190 -0
- data/src/monkstone/fastmath/Deglut.java +47 -38
- data/src/monkstone/fastmath/package-info.java +6 -0
- data/src/monkstone/vecmath/AppRender.java +19 -20
- data/src/monkstone/vecmath/JRender.java +19 -19
- data/src/monkstone/vecmath/ShapeRender.java +19 -19
- data/src/monkstone/vecmath/package-info.java +20 -0
- data/src/monkstone/vecmath/vec2/Vec2.java +694 -624
- data/src/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/monkstone/vecmath/vec3/Vec3.java +704 -669
- data/src/monkstone/vecmath/vec3/package-info.java +6 -0
- data/vendors/Rakefile +2 -2
- metadata +11 -5
@@ -28,7 +28,7 @@ public class PropaneLibrary implements Library{
|
|
28
28
|
* @param runtime
|
29
29
|
*/
|
30
30
|
public static void load(final Ruby runtime) {
|
31
|
-
|
31
|
+
MathToolModule.createMathToolModule(runtime);
|
32
32
|
Deglut.createDeglut(runtime);
|
33
33
|
Vec2.createVec2(runtime);
|
34
34
|
Vec3.createVec3(runtime);
|
@@ -0,0 +1,190 @@
|
|
1
|
+
/**
|
2
|
+
* This class allows JRubyArt to watch for changes to sketch files
|
3
|
+
* specifically those with a 'rb' or 'glsl' extension requires user to supply
|
4
|
+
* a path String and code listener to constructor. The code listener should
|
5
|
+
* accept a filesystem WatchEvent
|
6
|
+
*/
|
7
|
+
|
8
|
+
/*
|
9
|
+
* This code is a modified version of WatchDir.java
|
10
|
+
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
|
11
|
+
*
|
12
|
+
* Redistribution and use in source and binary forms, with or without
|
13
|
+
* modification, are permitted provided that the following conditions
|
14
|
+
* are met:
|
15
|
+
*
|
16
|
+
* - Redistributions of source code must retain the above copyright
|
17
|
+
* notice, this list of conditions and the following disclaimer.
|
18
|
+
*
|
19
|
+
* - Redistributions in binary form must reproduce the above copyright
|
20
|
+
* notice, this list of conditions and the following disclaimer in the
|
21
|
+
* documentation and/or other materials provided with the distribution.
|
22
|
+
*
|
23
|
+
* - Neither the name of Oracle nor the names of its
|
24
|
+
* contributors may be used to endorse or promote products derived
|
25
|
+
* from this software without specific prior written permission.
|
26
|
+
*
|
27
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
28
|
+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
29
|
+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
30
|
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
31
|
+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
32
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
33
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
34
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
35
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
36
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
37
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
38
|
+
*/
|
39
|
+
package monkstone;
|
40
|
+
|
41
|
+
import java.io.IOException;
|
42
|
+
import java.nio.file.FileSystems;
|
43
|
+
import java.nio.file.FileVisitResult;
|
44
|
+
import java.nio.file.Files;
|
45
|
+
import java.nio.file.Path;
|
46
|
+
import java.nio.file.Paths;
|
47
|
+
import java.nio.file.SimpleFileVisitor;
|
48
|
+
import static java.nio.file.StandardWatchEventKinds.*;
|
49
|
+
import java.nio.file.WatchEvent;
|
50
|
+
import java.nio.file.WatchKey;
|
51
|
+
import java.nio.file.WatchService;
|
52
|
+
import java.nio.file.attribute.BasicFileAttributes;
|
53
|
+
import java.util.HashMap;
|
54
|
+
import java.util.Map;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Example to watch a directory (or tree) for changes to files.
|
58
|
+
*/
|
59
|
+
public class WatchSketchDir {
|
60
|
+
|
61
|
+
private final WatchService watcher;
|
62
|
+
private final Map<WatchKey, Path> keys;
|
63
|
+
private boolean trace = false;
|
64
|
+
|
65
|
+
@SuppressWarnings("unchecked")
|
66
|
+
static <T> WatchEvent<T> cast(WatchEvent<?> event) {
|
67
|
+
return (WatchEvent<T>) event;
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Register the given directory with the WatchService
|
73
|
+
*/
|
74
|
+
private void register(Path dir) throws IOException {
|
75
|
+
WatchKey key = dir.register(watcher, ENTRY_MODIFY);
|
76
|
+
if (trace) {
|
77
|
+
Path prev = keys.get(key);
|
78
|
+
if (prev == null) {
|
79
|
+
System.out.format("register: %s\n", dir);
|
80
|
+
} else if (!dir.equals(prev)) {
|
81
|
+
System.out.format("update: %s -> %s\n", prev, dir);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
keys.put(key, dir);
|
85
|
+
}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Register the given directory, and all its sub-directories, with the
|
89
|
+
* WatchService.
|
90
|
+
*/
|
91
|
+
private void registerAll(final Path start) throws IOException {
|
92
|
+
// register directory and sub-directories
|
93
|
+
Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
|
94
|
+
@Override
|
95
|
+
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
|
96
|
+
throws IOException {
|
97
|
+
register(dir);
|
98
|
+
return FileVisitResult.CONTINUE;
|
99
|
+
}
|
100
|
+
});
|
101
|
+
}
|
102
|
+
|
103
|
+
static final WatchSketchDir watch(String dir) throws IOException{
|
104
|
+
return new WatchSketchDir(dir);
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Creates a WatchService and registers the given directory
|
109
|
+
* @param dir String
|
110
|
+
* @param obj CodeListener
|
111
|
+
* @throws IOException
|
112
|
+
*/
|
113
|
+
private WatchSketchDir(String dir) throws IOException {
|
114
|
+
this(Paths.get(dir));
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Creates a WatchService and registers the given directory
|
119
|
+
*
|
120
|
+
* @param dir Path
|
121
|
+
* @param obj CodeListener
|
122
|
+
* @throws java.io.IOException
|
123
|
+
*/
|
124
|
+
private WatchSketchDir(Path dir) throws IOException {
|
125
|
+
this.watcher = FileSystems.getDefault().newWatchService();
|
126
|
+
this.keys = new HashMap<>();
|
127
|
+
|
128
|
+
System.out.format("Scanning Codebase\n", dir);
|
129
|
+
registerAll(dir);
|
130
|
+
System.out.format("Watching %s\n", dir);
|
131
|
+
|
132
|
+
// enable trace after initial registration
|
133
|
+
this.trace = true;
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Process all events for keys queued to the watcher
|
138
|
+
*/
|
139
|
+
public void addListener(CodeListener obj) {
|
140
|
+
for (;;) {
|
141
|
+
|
142
|
+
// wait for key to be signalled
|
143
|
+
WatchKey key;
|
144
|
+
try {
|
145
|
+
key = watcher.take();
|
146
|
+
} catch (InterruptedException x) {
|
147
|
+
return;
|
148
|
+
}
|
149
|
+
|
150
|
+
Path dir = keys.get(key);
|
151
|
+
if (dir == null) {
|
152
|
+
System.err.println("WatchKey not recognized!!");
|
153
|
+
continue;
|
154
|
+
}
|
155
|
+
|
156
|
+
key.pollEvents().stream().forEach((WatchEvent<?> event) -> {
|
157
|
+
WatchEvent.Kind kind = event.kind();
|
158
|
+
// TBD - provide example of how OVERFLOW event is handled
|
159
|
+
if (!(kind == OVERFLOW)) {
|
160
|
+
// Context for directory entry event is the file name of entry
|
161
|
+
WatchEvent<Path> ev = cast(event);
|
162
|
+
Path name = ev.context();
|
163
|
+
Path child = dir.resolve(name);
|
164
|
+
if (kind == ENTRY_MODIFY){
|
165
|
+
if (child.toFile().getAbsolutePath().endsWith(".rb")
|
166
|
+
|| child.toFile().getAbsolutePath().endsWith(".glsl")) {
|
167
|
+
|
168
|
+
obj.code_event(event);
|
169
|
+
key.reset();
|
170
|
+
}
|
171
|
+
}
|
172
|
+
// if directory is created, and watching recursively, then
|
173
|
+
// register it and its sub-directories
|
174
|
+
}
|
175
|
+
});
|
176
|
+
|
177
|
+
// reset key and remove from set if directory no longer accessible
|
178
|
+
boolean valid = key.reset();
|
179
|
+
if (!valid) {
|
180
|
+
keys.remove(key);
|
181
|
+
|
182
|
+
// all directories are inaccessible
|
183
|
+
if (keys.isEmpty()) {
|
184
|
+
break;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
}
|
@@ -1,10 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015-16 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
|
+
|
1
21
|
package monkstone.fastmath;
|
2
22
|
|
3
23
|
import org.jruby.Ruby;
|
4
|
-
import org.jruby.
|
24
|
+
import org.jruby.RubyInteger;
|
5
25
|
import org.jruby.RubyModule;
|
6
|
-
import org.jruby.
|
7
|
-
import org.jruby.anno.JRubyClass;
|
26
|
+
import org.jruby.anno.JRubyModule;
|
8
27
|
import org.jruby.anno.JRubyMethod;
|
9
28
|
import org.jruby.runtime.ThreadContext;
|
10
29
|
import org.jruby.runtime.builtin.IRubyObject;
|
@@ -13,8 +32,8 @@ import org.jruby.runtime.builtin.IRubyObject;
|
|
13
32
|
*
|
14
33
|
* @author Martin Prout
|
15
34
|
*/
|
16
|
-
@
|
17
|
-
public class Deglut
|
35
|
+
@JRubyModule(name = "DegLut")
|
36
|
+
public class Deglut {
|
18
37
|
|
19
38
|
/**
|
20
39
|
* Lookup table for degree cosine/sine, has a fixed precision 1.0
|
@@ -34,10 +53,10 @@ public class Deglut extends RubyObject {
|
|
34
53
|
|
35
54
|
private final static int NINETY = 90;
|
36
55
|
private final static int FULL = 360;
|
37
|
-
|
56
|
+
private static final long serialVersionUID = -1466528933765940101L;
|
38
57
|
|
39
58
|
/**
|
40
|
-
*
|
59
|
+
* Initialize sin table with values (first quadrant only)
|
41
60
|
*/
|
42
61
|
public static final void initTable() {
|
43
62
|
if (initialized == false) {
|
@@ -46,41 +65,31 @@ public class Deglut extends RubyObject {
|
|
46
65
|
}
|
47
66
|
initialized = true;
|
48
67
|
}
|
49
|
-
}
|
50
|
-
|
51
|
-
|
68
|
+
}
|
69
|
+
|
52
70
|
/**
|
53
71
|
*
|
54
|
-
* @param runtime
|
72
|
+
* @param runtime Ruby
|
55
73
|
*/
|
56
74
|
|
57
75
|
public static void createDeglut(final Ruby runtime){
|
58
76
|
RubyModule deglutModule = runtime.defineModule("DegLut");
|
59
77
|
deglutModule.defineAnnotatedMethods(Deglut.class);
|
60
78
|
Deglut.initTable();
|
61
|
-
}
|
62
|
-
|
63
|
-
|
64
|
-
/**
|
65
|
-
*
|
66
|
-
* @param runtime
|
67
|
-
* @param klass
|
68
|
-
*/
|
69
|
-
private Deglut(Ruby runtime, RubyClass klass) {
|
70
|
-
super(runtime, klass);
|
71
79
|
}
|
72
|
-
|
80
|
+
|
81
|
+
|
73
82
|
/**
|
74
83
|
*
|
75
|
-
* @param context
|
76
|
-
* @param
|
77
|
-
* @param other
|
78
|
-
* @return sin
|
84
|
+
* @param context ThreadContext
|
85
|
+
* @param recv IRubyObject
|
86
|
+
* @param other IRubyObject degrees
|
87
|
+
* @return sin IRubyObject
|
79
88
|
*/
|
80
|
-
@JRubyMethod(name = "sin",
|
89
|
+
@JRubyMethod(name = "sin", module = true)
|
81
90
|
|
82
|
-
public static IRubyObject sin(ThreadContext context, IRubyObject
|
83
|
-
int thet = (
|
91
|
+
public static IRubyObject sin(ThreadContext context, IRubyObject recv, IRubyObject other) {
|
92
|
+
int thet = (int) ((RubyInteger)other).getLongValue();
|
84
93
|
while (thet < 0) {
|
85
94
|
thet += FULL; // Needed because negative modulus plays badly in java
|
86
95
|
}
|
@@ -89,19 +98,19 @@ public class Deglut extends RubyObject {
|
|
89
98
|
double result = (theta < NINETY) ? SIN_DEG_LUT[y] : (theta < 180)
|
90
99
|
? SIN_DEG_LUT[NINETY - y] : (theta < 270)
|
91
100
|
? -SIN_DEG_LUT[y] : -SIN_DEG_LUT[NINETY - y];
|
92
|
-
return context.
|
101
|
+
return context.runtime.newFloat(result);
|
93
102
|
}
|
94
103
|
|
95
104
|
/**
|
96
105
|
*
|
97
|
-
* @param context
|
98
|
-
* @param
|
99
|
-
* @param other
|
100
|
-
* @return cos
|
106
|
+
* @param context ThreadContext
|
107
|
+
* @param recv IRubyObject
|
108
|
+
* @param other IRubyObject degrees
|
109
|
+
* @return cos IRubyObject
|
101
110
|
*/
|
102
|
-
@JRubyMethod(name = "cos",
|
103
|
-
public static IRubyObject cos(ThreadContext context, IRubyObject
|
104
|
-
int thet = (
|
111
|
+
@JRubyMethod(name = "cos", module = true)
|
112
|
+
public static IRubyObject cos(ThreadContext context, IRubyObject recv, IRubyObject other) {
|
113
|
+
int thet = (int) ((RubyInteger)other).getLongValue();
|
105
114
|
while (thet < 0) {
|
106
115
|
thet += FULL; // Needed because negative modulus plays badly in java
|
107
116
|
}
|
@@ -110,6 +119,6 @@ public class Deglut extends RubyObject {
|
|
110
119
|
double result = (theta < NINETY) ? SIN_DEG_LUT[NINETY - y] : (theta < 180)
|
111
120
|
? -SIN_DEG_LUT[y] : (theta < 270)
|
112
121
|
? -SIN_DEG_LUT[NINETY - y] : SIN_DEG_LUT[y];
|
113
|
-
return context.
|
122
|
+
return context.runtime.newFloat(result);
|
114
123
|
}
|
115
124
|
}
|
@@ -12,7 +12,7 @@ public class AppRender implements JRender {
|
|
12
12
|
|
13
13
|
/**
|
14
14
|
*
|
15
|
-
* @param app
|
15
|
+
* @param app PApplet
|
16
16
|
*/
|
17
17
|
public AppRender(final PApplet app) {
|
18
18
|
this.app = app;
|
@@ -20,8 +20,8 @@ public class AppRender implements JRender {
|
|
20
20
|
|
21
21
|
/**
|
22
22
|
*
|
23
|
-
* @param x
|
24
|
-
* @param y
|
23
|
+
* @param x double
|
24
|
+
* @param y double
|
25
25
|
*/
|
26
26
|
@Override
|
27
27
|
public void vertex(double x, double y) {
|
@@ -30,8 +30,8 @@ public class AppRender implements JRender {
|
|
30
30
|
|
31
31
|
/**
|
32
32
|
*
|
33
|
-
* @param x
|
34
|
-
* @param y
|
33
|
+
* @param x double
|
34
|
+
* @param y double
|
35
35
|
*/
|
36
36
|
@Override
|
37
37
|
public void curveVertex(double x, double y) {
|
@@ -40,9 +40,9 @@ public class AppRender implements JRender {
|
|
40
40
|
|
41
41
|
/**
|
42
42
|
*
|
43
|
-
* @param x
|
44
|
-
* @param y
|
45
|
-
* @param z
|
43
|
+
* @param x double
|
44
|
+
* @param y double
|
45
|
+
* @param z double
|
46
46
|
*/
|
47
47
|
@Override
|
48
48
|
public void vertex(double x, double y, double z) {
|
@@ -51,9 +51,9 @@ public class AppRender implements JRender {
|
|
51
51
|
|
52
52
|
/**
|
53
53
|
*
|
54
|
-
* @param x
|
55
|
-
* @param y
|
56
|
-
* @param z
|
54
|
+
* @param x double
|
55
|
+
* @param y double
|
56
|
+
* @param z double
|
57
57
|
*/
|
58
58
|
@Override
|
59
59
|
public void normal(double x, double y, double z) {
|
@@ -62,11 +62,11 @@ public class AppRender implements JRender {
|
|
62
62
|
|
63
63
|
/**
|
64
64
|
*
|
65
|
-
* @param x
|
66
|
-
* @param y
|
67
|
-
* @param z
|
68
|
-
* @param u
|
69
|
-
* @param v
|
65
|
+
* @param x double
|
66
|
+
* @param y double
|
67
|
+
* @param z double
|
68
|
+
* @param u double
|
69
|
+
* @param v double
|
70
70
|
*/
|
71
71
|
@Override
|
72
72
|
public void vertex(double x, double y, double z, double u, double v) {
|
@@ -75,13 +75,12 @@ public class AppRender implements JRender {
|
|
75
75
|
|
76
76
|
/**
|
77
77
|
*
|
78
|
-
* @param x
|
79
|
-
* @param y
|
80
|
-
* @param z
|
78
|
+
* @param x double
|
79
|
+
* @param y double
|
80
|
+
* @param z double
|
81
81
|
*/
|
82
82
|
@Override
|
83
83
|
public void curveVertex(double x, double y, double z) {
|
84
84
|
app.curveVertex((float) x, (float) y, (float) z);
|
85
85
|
}
|
86
|
-
|
87
86
|
}
|
@@ -4,53 +4,53 @@ package monkstone.vecmath;
|
|
4
4
|
*
|
5
5
|
* @author Martin Prout
|
6
6
|
*/
|
7
|
-
public interface JRender {
|
7
|
+
public interface JRender {
|
8
8
|
|
9
9
|
/**
|
10
10
|
*
|
11
|
-
* @param x
|
12
|
-
* @param y
|
11
|
+
* @param x double
|
12
|
+
* @param y double
|
13
13
|
*/
|
14
14
|
public void vertex(double x, double y);
|
15
15
|
|
16
16
|
/**
|
17
17
|
*
|
18
|
-
* @param x
|
19
|
-
* @param y
|
18
|
+
* @param x double
|
19
|
+
* @param y double
|
20
20
|
*/
|
21
21
|
public void curveVertex(double x, double y);
|
22
22
|
|
23
23
|
/**
|
24
24
|
*
|
25
|
-
* @param x
|
26
|
-
* @param y
|
27
|
-
* @param z
|
25
|
+
* @param x double
|
26
|
+
* @param y double
|
27
|
+
* @param z double
|
28
28
|
*/
|
29
29
|
public void vertex(double x, double y, double z);
|
30
30
|
|
31
31
|
/**
|
32
32
|
*
|
33
|
-
* @param x
|
34
|
-
* @param y
|
35
|
-
* @param z
|
36
|
-
* @param u
|
37
|
-
* @param v
|
33
|
+
* @param x double
|
34
|
+
* @param y double
|
35
|
+
* @param z double
|
36
|
+
* @param u double
|
37
|
+
* @param v double
|
38
38
|
*/
|
39
39
|
public void vertex(double x, double y, double z, double u, double v);
|
40
40
|
|
41
41
|
/**
|
42
42
|
*
|
43
|
-
* @param x
|
44
|
-
* @param y
|
45
|
-
* @param z
|
43
|
+
* @param x double
|
44
|
+
* @param y double
|
45
|
+
* @param z double
|
46
46
|
*/
|
47
47
|
public void curveVertex(double x, double y, double z);
|
48
48
|
|
49
49
|
/**
|
50
50
|
*
|
51
|
-
* @param x
|
52
|
-
* @param y
|
53
|
-
* @param z
|
51
|
+
* @param x double
|
52
|
+
* @param y double
|
53
|
+
* @param z double
|
54
54
|
*/
|
55
55
|
public void normal(double x, double y, double z);
|
56
56
|
}
|