propane 3.3.1-java → 3.6.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -3
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +17 -5
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +16 -30
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +6 -4
  12. data/lib/propane/app.rb +20 -10
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +23 -24
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +21 -15
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +14 -6
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +28 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +6 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +7 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +4 -1
  37. data/mvnw +127 -51
  38. data/mvnw.cmd +182 -145
  39. data/pom.rb +53 -50
  40. data/pom.xml +17 -8
  41. data/propane.gemspec +13 -11
  42. data/src/main/java/monkstone/ColorUtil.java +13 -1
  43. data/src/main/java/monkstone/MathToolModule.java +253 -203
  44. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  45. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  46. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  47. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  48. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  53. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  54. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  55. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  56. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
  57. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  58. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  59. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  60. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  61. data/src/main/java/processing/awt/PGraphicsJava2D.java +2164 -1661
  62. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  63. data/src/main/java/processing/awt/PShapeJava2D.java +280 -268
  64. data/src/main/java/processing/awt/PSurfaceAWT.java +942 -829
  65. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  66. data/src/main/java/processing/core/PApplet.java +831 -824
  67. data/src/main/java/processing/core/PConstants.java +477 -447
  68. data/src/main/java/processing/core/PFont.java +914 -880
  69. data/src/main/java/processing/core/PGraphics.java +229 -213
  70. data/src/main/java/processing/core/PImage.java +620 -318
  71. data/src/main/java/processing/core/PMatrix.java +172 -159
  72. data/src/main/java/processing/core/PMatrix2D.java +478 -409
  73. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  74. data/src/main/java/processing/core/PShape.java +2888 -2652
  75. data/src/main/java/processing/core/PShapeOBJ.java +436 -415
  76. data/src/main/java/processing/core/PShapeSVG.java +1702 -1479
  77. data/src/main/java/processing/core/PStyle.java +40 -37
  78. data/src/main/java/processing/core/PSurface.java +139 -97
  79. data/src/main/java/processing/core/PSurfaceNone.java +296 -208
  80. data/src/main/java/processing/core/PVector.java +997 -965
  81. data/src/main/java/processing/core/ThinkDifferent.java +12 -17
  82. data/src/main/java/processing/data/DoubleDict.java +756 -710
  83. data/src/main/java/processing/data/DoubleList.java +749 -696
  84. data/src/main/java/processing/data/FloatDict.java +748 -702
  85. data/src/main/java/processing/data/FloatList.java +751 -697
  86. data/src/main/java/processing/data/IntDict.java +720 -673
  87. data/src/main/java/processing/data/IntList.java +699 -633
  88. data/src/main/java/processing/data/JSONArray.java +931 -873
  89. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  90. data/src/main/java/processing/data/JSONTokener.java +351 -341
  91. data/src/main/java/processing/data/LongDict.java +710 -663
  92. data/src/main/java/processing/data/LongList.java +701 -635
  93. data/src/main/java/processing/data/Sort.java +37 -41
  94. data/src/main/java/processing/data/StringDict.java +525 -486
  95. data/src/main/java/processing/data/StringList.java +626 -580
  96. data/src/main/java/processing/data/Table.java +3690 -3510
  97. data/src/main/java/processing/data/TableRow.java +182 -183
  98. data/src/main/java/processing/data/XML.java +957 -883
  99. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  100. data/src/main/java/processing/event/Event.java +87 -66
  101. data/src/main/java/processing/event/KeyEvent.java +48 -41
  102. data/src/main/java/processing/event/MouseEvent.java +88 -113
  103. data/src/main/java/processing/event/TouchEvent.java +10 -6
  104. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  105. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  106. data/src/main/java/processing/net/Client.java +744 -0
  107. data/src/main/java/processing/net/Server.java +388 -0
  108. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  109. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  110. data/src/main/java/processing/opengl/LinePath.java +547 -500
  111. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  112. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  113. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  114. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  115. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  116. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  117. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  118. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  119. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  120. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  121. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  122. data/test/create_test.rb +21 -20
  123. data/test/deglut_spec_test.rb +4 -2
  124. data/test/helper_methods_test.rb +49 -20
  125. data/test/math_tool_test.rb +39 -32
  126. data/test/native_folder.rb +47 -0
  127. data/test/respond_to_test.rb +3 -2
  128. data/test/sketches/key_event.rb +2 -2
  129. data/test/sketches/library/my_library/my_library.rb +3 -0
  130. data/test/test_helper.rb +2 -0
  131. data/test/vecmath_spec_test.rb +35 -22
  132. data/vendors/Rakefile +33 -62
  133. metadata +54 -45
  134. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  135. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  136. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  137. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  138. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  139. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  140. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  141. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  142. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  143. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  144. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  145. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  146. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  147. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  148. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  149. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  150. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  151. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  152. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  153. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  154. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  155. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  156. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  157. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -17,179 +19,190 @@
17
19
  Public License along with this library; if not, write to the
18
20
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19
21
  Boston, MA 02111-1307 USA
20
- */
22
+ */
23
+
21
24
  package processing.core;
22
25
 
26
+
23
27
  /**
24
28
  * A matrix is used to define graphical transformations. PMatrix is the common
25
29
  * interface for both the 2D and 3D matrix classes in Processing. A matrix is a
26
30
  * grid of numbers, which can be multiplied by a vector to give another vector.
27
- * Multiplying a point by a particular matrix might translate it, rotate it, or
28
- * carry out a combination of transformations.
31
+ * Multiplying a point by a particular matrix might translate it, rotate it,
32
+ * or carry out a combination of transformations.
29
33
  *
30
34
  * Multiplying matrices by each other combines their effects; use the
31
35
  * {@code apply} and {@code preApply} methods for this.
32
36
  */
