Matrix.java revision cc11f15f76a62ded3e403cb2bc818c6aa5bf261c
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.graphics; 18 19import java.io.PrintWriter; 20 21 22/** 23 * The Matrix class holds a 3x3 matrix for transforming coordinates. 24 */ 25public class Matrix { 26 27 public static final int MSCALE_X = 0; //!< use with getValues/setValues 28 public static final int MSKEW_X = 1; //!< use with getValues/setValues 29 public static final int MTRANS_X = 2; //!< use with getValues/setValues 30 public static final int MSKEW_Y = 3; //!< use with getValues/setValues 31 public static final int MSCALE_Y = 4; //!< use with getValues/setValues 32 public static final int MTRANS_Y = 5; //!< use with getValues/setValues 33 public static final int MPERSP_0 = 6; //!< use with getValues/setValues 34 public static final int MPERSP_1 = 7; //!< use with getValues/setValues 35 public static final int MPERSP_2 = 8; //!< use with getValues/setValues 36 37 /** @hide */ 38 public static Matrix IDENTITY_MATRIX = new Matrix() { 39 void oops() { 40 throw new IllegalStateException("Matrix can not be modified"); 41 } 42 43 @Override 44 public void set(Matrix src) { 45 oops(); 46 } 47 48 @Override 49 public void reset() { 50 oops(); 51 } 52 53 @Override 54 public void setTranslate(float dx, float dy) { 55 oops(); 56 } 57 58 @Override 59 public void setScale(float sx, float sy, float px, float py) { 60 oops(); 61 } 62 63 @Override 64 public void setScale(float sx, float sy) { 65 oops(); 66 } 67 68 @Override 69 public void setRotate(float degrees, float px, float py) { 70 oops(); 71 } 72 73 @Override 74 public void setRotate(float degrees) { 75 oops(); 76 } 77 78 @Override 79 public void setSinCos(float sinValue, float cosValue, float px, float py) { 80 oops(); 81 } 82 83 @Override 84 public void setSinCos(float sinValue, float cosValue) { 85 oops(); 86 } 87 88 @Override 89 public void setSkew(float kx, float ky, float px, float py) { 90 oops(); 91 } 92 93 @Override 94 public void setSkew(float kx, float ky) { 95 oops(); 96 } 97 98 @Override 99 public boolean setConcat(Matrix a, Matrix b) { 100 oops(); 101 return false; 102 } 103 104 @Override 105 public boolean preTranslate(float dx, float dy) { 106 oops(); 107 return false; 108 } 109 110 @Override 111 public boolean preScale(float sx, float sy, float px, float py) { 112 oops(); 113 return false; 114 } 115 116 @Override 117 public boolean preScale(float sx, float sy) { 118 oops(); 119 return false; 120 } 121 122 @Override 123 public boolean preRotate(float degrees, float px, float py) { 124 oops(); 125 return false; 126 } 127 128 @Override 129 public boolean preRotate(float degrees) { 130 oops(); 131 return false; 132 } 133 134 @Override 135 public boolean preSkew(float kx, float ky, float px, float py) { 136 oops(); 137 return false; 138 } 139 140 @Override 141 public boolean preSkew(float kx, float ky) { 142 oops(); 143 return false; 144 } 145 146 @Override 147 public boolean preConcat(Matrix other) { 148 oops(); 149 return false; 150 } 151 152 @Override 153 public boolean postTranslate(float dx, float dy) { 154 oops(); 155 return false; 156 } 157 158 @Override 159 public boolean postScale(float sx, float sy, float px, float py) { 160 oops(); 161 return false; 162 } 163 164 @Override 165 public boolean postScale(float sx, float sy) { 166 oops(); 167 return false; 168 } 169 170 @Override 171 public boolean postRotate(float degrees, float px, float py) { 172 oops(); 173 return false; 174 } 175 176 @Override 177 public boolean postRotate(float degrees) { 178 oops(); 179 return false; 180 } 181 182 @Override 183 public boolean postSkew(float kx, float ky, float px, float py) { 184 oops(); 185 return false; 186 } 187 188 @Override 189 public boolean postSkew(float kx, float ky) { 190 oops(); 191 return false; 192 } 193 194 @Override 195 public boolean postConcat(Matrix other) { 196 oops(); 197 return false; 198 } 199 200 @Override 201 public boolean setRectToRect(RectF src, RectF dst, ScaleToFit stf) { 202 oops(); 203 return false; 204 } 205 206 @Override 207 public boolean setPolyToPoly(float[] src, int srcIndex, float[] dst, int dstIndex, 208 int pointCount) { 209 oops(); 210 return false; 211 } 212 213 @Override 214 public void setValues(float[] values) { 215 oops(); 216 } 217 }; 218 219 /** 220 * @hide 221 */ 222 public long native_instance; 223 224 /** 225 * Create an identity matrix 226 */ 227 public Matrix() { 228 native_instance = native_create(0); 229 } 230 231 /** 232 * Create a matrix that is a (deep) copy of src 233 * @param src The matrix to copy into this matrix 234 */ 235 public Matrix(Matrix src) { 236 native_instance = native_create(src != null ? src.native_instance : 0); 237 } 238 239 /** 240 * Returns true if the matrix is identity. 241 * This maybe faster than testing if (getType() == 0) 242 */ 243 public boolean isIdentity() { 244 return native_isIdentity(native_instance); 245 } 246 247 /** 248 * Returns true if will map a rectangle to another rectangle. This can be 249 * true if the matrix is identity, scale-only, or rotates a multiple of 90 250 * degrees. 251 */ 252 public boolean rectStaysRect() { 253 return native_rectStaysRect(native_instance); 254 } 255 256 /** 257 * (deep) copy the src matrix into this matrix. If src is null, reset this 258 * matrix to the identity matrix. 259 */ 260 public void set(Matrix src) { 261 if (src == null) { 262 reset(); 263 } else { 264 native_set(native_instance, src.native_instance); 265 } 266 } 267 268 /** Returns true iff obj is a Matrix and its values equal our values. 269 */ 270 @Override 271 public boolean equals(Object obj) { 272 //if (obj == this) return true; -- NaN value would mean matrix != itself 273 if (!(obj instanceof Matrix)) return false; 274 return native_equals(native_instance, ((Matrix)obj).native_instance); 275 } 276 277 @Override 278 public int hashCode() { 279 // This should generate the hash code by performing some arithmetic operation on all 280 // the matrix elements -- our equals() does an element-by-element comparison, and we 281 // need to ensure that the hash code for two equal objects is the same. We're not 282 // really using this at the moment, so we take the easy way out. 283 return 44; 284 } 285 286 /** Set the matrix to identity */ 287 public void reset() { 288 native_reset(native_instance); 289 } 290 291 /** Set the matrix to translate by (dx, dy). */ 292 public void setTranslate(float dx, float dy) { 293 native_setTranslate(native_instance, dx, dy); 294 } 295 296 /** 297 * Set the matrix to scale by sx and sy, with a pivot point at (px, py). 298 * The pivot point is the coordinate that should remain unchanged by the 299 * specified transformation. 300 */ 301 public void setScale(float sx, float sy, float px, float py) { 302 native_setScale(native_instance, sx, sy, px, py); 303 } 304 305 /** Set the matrix to scale by sx and sy. */ 306 public void setScale(float sx, float sy) { 307 native_setScale(native_instance, sx, sy); 308 } 309 310 /** 311 * Set the matrix to rotate by the specified number of degrees, with a pivot 312 * point at (px, py). The pivot point is the coordinate that should remain 313 * unchanged by the specified transformation. 314 */ 315 public void setRotate(float degrees, float px, float py) { 316 native_setRotate(native_instance, degrees, px, py); 317 } 318 319 /** 320 * Set the matrix to rotate about (0,0) by the specified number of degrees. 321 */ 322 public void setRotate(float degrees) { 323 native_setRotate(native_instance, degrees); 324 } 325 326 /** 327 * Set the matrix to rotate by the specified sine and cosine values, with a 328 * pivot point at (px, py). The pivot point is the coordinate that should 329 * remain unchanged by the specified transformation. 330 */ 331 public void setSinCos(float sinValue, float cosValue, float px, float py) { 332 native_setSinCos(native_instance, sinValue, cosValue, px, py); 333 } 334 335 /** Set the matrix to rotate by the specified sine and cosine values. */ 336 public void setSinCos(float sinValue, float cosValue) { 337 native_setSinCos(native_instance, sinValue, cosValue); 338 } 339 340 /** 341 * Set the matrix to skew by sx and sy, with a pivot point at (px, py). 342 * The pivot point is the coordinate that should remain unchanged by the 343 * specified transformation. 344 */ 345 public void setSkew(float kx, float ky, float px, float py) { 346 native_setSkew(native_instance, kx, ky, px, py); 347 } 348 349 /** Set the matrix to skew by sx and sy. */ 350 public void setSkew(float kx, float ky) { 351 native_setSkew(native_instance, kx, ky); 352 } 353 354 /** 355 * Set the matrix to the concatenation of the two specified matrices and 356 * return true. 357 * 358 * <p>Either of the two matrices may also be the target matrix, that is 359 * <code>matrixA.setConcat(matrixA, matrixB);</code> is valid.</p> 360 * 361 * <p class="note">In {@link android.os.Build.VERSION_CODES#GINGERBREAD_MR1} and below, this 362 * function returns true only if the result can be represented. In 363 * {@link android.os.Build.VERSION_CODES#HONEYCOMB} and above, it always returns true.</p> 364 */ 365 public boolean setConcat(Matrix a, Matrix b) { 366 native_setConcat(native_instance, a.native_instance, b.native_instance); 367 return true; 368 } 369 370 /** 371 * Preconcats the matrix with the specified translation. 372 * M' = M * T(dx, dy) 373 */ 374 public boolean preTranslate(float dx, float dy) { 375 native_preTranslate(native_instance, dx, dy); 376 return true; 377 } 378 379 /** 380 * Preconcats the matrix with the specified scale. 381 * M' = M * S(sx, sy, px, py) 382 */ 383 public boolean preScale(float sx, float sy, float px, float py) { 384 native_preScale(native_instance, sx, sy, px, py); 385 return true; 386 } 387 388 /** 389 * Preconcats the matrix with the specified scale. 390 * M' = M * S(sx, sy) 391 */ 392 public boolean preScale(float sx, float sy) { 393 native_preScale(native_instance, sx, sy); 394 return true; 395 } 396 397 /** 398 * Preconcats the matrix with the specified rotation. 399 * M' = M * R(degrees, px, py) 400 */ 401 public boolean preRotate(float degrees, float px, float py) { 402 native_preRotate(native_instance, degrees, px, py); 403 return true; 404 } 405 406 /** 407 * Preconcats the matrix with the specified rotation. 408 * M' = M * R(degrees) 409 */ 410 public boolean preRotate(float degrees) { 411 native_preRotate(native_instance, degrees); 412 return true; 413 } 414 415 /** 416 * Preconcats the matrix with the specified skew. 417 * M' = M * K(kx, ky, px, py) 418 */ 419 public boolean preSkew(float kx, float ky, float px, float py) { 420 native_preSkew(native_instance, kx, ky, px, py); 421 return true; 422 } 423 424 /** 425 * Preconcats the matrix with the specified skew. 426 * M' = M * K(kx, ky) 427 */ 428 public boolean preSkew(float kx, float ky) { 429 native_preSkew(native_instance, kx, ky); 430 return true; 431 } 432 433 /** 434 * Preconcats the matrix with the specified matrix. 435 * M' = M * other 436 */ 437 public boolean preConcat(Matrix other) { 438 native_preConcat(native_instance, other.native_instance); 439 return true; 440 } 441 442 /** 443 * Postconcats the matrix with the specified translation. 444 * M' = T(dx, dy) * M 445 */ 446 public boolean postTranslate(float dx, float dy) { 447 native_postTranslate(native_instance, dx, dy); 448 return true; 449 } 450 451 /** 452 * Postconcats the matrix with the specified scale. 453 * M' = S(sx, sy, px, py) * M 454 */ 455 public boolean postScale(float sx, float sy, float px, float py) { 456 native_postScale(native_instance, sx, sy, px, py); 457 return true; 458 } 459 460 /** 461 * Postconcats the matrix with the specified scale. 462 * M' = S(sx, sy) * M 463 */ 464 public boolean postScale(float sx, float sy) { 465 native_postScale(native_instance, sx, sy); 466 return true; 467 } 468 469 /** 470 * Postconcats the matrix with the specified rotation. 471 * M' = R(degrees, px, py) * M 472 */ 473 public boolean postRotate(float degrees, float px, float py) { 474 native_postRotate(native_instance, degrees, px, py); 475 return true; 476 } 477 478 /** 479 * Postconcats the matrix with the specified rotation. 480 * M' = R(degrees) * M 481 */ 482 public boolean postRotate(float degrees) { 483 native_postRotate(native_instance, degrees); 484 return true; 485 } 486 487 /** 488 * Postconcats the matrix with the specified skew. 489 * M' = K(kx, ky, px, py) * M 490 */ 491 public boolean postSkew(float kx, float ky, float px, float py) { 492 native_postSkew(native_instance, kx, ky, px, py); 493 return true; 494 } 495 496 /** 497 * Postconcats the matrix with the specified skew. 498 * M' = K(kx, ky) * M 499 */ 500 public boolean postSkew(float kx, float ky) { 501 native_postSkew(native_instance, kx, ky); 502 return true; 503 } 504 505 /** 506 * Postconcats the matrix with the specified matrix. 507 * M' = other * M 508 */ 509 public boolean postConcat(Matrix other) { 510 native_postConcat(native_instance, other.native_instance); 511 return true; 512 } 513 514 /** Controlls how the src rect should align into the dst rect for 515 setRectToRect(). 516 */ 517 public enum ScaleToFit { 518 /** 519 * Scale in X and Y independently, so that src matches dst exactly. 520 * This may change the aspect ratio of the src. 521 */ 522 FILL (0), 523 /** 524 * Compute a scale that will maintain the original src aspect ratio, 525 * but will also ensure that src fits entirely inside dst. At least one 526 * axis (X or Y) will fit exactly. START aligns the result to the 527 * left and top edges of dst. 528 */ 529 START (1), 530 /** 531 * Compute a scale that will maintain the original src aspect ratio, 532 * but will also ensure that src fits entirely inside dst. At least one 533 * axis (X or Y) will fit exactly. The result is centered inside dst. 534 */ 535 CENTER (2), 536 /** 537 * Compute a scale that will maintain the original src aspect ratio, 538 * but will also ensure that src fits entirely inside dst. At least one 539 * axis (X or Y) will fit exactly. END aligns the result to the 540 * right and bottom edges of dst. 541 */ 542 END (3); 543 544 // the native values must match those in SkMatrix.h 545 ScaleToFit(int nativeInt) { 546 this.nativeInt = nativeInt; 547 } 548 final int nativeInt; 549 } 550 551 /** 552 * Set the matrix to the scale and translate values that map the source 553 * rectangle to the destination rectangle, returning true if the the result 554 * can be represented. 555 * 556 * @param src the source rectangle to map from. 557 * @param dst the destination rectangle to map to. 558 * @param stf the ScaleToFit option 559 * @return true if the matrix can be represented by the rectangle mapping. 560 */ 561 public boolean setRectToRect(RectF src, RectF dst, ScaleToFit stf) { 562 if (dst == null || src == null) { 563 throw new NullPointerException(); 564 } 565 return native_setRectToRect(native_instance, src, dst, stf.nativeInt); 566 } 567 568 // private helper to perform range checks on arrays of "points" 569 private static void checkPointArrays(float[] src, int srcIndex, 570 float[] dst, int dstIndex, 571 int pointCount) { 572 // check for too-small and too-big indices 573 int srcStop = srcIndex + (pointCount << 1); 574 int dstStop = dstIndex + (pointCount << 1); 575 if ((pointCount | srcIndex | dstIndex | srcStop | dstStop) < 0 || 576 srcStop > src.length || dstStop > dst.length) { 577 throw new ArrayIndexOutOfBoundsException(); 578 } 579 } 580 581 /** 582 * Set the matrix such that the specified src points would map to the 583 * specified dst points. The "points" are represented as an array of floats, 584 * order [x0, y0, x1, y1, ...], where each "point" is 2 float values. 585 * 586 * @param src The array of src [x,y] pairs (points) 587 * @param srcIndex Index of the first pair of src values 588 * @param dst The array of dst [x,y] pairs (points) 589 * @param dstIndex Index of the first pair of dst values 590 * @param pointCount The number of pairs/points to be used. Must be [0..4] 591 * @return true if the matrix was set to the specified transformation 592 */ 593 public boolean setPolyToPoly(float[] src, int srcIndex, 594 float[] dst, int dstIndex, 595 int pointCount) { 596 if (pointCount > 4) { 597 throw new IllegalArgumentException(); 598 } 599 checkPointArrays(src, srcIndex, dst, dstIndex, pointCount); 600 return native_setPolyToPoly(native_instance, src, srcIndex, 601 dst, dstIndex, pointCount); 602 } 603 604 /** 605 * If this matrix can be inverted, return true and if inverse is not null, 606 * set inverse to be the inverse of this matrix. If this matrix cannot be 607 * inverted, ignore inverse and return false. 608 */ 609 public boolean invert(Matrix inverse) { 610 return native_invert(native_instance, inverse.native_instance); 611 } 612 613 /** 614 * Apply this matrix to the array of 2D points specified by src, and write 615 * the transformed points into the array of points specified by dst. The 616 * two arrays represent their "points" as pairs of floats [x, y]. 617 * 618 * @param dst The array of dst points (x,y pairs) 619 * @param dstIndex The index of the first [x,y] pair of dst floats 620 * @param src The array of src points (x,y pairs) 621 * @param srcIndex The index of the first [x,y] pair of src floats 622 * @param pointCount The number of points (x,y pairs) to transform 623 */ 624 public void mapPoints(float[] dst, int dstIndex, float[] src, int srcIndex, 625 int pointCount) { 626 checkPointArrays(src, srcIndex, dst, dstIndex, pointCount); 627 native_mapPoints(native_instance, dst, dstIndex, src, srcIndex, 628 pointCount, true); 629 } 630 631 /** 632 * Apply this matrix to the array of 2D vectors specified by src, and write 633 * the transformed vectors into the array of vectors specified by dst. The 634 * two arrays represent their "vectors" as pairs of floats [x, y]. 635 * 636 * Note: this method does not apply the translation associated with the matrix. Use 637 * {@link Matrix#mapPoints(float[], int, float[], int, int)} if you want the translation 638 * to be applied. 639 * 640 * @param dst The array of dst vectors (x,y pairs) 641 * @param dstIndex The index of the first [x,y] pair of dst floats 642 * @param src The array of src vectors (x,y pairs) 643 * @param srcIndex The index of the first [x,y] pair of src floats 644 * @param vectorCount The number of vectors (x,y pairs) to transform 645 */ 646 public void mapVectors(float[] dst, int dstIndex, float[] src, int srcIndex, 647 int vectorCount) { 648 checkPointArrays(src, srcIndex, dst, dstIndex, vectorCount); 649 native_mapPoints(native_instance, dst, dstIndex, src, srcIndex, 650 vectorCount, false); 651 } 652 653 /** 654 * Apply this matrix to the array of 2D points specified by src, and write 655 * the transformed points into the array of points specified by dst. The 656 * two arrays represent their "points" as pairs of floats [x, y]. 657 * 658 * @param dst The array of dst points (x,y pairs) 659 * @param src The array of src points (x,y pairs) 660 */ 661 public void mapPoints(float[] dst, float[] src) { 662 if (dst.length != src.length) { 663 throw new ArrayIndexOutOfBoundsException(); 664 } 665 mapPoints(dst, 0, src, 0, dst.length >> 1); 666 } 667 668 /** 669 * Apply this matrix to the array of 2D vectors specified by src, and write 670 * the transformed vectors into the array of vectors specified by dst. The 671 * two arrays represent their "vectors" as pairs of floats [x, y]. 672 * 673 * Note: this method does not apply the translation associated with the matrix. Use 674 * {@link Matrix#mapPoints(float[], float[])} if you want the translation to be applied. 675 * 676 * @param dst The array of dst vectors (x,y pairs) 677 * @param src The array of src vectors (x,y pairs) 678 */ 679 public void mapVectors(float[] dst, float[] src) { 680 if (dst.length != src.length) { 681 throw new ArrayIndexOutOfBoundsException(); 682 } 683 mapVectors(dst, 0, src, 0, dst.length >> 1); 684 } 685 686 /** 687 * Apply this matrix to the array of 2D points, and write the transformed 688 * points back into the array 689 * 690 * @param pts The array [x0, y0, x1, y1, ...] of points to transform. 691 */ 692 public void mapPoints(float[] pts) { 693 mapPoints(pts, 0, pts, 0, pts.length >> 1); 694 } 695 696 /** 697 * Apply this matrix to the array of 2D vectors, and write the transformed 698 * vectors back into the array. 699 * 700 * Note: this method does not apply the translation associated with the matrix. Use 701 * {@link Matrix#mapPoints(float[])} if you want the translation to be applied. 702 * 703 * @param vecs The array [x0, y0, x1, y1, ...] of vectors to transform. 704 */ 705 public void mapVectors(float[] vecs) { 706 mapVectors(vecs, 0, vecs, 0, vecs.length >> 1); 707 } 708 709 /** 710 * Apply this matrix to the src rectangle, and write the transformed 711 * rectangle into dst. This is accomplished by transforming the 4 corners of 712 * src, and then setting dst to the bounds of those points. 713 * 714 * @param dst Where the transformed rectangle is written. 715 * @param src The original rectangle to be transformed. 716 * @return the result of calling rectStaysRect() 717 */ 718 public boolean mapRect(RectF dst, RectF src) { 719 if (dst == null || src == null) { 720 throw new NullPointerException(); 721 } 722 return native_mapRect(native_instance, dst, src); 723 } 724 725 /** 726 * Apply this matrix to the rectangle, and write the transformed rectangle 727 * back into it. This is accomplished by transforming the 4 corners of rect, 728 * and then setting it to the bounds of those points 729 * 730 * @param rect The rectangle to transform. 731 * @return the result of calling rectStaysRect() 732 */ 733 public boolean mapRect(RectF rect) { 734 return mapRect(rect, rect); 735 } 736 737 /** 738 * Return the mean radius of a circle after it has been mapped by 739 * this matrix. NOTE: in perspective this value assumes the circle 740 * has its center at the origin. 741 */ 742 public float mapRadius(float radius) { 743 return native_mapRadius(native_instance, radius); 744 } 745 746 /** Copy 9 values from the matrix into the array. 747 */ 748 public void getValues(float[] values) { 749 if (values.length < 9) { 750 throw new ArrayIndexOutOfBoundsException(); 751 } 752 native_getValues(native_instance, values); 753 } 754 755 /** Copy 9 values from the array into the matrix. 756 Depending on the implementation of Matrix, these may be 757 transformed into 16.16 integers in the Matrix, such that 758 a subsequent call to getValues() will not yield exactly 759 the same values. 760 */ 761 public void setValues(float[] values) { 762 if (values.length < 9) { 763 throw new ArrayIndexOutOfBoundsException(); 764 } 765 native_setValues(native_instance, values); 766 } 767 768 @Override 769 public String toString() { 770 StringBuilder sb = new StringBuilder(64); 771 sb.append("Matrix{"); 772 toShortString(sb); 773 sb.append('}'); 774 return sb.toString(); 775 776 } 777 778 public String toShortString() { 779 StringBuilder sb = new StringBuilder(64); 780 toShortString(sb); 781 return sb.toString(); 782 } 783 784 /** 785 * @hide 786 */ 787 public void toShortString(StringBuilder sb) { 788 float[] values = new float[9]; 789 getValues(values); 790 sb.append('['); 791 sb.append(values[0]); sb.append(", "); sb.append(values[1]); sb.append(", "); 792 sb.append(values[2]); sb.append("]["); 793 sb.append(values[3]); sb.append(", "); sb.append(values[4]); sb.append(", "); 794 sb.append(values[5]); sb.append("]["); 795 sb.append(values[6]); sb.append(", "); sb.append(values[7]); sb.append(", "); 796 sb.append(values[8]); sb.append(']'); 797 } 798 799 /** 800 * Print short string, to optimize dumping. 801 * @hide 802 */ 803 public void printShortString(PrintWriter pw) { 804 float[] values = new float[9]; 805 getValues(values); 806 pw.print('['); 807 pw.print(values[0]); pw.print(", "); pw.print(values[1]); pw.print(", "); 808 pw.print(values[2]); pw.print("]["); 809 pw.print(values[3]); pw.print(", "); pw.print(values[4]); pw.print(", "); 810 pw.print(values[5]); pw.print("]["); 811 pw.print(values[6]); pw.print(", "); pw.print(values[7]); pw.print(", "); 812 pw.print(values[8]); pw.print(']'); 813 814 } 815 816 @Override 817 protected void finalize() throws Throwable { 818 try { 819 finalizer(native_instance); 820 } finally { 821 super.finalize(); 822 } 823 } 824 825 /*package*/ final long ni() { 826 return native_instance; 827 } 828 829 private static native long native_create(long native_src_or_zero); 830 private static native boolean native_isIdentity(long native_object); 831 private static native boolean native_rectStaysRect(long native_object); 832 private static native void native_reset(long native_object); 833 private static native void native_set(long native_object, 834 long native_other); 835 private static native void native_setTranslate(long native_object, 836 float dx, float dy); 837 private static native void native_setScale(long native_object, 838 float sx, float sy, float px, float py); 839 private static native void native_setScale(long native_object, 840 float sx, float sy); 841 private static native void native_setRotate(long native_object, 842 float degrees, float px, float py); 843 private static native void native_setRotate(long native_object, 844 float degrees); 845 private static native void native_setSinCos(long native_object, 846 float sinValue, float cosValue, float px, float py); 847 private static native void native_setSinCos(long native_object, 848 float sinValue, float cosValue); 849 private static native void native_setSkew(long native_object, 850 float kx, float ky, float px, float py); 851 private static native void native_setSkew(long native_object, 852 float kx, float ky); 853 private static native void native_setConcat(long native_object, 854 long native_a, 855 long native_b); 856 private static native void native_preTranslate(long native_object, 857 float dx, float dy); 858 private static native void native_preScale(long native_object, 859 float sx, float sy, float px, float py); 860 private static native void native_preScale(long native_object, 861 float sx, float sy); 862 private static native void native_preRotate(long native_object, 863 float degrees, float px, float py); 864 private static native void native_preRotate(long native_object, 865 float degrees); 866 private static native void native_preSkew(long native_object, 867 float kx, float ky, float px, float py); 868 private static native void native_preSkew(long native_object, 869 float kx, float ky); 870 private static native void native_preConcat(long native_object, 871 long native_other_matrix); 872 private static native void native_postTranslate(long native_object, 873 float dx, float dy); 874 private static native void native_postScale(long native_object, 875 float sx, float sy, float px, float py); 876 private static native void native_postScale(long native_object, 877 float sx, float sy); 878 private static native void native_postRotate(long native_object, 879 float degrees, float px, float py); 880 private static native void native_postRotate(long native_object, 881 float degrees); 882 private static native void native_postSkew(long native_object, 883 float kx, float ky, float px, float py); 884 private static native void native_postSkew(long native_object, 885 float kx, float ky); 886 private static native void native_postConcat(long native_object, 887 long native_other_matrix); 888 private static native boolean native_setRectToRect(long native_object, 889 RectF src, RectF dst, int stf); 890 private static native boolean native_setPolyToPoly(long native_object, 891 float[] src, int srcIndex, float[] dst, int dstIndex, int pointCount); 892 private static native boolean native_invert(long native_object, 893 long native_inverse); 894 private static native void native_mapPoints(long native_object, 895 float[] dst, int dstIndex, float[] src, int srcIndex, 896 int ptCount, boolean isPts); 897 private static native boolean native_mapRect(long native_object, 898 RectF dst, RectF src); 899 private static native float native_mapRadius(long native_object, 900 float radius); 901 private static native void native_getValues(long native_object, 902 float[] values); 903 private static native void native_setValues(long native_object, 904 float[] values); 905 private static native boolean native_equals(long native_a, long native_b); 906 private static native void finalizer(long native_instance); 907} 908