2626
2727/**
2828 * 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()}.
32+ * <pre>
33+ * [m00 m01 m02][x] [m00*x + m01*y + m02*1] [x']
34+ * [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+ * (x', y') is returned. The values in the matrix determine the transformation.
37+ * They are modified by the various transformation functions.
2938 */
3039public class PMatrix2D implements PMatrix {
3140
3241 public float m00 , m01 , m02 ;
3342 public float m10 , m11 , m12 ;
3443
3544
45+ /**
46+ * Create a new matrix, set to the identity matrix.
47+ */
3648 public PMatrix2D () {
3749 reset ();
3850 }
@@ -69,6 +81,7 @@ public PMatrix2D get() {
6981 /**
7082 * Copies the matrix contents into a 6 entry float array.
7183 * If target is null (or not the correct size), a new array will be created.
84+ * Returned in the order {@code {m00, m01, m02, m10, m11, m12}}.
7285 */
7386 public float [] get (float [] target ) {
7487 if ((target == null ) || (target .length != 6 )) {
@@ -86,6 +99,10 @@ public float[] get(float[] target) {
8699 }
87100
88101
102+ /**
103+ * If matrix is a PMatrix2D, sets this matrix to be a copy of it.
104+ * @throws IllegalArgumentException If <tt>matrix</tt> is not 2D.
105+ */
89106 public void set (PMatrix matrix ) {
90107 if (matrix instanceof PMatrix2D ) {
91108 PMatrix2D src = (PMatrix2D ) matrix ;
@@ -97,6 +114,9 @@ public void set(PMatrix matrix) {
97114 }
98115
99116
117+ /**
118+ * Unavailable in 2D. Does nothing.
119+ */
100120 public void set (PMatrix3D src ) {
101121 }
102122
@@ -112,13 +132,19 @@ public void set(float[] source) {
112132 }
113133
114134
135+ /**
136+ * Sets the matrix content.
137+ */
115138 public void set (float m00 , float m01 , float m02 ,
116139 float m10 , float m11 , float m12 ) {
117140 this .m00 = m00 ; this .m01 = m01 ; this .m02 = m02 ;
118141 this .m10 = m10 ; this .m11 = m11 ; this .m12 = m12 ;
119142 }
120143
121144
145+ /**
146+ * Unavailable in 2D. Does nothing.
147+ */
122148 public void set (float m00 , float m01 , float m02 , float m03 ,
123149 float m10 , float m11 , float m12 , float m13 ,
124150 float m20 , float m21 , float m22 , float m23 ,
@@ -133,6 +159,10 @@ public void translate(float tx, float ty) {
133159 }
134160
135161
162+ /**
163+ * Unavailable in 2D.
164+ * @throws IllegalArgumentException
165+ */
136166 public void translate (float x , float y , float z ) {
137167 throw new IllegalArgumentException ("Cannot use translate(x, y, z) on a PMatrix2D." );
138168 }
@@ -154,11 +184,19 @@ public void rotate(float angle) {
154184 }
155185
156186
187+ /**
188+ * Unavailable in 2D.
189+ * @throws IllegalArgumentException
190+ */
157191 public void rotateX (float angle ) {
158192 throw new IllegalArgumentException ("Cannot use rotateX() on a PMatrix2D." );
159193 }
160194
161195
196+ /**
197+ * Unavailable in 2D.
198+ * @throws IllegalArgumentException
199+ */
162200 public void rotateY (float angle ) {
163201 throw new IllegalArgumentException ("Cannot use rotateY() on a PMatrix2D." );
164202 }
@@ -169,6 +207,10 @@ public void rotateZ(float angle) {
169207 }
170208
171209
210+ /**
211+ * Unavailable in 2D.
212+ * @throws IllegalArgumentException
213+ */
172214 public void rotate (float angle , float v0 , float v1 , float v2 ) {
173215 throw new IllegalArgumentException ("Cannot use this version of rotate() on a PMatrix2D." );
174216 }
@@ -185,6 +227,10 @@ public void scale(float sx, float sy) {
185227 }
186228
187229
230+ /**
231+ * Unavailable in 2D.
232+ * @throws IllegalArgumentException
233+ */
188234 public void scale (float x , float y , float z ) {
189235 throw new IllegalArgumentException ("Cannot use this version of scale() on a PMatrix2D." );
190236 }
@@ -215,6 +261,10 @@ public void apply(PMatrix2D source) {
215261 }
216262
217263
264+ /**
265+ * Unavailable in 2D.
266+ * @throws IllegalArgumentException
267+ */
218268 public void apply (PMatrix3D source ) {
219269 throw new IllegalArgumentException ("Cannot use apply(PMatrix3D) on a PMatrix2D." );
220270 }
@@ -236,6 +286,10 @@ public void apply(float n00, float n01, float n02,
236286 }
237287
238288
289+ /**
290+ * Unavailable in 2D.
291+ * @throws IllegalArgumentException
292+ */
239293 public void apply (float n00 , float n01 , float n02 , float n03 ,
240294 float n10 , float n11 , float n12 , float n13 ,
241295 float n20 , float n21 , float n22 , float n23 ,
@@ -262,6 +316,10 @@ public void preApply(PMatrix2D left) {
262316 }
263317
264318
319+ /**
320+ * Unavailable in 2D.
321+ * @throws IllegalArgumentException
322+ */
265323 public void preApply (PMatrix3D left ) {
266324 throw new IllegalArgumentException ("Cannot use preApply(PMatrix3D) on a PMatrix2D." );
267325 }
@@ -289,6 +347,10 @@ public void preApply(float n00, float n01, float n02,
289347 }
290348
291349
350+ /**
351+ * Unavailable in 2D.
352+ * @throws IllegalArgumentException
353+ */
292354 public void preApply (float n00 , float n01 , float n02 , float n03 ,
293355 float n10 , float n11 , float n12 , float n13 ,
294356 float n20 , float n21 , float n22 , float n23 ,
@@ -301,7 +363,8 @@ public void preApply(float n00, float n01, float n02, float n03,
301363
302364
303365 /**
304- * Multiply the x and y coordinates of a PVector against this matrix.
366+ * {@inheritDoc}
367+ * Ignores any z component.
305368 */
306369 public PVector mult (PVector source , PVector target ) {
307370 if (target == null ) {
@@ -339,26 +402,34 @@ public float[] mult(float vec[], float out[]) {
339402 }
340403
341404
405+ /**
406+ * Returns the x-coordinate of the result of multiplying the point (x, y)
407+ * by this matrix.
408+ */
342409 public float multX (float x , float y ) {
343410 return m00 *x + m01 *y + m02 ;
344411 }
345412
346413
414+ /**
415+ * Returns the y-coordinate of the result of multiplying the point (x, y)
416+ * by this matrix.
417+ */
347418 public float multY (float x , float y ) {
348419 return m10 *x + m11 *y + m12 ;
349420 }
350421
351422
423+
352424 /**
353- * Transpose this matrix .
425+ * Unavailable in 2D. Does nothing .
354426 */
355427 public void transpose () {
356428 }
357429
358430
359- /**
360- * Invert this matrix. Implementation stolen from OpenJDK.
361- * @return true if successful
431+ /*
432+ * Implementation stolen from OpenJDK.
362433 */
363434 public boolean invert () {
364435 float determinant = determinant ();
0 commit comments