33
37
  public interface PMatrix {
34
-
35
- /**
36
- * Make this an identity matrix. Multiplying by it will have no effect.
37
- */
38
- public void reset();
39
-
40
- /**
41
- * Returns a copy of this PMatrix.
42
- */
43
- public PMatrix get();
44
-
45
- /**
46
- * Copies the matrix contents into a float array. If target is null (or not
47
- * the correct size), a new array will be created.
48
- */
49
- public float[] get(float[] target);
50
-
51
- /**
52
- * Make this matrix become a copy of src.
53
- */
54
- public void set(PMatrix src);
55
-
56
- /**
57
- * Set the contents of this matrix to the contents of source. Fills the
58
- * matrix left-to-right, starting in the top row.
59
- */
60
- public void set(float[] source);
61
-
62
- /**
63
- * Set the matrix content to this 2D matrix or its 3D equivalent.
64
- */
65
- public void set(float m00, float m01, float m02,
66
- float m10, float m11, float m12);
67
-
68
- /**
69
- * Set the matrix content to the 3D matrix supplied, if this matrix is 3D.
70
- */
71
- public void set(float m00, float m01, float m02, float m03,
72
- float m10, float m11, float m12, float m13,
73
- float m20, float m21, float m22, float m23,
74
- float m30, float m31, float m32, float m33);
75
-
76
- public void translate(float tx, float ty);
77
-
78
- public void translate(float tx, float ty, float tz);
79
-
80
- public void rotate(float angle);
81
-
82
- public void rotateX(float angle);
83
-
84
- public void rotateY(float angle);
85
-
86
- public void rotateZ(float angle);
87
-
88
- public void rotate(float angle, float v0, float v1, float v2);
89
-
90
- public void scale(float s);
91
-
92
- public void scale(float sx, float sy);
93
-
94
- public void scale(float x, float y, float z);
95
-
96
- public void shearX(float angle);
97
-
98
- public void shearY(float angle);
99
-
100
- /**
101
- * Multiply this matrix by another.
102
- */
103
- public void apply(PMatrix source);
104
-
105
- /**
106
- * Multiply this matrix by another.
107
- */
108
- public void apply(PMatrix2D source);
109
-
110
- /**
111
- * Multiply this matrix by another.
112
- */
113
- public void apply(PMatrix3D source);
114
-
115
- /**
116
- * Multiply this matrix by another.
117
- */
118
- public void apply(float n00, float n01, float n02,
119
- float n10, float n11, float n12);
120
-
121
- /**
122
- * Multiply this matrix by another.
123
- */
124
- public void apply(float n00, float n01, float n02, float n03,
125
- float n10, float n11, float n12, float n13,
126
- float n20, float n21, float n22, float n23,
127
- float n30, float n31, float n32, float n33);
128
-
129
- /**
130
- * Apply another matrix to the left of this one.
131
- */
132
- public void preApply(PMatrix left);
133
-
134
- /**
135
- * Apply another matrix to the left of this one.
136
- */
137
- public void preApply(PMatrix2D left);
138
-
139
- /**
140
- * Apply another matrix to the left of this one. 3D only.
141
- */
142
- public void preApply(PMatrix3D left);
143
-
144
- /**
145
- * Apply another matrix to the left of this one.
146
- */
147
- public void preApply(float n00, float n01, float n02,
148
- float n10, float n11, float n12);
149
-
150
- /**
151
- * Apply another matrix to the left of this one. 3D only.
152
- */
153
- public void preApply(float n00, float n01, float n02, float n03,
154
- float n10, float n11, float n12, float n13,
155
- float n20, float n21, float n22, float n23,
156
- float n30, float n31, float n32, float n33);
157
-
158
- /**
159
- * Multiply source by this matrix, and return the result. The result will be
160
- * stored in target if target is non-null, and target will then be the
161
- * matrix returned. This improves performance if you reuse target, so it's
162
- * recommended if you call this many times in draw().
163
- */
164
- public PVector mult(PVector source, PVector target);
165
-
166
- /**
167
- * Multiply a multi-element vector against this matrix. Supplying and
168
- * recycling a target array improves performance, so it's recommended if you
169
- * call this many times in draw().
170
- */
171
- public float[] mult(float[] source, float[] target);
172
-
38
+
39
+ /**
40
+ * Make this an identity matrix. Multiplying by it will have no effect.
41
+ */
42
+ public void reset();
43
+
44
+ /**
45
+ * Returns a copy of this PMatrix.
46
+ */
47
+ public PMatrix get();
48
+
49
+ /**
50
+ * Copies the matrix contents into a float array.
51
+ * If target is null (or not the correct size), a new array will be created.
52
+ */
53
+ public float[] get(float[] target);
54
+
55
+
56
+ /**
57
+ * Make this matrix become a copy of src.
58
+ */
59
+ public void set(PMatrix src);
60
+
61
+ /**
62
+ * Set the contents of this matrix to the contents of source. Fills the
63
+ * matrix left-to-right, starting in the top row.
64
+ */
65
+ public void set(float[] source);
66
+
67
+ /**
68
+ * Set the matrix content to this 2D matrix or its 3D equivalent.
69
+ */
70
+ public void set(float m00, float m01, float m02,
71
+ float m10, float m11, float m12);
72
+
73
+ /**
74
+ * Set the matrix content to the 3D matrix supplied, if this matrix is 3D.
75
+ */
76
+ public void set(float m00, float m01, float m02, float m03,
77
+ float m10, float m11, float m12, float m13,
78
+ float m20, float m21, float m22, float m23,
79
+ float m30, float m31, float m32, float m33);
80
+
81
+
82
+ public void translate(float tx, float ty);
83
+
84
+ public void translate(float tx, float ty, float tz);
85
+
86
+ public void rotate(float angle);
87
+
88
+ public void rotateX(float angle);
89
+
90
+ public void rotateY(float angle);
91
+
92
+ public void rotateZ(float angle);
93
+
94
+ public void rotate(float angle, float v0, float v1, float v2);
95
+
96
+ public void scale(float s);
97
+
98
+ public void scale(float sx, float sy);
99
+
100
+ public void scale(float x, float y, float z);
101
+
102
+ public void shearX(float angle);
103
+
104
+ public void shearY(float angle);
105
+
106
+ /**
107
+ * Multiply this matrix by another.
108
+ */
109
+ public void apply(PMatrix source);
110
+
111
+ /**
112
+ * Multiply this matrix by another.
113
+ */
114
+ public void apply(PMatrix2D source);
115
+
116
+ /**
117
+ * Multiply this matrix by another.
118
+ */
119
+ public void apply(PMatrix3D source);
120
+
121
+ /**
122
+ * Multiply this matrix by another.
123
+ */
124
+ public void apply(float n00, float n01, float n02,
125
+ float n10, float n11, float n12);
126
+
127
+ /**
128
+ * Multiply this matrix by another.
129
+ */
130
+ public void apply(float n00, float n01, float n02, float n03,
131
+ float n10, float n11, float n12, float n13,
132
+ float n20, float n21, float n22, float n23,
133
+ float n30, float n31, float n32, float n33);
134
+
135
+ /**
136
+ * Apply another matrix to the left of this one.
137
+ */
138
+ public void preApply(PMatrix left);
139
+
140
+ /**
141
+ * Apply another matrix to the left of this one.
142
+ */
143
+ public void preApply(PMatrix2D left);
144
+
145
+ /**
146
+ * Apply another matrix to the left of this one. 3D only.
147
+ */
148
+ public void preApply(PMatrix3D left);
149
+
150
+ /**
151
+ * Apply another matrix to the left of this one.
152
+ */
153
+ public void preApply(float n00, float n01, float n02,
154
+ float n10, float n11, float n12);
155
+
156
+ /**
157
+ * Apply another matrix to the left of this one. 3D only.
158
+ */
159
+ public void preApply(float n00, float n01, float n02, float n03,
160
+ float n10, float n11, float n12, float n13,
161
+ float n20, float n21, float n22, float n23,
162
+ float n30, float n31, float n32, float n33);
163
+
164
+
165
+ /**
166
+ * Multiply source by this matrix, and return the result.
167
+ * The result will be stored in target if target is non-null, and target
168
+ * will then be the matrix returned. This improves performance if you reuse
169
+ * target, so it's recommended if you call this many times in draw().
170
+ */
171
+ public PVector mult(PVector source, PVector target);
172
+
173
+
174
+ /**
175
+ * Multiply a multi-element vector against this matrix.
176
+ * Supplying and recycling a target array improves performance, so it's
177
+ * recommended if you call this many times in draw().
178
+ */
179
+ public float[] mult(float[] source, float[] target);
180
+
181
+
173
182
  // public float multX(float x, float y);
174
183
  // public float multY(float x, float y);
184
+
175
185
  // public float multX(float x, float y, float z);
176
186
  // public float multY(float x, float y, float z);
177
187
  // public float multZ(float x, float y, float z);
178
- /**
179
- * Transpose this matrix; rows become columns and columns rows.
180
- */
181
- public void transpose();
182
-
183
- /**
184
- * Invert this matrix. Will not necessarily succeed, because some matrices
185
- * map more than one point to the same image point, and so are irreversible.
186
- *
187
- * @return true if successful
188
- */
189
- public boolean invert();
190
-
191
- /**
192
- * @return the determinant of the matrix
193
- */
194
- public float determinant();
188
+
189
+
190
+ /**
191
+ * Transpose this matrix; rows become columns and columns rows.
192
+ */
193
+ public void transpose();
194
+
195
+
196
+ /**
197
+ * Invert this matrix. Will not necessarily succeed, because some matrices
198
+ * map more than one point to the same image point, and so are irreversible.
199
+ * @return true if successful
200
+ */
201
+ public boolean invert();
202
+
203
+
204
+ /**
205
+ * @return the determinant of the matrix
206
+ */
207
+ public float determinant();
195
208
  }
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -17,477 +19,544 @@
17
19
  Public License along with this library; if not, write to the
