picrate 0.7.0-java → 0.8.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
- data/.mvn/wrapper/maven-wrapper.properties +2 -1
- data/.travis.yml +2 -5
- data/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/Rakefile +15 -27
- data/docs/_config.yml +1 -1
- data/docs/_posts/2018-05-11-arch-linux-arm.md +1 -1
- data/docs/_posts/2018-11-18-building-gem.md +1 -1
- data/lib/picrate/app.rb +1 -1
- data/lib/picrate/native_folder.rb +1 -1
- data/lib/picrate/version.rb +1 -1
- data/mvnw +127 -51
- data/mvnw.cmd +182 -0
- data/pom.rb +39 -30
- data/pom.xml +50 -37
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/core/LibraryProxy.java +0 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +1 -1
- data/src/main/java/monkstone/vecmath/GfxRender.java +87 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +48 -50
- data/src/main/java/processing/awt/PShapeJava2D.java +10 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +315 -371
- data/src/main/java/processing/core/PApplet.java +15424 -15495
- data/src/main/java/processing/core/PConstants.java +4 -4
- data/src/main/java/processing/core/PFont.java +394 -369
- data/src/main/java/processing/core/PGraphics.java +11 -10
- data/src/main/java/processing/core/PImage.java +1389 -1435
- data/src/main/java/processing/core/PMatrix2D.java +297 -294
- data/src/main/java/processing/core/PMatrix3D.java +641 -594
- data/src/main/java/processing/core/PShape.java +1755 -1784
- data/src/main/java/processing/core/PShapeOBJ.java +145 -133
- data/src/main/java/processing/core/PShapeSVG.java +808 -801
- data/src/main/java/processing/core/PStyle.java +141 -149
- data/src/main/java/processing/core/PSurface.java +111 -117
- data/src/main/java/processing/core/PSurfaceNone.java +178 -187
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +349 -346
- data/src/main/java/processing/opengl/FontTexture.java +40 -59
- data/src/main/java/processing/opengl/FrameBuffer.java +28 -18
- data/src/main/java/processing/opengl/LinePath.java +7 -7
- data/src/main/java/processing/opengl/LineStroker.java +6 -10
- data/src/main/java/processing/opengl/PGL.java +56 -44
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +909 -2338
- data/src/main/java/processing/opengl/PJOGL.java +1722 -1763
- data/src/main/java/processing/opengl/PShader.java +1308 -1192
- data/src/main/java/processing/opengl/PShapeOpenGL.java +487 -1811
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +482 -497
- data/src/main/java/processing/opengl/Texture.java +99 -76
- data/src/main/java/processing/opengl/VertexBuffer.java +41 -43
- data/vendors/Rakefile +1 -1
- metadata +7 -4
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
2
|
|
3
|
-
/*
|
3
|
+
/*
|
4
4
|
Part of the Processing project - http://processing.org
|
5
5
|
|
6
6
|
Copyright (c) 2005-08 Ben Fry and Casey Reas
|
@@ -19,56 +19,48 @@
|
|
19
19
|
Public License along with this library; if not, write to the
|
20
20
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
21
21
|
Boston, MA 02111-1307 USA
|
22
|
-
*/
|
23
|
-
|
22
|
+
*/
|
24
23
|
package processing.core;
|
25
24
|
|
26
|
-
|
27
25
|
/**
|
28
|
-
* 3x2 affine matrix implementation.
|
29
|
-
*
|
30
|
-
*
|
31
|
-
* a vector (x, y) in {@code mult()}.
|
26
|
+
* 3x2 affine matrix implementation. Matrices are used to describe a
|
27
|
+
* transformation; see {@link PMatrix} for a general description. This matrix
|
28
|
+
* looks like the following when multiplying a vector (x, y) in {@code mult()}.
|
32
29
|
* <pre>
|
33
30
|
* [m00 m01 m02][x] [m00*x + m01*y + m02*1] [x']
|
34
31
|
* [m10 m11 m12][y] = [m10*x + m11*y + m12*1] = [y']
|
35
|
-
* [ 0 0 1 ][1] [ 0*x + 0*y + 1*1 ] [ 1]</pre>
|
36
|
-
*
|
37
|
-
*
|
32
|
+
* [ 0 0 1 ][1] [ 0*x + 0*y + 1*1 ] [ 1]</pre> (x', y') is returned. The values
|
33
|
+
* in the matrix determine the transformation. They are modified by the various
|
34
|
+
* transformation functions.
|
38
35
|
*/
|
39
36
|
public class PMatrix2D implements PMatrix {
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
38
|
+
/**
|
39
|
+
*
|
40
|
+
*/
|
41
|
+
public float m00,
|
46
42
|
/**
|
47
43
|
*
|
48
44
|
*/
|
49
45
|
m01,
|
50
|
-
|
51
46
|
/**
|
52
47
|
*
|
53
48
|
*/
|
54
49
|
m02;
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
*/
|
54
|
+
public float m10,
|
61
55
|
/**
|
62
56
|
*
|
63
57
|
*/
|
64
58
|
m11,
|
65
|
-
|
66
59
|
/**
|
67
60
|
*
|
68
61
|
*/
|
69
62
|
m12;
|
70
63
|
|
71
|
-
|
72
64
|
/**
|
73
65
|
* Create a new matrix, set to the identity matrix.
|
74
66
|
*/
|
@@ -76,54 +68,56 @@ public class PMatrix2D implements PMatrix {
|
|
76
68
|
reset();
|
77
69
|
}
|
78
70
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
71
|
+
/**
|
72
|
+
*
|
73
|
+
* @param m00
|
74
|
+
* @param m01
|
75
|
+
* @param m02
|
76
|
+
* @param m10
|
77
|
+
* @param m11
|
78
|
+
* @param m12
|
79
|
+
*/
|
80
|
+
public PMatrix2D(float m00, float m01, float m02,
|
81
|
+
float m10, float m11, float m12) {
|
90
82
|
set(m00, m01, m02,
|
91
|
-
|
83
|
+
m10, m11, m12);
|
92
84
|
}
|
93
85
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
86
|
+
/**
|
87
|
+
*
|
88
|
+
* @param matrix
|
89
|
+
*/
|
90
|
+
public PMatrix2D(PMatrix matrix) {
|
99
91
|
set(matrix);
|
100
92
|
}
|
101
93
|
|
102
|
-
|
103
|
-
public void reset() {
|
94
|
+
@Override
|
95
|
+
public final void reset() {
|
104
96
|
set(1, 0, 0,
|
105
|
-
|
97
|
+
0, 1, 0);
|
106
98
|
}
|
107
99
|
|
108
|
-
|
109
100
|
/**
|
110
101
|
* Returns a copy of this PMatrix.
|
111
|
-
|
102
|
+
*
|
103
|
+
* @return
|
112
104
|
*/
|
105
|
+
@Override
|
113
106
|
public PMatrix2D get() {
|
114
107
|
PMatrix2D outgoing = new PMatrix2D();
|
115
108
|
outgoing.set(this);
|
116
109
|
return outgoing;
|
117
110
|
}
|
118
111
|
|
119
|
-
|
120
112
|
/**
|
121
|
-
* Copies the matrix contents into a 6 entry float array.
|
122
|
-
*
|
123
|
-
*
|
124
|
-
|
125
|
-
|
113
|
+
* Copies the matrix contents into a 6 entry float array. If target is null
|
114
|
+
* (or not the correct size), a new array will be created. Returned in the
|
115
|
+
* order {@code {m00, m01, m02, m10, m11, m12}}.
|
116
|
+
*
|
117
|
+
* @param target
|
118
|
+
* @return
|
126
119
|
*/
|
120
|
+
@Override
|
127
121
|
public float[] get(float[] target) {
|
128
122
|
if ((target == null) || (target.length != 6)) {
|
129
123
|
target = new float[6];
|
@@ -139,31 +133,32 @@ public class PMatrix2D implements PMatrix {
|
|
139
133
|
return target;
|
140
134
|
}
|
141
135
|
|
142
|
-
|
143
136
|
/**
|
144
137
|
* If matrix is a PMatrix2D, sets this matrix to be a copy of it.
|
145
|
-
|
138
|
+
*
|
139
|
+
* @param matrix
|
146
140
|
* @throws IllegalArgumentException If <tt>matrix</tt> is not 2D.
|
147
141
|
*/
|
148
|
-
|
142
|
+
@Override
|
143
|
+
public final void set(PMatrix matrix) {
|
149
144
|
if (matrix instanceof PMatrix2D) {
|
150
145
|
PMatrix2D src = (PMatrix2D) matrix;
|
151
146
|
set(src.m00, src.m01, src.m02,
|
152
|
-
|
147
|
+
src.m10, src.m11, src.m12);
|
153
148
|
} else {
|
154
149
|
throw new IllegalArgumentException("PMatrix2D.set() only accepts PMatrix2D objects.");
|
155
150
|
}
|
156
151
|
}
|
157
152
|
|
158
|
-
|
159
153
|
/**
|
160
154
|
* Unavailable in 2D. Does nothing.
|
161
|
-
|
155
|
+
*
|
156
|
+
* @param src
|
162
157
|
*/
|
163
158
|
public void set(PMatrix3D src) {
|
164
159
|
}
|
165
160
|
|
166
|
-
|
161
|
+
@Override
|
167
162
|
public void set(float[] source) {
|
168
163
|
m00 = source[0];
|
169
164
|
m01 = source[1];
|
@@ -174,180 +169,198 @@ public class PMatrix2D implements PMatrix {
|
|
174
169
|
m12 = source[5];
|
175
170
|
}
|
176
171
|
|
177
|
-
|
178
172
|
/**
|
179
173
|
* Sets the matrix content.
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
174
|
+
*
|
175
|
+
* @param m00
|
176
|
+
* @param m01
|
177
|
+
* @param m02
|
178
|
+
* @param m11
|
179
|
+
* @param m10
|
180
|
+
* @param m12
|
186
181
|
*/
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
this.
|
182
|
+
@Override
|
183
|
+
public final void set(float m00, float m01, float m02,
|
184
|
+
float m10, float m11, float m12) {
|
185
|
+
this.m00 = m00;
|
186
|
+
this.m01 = m01;
|
187
|
+
this.m02 = m02;
|
188
|
+
this.m10 = m10;
|
189
|
+
this.m11 = m11;
|
190
|
+
this.m12 = m12;
|
191
191
|
}
|
192
192
|
|
193
|
-
|
194
193
|
/**
|
195
194
|
* Unavailable in 2D. Does nothing.
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
195
|
+
*
|
196
|
+
* @param m00
|
197
|
+
* @param m23
|
198
|
+
* @param m02
|
199
|
+
* @param m01
|
200
|
+
* @param m10
|
201
|
+
* @param m12
|
202
|
+
* @param m03
|
203
|
+
* @param m11
|
204
|
+
* @param m20
|
205
|
+
* @param m21
|
206
|
+
* @param m13
|
207
|
+
* @param m31
|
208
|
+
* @param m33
|
209
|
+
* @param m22
|
210
|
+
* @param m30
|
211
|
+
* @param m32
|
212
212
|
*/
|
213
|
+
@Override
|
213
214
|
public void set(float m00, float m01, float m02, float m03,
|
214
|
-
|
215
|
-
|
216
|
-
|
215
|
+
float m10, float m11, float m12, float m13,
|
216
|
+
float m20, float m21, float m22, float m23,
|
217
|
+
float m30, float m31, float m32, float m33) {
|
217
218
|
|
218
219
|
}
|
219
220
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
221
|
+
/**
|
222
|
+
*
|
223
|
+
* @param tx
|
224
|
+
* @param ty
|
225
|
+
*/
|
226
|
+
@Override
|
227
|
+
public void translate(float tx, float ty) {
|
228
|
+
m02 = tx * m00 + ty * m01 + m02;
|
229
|
+
m12 = tx * m10 + ty * m11 + m12;
|
228
230
|
}
|
229
231
|
|
230
|
-
|
231
232
|
/**
|
232
233
|
* Unavailable in 2D.
|
233
|
-
|
234
|
-
|
235
|
-
|
234
|
+
*
|
235
|
+
* @param x
|
236
|
+
* @param y
|
237
|
+
* @param z
|
236
238
|
* @throws IllegalArgumentException
|
237
239
|
*/
|
240
|
+
@Override
|
238
241
|
public void translate(float x, float y, float z) {
|
239
242
|
throw new IllegalArgumentException("Cannot use translate(x, y, z) on a PMatrix2D.");
|
240
243
|
}
|
241
244
|
|
242
|
-
|
243
245
|
// Implementation roughly based on AffineTransform.
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
246
|
+
/**
|
247
|
+
*
|
248
|
+
* @param angle
|
249
|
+
*/
|
250
|
+
@Override
|
249
251
|
public void rotate(float angle) {
|
250
252
|
float s = sin(angle);
|
251
253
|
float c = cos(angle);
|
252
254
|
|
253
255
|
float temp1 = m00;
|
254
256
|
float temp2 = m01;
|
255
|
-
m00 =
|
257
|
+
m00 = c * temp1 + s * temp2;
|
256
258
|
m01 = -s * temp1 + c * temp2;
|
257
259
|
temp1 = m10;
|
258
260
|
temp2 = m11;
|
259
|
-
m10 =
|
261
|
+
m10 = c * temp1 + s * temp2;
|
260
262
|
m11 = -s * temp1 + c * temp2;
|
261
263
|
}
|
262
264
|
|
263
|
-
|
264
265
|
/**
|
265
266
|
* Unavailable in 2D.
|
266
|
-
|
267
|
+
*
|
268
|
+
* @param angle
|
267
269
|
* @throws IllegalArgumentException
|
268
270
|
*/
|
271
|
+
@Override
|
269
272
|
public void rotateX(float angle) {
|
270
273
|
throw new IllegalArgumentException("Cannot use rotateX() on a PMatrix2D.");
|
271
274
|
}
|
272
275
|
|
273
|
-
|
274
276
|
/**
|
275
277
|
* Unavailable in 2D.
|
276
|
-
|
278
|
+
*
|
279
|
+
* @param angle
|
277
280
|
* @throws IllegalArgumentException
|
278
281
|
*/
|
282
|
+
@Override
|
279
283
|
public void rotateY(float angle) {
|
280
284
|
throw new IllegalArgumentException("Cannot use rotateY() on a PMatrix2D.");
|
281
285
|
}
|
282
286
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
287
|
+
/**
|
288
|
+
*
|
289
|
+
* @param angle
|
290
|
+
*/
|
291
|
+
@Override
|
292
|
+
public void rotateZ(float angle) {
|
288
293
|
rotate(angle);
|
289
294
|
}
|
290
295
|
|
291
|
-
|
292
296
|
/**
|
293
297
|
* Unavailable in 2D.
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
+
*
|
299
|
+
* @param angle
|
300
|
+
* @param v0
|
301
|
+
* @param v1
|
302
|
+
* @param v2
|
298
303
|
* @throws IllegalArgumentException
|
299
304
|
*/
|
305
|
+
@Override
|
300
306
|
public void rotate(float angle, float v0, float v1, float v2) {
|
301
307
|
throw new IllegalArgumentException("Cannot use this version of rotate() on a PMatrix2D.");
|
302
308
|
}
|
303
309
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
310
|
+
/**
|
311
|
+
*
|
312
|
+
* @param s
|
313
|
+
*/
|
314
|
+
@Override
|
315
|
+
public void scale(float s) {
|
309
316
|
scale(s, s);
|
310
317
|
}
|
311
318
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
319
|
+
/**
|
320
|
+
*
|
321
|
+
* @param sx
|
322
|
+
* @param sy
|
323
|
+
*/
|
324
|
+
@Override
|
325
|
+
public void scale(float sx, float sy) {
|
326
|
+
m00 *= sx;
|
327
|
+
m01 *= sy;
|
328
|
+
m10 *= sx;
|
329
|
+
m11 *= sy;
|
320
330
|
}
|
321
331
|
|
322
|
-
|
323
332
|
/**
|
324
333
|
* Unavailable in 2D.
|
325
|
-
|
326
|
-
|
327
|
-
|
334
|
+
*
|
335
|
+
* @param x
|
336
|
+
* @param y
|
337
|
+
* @param z
|
328
338
|
* @throws IllegalArgumentException
|
329
339
|
*/
|
340
|
+
@Override
|
330
341
|
public void scale(float x, float y, float z) {
|
331
342
|
throw new IllegalArgumentException("Cannot use this version of scale() on a PMatrix2D.");
|
332
343
|
}
|
333
344
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
345
|
+
/**
|
346
|
+
*
|
347
|
+
* @param angle
|
348
|
+
*/
|
349
|
+
@Override
|
350
|
+
public void shearX(float angle) {
|
351
|
+
apply(1, 0, 1, tan(angle), 0, 0);
|
340
352
|
}
|
341
353
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
354
|
+
/**
|
355
|
+
*
|
356
|
+
* @param angle
|
357
|
+
*/
|
358
|
+
@Override
|
359
|
+
public void shearY(float angle) {
|
360
|
+
apply(1, 0, 1, 0, tan(angle), 0);
|
348
361
|
}
|
349
362
|
|
350
|
-
|
363
|
+
@Override
|
351
364
|
public void apply(PMatrix source) {
|
352
365
|
if (source instanceof PMatrix2D) {
|
353
366
|
apply((PMatrix2D) source);
|
@@ -356,71 +369,74 @@ public class PMatrix2D implements PMatrix {
|
|
356
369
|
}
|
357
370
|
}
|
358
371
|
|
359
|
-
|
372
|
+
@Override
|
360
373
|
public void apply(PMatrix2D source) {
|
361
374
|
apply(source.m00, source.m01, source.m02,
|
362
|
-
|
375
|
+
source.m10, source.m11, source.m12);
|
363
376
|
}
|
364
377
|
|
365
|
-
|
366
378
|
/**
|
367
379
|
* Unavailable in 2D.
|
368
|
-
|
380
|
+
*
|
381
|
+
* @param source
|
369
382
|
* @throws IllegalArgumentException
|
370
383
|
*/
|
384
|
+
@Override
|
371
385
|
public void apply(PMatrix3D source) {
|
372
386
|
throw new IllegalArgumentException("Cannot use apply(PMatrix3D) on a PMatrix2D.");
|
373
387
|
}
|
374
388
|
|
375
|
-
|
389
|
+
@Override
|
376
390
|
public void apply(float n00, float n01, float n02,
|
377
|
-
|
391
|
+
float n10, float n11, float n12) {
|
378
392
|
float t0 = m00;
|
379
393
|
float t1 = m01;
|
380
|
-
m00
|
381
|
-
m01
|
394
|
+
m00 = n00 * t0 + n10 * t1;
|
395
|
+
m01 = n01 * t0 + n11 * t1;
|
382
396
|
m02 += n02 * t0 + n12 * t1;
|
383
397
|
|
384
398
|
t0 = m10;
|
385
399
|
t1 = m11;
|
386
|
-
m10
|
387
|
-
m11
|
400
|
+
m10 = n00 * t0 + n10 * t1;
|
401
|
+
m11 = n01 * t0 + n11 * t1;
|
388
402
|
m12 += n02 * t0 + n12 * t1;
|
389
403
|
}
|
390
404
|
|
391
|
-
|
392
405
|
/**
|
393
406
|
* Unavailable in 2D.
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
407
|
+
*
|
408
|
+
* @param n00
|
409
|
+
* @param n21
|
410
|
+
* @param n02
|
411
|
+
* @param n01
|
412
|
+
* @param n03
|
413
|
+
* @param n11
|
414
|
+
* @param n10
|
415
|
+
* @param n30
|
416
|
+
* @param n23
|
417
|
+
* @param n13
|
418
|
+
* @param n12
|
419
|
+
* @param n22
|
420
|
+
* @param n32
|
421
|
+
* @param n20
|
422
|
+
* @param n31
|
423
|
+
* @param n33
|
410
424
|
* @throws IllegalArgumentException
|
411
425
|
*/
|
426
|
+
@Override
|
412
427
|
public void apply(float n00, float n01, float n02, float n03,
|
413
|
-
|
414
|
-
|
415
|
-
|
428
|
+
float n10, float n11, float n12, float n13,
|
429
|
+
float n20, float n21, float n22, float n23,
|
430
|
+
float n30, float n31, float n32, float n33) {
|
416
431
|
throw new IllegalArgumentException("Cannot use this version of apply() on a PMatrix2D.");
|
417
432
|
}
|
418
433
|
|
419
|
-
|
420
434
|
/**
|
421
435
|
* Apply another matrix to the left of this one.
|
422
|
-
|
436
|
+
*
|
437
|
+
* @param source
|
423
438
|
*/
|
439
|
+
@Override
|
424
440
|
public void preApply(PMatrix source) {
|
425
441
|
if (source instanceof PMatrix2D) {
|
426
442
|
preApply((PMatrix2D) source);
|
@@ -429,25 +445,26 @@ public class PMatrix2D implements PMatrix {
|
|
429
445
|
}
|
430
446
|
}
|
431
447
|
|
432
|
-
|
448
|
+
@Override
|
433
449
|
public void preApply(PMatrix2D left) {
|
434
450
|
preApply(left.m00, left.m01, left.m02,
|
435
|
-
|
451
|
+
left.m10, left.m11, left.m12);
|
436
452
|
}
|
437
453
|
|
438
|
-
|
439
454
|
/**
|
440
455
|
* Unavailable in 2D.
|
441
|
-
|
456
|
+
*
|
457
|
+
* @param left
|
442
458
|
* @throws IllegalArgumentException
|
443
459
|
*/
|
460
|
+
@Override
|
444
461
|
public void preApply(PMatrix3D left) {
|
445
462
|
throw new IllegalArgumentException("Cannot use preApply(PMatrix3D) on a PMatrix2D.");
|
446
463
|
}
|
447
464
|
|
448
|
-
|
465
|
+
@Override
|
449
466
|
public void preApply(float n00, float n01, float n02,
|
450
|
-
|
467
|
+
float n10, float n11, float n12) {
|
451
468
|
float t0 = m02;
|
452
469
|
float t1 = m12;
|
453
470
|
n02 += t0 * n00 + t1 * n01;
|
@@ -467,109 +484,107 @@ public class PMatrix2D implements PMatrix {
|
|
467
484
|
m11 = t0 * n10 + t1 * n11;
|
468
485
|
}
|
469
486
|
|
470
|
-
|
471
487
|
/**
|
472
488
|
* Unavailable in 2D.
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
+
*
|
490
|
+
* @param n00
|
491
|
+
* @param n01
|
492
|
+
* @param n03
|
493
|
+
* @param n02
|
494
|
+
* @param n10
|
495
|
+
* @param n12
|
496
|
+
* @param n21
|
497
|
+
* @param n13
|
498
|
+
* @param n11
|
499
|
+
* @param n30
|
500
|
+
* @param n23
|
501
|
+
* @param n20
|
502
|
+
* @param n32
|
503
|
+
* @param n22
|
504
|
+
* @param n31
|
505
|
+
* @param n33
|
489
506
|
* @throws IllegalArgumentException
|
490
507
|
*/
|
508
|
+
@Override
|
491
509
|
public void preApply(float n00, float n01, float n02, float n03,
|
492
|
-
|
493
|
-
|
494
|
-
|
510
|
+
float n10, float n11, float n12, float n13,
|
511
|
+
float n20, float n21, float n22, float n23,
|
512
|
+
float n30, float n31, float n32, float n33) {
|
495
513
|
throw new IllegalArgumentException("Cannot use this version of preApply() on a PMatrix2D.");
|
496
514
|
}
|
497
515
|
|
498
|
-
|
499
516
|
//////////////////////////////////////////////////////////////
|
500
|
-
|
501
|
-
|
502
517
|
/**
|
503
|
-
* {@inheritDoc}
|
504
|
-
* Ignores any z component.
|
518
|
+
* {@inheritDoc} Ignores any z component.
|
505
519
|
*/
|
520
|
+
@Override
|
506
521
|
public PVector mult(PVector source, PVector target) {
|
507
522
|
if (target == null) {
|
508
523
|
target = new PVector();
|
509
524
|
}
|
510
|
-
target.x = m00*source.x + m01*source.y + m02;
|
511
|
-
target.y = m10*source.x + m11*source.y + m12;
|
525
|
+
target.x = m00 * source.x + m01 * source.y + m02;
|
526
|
+
target.y = m10 * source.x + m11 * source.y + m12;
|
512
527
|
return target;
|
513
528
|
}
|
514
529
|
|
515
|
-
|
516
530
|
/**
|
517
|
-
* Multiply a two element vector against this matrix.
|
518
|
-
*
|
519
|
-
*
|
520
|
-
|
521
|
-
|
522
|
-
|
531
|
+
* Multiply a two element vector against this matrix. If out is null or not
|
532
|
+
* length four, a new float array will be returned. The values for vec and out
|
533
|
+
* can be the same (though that's less efficient).
|
534
|
+
*
|
535
|
+
* @param vec
|
536
|
+
* @param out
|
537
|
+
* @return
|
523
538
|
*/
|
539
|
+
@Override
|
524
540
|
public float[] mult(float vec[], float out[]) {
|
525
541
|
if (out == null || out.length != 2) {
|
526
542
|
out = new float[2];
|
527
543
|
}
|
528
544
|
|
529
545
|
if (vec == out) {
|
530
|
-
float tx = m00*vec[0] + m01*vec[1] + m02;
|
531
|
-
float ty = m10*vec[0] + m11*vec[1] + m12;
|
546
|
+
float tx = m00 * vec[0] + m01 * vec[1] + m02;
|
547
|
+
float ty = m10 * vec[0] + m11 * vec[1] + m12;
|
532
548
|
|
533
549
|
out[0] = tx;
|
534
550
|
out[1] = ty;
|
535
551
|
|
536
552
|
} else {
|
537
|
-
out[0] = m00*vec[0] + m01*vec[1] + m02;
|
538
|
-
out[1] = m10*vec[0] + m11*vec[1] + m12;
|
553
|
+
out[0] = m00 * vec[0] + m01 * vec[1] + m02;
|
554
|
+
out[1] = m10 * vec[0] + m11 * vec[1] + m12;
|
539
555
|
}
|
540
556
|
|
541
557
|
return out;
|
542
558
|
}
|
543
559
|
|
544
|
-
|
545
560
|
/**
|
546
|
-
* Returns the x-coordinate of the result of multiplying the point (x, y)
|
547
|
-
*
|
548
|
-
|
549
|
-
|
550
|
-
|
561
|
+
* Returns the x-coordinate of the result of multiplying the point (x, y) by
|
562
|
+
* this matrix.
|
563
|
+
*
|
564
|
+
* @param x
|
565
|
+
* @param y
|
566
|
+
* @return
|
551
567
|
*/
|
552
568
|
public float multX(float x, float y) {
|
553
|
-
return m00*x + m01*y + m02;
|
569
|
+
return m00 * x + m01 * y + m02;
|
554
570
|
}
|
555
571
|
|
556
|
-
|
557
572
|
/**
|
558
|
-
* Returns the y-coordinate of the result of multiplying the point (x, y)
|
559
|
-
*
|
560
|
-
|
561
|
-
|
562
|
-
|
573
|
+
* Returns the y-coordinate of the result of multiplying the point (x, y) by
|
574
|
+
* this matrix.
|
575
|
+
*
|
576
|
+
* @param x
|
577
|
+
* @param y
|
578
|
+
* @return
|
563
579
|
*/
|
564
580
|
public float multY(float x, float y) {
|
565
|
-
return m10*x + m11*y + m12;
|
581
|
+
return m10 * x + m11 * y + m12;
|
566
582
|
}
|
567
583
|
|
568
|
-
|
569
|
-
|
570
584
|
/**
|
571
585
|
* Unavailable in 2D. Does nothing.
|
572
586
|
*/
|
587
|
+
@Override
|
573
588
|
public void transpose() {
|
574
589
|
}
|
575
590
|
|
@@ -577,6 +592,7 @@ public class PMatrix2D implements PMatrix {
|
|
577
592
|
/*
|
578
593
|
* Implementation stolen from OpenJDK.
|
579
594
|
*/
|
595
|
+
@Override
|
580
596
|
public boolean invert() {
|
581
597
|
float determinant = determinant();
|
582
598
|
if (Math.abs(determinant) <= Float.MIN_VALUE) {
|
@@ -590,17 +606,16 @@ public class PMatrix2D implements PMatrix {
|
|
590
606
|
float t11 = m11;
|
591
607
|
float t12 = m12;
|
592
608
|
|
593
|
-
m00 =
|
609
|
+
m00 = t11 / determinant;
|
594
610
|
m10 = -t10 / determinant;
|
595
611
|
m01 = -t01 / determinant;
|
596
|
-
m11 =
|
612
|
+
m11 = t00 / determinant;
|
597
613
|
m02 = (t01 * t12 - t11 * t02) / determinant;
|
598
614
|
m12 = (t10 * t02 - t00 * t12) / determinant;
|
599
615
|
|
600
616
|
return true;
|
601
617
|
}
|
602
618
|
|
603
|
-
|
604
619
|
/**
|
605
620
|
* @return the determinant of the matrix
|
606
621
|
*/
|
@@ -608,87 +623,75 @@ public class PMatrix2D implements PMatrix {
|
|
608
623
|
return m00 * m11 - m01 * m10;
|
609
624
|
}
|
610
625
|
|
611
|
-
|
612
626
|
//////////////////////////////////////////////////////////////
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
*/
|
617
|
-
|
618
|
-
|
627
|
+
/**
|
628
|
+
*
|
629
|
+
*/
|
619
630
|
public void print() {
|
620
631
|
int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)),
|
621
|
-
|
632
|
+
PApplet.max(abs(m10), abs(m11), abs(m12))));
|
622
633
|
|
623
634
|
int digits = 1;
|
624
635
|
if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
|
625
636
|
digits = 5;
|
626
637
|
} else {
|
627
|
-
while ((big /= 10) != 0)
|
638
|
+
while ((big /= 10) != 0) {
|
639
|
+
digits++; // cheap log()
|
640
|
+
}
|
628
641
|
}
|
629
642
|
|
630
|
-
System.out.println(PApplet.nfs(m00, digits, 4) + " "
|
631
|
-
|
632
|
-
|
643
|
+
System.out.println(PApplet.nfs(m00, digits, 4) + " "
|
644
|
+
+ PApplet.nfs(m01, digits, 4) + " "
|
645
|
+
+ PApplet.nfs(m02, digits, 4));
|
633
646
|
|
634
|
-
System.out.println(PApplet.nfs(m10, digits, 4) + " "
|
635
|
-
|
636
|
-
|
647
|
+
System.out.println(PApplet.nfs(m10, digits, 4) + " "
|
648
|
+
+ PApplet.nfs(m11, digits, 4) + " "
|
649
|
+
+ PApplet.nfs(m12, digits, 4));
|
637
650
|
|
638
651
|
System.out.println();
|
639
652
|
}
|
640
653
|
|
641
|
-
|
642
654
|
//////////////////////////////////////////////////////////////
|
643
|
-
|
644
655
|
// TODO these need to be added as regular API, but the naming and
|
645
656
|
// implementation needs to be improved first. (e.g. actually keeping track
|
646
657
|
// of whether the matrix is in fact identity internally.)
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
*/
|
652
|
-
|
653
|
-
|
658
|
+
/**
|
659
|
+
*
|
660
|
+
* @return
|
661
|
+
*/
|
654
662
|
protected boolean isIdentity() {
|
655
|
-
return ((m00 == 1) && (m01 == 0) && (m02 == 0)
|
656
|
-
|
663
|
+
return ((m00 == 1) && (m01 == 0) && (m02 == 0)
|
664
|
+
&& (m10 == 0) && (m11 == 1) && (m12 == 0));
|
657
665
|
}
|
658
666
|
|
659
|
-
|
660
667
|
// TODO make this more efficient, or move into PMatrix2D
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
*/
|
668
|
+
/**
|
669
|
+
*
|
670
|
+
* @return
|
671
|
+
*/
|
666
672
|
protected boolean isWarped() {
|
667
|
-
return ((m00 != 1) || (m01 != 0)
|
668
|
-
|
673
|
+
return ((m00 != 1) || (m01 != 0)
|
674
|
+
&& (m10 != 0) || (m11 != 1));
|
669
675
|
}
|
670
676
|
|
671
|
-
|
672
677
|
//////////////////////////////////////////////////////////////
|
673
|
-
|
674
|
-
|
675
|
-
static private final float max(float a, float b) {
|
678
|
+
private static float max(float a, float b) {
|
676
679
|
return (a > b) ? a : b;
|
677
680
|
}
|
678
681
|
|
679
|
-
|
682
|
+
private static float abs(float a) {
|
680
683
|
return (a < 0) ? -a : a;
|
681
684
|
}
|
682
685
|
|
683
|
-
|
684
|
-
return (float)Math.sin(angle);
|
686
|
+
private static float sin(float angle) {
|
687
|
+
return (float) Math.sin(angle);
|
685
688
|
}
|
686
689
|
|
687
|
-
|
688
|
-
return (float)Math.cos(angle);
|
690
|
+
private static float cos(float angle) {
|
691
|
+
return (float) Math.cos(angle);
|
689
692
|
}
|
690
693
|
|
691
|
-
|
692
|
-
return (float)Math.tan(angle);
|
694
|
+
private static float tan(float angle) {
|
695
|
+
return (float) Math.tan(angle);
|
693
696
|
}
|
694
697
|
}
|