コード例 #1
0
  @Test
  public void testScalePivotCtor() {
    final Scale trans = new Scale(11, 22, 33, 44);
    final Rectangle n = new Rectangle();
    n.getTransforms().add(trans);

    Affine2D expT = new Affine2D();
    expT.translate(33, 44);
    expT.scale(11, 22);
    expT.translate(-33, -44);
    assertTx(n, expT);
  }
コード例 #2
0
  @Test
  public void testScale() {
    final Scale trans =
        new Scale() {
          {
            setX(25);
            setY(52);
          }
        };
    final Rectangle n = new Rectangle();
    n.getTransforms().add(trans);

    assertTx(n, BaseTransform.getScaleInstance(25, 52));
    TransformHelper.assertMatrix(trans, 25, 0, 0, 0, 0, 52, 0, 0, 0, 0, 1, 0);

    trans.setX(34);
    Assert.assertEquals(34, trans.getX(), 1e-100);
    assertTx(n, BaseTransform.getScaleInstance(34, 52));
    TransformHelper.assertMatrix(trans, 34, 0, 0, 0, 0, 52, 0, 0, 0, 0, 1, 0);

    trans.setY(67);
    assertTx(n, BaseTransform.getScaleInstance(34, 67));
    TransformHelper.assertMatrix(trans, 34, 0, 0, 0, 0, 67, 0, 0, 0, 0, 1, 0);

    trans.setPivotX(66);

    Affine2D expTx = new Affine2D();
    expTx.setToTranslation(trans.getPivotX(), trans.getPivotY());
    expTx.scale(trans.getX(), trans.getY());
    expTx.translate(-trans.getPivotX(), -trans.getPivotY());
    assertTx(n, expTx);
    TransformHelper.assertMatrix(trans, 34, 0, 0, -2178, 0, 67, 0, 0, 0, 0, 1, 0);

    trans.setPivotY(77);

    expTx.setToTranslation(trans.getPivotX(), trans.getPivotY());
    expTx.scale(trans.getX(), trans.getY());
    expTx.translate(-trans.getPivotX(), -trans.getPivotY());
    assertTx(n, expTx);
    TransformHelper.assertMatrix(trans, 34, 0, 0, -2178, 0, 67, 0, -5082, 0, 0, 1, 0);

    trans.setZ(10);
    trans.setPivotZ(5);
    TransformHelper.assertMatrix(trans, 34, 0, 0, -2178, 0, 67, 0, -5082, 0, 0, 10, -45);
  }