18
20
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19
21
  Boston, MA 02111-1307 USA
20
- */
22
+ */
23
+
21
24
  package processing.core;
22
25
 
26
+
23
27
  /**
24
- * 3x2 affine matrix implementation. Matrices are used to describe a
25
- * transformation; see {@link PMatrix} for a general description. This matrix
26
- * looks like the following when multiplying a vector (x, y) in {@code mult()}.
28
+ * 3x2 affine matrix implementation.
29
+ * Matrices are used to describe a transformation; see {@link PMatrix} for a
30
+ * general description. This matrix looks like the following when multiplying
31
+ * a vector (x, y) in {@code mult()}.
27
32
  * <pre>
28
33
  * [m00 m01 m02][x] [m00*x + m01*y + m02*1] [x']
29
34
  * [m10 m11 m12][y] = [m10*x + m11*y + m12*1] = [y']
30
- * [ 0 0 1 ][1] [ 0*x + 0*y + 1*1 ] [ 1]</pre> (x', y') is returned. The values
31
- * in the matrix determine the transformation. They are modified by the various
32
- * transformation functions.
35
+ * [ 0 0 1 ][1] [ 0*x + 0*y + 1*1 ] [ 1]</pre>
36
+ * (x', y') is returned. The values in the matrix determine the transformation.
37
+ * They are modified by the various transformation functions.
33
38
  */
