1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.scene.transform;
  27 
  28 import javafx.beans.Observable;
  29 import static test.javafx.scene.transform.TransformTest.assertTx;
  30 import javafx.scene.shape.Rectangle;
  31 
  32 import org.junit.Assert;
  33 import org.junit.Test;
  34 import static org.junit.Assert.*;
  35 
  36 import test.com.sun.javafx.test.TransformHelper;
  37 import com.sun.javafx.geom.transform.Affine2D;
  38 import com.sun.javafx.geom.transform.Affine3D;
  39 import com.sun.javafx.scene.transform.TransformUtils;
  40 import javafx.geometry.Point3D;
  41 import javafx.beans.InvalidationListener;
  42 import javafx.scene.transform.Affine;
  43 import javafx.scene.transform.MatrixType;
  44 import javafx.scene.transform.Rotate;
  45 import javafx.scene.transform.Transform;
  46 
  47 public class AffineTest {
  48 
  49     private static final double[] array2d = new double[] {
  50          0, 1,
  51          2,  3,  4,
  52          6,  7,  8,
  53          0,  0,  1 };
  54 
  55     private static final double[] array3d = new double[] {
  56          0, 1,
  57          2,  3,  4,  5,
  58          6,  7,  8,  9,
  59         10, 11, 12, 13,
  60          0,  0,  0,  1 };
  61 
  62     private static final double[] arrayZeros = new double[] {
  63          0, 0, 0, 0, 
  64          0, 0, 0, 0,
  65          0, 0, 0, 0,
  66          0, 0, 0, 0, 1, 0, 0, 0, 0 };
  67 
  68     @Test
  69     public void testTransformConstructor() {
  70         Rotate r = new Rotate(23, 11, 12, 13, new Point3D(10, 20, 30));
  71         Affine a = new Affine(r);
  72 
  73         TransformHelper.assertMatrix(a, r);
  74     }
  75 
  76     @Test(expected=NullPointerException.class)
  77     public void testTransformConstructorNull() {
  78         Affine a = new Affine(null);
  79     }
  80 
  81     @Test
  82     public void test2DConstructor() {
  83         Affine a = new Affine(2, 3, 4, 5, 6, 7);
  84 
  85         TransformHelper.assertMatrix(a,
  86                 2, 3, 0, 4,
  87                 5, 6, 0, 7,
  88                 0, 0, 1, 0);
  89     }
  90 
  91     @Test
  92     public void test3DConstructor() {
  93         Affine a = new Affine( 2,  3,  4,  5,
  94                                6,  7,  8,  9,
  95                               10, 11, 12, 13);
  96 
  97         TransformHelper.assertMatrix(a,
  98                  2,  3,  4,  5,
  99                  6,  7,  8,  9,
 100                 10, 11, 12, 13);
 101     }
 102 
 103     @Test
 104     public void testArrayConstructor() {
 105 
 106         Affine a = new Affine(array2d, MatrixType.MT_2D_2x3, 2);
 107         TransformHelper.assertMatrix(a,
 108                 2,  3,  0,  4,
 109                 6,  7,  0,  8,
 110                 0,  0,  1,  0);
 111 
 112         a = new Affine(array2d, MatrixType.MT_2D_3x3, 2);
 113         TransformHelper.assertMatrix(a,
 114                 2,  3,  0,  4,
 115                 6,  7,  0,  8,
 116                 0,  0,  1,  0);
 117 
 118         a = new Affine(array3d, MatrixType.MT_3D_3x4, 2);
 119         TransformHelper.assertMatrix(a,
 120                 2,  3,  4,  5,
 121                 6,  7,  8,  9,
 122                10, 11, 12, 13);
 123 
 124         a = new Affine(array3d, MatrixType.MT_3D_4x4, 2);
 125         TransformHelper.assertMatrix(a,
 126                 2,  3,  4,  5,
 127                 6,  7,  8,  9,
 128                10, 11, 12, 13);
 129     }
 130 
 131     @Test(expected=NullPointerException.class)
 132     public void testArrayConstructorNullMatrix() {
 133         Affine a = new Affine(null, MatrixType.MT_2D_2x3, 6);
 134     }
 135 
 136     @Test(expected=NullPointerException.class)
 137     public void testArrayConstructorNullType() {
 138         Affine a = new Affine(array2d, null, 6);
 139     }
 140 
 141     @Test(expected=IndexOutOfBoundsException.class)
 142     public void testArrayConstructor2x3ShortArray() {
 143         Affine a = new Affine(array2d, MatrixType.MT_2D_2x3, 6);
 144     }
 145 
 146     @Test(expected=IndexOutOfBoundsException.class)
 147     public void testArrayConstructor3x3ShortArray() {
 148         Affine a = new Affine(array2d, MatrixType.MT_2D_3x3, 4);
 149     }
 150 
 151     @Test(expected=IndexOutOfBoundsException.class)
 152     public void testArrayConstructor3x4ShortArray() {
 153         Affine a = new Affine(array3d, MatrixType.MT_3D_3x4, 7);
 154     }
 155 
 156     @Test(expected=IndexOutOfBoundsException.class)
 157     public void testArrayConstructor4x4ShortArray() {
 158         Affine a = new Affine(array3d, MatrixType.MT_3D_4x4, 4);
 159     }
 160 
 161     @Test(expected=IllegalArgumentException.class)
 162     public void testArrayConstructor3x3NotAffineX() {
 163         Affine a = new Affine(arrayZeros, MatrixType.MT_2D_3x3, 10);
 164     }
 165 
 166     @Test(expected=IllegalArgumentException.class)
 167     public void testArrayConstructor3x3NotAffineY() {
 168         Affine a = new Affine(arrayZeros, MatrixType.MT_2D_3x3, 9);
 169     }
 170 
 171     @Test(expected=IllegalArgumentException.class)
 172     public void testArrayConstructor3x3NotAffineT() {
 173         Affine a = new Affine(arrayZeros, MatrixType.MT_2D_3x3, 0);
 174     }
 175 
 176     @Test(expected=IllegalArgumentException.class)
 177     public void testArrayConstructor4x4NotAffineX() {
 178         Affine a = new Affine(arrayZeros, MatrixType.MT_3D_4x4, 4);
 179     }
 180 
 181     @Test(expected=IllegalArgumentException.class)
 182     public void testArrayConstructor4x4NotAffineY() {
 183         Affine a = new Affine(arrayZeros, MatrixType.MT_3D_4x4, 3);
 184     }
 185 
 186     @Test(expected=IllegalArgumentException.class)
 187     public void testArrayConstructor4x4NotAffineZ() {
 188         Affine a = new Affine(arrayZeros, MatrixType.MT_3D_4x4, 2);
 189     }
 190 
 191     @Test(expected=IllegalArgumentException.class)
 192     public void testArrayConstructor4x4NotAffineT() {
 193         Affine a = new Affine(arrayZeros, MatrixType.MT_3D_4x4, 0);
 194     }
 195 
 196     @Test
 197     public void testTransformSetToTransform() {
 198         Rotate r = new Rotate(23, 11, 12, 13, new Point3D(10, 20, 30));
 199         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 200 
 201         a.setToTransform(r);
 202         TransformHelper.assertMatrix(a, r);
 203     }
 204 
 205     @Test(expected=NullPointerException.class)
 206     public void testTransformSetToTransformNull() {
 207         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 208         a.setToTransform(null);
 209     }
 210 
 211     @Test
 212     public void test2DSetToTransform() {
 213         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 214         a.setToTransform(2, 3, 4, 5, 6, 7);
 215 
 216         TransformHelper.assertMatrix(a,
 217                 2, 3, 0, 4,
 218                 5, 6, 0, 7,
 219                 0, 0, 1, 0);
 220     }
 221 
 222     @Test
 223     public void test3DSetToTransform() {
 224         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 225         a.setToTransform( 2,  3,  4,  5,
 226                           6,  7,  8,  9,
 227                          10, 11, 12, 13);
 228 
 229         TransformHelper.assertMatrix(a,
 230                  2,  3,  4,  5,
 231                  6,  7,  8,  9,
 232                 10, 11, 12, 13);
 233     }
 234 
 235     @Test
 236     public void testArraySetToTransform() {
 237 
 238         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 239         a.setToTransform(array2d, MatrixType.MT_2D_2x3, 2);
 240         TransformHelper.assertMatrix(a,
 241                 2,  3,  0,  4,
 242                 6,  7,  0,  8,
 243                 0,  0,  1,  0);
 244 
 245         a = new Affine(1, 2, 3, 6, 7, 128);
 246         a.setToTransform(array2d, MatrixType.MT_2D_3x3, 2);
 247         TransformHelper.assertMatrix(a,
 248                 2,  3,  0,  4,
 249                 6,  7,  0,  8,
 250                 0,  0,  1,  0);
 251 
 252         a = new Affine(1, 2, 3, 6, 7, 128);
 253         a.setToTransform(array3d, MatrixType.MT_3D_3x4, 2);
 254         TransformHelper.assertMatrix(a,
 255                 2,  3,  4,  5,
 256                 6,  7,  8,  9,
 257                10, 11, 12, 13);
 258 
 259         a = new Affine(1, 2, 3, 6, 7, 128);
 260         a.setToTransform(array3d, MatrixType.MT_3D_4x4, 2);
 261         TransformHelper.assertMatrix(a,
 262                 2,  3,  4,  5,
 263                 6,  7,  8,  9,
 264                10, 11, 12, 13);
 265     }
 266 
 267     @Test(expected=NullPointerException.class)
 268     public void testArraySetToTransformNullMatrix() {
 269         Affine a = new Affine();
 270         a.setToTransform(new double[] { 1, 2, 3 }, null, 0);
 271     }
 272 
 273     @Test(expected=NullPointerException.class)
 274     public void testArraySetToTransformNullType() {
 275         Affine a = new Affine();
 276         a.setToTransform(null, MatrixType.MT_2D_2x3, 0);
 277     }
 278 
 279     @Test(expected=IndexOutOfBoundsException.class)
 280     public void testArraySetToTransform2x3ShortArray() {
 281         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 282         try {
 283             a.setToTransform(array2d, MatrixType.MT_2D_2x3, 6);
 284         } catch(IndexOutOfBoundsException e) {
 285             TransformHelper.assertMatrix(a,
 286                     1, 2, 0, 3,
 287                     6, 7, 0, 128,
 288                     0, 0, 1, 0);
 289             throw e;
 290         }
 291     }
 292 
 293     @Test(expected=IndexOutOfBoundsException.class)
 294     public void testArraySetToTransform3x3ShortArray() {
 295         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 296         try {
 297             a.setToTransform(array2d, MatrixType.MT_2D_3x3, 4);
 298         } catch(IndexOutOfBoundsException e) {
 299             TransformHelper.assertMatrix(a,
 300                     1, 2, 0, 3,
 301                     6, 7, 0, 128,
 302                     0, 0, 1, 0);
 303             throw e;
 304         }
 305     }
 306 
 307     @Test(expected=IndexOutOfBoundsException.class)
 308     public void testArraySetToTransform3x4ShortArray() {
 309         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 310         try {
 311             a.setToTransform(array3d, MatrixType.MT_3D_3x4, 7);
 312         } catch(IndexOutOfBoundsException e) {
 313             TransformHelper.assertMatrix(a,
 314                     1, 2, 0, 3,
 315                     6, 7, 0, 128,
 316                     0, 0, 1, 0);
 317             throw e;
 318         }
 319     }
 320 
 321     @Test(expected=IndexOutOfBoundsException.class)
 322     public void testArraySetToTransform4x4ShortArray() {
 323         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 324         try {
 325             a.setToTransform(array3d, MatrixType.MT_3D_4x4, 4);
 326         } catch(IndexOutOfBoundsException e) {
 327             TransformHelper.assertMatrix(a,
 328                     1, 2, 0, 3,
 329                     6, 7, 0, 128,
 330                     0, 0, 1, 0);
 331             throw e;
 332         }
 333     }
 334 
 335     @Test(expected=IllegalArgumentException.class)
 336     public void testArraySetToTransform3x3NotAffineX() {
 337         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 338         try {
 339             a.setToTransform(arrayZeros, MatrixType.MT_2D_3x3, 10);
 340         } catch(IllegalArgumentException e) {
 341             TransformHelper.assertMatrix(a,
 342                     1, 2, 0, 3,
 343                     6, 7, 0, 128,
 344                     0, 0, 1, 0);
 345             throw e;
 346         }
 347     }
 348 
 349     @Test(expected=IllegalArgumentException.class)
 350     public void testArraySetToTransform3x3NotAffineY() {
 351         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 352         try {
 353             a.setToTransform(arrayZeros, MatrixType.MT_2D_3x3, 9);
 354         } catch(IllegalArgumentException e) {
 355             TransformHelper.assertMatrix(a,
 356                     1, 2, 0, 3,
 357                     6, 7, 0, 128,
 358                     0, 0, 1, 0);
 359             throw e;
 360         }
 361     }
 362 
 363     @Test(expected=IllegalArgumentException.class)
 364     public void testArraySetToTransform3x3NotAffineT() {
 365         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 366         try {
 367             a.setToTransform(arrayZeros, MatrixType.MT_2D_3x3, 0);
 368         } catch(IllegalArgumentException e) {
 369             TransformHelper.assertMatrix(a,
 370                     1, 2, 0, 3,
 371                     6, 7, 0, 128,
 372                     0, 0, 1, 0);
 373             throw e;
 374         }
 375     }
 376 
 377     @Test(expected=IllegalArgumentException.class)
 378     public void testArraySetToTransform4x4NotAffineX() {
 379         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 380         try {
 381             a.setToTransform(arrayZeros, MatrixType.MT_3D_4x4, 4);
 382         } catch(IllegalArgumentException e) {
 383             TransformHelper.assertMatrix(a,
 384                     1, 2, 0, 3,
 385                     6, 7, 0, 128,
 386                     0, 0, 1, 0);
 387             throw e;
 388         }
 389     }
 390 
 391     @Test(expected=IllegalArgumentException.class)
 392     public void testArraySetToTransform4x4NotAffineY() {
 393         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 394         try {
 395             a.setToTransform(arrayZeros, MatrixType.MT_3D_4x4, 3);
 396         } catch(IllegalArgumentException e) {
 397             TransformHelper.assertMatrix(a,
 398                     1, 2, 0, 3,
 399                     6, 7, 0, 128,
 400                     0, 0, 1, 0);
 401             throw e;
 402         }
 403     }
 404 
 405     @Test(expected=IllegalArgumentException.class)
 406     public void testArraySetToTransform4x4NotAffineZ() {
 407         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 408         try {
 409             a.setToTransform(arrayZeros, MatrixType.MT_3D_4x4, 2);
 410         } catch(IllegalArgumentException e) {
 411             TransformHelper.assertMatrix(a,
 412                     1, 2, 0, 3,
 413                     6, 7, 0, 128,
 414                     0, 0, 1, 0);
 415             throw e;
 416         }
 417     }
 418 
 419     @Test(expected=IllegalArgumentException.class)
 420     public void testArraySetToTransform4x4NotAffineT() {
 421         Affine a = new Affine(1, 2, 3, 6, 7, 128);
 422         try {
 423             a.setToTransform(arrayZeros, MatrixType.MT_3D_4x4, 0);
 424         } catch(IllegalArgumentException e) {
 425             TransformHelper.assertMatrix(a,
 426                     1, 2, 0, 3,
 427                     6, 7, 0, 128,
 428                     0, 0, 1, 0);
 429             throw e;
 430         }
 431     }
 432 
 433     private int listenerCounter;
 434     private class ElementListener implements InvalidationListener {
 435 
 436         private boolean called = false;
 437 
 438         @Override
 439         public void invalidated(Observable observable) {
 440             if (called) {
 441                 fail("Element listener notified twice");
 442             }
 443             called = true;
 444             listenerCounter++;
 445         }
 446     }
 447 
 448     @Test
 449     public void everybodyShouldBeNotifiedAfterAtomicChange() {
 450         final Affine a = new Affine();
 451 
 452         a.mxxProperty().addListener(new ElementListener());
 453         a.mxyProperty().addListener(new ElementListener());
 454         a.mxzProperty().addListener(new ElementListener());
 455         a.txProperty().addListener(new ElementListener());
 456         a.myxProperty().addListener(new ElementListener());
 457         a.myyProperty().addListener(new ElementListener());
 458         a.myzProperty().addListener(new ElementListener());
 459         a.tyProperty().addListener(new ElementListener());
 460         a.mzxProperty().addListener(new ElementListener());
 461         a.mzyProperty().addListener(new ElementListener());
 462         a.mzzProperty().addListener(new ElementListener());
 463         a.tzProperty().addListener(new ElementListener());
 464 
 465         listenerCounter = 0;
 466         a.setToTransform( 2,  3,  4,  5,
 467                           6,  7,  8,  9,
 468                          10, 11, 12, 13);
 469 
 470         assertEquals(12, listenerCounter);
 471     }
 472 
 473     @Test
 474     public void atomicChangeShouldnotifyOnlyChangedMembers() {
 475         final Affine a = new Affine();
 476 
 477         a.mxxProperty().addListener(new ElementListener());
 478         a.mxyProperty().addListener(new ElementListener());
 479         a.mxzProperty().addListener(new ElementListener());
 480         a.txProperty().addListener(new ElementListener());
 481         a.myxProperty().addListener(new ElementListener());
 482         a.myyProperty().addListener(new ElementListener());
 483         a.myzProperty().addListener(new ElementListener());
 484         a.tyProperty().addListener(new ElementListener());
 485         a.mzxProperty().addListener(new ElementListener());
 486         a.mzyProperty().addListener(new ElementListener());
 487         a.mzzProperty().addListener(new ElementListener());
 488         a.tzProperty().addListener(new ElementListener());
 489 
 490         listenerCounter = 0;
 491         a.setToTransform( 2,  3,  0,  5,
 492                           6,  7,  8,  0,
 493                          10, 11,  1, 13);
 494 
 495         assertEquals(9, listenerCounter);
 496     }
 497 
 498     @Test
 499     public void testRepeatedAtomicChangeNotifications() {
 500         final Affine a = new Affine();
 501 
 502         a.mxxProperty().addListener(observable -> {
 503             a.getMxx();
 504             listenerCounter++;
 505         });
 506 
 507         a.tyProperty().addListener(observable -> {
 508             a.getTy();
 509             listenerCounter++;
 510         });
 511 
 512         listenerCounter = 0;
 513         a.setToTransform( 2,  3,  4,  5,
 514                           6,  7,  8,  9,
 515                          10, 11, 12, 13);
 516         assertEquals(2, listenerCounter);
 517 
 518         a.setToTransform( 3,  5,  6,  5,
 519                           6,  5,  6,  9,
 520                          10, 11,  9, 13);
 521         assertEquals(3, listenerCounter);
 522 
 523         a.setToTransform( 3,  5,  6,  5,
 524                           6,  7,  6, 11,
 525                          10, 11,  9, 13);
 526         assertEquals(4, listenerCounter);
 527 
 528         a.setToTransform( 3,  5,  7,  5,
 529                           6,  8,  6, 11,
 530                          10, 52,  9, 13);
 531         assertEquals(4, listenerCounter);
 532     }
 533 
 534     @Test
 535     public void atomicChangeBackAndForthShouldNotNotify() {
 536         final Affine a = new Affine();
 537 
 538         a.txProperty().addListener(observable -> {
 539             a.getTx();
 540             listenerCounter++;
 541         });
 542 
 543         listenerCounter = 0;
 544         a.appendScale(1.0, 2.0, 1.0, 45, 0, 60);
 545 
 546         assertEquals(0, listenerCounter);
 547     }
 548 
 549     @Test
 550     public void recursiveAtomicChangeShouldBeFine() {
 551         final Affine a = new Affine();
 552 
 553         a.tyProperty().addListener(observable -> a.setToTransform( 3,  4,  5,  6,
 554                           7,  8, 10,  9,
 555                          11, 12, 13, 14));
 556 
 557         listenerCounter = 0;
 558         a.setToTransform( 2,  3,  4,  5,
 559                           6,  7,  8,  9,
 560                          10, 11, 12, 13);
 561 
 562         TransformHelper.assertMatrix(a,  3,  4,  5,  6,
 563                                          7,  8, 10,  9,
 564                                         11, 12, 13, 14);
 565     }
 566 
 567     @Test
 568     public void testAffine() {
 569         final Affine trans = new Affine() {{
 570             setMxx(11);
 571             setMyx(22);
 572             setMxy(33);
 573             setMyy(44);
 574             setTx(55);
 575             setTy(66);
 576         }};
 577         Assert.assertEquals(1.0f, trans.getMzz(), 1e-50);
 578 
 579         final Rectangle n = new Rectangle();
 580         n.getTransforms().add(trans);
 581 
 582         final Affine2D affine2D = new Affine2D(11, 22, 33, 44, 55, 66);
 583         Assert.assertEquals(1, affine2D.getMzz(), 1e-50);
 584         final Affine3D affine3D = new Affine3D(affine2D);
 585         Assert.assertEquals(1, affine3D.getMzz(), 1e-50);
 586         assertTx(n, affine3D);
 587 
 588         trans.setMxx(10);
 589         assertTx(n, new Affine2D(10, 22, 33, 44, 55, 66));
 590 
 591         trans.setMyx(21);
 592         assertTx(n, new Affine2D(10, 21, 33, 44, 55, 66));
 593 
 594         trans.setMxy(32);
 595         assertTx(n, new Affine2D(10, 21, 32, 44, 55, 66));
 596 
 597         trans.setMyy(43);
 598         assertTx(n, new Affine2D(10, 21, 32, 43, 55, 66));
 599 
 600         trans.setTx(54);
 601         assertTx(n, new Affine2D(10, 21, 32, 43, 54, 66));
 602 
 603         trans.setTy(65);
 604         assertTx(n, new Affine2D(10, 21, 32, 43, 54, 65));
 605     }
 606 
 607     @Test public void testGetters() {
 608         final Affine trans = new Affine(
 609                 0.5,  2,  3,  4,
 610                 5,  6,  7,  8,
 611                 9, 10, 11, 12);
 612         TransformHelper.assertMatrix(trans,
 613                 0.5,  2,  3,  4,
 614                 5,  6,  7,  8,
 615                 9, 10, 11, 12);
 616 
 617         trans.setMxx(12);
 618         trans.setMxy(11);
 619         trans.setMxz(10);
 620         trans.setTx(9);
 621         trans.setMyx(8);
 622         trans.setMyy(7);
 623         trans.setMyz(6);
 624         trans.setTy(5);
 625         trans.setMzx(4);
 626         trans.setMzy(3);
 627         trans.setMzz(2);
 628         trans.setTz(1);
 629 
 630         TransformHelper.assertMatrix(trans,
 631                 12, 11, 10, 9,
 632                  8,  7,  6, 5,
 633                  4,  3,  2, 1);
 634     }
 635 
 636     @Test public void testConstructingIdentityTransform() {
 637         final Affine trans = new Affine(
 638                 1, 0, 0, 0,
 639                 0, 1, 0, 0,
 640                 0, 0, 1, 0);
 641 
 642         TransformHelper.assertMatrix(trans,
 643                 1, 0, 0, 0,
 644                 0, 1, 0, 0,
 645                 0, 0, 1, 0);
 646 
 647         trans.setMxx(12);
 648         trans.setMxy(11);
 649         trans.setMxz(10);
 650         trans.setTx(9);
 651         trans.setMyx(8);
 652         trans.setMyy(7);
 653         trans.setMyz(6);
 654         trans.setTy(5);
 655         trans.setMzx(4);
 656         trans.setMzy(3);
 657         trans.setMzz(2);
 658         trans.setTz(1);
 659 
 660         TransformHelper.assertMatrix(trans,
 661                 12, 11, 10, 9,
 662                  8,  7,  6, 5,
 663                  4,  3,  2, 1);
 664     }
 665 
 666     @Test public void testSettingTransform() {
 667         final Affine trans = new Affine(
 668                 1,  2,  3,  4,
 669                 5,  6,  7,  8,
 670                 9, 10, 11, 12);
 671 
 672         TransformHelper.assertMatrix(trans,
 673                 1,  2,  3,  4,
 674                 5,  6,  7,  8,
 675                 9, 10, 11, 12);
 676 
 677         Transform it = TransformUtils.immutableTransform(
 678                 12, 11, 10, 9,
 679                  8,  7,  6, 5,
 680                  4,  3,  2, 1);
 681 
 682         trans.setToTransform(it);
 683 
 684         TransformHelper.assertMatrix(trans,
 685                 12, 11, 10, 9,
 686                  8,  7,  6, 5,
 687                  4,  3,  2, 1);
 688     }
 689 
 690     @Test
 691     public void testCopying() {
 692         final Affine trans = new Affine(
 693                 1,  2,  3,  4,
 694                 5,  6,  7,  8,
 695                 9, 10, 11, 12);
 696 
 697         Transform copy = trans.clone();
 698 
 699         TransformHelper.assertMatrix(copy,
 700                 1,  2,  3,  4,
 701                 5,  6,  7,  8,
 702                 9, 10, 11, 12);
 703 
 704         trans.setMxz(1234);
 705         assertEquals(3.0, copy.getMxz(), 0.0001);
 706     }
 707 
 708     @Test public void testToString() {
 709         final Affine trans = new Affine(
 710                 1,  2,  3,  4,
 711                 5,  6,  7,  8,
 712                 9, 10, 11, 12);
 713 
 714         String s = trans.toString();
 715 
 716         assertNotNull(s);
 717         assertFalse(s.isEmpty());
 718     }
 719 
 720     @Test public void testBoundPropertySynced() throws Exception {
 721 
 722         TransformTest.checkDoublePropertySynced(createTransform(), "mxx" , 2.0);
 723         TransformTest.checkDoublePropertySynced(createTransform(), "myx" , 2.0);
 724         TransformTest.checkDoublePropertySynced(createTransform(), "mxy" , 2.0);
 725         TransformTest.checkDoublePropertySynced(createTransform(), "mxz" , 2.0);
 726         TransformTest.checkDoublePropertySynced(createTransform(), "myy" , 2.0);
 727         TransformTest.checkDoublePropertySynced(createTransform(), "myz" , 2.0);
 728         TransformTest.checkDoublePropertySynced(createTransform(), "mzx" , 2.0);
 729         TransformTest.checkDoublePropertySynced(createTransform(), "mzy" , 2.0);
 730         TransformTest.checkDoublePropertySynced(createTransform(), "mzz" , 2.0);
 731         TransformTest.checkDoublePropertySynced(createTransform(), "tx" , 2.0);
 732         TransformTest.checkDoublePropertySynced(createTransform(), "ty" , 2.0);
 733         TransformTest.checkDoublePropertySynced(createTransform(), "tz" , 2.0);
 734     }
 735 
 736     private Affine createTransform() {
 737         final Affine trans = new Affine() {{
 738             setMxx(11);
 739             setMyx(22);
 740             setMxy(33);
 741             setMyy(44);
 742             setTx(55);
 743             setTy(66);
 744         }};
 745         return trans;
 746     }
 747 }