34
39
  public class PMatrix2D implements PMatrix {
35
40
 
36
- public float m00, m01, m02;
37
- public float m10, m11, m12;
41
+ public float m00, m01, m02;
42
+ public float m10, m11, m12;
38
43
 
39
- /**
40
- * Create a new matrix, set to the identity matrix.
41
- */
42
- public PMatrix2D() {
43
- reset();
44
- }
45
44
 
46
- public PMatrix2D(float m00, float m01, float m02,
47
- float m10, float m11, float m12) {
48
- set(m00, m01, m02,
49
- m10, m11, m12);
50
- }
45
+ /**
46
+ * Create a new matrix, set to the identity matrix.
47
+ */
48
+ public PMatrix2D() {
49
+ reset();
50
+ }
51
51
 
52
- public PMatrix2D(PMatrix matrix) {
53
- set(matrix);
54
- }
55
52
 
56
- public void reset() {
57
- set(1, 0, 0,
58
- 0, 1, 0);
59
- }
53
+ public PMatrix2D(float m00, float m01, float m02,
54
+ float m10, float m11, float m12) {
55
+ set(m00, m01, m02,
56
+ m10, m11, m12);
57
+ }
60
58
 
61
- /**
62
- * Returns a copy of this PMatrix.
63
- */
64
- public PMatrix2D get() {
65
- PMatrix2D outgoing = new PMatrix2D();
66
- outgoing.set(this);
67
- return outgoing;
68
- }
69
59
 
70
- /**
71
- * Copies the matrix contents into a 6 entry float array. If target is null
72
- * (or not the correct size), a new array will be created. Returned in the
73
- * order {@code {m00, m01, m02, m10, m11, m12}}.
74
- */
75
- public float[] get(float[] target) {
76
- if ((target == null) || (target.length != 6)) {
77
- target = new float[6];
78
- }
79
- target[0] = m00;
80
- target[1] = m01;
81
- target[2] = m02;
82
-
83
- target[3] = m10;
84
- target[4] = m11;
85
- target[5] = m12;
86
-
87
- return target;
88
- }
60
+ public PMatrix2D(PMatrix matrix) {
61
+ set(matrix);
62
+ }
89
63
 
90
- /**
91
- * If matrix is a PMatrix2D, sets this matrix to be a copy of it.
92
- *
93
- * @throws IllegalArgumentException If <tt>matrix</tt> is not 2D.
94
- */
95
- public void set(PMatrix matrix) {
96
- if (matrix instanceof PMatrix2D) {
97
- PMatrix2D src = (PMatrix2D) matrix;
98
- set(src.m00, src.m01, src.m02,
99
- src.m10, src.m11, src.m12);
100
- } else {
101
- throw new IllegalArgumentException("PMatrix2D.set() only accepts PMatrix2D objects.");
102
- }
103
- }
104
64
 
105
- /**
106
- * Unavailable in 2D. Does nothing.
107
- */
108
- public void set(PMatrix3D src) {
109
- }
65
+ @Override
66
+ public void reset() {
67
+ set(1, 0, 0,
68
+ 0, 1, 0);
69
+ }
110
70
 
111
- public void set(float[] source) {
112
- m00 = source[0];
113
- m01 = source[1];
114
- m02 = source[2];
115
71
 
116
- m10 = source[3];
117
- m11 = source[4];
118
- m12 = source[5];
119
- }
72
+ /**
73
+ * Returns a copy of this PMatrix.
74
+ */
75
+ @Override
76
+ public PMatrix2D get() {
77
+ PMatrix2D outgoing = new PMatrix2D();
78
+ outgoing.set(this);
79
+ return outgoing;
80
+ }
120
81
 
121
- /**
122
- * Sets the matrix content.
123
- */
124
- public void set(float m00, float m01, float m02,
125
- float m10, float m11, float m12) {
126
- this.m00 = m00;
127
- this.m01 = m01;
128
- this.m02 = m02;
129
- this.m10 = m10;
130
- this.m11 = m11;
131
- this.m12 = m12;
132
- }
133
82
 
134
- /**
135
- * Unavailable in 2D. Does nothing.
136
- */
137
- public void set(float m00, float m01, float m02, float m03,
138
- float m10, float m11, float m12, float m13,
139
- float m20, float m21, float m22, float m23,
140
- float m30, float m31, float m32, float m33) {
83
+ /**
84
+ * Copies the matrix contents into a 6 entry float array.
85
+ * If target is null (or not the correct size), a new array will be created.
86
+ * Returned in the order {@code {m00, m01, m02, m10, m11, m12}}.
87
+ */
88
+ @Override
89
+ public float[] get(float[] target) {
90
+ if ((target == null) || (target.length != 6)) {
91
+ target = new float[6];
92
+ }
93
+ target[0] = m00;
94
+ target[1] = m01;
95
+ target[2] = m02;
96
+
97
+ target[3] = m10;
98
+ target[4] = m11;
99
+ target[5] = m12;
100
+
101
+ return target;
102
+ }
103
+
104
+
105
+ /**
106
+ * If matrix is a PMatrix2D, sets this matrix to be a copy of it.
107
+ * @throws IllegalArgumentException If <tt>matrix</tt> is not 2D.
108
+ */
109
+ public void set(PMatrix matrix) {
110
+ if (matrix instanceof PMatrix2D) {
111
+ PMatrix2D src = (PMatrix2D) matrix;
112
+ set(src.m00, src.m01, src.m02,
113
+ src.m10, src.m11, src.m12);
114
+ } else {
115
+ throw new IllegalArgumentException("PMatrix2D.set() only accepts PMatrix2D objects.");
116
+ }
117
+ }
118
+
119
+
120
+ /**
121
+ * Unavailable in 2D. Does nothing.
122
+ */
123
+ public void set(PMatrix3D src) {
124
+ }
125
+
126
+
127
+ @Override
128
+ public void set(float[] source) {
129
+ m00 = source[0];
130
+ m01 = source[1];
131
+ m02 = source[2];
132
+
133
+ m10 = source[3];
134
+ m11 = source[4];
135
+ m12 = source[5];
136
+ }
137
+
138
+
139
+ /**
140
+ * Sets the matrix content.
141
+ */
142
+ @Override
143
+ public void set(float m00, float m01, float m02,
144
+ float m10, float m11, float m12) {
145
+ this.m00 = m00; this.m01 = m01; this.m02 = m02;
146
+ this.m10 = m10; this.m11 = m11; this.m12 = m12;
147
+ }
148
+
149
+
150
+ /**
151
+ * Unavailable in 2D. Does nothing.
152
+ */
153
+ public void set(float m00, float m01, float m02, float m03,
154
+ float m10, float m11, float m12, float m13,
155
+ float m20, float m21, float m22, float m23,
156
+ float m30, float m31, float m32, float m33) {
157
+
158
+ }
159
+
160
+
161
+ @Override
162
+ public void translate(float tx, float ty) {
163
+ m02 = tx*m00 + ty*m01 + m02;
164
+ m12 = tx*m10 + ty*m11 + m12;
165
+ }
166
+
167
+
168
+ /**
169
+ * Unavailable in 2D.
170
+ * @throws IllegalArgumentException
171
+ */
172
+ @Override
173
+ public void translate(float x, float y, float z) {
174
+ throw new IllegalArgumentException("Cannot use translate(x, y, z) on a PMatrix2D.");
175
+ }
176
+
177
+
178
+ // Implementation roughly based on AffineTransform.
179
+ @Override
180
+ public void rotate(float angle) {
181
+ float s = sin(angle);
182
+ float c = cos(angle);
183
+
184
+ float temp1 = m00;
185
+ float temp2 = m01;
186
+ m00 = c * temp1 + s * temp2;
187
+ m01 = -s * temp1 + c * temp2;
188
+ temp1 = m10;
189
+ temp2 = m11;
190
+ m10 = c * temp1 + s * temp2;
191
+ m11 = -s * temp1 + c * temp2;
192
+ }
193
+
194
+
195
+ /**
196
+ * Unavailable in 2D.
197
+ * @throws IllegalArgumentException
198
+ */
199
+ @Override
200
+ public void rotateX(float angle) {
201
+ throw new IllegalArgumentException("Cannot use rotateX() on a PMatrix2D.");
202
+ }
203
+
204
+
205
+ /**
206
+ * Unavailable in 2D.
207
+ * @throws IllegalArgumentException
208
+ */
209
+ @Override
210
+ public void rotateY(float angle) {
211
+ throw new IllegalArgumentException("Cannot use rotateY() on a PMatrix2D.");
212
+ }
213
+
214
+
215
+ @Override
216
+ public void rotateZ(float angle) {
217
+ rotate(angle);
218
+ }
219
+
220
+
221
+ /**
222
+ * Unavailable in 2D.
223
+ * @throws IllegalArgumentException
224
+ */
225
+ @Override
226
+ public void rotate(float angle, float v0, float v1, float v2) {
227
+ throw new IllegalArgumentException("Cannot use this version of rotate() on a PMatrix2D.");
228
+ }
229
+
230
+
231
+ @Override
232
+ public void scale(float s) {
233
+ scale(s, s);
234
+ }
235
+
236
+
237
+ @Override
238
+ public void scale(float sx, float sy) {
239
+ m00 *= sx; m01 *= sy;
240
+ m10 *= sx; m11 *= sy;
241
+ }
242
+
243
+
244
+ /**
245
+ * Unavailable in 2D.
246
+ * @throws IllegalArgumentException
247
+ */
248
+ @Override
249
+ public void scale(float x, float y, float z) {
250
+ throw new IllegalArgumentException("Cannot use this version of scale() on a PMatrix2D.");
251
+ }
252
+
253
+
254
+ @Override
255
+ public void shearX(float angle) {
256
+ apply(1, 0, 1, tan(angle), 0, 0);
257
+ }
258
+
259
+
260
+ @Override
261
+ public void shearY(float angle) {
262
+ apply(1, 0, 1, 0, tan(angle), 0);
263
+ }
264
+
265
+
266
+ @Override
267
+ public void apply(PMatrix source) {
268
+ if (source instanceof PMatrix2D) {
269
+ apply((PMatrix2D) source);
270
+ } else if (source instanceof PMatrix3D) {
271
+ apply((PMatrix3D) source);
272
+ }
273
+ }
274
+
275
+
276
+ @Override
277
+ public void apply(PMatrix2D source) {
278
+ apply(source.m00, source.m01, source.m02,
279
+ source.m10, source.m11, source.m12);
280
+ }
281
+
282
+
283
+ /**
284
+ * Unavailable in 2D.
285
+ * @throws IllegalArgumentException
286
+ */
287
+ @Override
288
+ public void apply(PMatrix3D source) {
289
+ throw new IllegalArgumentException("Cannot use apply(PMatrix3D) on a PMatrix2D.");
290
+ }
291
+
292
+
293
+ @Override
294
+ public void apply(float n00, float n01, float n02,
295
+ float n10, float n11, float n12) {
296
+ float t0 = m00;
297
+ float t1 = m01;
298
+ m00 = n00 * t0 + n10 * t1;
299
+ m01 = n01 * t0 + n11 * t1;
300
+ m02 += n02 * t0 + n12 * t1;
301
+
302
+ t0 = m10;
303
+ t1 = m11;
304
+ m10 = n00 * t0 + n10 * t1;
305
+ m11 = n01 * t0 + n11 * t1;
306
+ m12 += n02 * t0 + n12 * t1;
307
+ }
308
+
309
+
310
+ /**
311
+ * Unavailable in 2D.
312
+ * @throws IllegalArgumentException
313
+ */
314
+ public void apply(float n00, float n01, float n02, float n03,
315
+ float n10, float n11, float n12, float n13,
316
+ float n20, float n21, float n22, float n23,
317
+ float n30, float n31, float n32, float n33) {
318
+ throw new IllegalArgumentException("Cannot use this version of apply() on a PMatrix2D.");
319
+ }
320
+
321
+
322
+ /**
323
+ * Apply another matrix to the left of this one.
324
+ */
325
+ @Override
326
+ public void preApply(PMatrix source) {
327
+ if (source instanceof PMatrix2D) {
328
+ preApply((PMatrix2D) source);
329
+ } else if (source instanceof PMatrix3D) {
330
+ preApply((PMatrix3D) source);
331
+ }
332
+ }
333
+
334
+
335
+ @Override
336
+ public void preApply(PMatrix2D left) {
337
+ preApply(left.m00, left.m01, left.m02,
338
+ left.m10, left.m11, left.m12);
339
+ }
340
+
341
+
342
+ /**
343
+ * Unavailable in 2D.
344
+ * @throws IllegalArgumentException
345
+ */
346
+ @Override
347
+ public void preApply(PMatrix3D left) {
348
+ throw new IllegalArgumentException("Cannot use preApply(PMatrix3D) on a PMatrix2D.");
349
+ }
141
350
 
142
- }
143
351
 
144
- public void translate(float tx, float ty) {
145
- m02 = tx * m00 + ty * m01 + m02;
146
- m12 = tx * m10 + ty * m11 + m12;
147
- }
352
+ @Override
353
+ public void preApply(float n00, float n01, float n02,
354
+ float n10, float n11, float n12) {
355
+ float t0 = m02;
356
+ float t1 = m12;
357
+ n02 += t0 * n00 + t1 * n01;
358
+ n12 += t0 * n10 + t1 * n11;
359
+
360
+ m02 = n02;
361
+ m12 = n12;
362
+
363
+ t0 = m00;
364
+ t1 = m10;
365
+ m00 = t0 * n00 + t1 * n01;
366
+ m10 = t0 * n10 + t1 * n11;
367
+
368
+ t0 = m01;
369
+ t1 = m11;
370
+ m01 = t0 * n00 + t1 * n01;
371
+ m11 = t0 * n10 + t1 * n11;
372
+ }
373
+
374
+
375
+ /**
376
+ * Unavailable in 2D.
377
+ * @throws IllegalArgumentException
378
+ */
379
+ public void preApply(float n00, float n01, float n02, float n03,
380
+ float n10, float n11, float n12, float n13,
381
+ float n20, float n21, float n22, float n23,
382
+ float n30, float n31, float n32, float n33) {
383
+ throw new IllegalArgumentException("Cannot use this version of preApply() on a PMatrix2D.");
384
+ }
385
+
386
+
387
+ //////////////////////////////////////////////////////////////
388
+
389
+
390
+ /**
391
+ * {@inheritDoc}
392
+ * Ignores any z component.
393
+ */
394
+ public PVector mult(PVector source, PVector target) {
395
+ if (target == null) {
396
+ target = new PVector();
397
+ }
398
+ target.x = m00*source.x + m01*source.y + m02;
399
+ target.y = m10*source.x + m11*source.y + m12;
400
+ return target;
401
+ }
148
402
 
149
- /**
150
- * Unavailable in 2D.
151
- *
152
- * @throws IllegalArgumentException
153
- */
154
- public void translate(float x, float y, float z) {
155
- throw new IllegalArgumentException("Cannot use translate(x, y, z) on a PMatrix2D.");
156
- }
157
403
 
158
- // Implementation roughly based on AffineTransform.
159
- public void rotate(float angle) {
160
- float s = sin(angle);
161
- float c = cos(angle);
162
-
163
- float temp1 = m00;
164
- float temp2 = m01;
165
- m00 = c * temp1 + s * temp2;
166
- m01 = -s * temp1 + c * temp2;
167
- temp1 = m10;
168
- temp2 = m11;
169
- m10 = c * temp1 + s * temp2;
170
- m11 = -s * temp1 + c * temp2;
404
+ /**
405
+ * Multiply a two element vector against this matrix.
406
+ * If out is null or not length four, a new float array will be returned.
407
+ * The values for vec and out can be the same (though that's less efficient).
408
+ */
409
+ public float[] mult(float[] vec, float[] out) {
410
+ if (out == null || out.length != 2) {
411
+ out = new float[2];
171
412
  }
172
413
 
173
- /**
174
- * Unavailable in 2D.
175
- *
176
- * @throws IllegalArgumentException
177
- */
178
- public void rotateX(float angle) {
179
- throw new IllegalArgumentException("Cannot use rotateX() on a PMatrix2D.");
180
- }
414
+ if (vec == out) {
415
+ float tx = m00*vec[0] + m01*vec[1] + m02;
416
+ float ty = m10*vec[0] + m11*vec[1] + m12;
181
417
 
182
- /**
183
- * Unavailable in 2D.
184
- *
185
- * @throws IllegalArgumentException
186
- */
187
- public void rotateY(float angle) {
188
- throw new IllegalArgumentException("Cannot use rotateY() on a PMatrix2D.");
189
- }
418
+ out[0] = tx;
419
+ out[1] = ty;
190
420
 
191
- public void rotateZ(float angle) {
192
- rotate(angle);
421
+ } else {
422
+ out[0] = m00*vec[0] + m01*vec[1] + m02;
423
+ out[1] = m10*vec[0] + m11*vec[1] + m12;
193
424
  }
194
425
 
195
- /**
196
- * Unavailable in 2D.
197
- *
198
- * @throws IllegalArgumentException
199
- */
200
- public void rotate(float angle, float v0, float v1, float v2) {
201
- throw new IllegalArgumentException("Cannot use this version of rotate() on a PMatrix2D.");
202
- }
426
+ return out;
427
+ }
203
428
 
204
- public void scale(float s) {
205
- scale(s, s);
206
- }
207
429
 
208
- public void scale(float sx, float sy) {
209
- m00 *= sx;
210
- m01 *= sy;
211
- m10 *= sx;
212
- m11 *= sy;
213
- }
430
+ /**
431
+ * Returns the x-coordinate of the result of multiplying the point (x, y)
432
+ * by this matrix.
433
+ */
434
+ public float multX(float x, float y) {
435
+ return m00*x + m01*y + m02;
436
+ }
214
437
 
215
- /**
216
- * Unavailable in 2D.
217
- *
218
- * @throws IllegalArgumentException
219
- */
220
- public void scale(float x, float y, float z) {
221
- throw new IllegalArgumentException("Cannot use this version of scale() on a PMatrix2D.");
222
- }
223
438
 
224
- public void shearX(float angle) {
225
- apply(1, 0, 1, tan(angle), 0, 0);
226
- }
439
+ /**
440
+ * Returns the y-coordinate of the result of multiplying the point (x, y)
441
+ * by this matrix.
442
+ */
443
+ public float multY(float x, float y) {
444
+ return m10*x + m11*y + m12;
445
+ }
227
446
 
228
- public void shearY(float angle) {
229
- apply(1, 0, 1, 0, tan(angle), 0);
230
- }
231
447
 
232
- public void apply(PMatrix source) {
233
- if (source instanceof PMatrix2D) {
234
- apply((PMatrix2D) source);
235
- } else if (source instanceof PMatrix3D) {
236
- apply((PMatrix3D) source);
237
- }
238
- }
239
448
 
240
- public void apply(PMatrix2D source) {
241
- apply(source.m00, source.m01, source.m02,
242
- source.m10, source.m11, source.m12);
243
- }
449
+ /**
450
+ * Unavailable in 2D. Does nothing.
451
+ */
452
+ @Override
453
+ public void transpose() {
454
+ }
244
455
 
245
- /**
246
- * Unavailable in 2D.
247
- *
248
- * @throws IllegalArgumentException
249
- */
250
- public void apply(PMatrix3D source) {
251
- throw new IllegalArgumentException("Cannot use apply(PMatrix3D) on a PMatrix2D.");
252
- }
253
456
 
254
- public void apply(float n00, float n01, float n02,
255
- float n10, float n11, float n12) {
256
- float t0 = m00;
257
- float t1 = m01;
258
- m00 = n00 * t0 + n10 * t1;
259
- m01 = n01 * t0 + n11 * t1;
260
- m02 += n02 * t0 + n12 * t1;
261
-
262
- t0 = m10;
263
- t1 = m11;
264
- m10 = n00 * t0 + n10 * t1;
265
- m11 = n01 * t0 + n11 * t1;
266
- m12 += n02 * t0 + n12 * t1;
457
+ /*
458
+ * Implementation stolen from OpenJDK.
459
+ */
460
+ @Override
461
+ public boolean invert() {
462
+ float determinant = determinant();
463
+ if (Math.abs(determinant) <= Float.MIN_VALUE) {
464
+ return false;
267
465
  }
268
466
 
269
- /**
270
- * Unavailable in 2D.
271
- *
272
- * @throws IllegalArgumentException
273
- */
274
- public void apply(float n00, float n01, float n02, float n03,
275
- float n10, float n11, float n12, float n13,
276
- float n20, float n21, float n22, float n23,
277
- float n30, float n31, float n32, float n33) {
278
- throw new IllegalArgumentException("Cannot use this version of apply() on a PMatrix2D.");
279
- }
467
+ float t00 = m00;
468
+ float t01 = m01;
469
+ float t02 = m02;
470
+ float t10 = m10;
471
+ float t11 = m11;
472
+ float t12 = m12;
280
473
 
281
- /**
282
- * Apply another matrix to the left of this one.
283
- */
284
- public void preApply(PMatrix source) {
285
- if (source instanceof PMatrix2D) {
286
- preApply((PMatrix2D) source);
287
- } else if (source instanceof PMatrix3D) {
288
- preApply((PMatrix3D) source);
289
- }
290
- }
474
+ m00 = t11 / determinant;
475
+ m10 = -t10 / determinant;
476
+ m01 = -t01 / determinant;
477
+ m11 = t00 / determinant;
478
+ m02 = (t01 * t12 - t11 * t02) / determinant;
479
+ m12 = (t10 * t02 - t00 * t12) / determinant;
291
480
 
292
- public void preApply(PMatrix2D left) {
293
- preApply(left.m00, left.m01, left.m02,
294
- left.m10, left.m11, left.m12);
295
- }
481
+ return true;
482
+ }
296
483
 
297
- /**
298
- * Unavailable in 2D.
299
- *
300
- * @throws IllegalArgumentException
301
- */
302
- public void preApply(PMatrix3D left) {
303
- throw new IllegalArgumentException("Cannot use preApply(PMatrix3D) on a PMatrix2D.");
304
- }
305
484
 
306
- public void preApply(float n00, float n01, float n02,
307
- float n10, float n11, float n12) {
308
- float t0 = m02;
309
- float t1 = m12;
310
- n02 += t0 * n00 + t1 * n01;
311
- n12 += t0 * n10 + t1 * n11;
312
-
313
- m02 = n02;
314
- m12 = n12;
315
-
316
- t0 = m00;
317
- t1 = m10;
318
- m00 = t0 * n00 + t1 * n01;
319
- m10 = t0 * n10 + t1 * n11;
320
-
321
- t0 = m01;
322
- t1 = m11;
323
- m01 = t0 * n00 + t1 * n01;
324
- m11 = t0 * n10 + t1 * n11;
325
- }
485
+ /**
486
+ * @return the determinant of the matrix
487
+ */
488
+ @Override
489
+ public float determinant() {
490
+ return m00 * m11 - m01 * m10;
491
+ }
326
492
 
327
- /**
328
- * Unavailable in 2D.
329
- *
330
- * @throws IllegalArgumentException
331
- */
332
- public void preApply(float n00, float n01, float n02, float n03,
333
- float n10, float n11, float n12, float n13,
334
- float n20, float n21, float n22, float n23,
335
- float n30, float n31, float n32, float n33) {
336
- throw new IllegalArgumentException("Cannot use this version of preApply() on a PMatrix2D.");
337
- }
338
493
 
339
- //////////////////////////////////////////////////////////////
340
- /**
341
- * {@inheritDoc} Ignores any z component.
342
- */
343
- public PVector mult(PVector source, PVector target) {
344
- if (target == null) {
345
- target = new PVector();
346
- }
347
- target.x = m00 * source.x + m01 * source.y + m02;
348
- target.y = m10 * source.x + m11 * source.y + m12;
349
- return target;
350
- }
494
+ //////////////////////////////////////////////////////////////
351
495
 
352
- /**
353
- * Multiply a two element vector against this matrix. If out is null or not
354
- * length four, a new float array will be returned. The values for vec and
355
- * out can be the same (though that's less efficient).
356
- */
357
- public float[] mult(float vec[], float out[]) {
358
- if (out == null || out.length != 2) {
359
- out = new float[2];
360
- }
361
-
362
- if (vec == out) {
363
- float tx = m00 * vec[0] + m01 * vec[1] + m02;
364
- float ty = m10 * vec[0] + m11 * vec[1] + m12;
365
-
366
- out[0] = tx;
367
- out[1] = ty;
368
-
369
- } else {
370
- out[0] = m00 * vec[0] + m01 * vec[1] + m02;
371
- out[1] = m10 * vec[0] + m11 * vec[1] + m12;
372
- }
373
-
374
- return out;
375
- }
376
496
 
377
- /**
378
- * Returns the x-coordinate of the result of multiplying the point (x, y) by
379
- * this matrix.
380
- */
381
- public float multX(float x, float y) {
382
- return m00 * x + m01 * y + m02;
383
- }
497
+ public void print() {
498
+ int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)),
499
+ PApplet.max(abs(m10), abs(m11), abs(m12))));
384
500
 
385
- /**
386
- * Returns the y-coordinate of the result of multiplying the point (x, y) by
387
- * this matrix.
388
- */
389
- public float multY(float x, float y) {
390
- return m10 * x + m11 * y + m12;
501
+ int digits = 1;
502
+ if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
503
+ digits = 5;
504
+ } else {
505
+ while ((big /= 10) != 0) digits++; // cheap log()
391
506
  }
392
507
 
393
- /**
394
- * Unavailable in 2D. Does nothing.
395
- */
396
- public void transpose() {
397
- }
508
+ System.out.println(PApplet.nfs(m00, digits, 4) + " " +
509
+ PApplet.nfs(m01, digits, 4) + " " +
510
+ PApplet.nfs(m02, digits, 4));
398
511
 
512
+ System.out.println(PApplet.nfs(m10, digits, 4) + " " +
513
+ PApplet.nfs(m11, digits, 4) + " " +
514
+ PApplet.nfs(m12, digits, 4));
399
515
 
400
- /*
401
- * Implementation stolen from OpenJDK.
402
- */
403
- public boolean invert() {
404
- float determinant = determinant();
405
- if (Math.abs(determinant) <= Float.MIN_VALUE) {
406
- return false;
407
- }
408
-
409
- float t00 = m00;
410
- float t01 = m01;
411
- float t02 = m02;
412
- float t10 = m10;
413
- float t11 = m11;
414
- float t12 = m12;
415
-
416
- m00 = t11 / determinant;
417
- m10 = -t10 / determinant;
418
- m01 = -t01 / determinant;
419
- m11 = t00 / determinant;
420
- m02 = (t01 * t12 - t11 * t02) / determinant;
421
- m12 = (t10 * t02 - t00 * t12) / determinant;
422
-
423
- return true;
424
- }
516
+ System.out.println();
517
+ }
425
518
 
426
- /**
427
- * @return the determinant of the matrix
428
- */
429
- public float determinant() {
430
- return m00 * m11 - m01 * m10;
431
- }
432
519
 
433
- //////////////////////////////////////////////////////////////
434
- public void print() {
435
- int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)),
436
- PApplet.max(abs(m10), abs(m11), abs(m12))));
437
-
438
- int digits = 1;
439
- if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
440
- digits = 5;
441
- } else {
442
- while ((big /= 10) != 0) {
443
- digits++; // cheap log()
444
- }
445
- }
446
-
447
- System.out.println(PApplet.nfs(m00, digits, 4) + " "
448
- + PApplet.nfs(m01, digits, 4) + " "
449
- + PApplet.nfs(m02, digits, 4));
450
-
451
- System.out.println(PApplet.nfs(m10, digits, 4) + " "
452
- + PApplet.nfs(m11, digits, 4) + " "
453
- + PApplet.nfs(m12, digits, 4));
454
-
455
- System.out.println();
456
- }
520
+ //////////////////////////////////////////////////////////////
457
521
 
458
- //////////////////////////////////////////////////////////////
459
- // TODO these need to be added as regular API, but the naming and
460
- // implementation needs to be improved first. (e.g. actually keeping track
461
- // of whether the matrix is in fact identity internally.)
462
- protected boolean isIdentity() {
463
- return ((m00 == 1) && (m01 == 0) && (m02 == 0)
464
- && (m10 == 0) && (m11 == 1) && (m12 == 0));
465
- }
522
+ // TODO these need to be added as regular API, but the naming and
523
+ // implementation needs to be improved first. (e.g. actually keeping track
524
+ // of whether the matrix is in fact identity internally.)
466
525
 
467
- // TODO make this more efficient, or move into PMatrix2D
468
- protected boolean isWarped() {
469
- return ((m00 != 1) || (m01 != 0)
470
- && (m10 != 0) || (m11 != 1));
471
- }
472
526
 
473
- //////////////////////////////////////////////////////////////
474
- static private final float max(float a, float b) {
475
- return (a > b) ? a : b;
476
- }
527
+ protected boolean isIdentity() {
528
+ return ((m00 == 1) && (m01 == 0) && (m02 == 0) &&
529
+ (m10 == 0) && (m11 == 1) && (m12 == 0));
530
+ }
477
531
 
478
- static private final float abs(float a) {
479
- return (a < 0) ? -a : a;
480
- }
481
532
 
482
- static private final float sin(float angle) {
483
- return (float) Math.sin(angle);
484
- }
533
+ // TODO make this more efficient, or move into PMatrix2D
534
+ protected boolean isWarped() {
535
+ return ((m00 != 1) || (m01 != 0) &&
536
+ (m10 != 0) || (m11 != 1));
537
+ }
485
538
 
486
- static private final float cos(float angle) {
487
- return (float) Math.cos(angle);
488
- }
489
539
 
490
- static private final float tan(float angle) {
491
- return (float) Math.tan(angle);
492
- }
540
+ //////////////////////////////////////////////////////////////
541
+
542
+
543
+ private static float max(float a, float b) {
544
+ return (a > b) ? a : b;
545
+ }
546
+
547
+ private static float abs(float a) {
548
+ return (a < 0) ? -a : a;
549
+ }
550
+
551
+ private static float sin(float angle) {
552
+ return (float)Math.sin(angle);
553
+ }
554
+
555
+ private static float cos(float angle) {
556
+ return (float)Math.cos(angle);
557
+ }
558
+
559
+ private static float tan(float angle) {
560
+ return (float)Math.tan(angle);
561
+ }
493
562
  }