--- old/modules/graphics/src/main/java/com/sun/javafx/scene/SceneUtils.java 2016-05-03 23:06:38.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/javafx/scene/SceneUtils.java 2016-05-03 23:06:38.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -122,7 +122,7 @@ // // // convert it to node's local pickRay // final Affine3D localToSceneTx = new Affine3D(); -// n.getLocalToSceneTransform().impl_apply(localToSceneTx); +// TransformHelper.apply(n.getLocalToSceneTransform(), localToSceneTx); // try { // Vec3d origin = pickRay.getOriginNoClone(); // Vec3d direction = pickRay.getDirectionNoClone(); --- old/modules/graphics/src/main/java/com/sun/javafx/scene/transform/TransformUtils.java 2016-05-03 23:06:39.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/javafx/scene/transform/TransformUtils.java 2016-05-03 23:06:39.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,14 +25,7 @@ package com.sun.javafx.scene.transform; -import com.sun.javafx.geom.transform.Affine2D; -import com.sun.javafx.geom.transform.Affine3D; -import com.sun.javafx.geom.transform.BaseTransform; -import javafx.geometry.Point2D; -import javafx.geometry.Point3D; -import javafx.scene.transform.NonInvertibleTransformException; import javafx.scene.transform.Transform; -import javafx.scene.transform.Affine; /** * Internal utilities for transformations @@ -48,7 +41,7 @@ double mxx, double mxy, double mxz, double tx, double myx, double myy, double myz, double ty, double mzx, double mzy, double mzz, double tz) { - return new ImmutableTransform( + return TransformHelper.createImmutableTransform( mxx, mxy, mxz, tx, myx, myy, myz, ty, mzx, mzy, mzz, tz); @@ -61,7 +54,7 @@ * class. */ public static Transform immutableTransform(Transform t) { - return new ImmutableTransform( + return TransformHelper.createImmutableTransform( t.getMxx(), t.getMxy(), t.getMxz(), t.getTx(), t.getMyx(), t.getMyy(), t.getMyz(), t.getTy(), t.getMzx(), t.getMzy(), t.getMzz(), t.getTz()); @@ -80,18 +73,10 @@ double myx, double myy, double myz, double ty, double mzx, double mzy, double mzz, double tz) { - if (reuse == null) { - return new ImmutableTransform( + return TransformHelper.createImmutableTransform(reuse, mxx, mxy, mxz, tx, myx, myy, myz, ty, mzx, mzy, mzz, tz); - } - - ((ImmutableTransform) reuse).setToTransform( - mxx, mxy, mxz, tx, - myx, myy, myz, ty, - mzx, mzy, mzz, tz); - return reuse; } /** @@ -105,7 +90,7 @@ */ public static Transform immutableTransform(Transform reuse, Transform t) { - return immutableTransform((ImmutableTransform) reuse, + return TransformHelper.createImmutableTransform(reuse, t.getMxx(), t.getMxy(), t.getMxz(), t.getTx(), t.getMyx(), t.getMyy(), t.getMyz(), t.getTy(), t.getMzx(), t.getMzy(), t.getMzz(), t.getTz()); @@ -123,751 +108,7 @@ public static Transform immutableTransform(Transform reuse, Transform left, Transform right) { - if (reuse == null) { - reuse = new ImmutableTransform(); - } - - ((ImmutableTransform) reuse).setToConcatenation( - (ImmutableTransform) left, ((ImmutableTransform) right)); - - return reuse; + return TransformHelper.createImmutableTransform(reuse, left, right); } - /** - * Immutable transformation with performance optimizations based on Affine. - * - * From user's perspective, this transform is immutable. However, we can - * modify it internally. This allows for reusing instances that were - * not handed to users. The caller is responsible for not modifying - * user-visible instances. - * - * Note: can't override Transform's package private methods so they cannot - * be optimized. Currently not a big deal. - */ - static class ImmutableTransform extends Transform { - - private static final int APPLY_IDENTITY = 0; - private static final int APPLY_TRANSLATE = 1; - private static final int APPLY_SCALE = 2; - private static final int APPLY_SHEAR = 4; - private static final int APPLY_NON_3D = 0; - private static final int APPLY_3D_COMPLEX = 4; - private transient int state2d; - private transient int state3d; - - private double xx; - private double xy; - private double xz; - private double yx; - private double yy; - private double yz; - private double zx; - private double zy; - private double zz; - private double xt; - private double yt; - private double zt; - - public ImmutableTransform() { - xx = yy = zz = 1.0; - } - - public ImmutableTransform(Transform transform) { - this(transform.getMxx(), transform.getMxy(), transform.getMxz(), - transform.getTx(), - transform.getMyx(), transform.getMyy(), transform.getMyz(), - transform.getTy(), - transform.getMzx(), transform.getMzy(), transform.getMzz(), - transform.getTz()); - } - - public ImmutableTransform(double mxx, double mxy, double mxz, double tx, - double myx, double myy, double myz, double ty, - double mzx, double mzy, double mzz, double tz) { - xx = mxx; - xy = mxy; - xz = mxz; - xt = tx; - - yx = myx; - yy = myy; - yz = myz; - yt = ty; - - zx = mzx; - zy = mzy; - zz = mzz; - zt = tz; - - updateState(); - } - - // Beware: this is modifying immutable transform! - // It is private and it is there just for the purpose of reusing - // instances not given to users - private void setToTransform(double mxx, double mxy, double mxz, double tx, - double myx, double myy, double myz, double ty, - double mzx, double mzy, double mzz, double tz) - { - xx = mxx; - xy = mxy; - xz = mxz; - xt = tx; - yx = myx; - yy = myy; - yz = myz; - yt = ty; - zx = mzx; - zy = mzy; - zz = mzz; - zt = tz; - updateState(); - } - - // Beware: this is modifying immutable transform! - // It is private and it is there just for the purpose of reusing - // instances not given to users - private void setToConcatenation(ImmutableTransform left, ImmutableTransform right) { - if (left.state3d == APPLY_NON_3D && right.state3d == APPLY_NON_3D) { - xx = left.xx * right.xx + left.xy * right.yx; - xy = left.xx * right.xy + left.xy * right.yy; - xt = left.xx * right.xt + left.xy * right.yt + left.xt; - yx = left.yx * right.xx + left.yy * right.yx; - yy = left.yx * right.xy + left.yy * right.yy; - yt = left.yx * right.xt + left.yy * right.yt + left.yt; - if (state3d != APPLY_NON_3D) { - xz = yz = zx = zy = zt = 0.0; - zz = 1.0; - state3d = APPLY_NON_3D; - } - updateState2D(); - } else { - xx = left.xx * right.xx + left.xy * right.yx + left.xz * right.zx; - xy = left.xx * right.xy + left.xy * right.yy + left.xz * right.zy; - xz = left.xx * right.xz + left.xy * right.yz + left.xz * right.zz; - xt = left.xx * right.xt + left.xy * right.yt + left.xz * right.zt + left.xt; - yx = left.yx * right.xx + left.yy * right.yx + left.yz * right.zx; - yy = left.yx * right.xy + left.yy * right.yy + left.yz * right.zy; - yz = left.yx * right.xz + left.yy * right.yz + left.yz * right.zz; - yt = left.yx * right.xt + left.yy * right.yt + left.yz * right.zt + left.yt; - zx = left.zx * right.xx + left.zy * right.yx + left.zz * right.zx; - zy = left.zx * right.xy + left.zy * right.yy + left.zz * right.zy; - zz = left.zx * right.xz + left.zy * right.yz + left.zz * right.zz; - zt = left.zx * right.xt + left.zy * right.yt + left.zz * right.zt + left.zt; - updateState(); - } - // could be further optimized using the states, but that would - // require a lot of code (see Affine and all its append* methods) - } - - @Override - public double getMxx() { - return xx; - } - - @Override - public double getMxy() { - return xy; - } - - @Override - public double getMxz() { - return xz; - } - - @Override - public double getTx() { - return xt; - } - - @Override - public double getMyx() { - return yx; - } - - @Override - public double getMyy() { - return yy; - } - - @Override - public double getMyz() { - return yz; - } - - @Override - public double getTy() { - return yt; - } - - @Override - public double getMzx() { - return zx; - } - - @Override - public double getMzy() { - return zy; - } - - @Override - public double getMzz() { - return zz; - } - - @Override - public double getTz() { - return zt; - } - - /* ************************************************************************* - * * - * State getters * - * * - **************************************************************************/ - - @Override - public double determinant() { - switch(state3d) { - default: - stateError(); - // cannot reach - case APPLY_NON_3D: - switch (state2d) { - default: - stateError(); - // cannot reach - case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SHEAR | APPLY_SCALE: - return xx * yy - xy * yx; - case APPLY_SHEAR | APPLY_TRANSLATE: - case APPLY_SHEAR: - return -(xy* yx); - case APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SCALE: - return xx * yy; - case APPLY_TRANSLATE: - case APPLY_IDENTITY: - return 1.0; - } - case APPLY_TRANSLATE: - return 1.0; - case APPLY_SCALE: - case APPLY_SCALE | APPLY_TRANSLATE: - return xx * yy * zz; - case APPLY_3D_COMPLEX: - return (xx* (yy * zz - zy * yz) + - xy* (yz * zx - zz * yx) + - xz* (yx * zy - zx * yy)); - } - } - - @Override - public Transform createConcatenation(Transform transform) { - javafx.scene.transform.Affine a = new Affine(this); - a.append(transform); - return a; - } - - @Override - public javafx.scene.transform.Affine createInverse() throws NonInvertibleTransformException { - javafx.scene.transform.Affine t = new Affine(this); - t.invert(); - return t; - } - - @Override - public Transform clone() { - return new ImmutableTransform(this); - } - - /* ************************************************************************* - * * - * Transform, Inverse Transform * - * * - **************************************************************************/ - - @Override - public Point2D transform(double x, double y) { - ensureCanTransform2DPoint(); - - switch (state2d) { - default: - stateError(); - // cannot reach - case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: - return new Point2D( - xx * x + xy * y + xt, - yx * x + yy * y + yt); - case APPLY_SHEAR | APPLY_SCALE: - return new Point2D( - xx * x + xy * y, - yx * x + yy * y); - case APPLY_SHEAR | APPLY_TRANSLATE: - return new Point2D( - xy * y + xt, - yx * x + yt); - case APPLY_SHEAR: - return new Point2D(xy * y, yx * x); - case APPLY_SCALE | APPLY_TRANSLATE: - return new Point2D( - xx * x + xt, - yy * y + yt); - case APPLY_SCALE: - return new Point2D(xx * x, yy * y); - case APPLY_TRANSLATE: - return new Point2D(x + xt, y + yt); - case APPLY_IDENTITY: - return new Point2D(x, y); - } - } - - @Override - public Point3D transform(double x, double y, double z) { - switch (state3d) { - default: - stateError(); - // cannot reach - case APPLY_NON_3D: - switch (state2d) { - default: - stateError(); - // cannot reach - case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: - return new Point3D( - xx * x + xy * y + xt, - yx * x + yy * y + yt, z); - case APPLY_SHEAR | APPLY_SCALE: - return new Point3D( - xx * x + xy * y, - yx * x + yy * y, z); - case APPLY_SHEAR | APPLY_TRANSLATE: - return new Point3D( - xy * y + xt, yx * x + yt, - z); - case APPLY_SHEAR: - return new Point3D(xy * y, yx * x, z); - case APPLY_SCALE | APPLY_TRANSLATE: - return new Point3D( - xx * x + xt, yy * y + yt, - z); - case APPLY_SCALE: - return new Point3D(xx * x, yy * y, z); - case APPLY_TRANSLATE: - return new Point3D(x + xt, y + yt, z); - case APPLY_IDENTITY: - return new Point3D(x, y, z); - } - case APPLY_TRANSLATE: - return new Point3D(x + xt, y + yt, z + zt); - case APPLY_SCALE: - return new Point3D(xx * x, yy * y, zz * z); - case APPLY_SCALE | APPLY_TRANSLATE: - return new Point3D( - xx * x + xt, - yy * y + yt, - zz * z + zt); - case APPLY_3D_COMPLEX: - return new Point3D( - xx * x + xy * y + xz * z + xt, - yx * x + yy * y + yz * z + yt, - zx * x + zy * y + zz * z + zt); - } - } - - @Override - public Point2D deltaTransform(double x, double y) { - ensureCanTransform2DPoint(); - - switch (state2d) { - default: - stateError(); - // cannot reach - case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SHEAR | APPLY_SCALE: - return new Point2D( - xx * x + xy * y, - yx * x + yy * y); - case APPLY_SHEAR | APPLY_TRANSLATE: - case APPLY_SHEAR: - return new Point2D(xy * y, yx * x); - case APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SCALE: - return new Point2D(xx * x, yy * y); - case APPLY_TRANSLATE: - case APPLY_IDENTITY: - return new Point2D(x, y); - } - } - - @Override - public Point3D deltaTransform(double x, double y, double z) { - switch (state3d) { - default: - stateError(); - // cannot reach - case APPLY_NON_3D: - switch (state2d) { - default: - stateError(); - // cannot reach - case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SHEAR | APPLY_SCALE: - return new Point3D( - xx * x + xy * y, - yx * x + yy * y, z); - case APPLY_SHEAR | APPLY_TRANSLATE: - case APPLY_SHEAR: - return new Point3D(xy * y, yx * x, z); - case APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SCALE: - return new Point3D(xx * x, yy * y, z); - case APPLY_TRANSLATE: - case APPLY_IDENTITY: - return new Point3D(x, y, z); - } - case APPLY_TRANSLATE: - return new Point3D(x, y, z); - case APPLY_SCALE: - case APPLY_SCALE | APPLY_TRANSLATE: - return new Point3D(xx * x, yy * y, zz * z); - case APPLY_3D_COMPLEX: - return new Point3D( - xx * x + xy * y + xz * z, - yx * x + yy * y + yz * z, - zx * x + zy * y + zz * z); - } - } - - @Override - public Point2D inverseTransform(double x, double y) - throws NonInvertibleTransformException { - ensureCanTransform2DPoint(); - - switch (state2d) { - default: - return super.inverseTransform(x, y); - case APPLY_SHEAR | APPLY_TRANSLATE: - if (xy == 0.0 || yx == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point2D( - (1.0 / yx) * y - yt / yx, - (1.0 / xy) * x - xt / xy); - case APPLY_SHEAR: - if (xy == 0.0 || yx == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point2D((1.0 / yx) * y, (1.0 / xy) * x); - case APPLY_SCALE | APPLY_TRANSLATE: - if (xx == 0.0 || yy == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point2D( - (1.0 / xx) * x - xt / xx, - (1.0 / yy) * y - yt / yy); - case APPLY_SCALE: - if (xx == 0.0 || yy == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point2D((1.0 / xx) * x, (1.0 / yy) * y); - case APPLY_TRANSLATE: - return new Point2D(x - xt, y - yt); - case APPLY_IDENTITY: - return new Point2D(x, y); - } - } - - @Override - public Point3D inverseTransform(double x, double y, double z) - throws NonInvertibleTransformException { - switch(state3d) { - default: - stateError(); - // cannot reach - case APPLY_NON_3D: - switch (state2d) { - default: - return super.inverseTransform(x, y, z); - case APPLY_SHEAR | APPLY_TRANSLATE: - if (xy == 0.0 || yx == 0.0) { - throw new NonInvertibleTransformException( - "Determinant is 0"); - } - return new Point3D( - (1.0 / yx) * y - yt / yx, - (1.0 / xy) * x - xt / xy, z); - case APPLY_SHEAR: - if (xy == 0.0 || yx == 0.0) { - throw new NonInvertibleTransformException( - "Determinant is 0"); - } - return new Point3D( - (1.0 / yx) * y, - (1.0 / xy) * x, z); - case APPLY_SCALE | APPLY_TRANSLATE: - if (xx == 0.0 || yy == 0.0) { - throw new NonInvertibleTransformException( - "Determinant is 0"); - } - return new Point3D( - (1.0 / xx) * x - xt / xx, - (1.0 / yy) * y - yt / yy, z); - case APPLY_SCALE: - if (xx == 0.0 || yy == 0.0) { - throw new NonInvertibleTransformException( - "Determinant is 0"); - } - return new Point3D((1.0 / xx) * x, (1.0 / yy) * y, z); - case APPLY_TRANSLATE: - return new Point3D(x - xt, y - yt, z); - case APPLY_IDENTITY: - return new Point3D(x, y, z); - } - case APPLY_TRANSLATE: - return new Point3D(x - xt, y - yt, z - zt); - case APPLY_SCALE: - if (xx == 0.0 || yy == 0.0 || zz == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point3D( - (1.0 / xx) * x, - (1.0 / yy) * y, - (1.0 / zz) * z); - case APPLY_SCALE | APPLY_TRANSLATE: - if (xx == 0.0 || yy == 0.0 || zz == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point3D( - (1.0 / xx) * x - xt / xx, - (1.0 / yy) * y - yt / yy, - (1.0 / zz) * z - zt / zz); - case APPLY_3D_COMPLEX: - return super.inverseTransform(x, y, z); - } - } - - @Override - public Point2D inverseDeltaTransform(double x, double y) - throws NonInvertibleTransformException { - ensureCanTransform2DPoint(); - - switch (state2d) { - default: - return super.inverseDeltaTransform(x, y); - case APPLY_SHEAR | APPLY_TRANSLATE: - case APPLY_SHEAR: - if (xy == 0.0 || yx == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point2D((1.0 / yx) * y, (1.0 / xy) * x); - case APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SCALE: - if (xx == 0.0 || yy == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point2D((1.0 / xx) * x, (1.0 / yy) * y); - case APPLY_TRANSLATE: - case APPLY_IDENTITY: - return new Point2D(x, y); - } - } - - @Override - public Point3D inverseDeltaTransform(double x, double y, double z) - throws NonInvertibleTransformException { - switch(state3d) { - default: - stateError(); - // cannot reach - case APPLY_NON_3D: - switch (state2d) { - default: - return super.inverseDeltaTransform(x, y, z); - case APPLY_SHEAR | APPLY_TRANSLATE: - case APPLY_SHEAR: - if (xy == 0.0 || yx == 0.0) { - throw new NonInvertibleTransformException( - "Determinant is 0"); - } - return new Point3D( - (1.0 / yx) * y, - (1.0 / xy) * x, z); - case APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SCALE: - if (xx == 0.0 || yy == 0.0) { - throw new NonInvertibleTransformException( - "Determinant is 0"); - } - return new Point3D( - (1.0 / xx) * x, - (1.0 / yy) * y, z); - case APPLY_TRANSLATE: - case APPLY_IDENTITY: - return new Point3D(x, y, z); - } - - case APPLY_TRANSLATE: - return new Point3D(x, y, z); - case APPLY_SCALE | APPLY_TRANSLATE: - case APPLY_SCALE: - if (xx == 0.0 || yy == 0.0 || zz == 0.0) { - throw new NonInvertibleTransformException("Determinant is 0"); - } - return new Point3D( - (1.0 / xx) * x, - (1.0 / yy) * y, - (1.0 / zz) * z); - case APPLY_3D_COMPLEX: - return super.inverseDeltaTransform(x, y, z); - } - } - - /* ************************************************************************* - * * - * Other API * - * * - **************************************************************************/ - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("Transform [\n"); - - sb.append("\t").append(xx); - sb.append(", ").append(xy); - sb.append(", ").append(xz); - sb.append(", ").append(xt); - sb.append('\n'); - sb.append("\t").append(yx); - sb.append(", ").append(yy); - sb.append(", ").append(yz); - sb.append(", ").append(yt); - sb.append('\n'); - sb.append("\t").append(zx); - sb.append(", ").append(zy); - sb.append(", ").append(zz); - sb.append(", ").append(zt); - - return sb.append("\n]").toString(); - } - - /* ************************************************************************* - * * - * Internal implementation stuff * - * * - **************************************************************************/ - - private void updateState() { - updateState2D(); - - state3d = APPLY_NON_3D; - - if (xz != 0.0 || - yz != 0.0 || - zx != 0.0 || - zy != 0.0) - { - state3d = APPLY_3D_COMPLEX; - } else { - if ((state2d & APPLY_SHEAR) == 0) { - if (zt != 0.0) { - state3d |= APPLY_TRANSLATE; - } - if (zz != 1.0) { - state3d |= APPLY_SCALE; - } - if (state3d != APPLY_NON_3D) { - state3d |= (state2d & (APPLY_SCALE | APPLY_TRANSLATE)); - } - } else { - if (zz != 1.0 || zt != 0.0) { - state3d = APPLY_3D_COMPLEX; - } - } - } - } - - private void updateState2D() { - if (xy == 0.0 && yx == 0.0) { - if (xx == 1.0 && yy == 1.0) { - if (xt == 0.0 && yt == 0.0) { - state2d = APPLY_IDENTITY; - } else { - state2d = APPLY_TRANSLATE; - } - } else { - if (xt == 0.0 && yt == 0.0) { - state2d = APPLY_SCALE; - } else { - state2d = (APPLY_SCALE | APPLY_TRANSLATE); - } - } - } else { - if (xx == 0.0 && yy == 0.0) { - if (xt == 0.0 && yt == 0.0) { - state2d = APPLY_SHEAR; - } else { - state2d = (APPLY_SHEAR | APPLY_TRANSLATE); - } - } else { - if (xt == 0.0 && yt == 0.0) { - state2d = (APPLY_SHEAR | APPLY_SCALE); - } else { - state2d = (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE); - } - } - } - } - - void ensureCanTransform2DPoint() throws IllegalStateException { - if (state3d != APPLY_NON_3D) { - throw new IllegalStateException("Cannot transform 2D point " - + "with a 3D transform"); - } - } - - private static void stateError() { - throw new InternalError("missing case in a switch"); - } - - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated - @Override - public void impl_apply(final Affine3D trans) { - trans.concatenate(xx, xy, xz, xt, - yx, yy, yz, yt, - zx, zy, zz, zt); - } - - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated - @Override - public BaseTransform impl_derive(final BaseTransform trans) { - return trans.deriveWithConcatenation(xx, xy, xz, xt, - yx, yy, yz, yt, - zx, zy, zz, zt); - } - - /** - * Used only by tests to check the 2d matrix state - */ - int getState2d() { - return state2d; - } - - /** - * Used only by tests to check the 3d matrix state - */ - int getState3d() { - return state3d; - } - - } } - --- old/modules/graphics/src/main/java/javafx/scene/Camera.java 2016-05-03 23:06:40.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/Camera.java 2016-05-03 23:06:40.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,7 @@ import com.sun.javafx.jmx.MXNodeAlgorithmContext; import com.sun.javafx.scene.CameraHelper; import com.sun.javafx.scene.DirtyBits; +import com.sun.javafx.scene.transform.TransformHelper; import com.sun.javafx.sg.prism.NGCamera; import sun.util.logging.PlatformLogger; @@ -359,7 +360,7 @@ Affine3D getCameraTransform() { if (!localToSceneValid) { localToSceneTx.setToIdentity(); - getLocalToSceneTransform().impl_apply(localToSceneTx); + TransformHelper.apply(getLocalToSceneTransform(), localToSceneTx); localToSceneValid = true; } return localToSceneTx; @@ -412,7 +413,7 @@ final PickRay ray = computePickRay(x, y, null); final Affine3D localToScene = new Affine3D(); - node.getLocalToSceneTransform().impl_apply(localToScene); + TransformHelper.apply(node.getLocalToSceneTransform(), localToScene); final Vec3d o = ray.getOriginNoClone(); final Vec3d d = ray.getDirectionNoClone(); --- old/modules/graphics/src/main/java/javafx/scene/LightBase.java 2016-05-03 23:06:41.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/LightBase.java 2016-05-03 23:06:41.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,6 +33,7 @@ import com.sun.javafx.jmx.MXNodeAlgorithm; import com.sun.javafx.jmx.MXNodeAlgorithmContext; import com.sun.javafx.scene.DirtyBits; +import com.sun.javafx.scene.transform.TransformHelper; import com.sun.javafx.sg.prism.NGLightBase; import com.sun.javafx.tk.Toolkit; import javafx.application.ConditionalFeature; @@ -277,7 +278,7 @@ if (impl_isDirty(DirtyBits.NODE_LIGHT_TRANSFORM)) { localToSceneTx.setToIdentity(); - getLocalToSceneTransform().impl_apply(localToSceneTx); + TransformHelper.apply(getLocalToSceneTransform(), localToSceneTx); // TODO: 3D - For now, we are treating the scene as world. This may need to change // for the fixed eye position case. peer.setWorldTransform(localToSceneTx); --- old/modules/graphics/src/main/java/javafx/scene/Node.java 2016-05-03 23:06:42.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/Node.java 2016-05-03 23:06:41.000000000 -0700 @@ -153,6 +153,7 @@ import com.sun.javafx.scene.SceneHelper; import com.sun.javafx.scene.SceneUtils; import com.sun.javafx.scene.input.PickResultChooser; +import com.sun.javafx.scene.transform.TransformHelper; import com.sun.javafx.scene.transform.TransformUtils; import com.sun.javafx.scene.traversal.Direction; import com.sun.javafx.sg.prism.NGNode; @@ -1865,7 +1866,7 @@ BaseTransform transform = BaseTransform.IDENTITY_TRANSFORM; if (params.getTransform() != null) { Affine3D tempTx = new Affine3D(); - params.getTransform().impl_apply(tempTx); + TransformHelper.apply(params.getTransform(), tempTx); transform = tempTx; } double x; @@ -3093,9 +3094,9 @@ BaseBounds nodeInCameraBounds = new BoxBounds(); // We need to set tempTx to identity since it is a recycled transform. - // This is because impl_apply is a matrix concatenation operation. + // This is because TransformHelper.apply() is a matrix concatenation operation. tempTx.setToIdentity(); - localToSceneTx.impl_apply(tempTx); + TransformHelper.apply(localToSceneTx, tempTx); // Convert node from local coordinate to camera coordinate tempTx.preConcatenate(camera.getSceneToLocalTransform()); @@ -3113,9 +3114,9 @@ projViewTx.set(camera.getProjViewTransform()); // We need to set tempTx to identity since it is a recycled transform. - // This is because impl_apply is a matrix concatenation operation. + // This is because TransformHelper.apply() is a matrix concatenation operation. tempTx.setToIdentity(); - localToSceneTx.impl_apply(tempTx); + TransformHelper.apply(localToSceneTx, tempTx); // The product of projViewTx * localToSceneTransform GeneralTransform3D tx = projViewTx.mul(tempTx); @@ -4822,7 +4823,7 @@ if (impl_hasTransforms()) { for (Transform t : getTransforms()) { - localToParentTx = t.impl_derive(localToParentTx); + localToParentTx = TransformHelper.derive(t, localToParentTx); } } @@ -6091,10 +6092,10 @@ protected void onChanged(Change c) { while (c.next()) { for (Transform t : c.getRemoved()) { - t.impl_remove(Node.this); + TransformHelper.remove(t, Node.this); } for (Transform t : c.getAddedSubList()) { - t.impl_add(Node.this); + TransformHelper.add(t, Node.this); } } --- old/modules/graphics/src/main/java/javafx/scene/transform/Affine.java 2016-05-03 23:06:43.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/transform/Affine.java 2016-05-03 23:06:42.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -5702,25 +5702,15 @@ throw new InternalError("missing case in a switch"); } - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public void impl_apply(final Affine3D trans) { + void apply(final Affine3D trans) { trans.concatenate(getMxx(), getMxy(), getMxz(), getTx(), getMyx(), getMyy(), getMyz(), getTy(), getMzx(), getMzy(), getMzz(), getTz()); } - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public BaseTransform impl_derive(final BaseTransform trans) { + BaseTransform derive(final BaseTransform trans) { switch(state3d) { default: stateError(); --- old/modules/graphics/src/main/java/javafx/scene/transform/Rotate.java 2016-05-03 23:06:44.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/transform/Rotate.java 2016-05-03 23:06:43.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -720,13 +720,8 @@ * * **************************************************************************/ - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public void impl_apply(final Affine3D trans) { + void apply(final Affine3D trans) { double localPivotX = getPivotX(); double localPivotY = getPivotY(); double localPivotZ = getPivotZ(); @@ -743,13 +738,8 @@ } } - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public BaseTransform impl_derive(BaseTransform trans) { + BaseTransform derive(BaseTransform trans) { if (isIdentity()) { return trans; } --- old/modules/graphics/src/main/java/javafx/scene/transform/Scale.java 2016-05-03 23:06:44.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/transform/Scale.java 2016-05-03 23:06:44.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -756,13 +756,8 @@ * * **************************************************************************/ - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public void impl_apply(final Affine3D trans) { + void apply(final Affine3D trans) { if (getPivotX() != 0 || getPivotY() != 0 || getPivotZ() != 0) { trans.translate(getPivotX(), getPivotY(), getPivotZ()); trans.scale(getX(), getY(), getZ()); @@ -772,13 +767,8 @@ } } - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public BaseTransform impl_derive(BaseTransform trans) { + BaseTransform derive(BaseTransform trans) { if (isIdentity()) { return trans; } --- old/modules/graphics/src/main/java/javafx/scene/transform/Shear.java 2016-05-03 23:06:45.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/transform/Shear.java 2016-05-03 23:06:45.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -688,13 +688,8 @@ * * **************************************************************************/ - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public void impl_apply(final Affine3D trans) { + void apply(final Affine3D trans) { if (getPivotX() != 0 || getPivotY() != 0) { trans.translate(getPivotX(), getPivotY()); trans.shear(getX(), getY()); @@ -704,13 +699,8 @@ } } - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public BaseTransform impl_derive(final BaseTransform trans) { + BaseTransform derive(final BaseTransform trans) { return trans.deriveWithConcatenation( 1.0, getY(), getX(), 1.0, --- old/modules/graphics/src/main/java/javafx/scene/transform/Transform.java 2016-05-03 23:06:46.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/transform/Transform.java 2016-05-03 23:06:46.000000000 -0700 @@ -35,10 +35,9 @@ import com.sun.javafx.util.WeakReferenceQueue; import com.sun.javafx.binding.ExpressionHelper; import com.sun.javafx.event.EventHandlerManager; -import com.sun.javafx.geom.transform.Affine2D; import com.sun.javafx.geom.transform.Affine3D; -import com.sun.javafx.geom.transform.AffineBase; import com.sun.javafx.geom.transform.BaseTransform; +import com.sun.javafx.scene.transform.TransformHelper; import com.sun.javafx.scene.transform.TransformUtils; import java.lang.ref.SoftReference; import javafx.beans.InvalidationListener; @@ -50,7 +49,6 @@ import javafx.event.EventHandler; import javafx.event.EventTarget; import javafx.event.EventType; -import javafx.geometry.BoundingBox; import javafx.geometry.Bounds; import javafx.geometry.Point2D; import javafx.geometry.Point3D; @@ -72,6 +70,62 @@ */ public abstract class Transform implements Cloneable, EventTarget { + static { + // This is used by classes in different packages to get access to + // private and package private methods. + TransformHelper.setTransformAccessor(new TransformHelper.TransformAccessor() { + + @Override + public void add(Transform transform, Node node) { + transform.add(node); + } + + @Override + public void remove(Transform transform, Node node) { + transform.remove(node); + } + + @Override + public void apply(Transform transform, Affine3D affine3D) { + transform.apply(affine3D); + } + + @Override + public BaseTransform derive(Transform transform, BaseTransform baseTransform) { + return transform.derive(baseTransform); + } + + @Override + public Transform createImmutableTransform() { + return Transform.createImmutableTransform(); + } + + @Override + public Transform createImmutableTransform( + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + return Transform.createImmutableTransform(mxx, mxy, mxz, tx, + myx, myy, myz, ty, mzx, mzy, mzz, tz); + } + + @Override + public Transform createImmutableTransform(Transform transform, + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + return Transform.createImmutableTransform(transform, + mxx, mxy, mxz, tx, myx, myy, myz, ty, mzx, mzy, mzz, tz); + } + + @Override + public Transform createImmutableTransform(Transform transform, + Transform left, Transform right) { + return Transform.createImmutableTransform(transform, left, right); + } + }); + } + /* ************************************************************************* * * * Factories * @@ -1991,35 +2045,15 @@ getMzx(); getMzy(); getMzz(); getTz(); } - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated - public abstract void impl_apply(Affine3D t); + abstract void apply(Affine3D t); - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated - public abstract BaseTransform impl_derive(BaseTransform t); + abstract BaseTransform derive(BaseTransform t); - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated - public void impl_add(final Node node) { + private void add(final Node node) { nodes.add(node); } - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated - public void impl_remove(final Node node) { + private void remove(final Node node) { nodes.remove(node); } @@ -2111,4 +2145,778 @@ inverseCache.clear(); } } + + /************************************************************************** + * ImmutableTransform Class and supporting methods + **************************************************************************/ + + static Transform createImmutableTransform() { + return new ImmutableTransform(); + } + + static Transform createImmutableTransform( + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + return new ImmutableTransform( + mxx, mxy, mxz, tx, + myx, myy, myz, ty, + mzx, mzy, mzz, tz); + } + + static Transform createImmutableTransform(Transform transform, + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + if (transform == null) { + return createImmutableTransform( + mxx, mxy, mxz, tx, + myx, myy, myz, ty, + mzx, mzy, mzz, tz); + } + ((Transform.ImmutableTransform) transform).setToTransform( + mxx, mxy, mxz, tx, + myx, myy, myz, ty, + mzx, mzy, mzz, tz); + return transform; + } + + static Transform createImmutableTransform(Transform transform, + Transform left, Transform right) { + if (transform == null) { + transform = createImmutableTransform(); + } + ((Transform.ImmutableTransform) transform).setToConcatenation( + (ImmutableTransform) left, (ImmutableTransform) right); + return transform; + } + + /** + * Immutable transformation with performance optimizations based on Affine. + * + * From user's perspective, this transform is immutable. However, we can + * modify it internally. This allows for reusing instances that were + * not handed to users. The caller is responsible for not modifying + * user-visible instances. + * + * Note: can't override Transform's package private methods so they cannot + * be optimized. Currently not a big deal. + */ + static class ImmutableTransform extends Transform { + + private static final int APPLY_IDENTITY = 0; + private static final int APPLY_TRANSLATE = 1; + private static final int APPLY_SCALE = 2; + private static final int APPLY_SHEAR = 4; + private static final int APPLY_NON_3D = 0; + private static final int APPLY_3D_COMPLEX = 4; + private transient int state2d; + private transient int state3d; + + private double xx; + private double xy; + private double xz; + private double yx; + private double yy; + private double yz; + private double zx; + private double zy; + private double zz; + private double xt; + private double yt; + private double zt; + + ImmutableTransform() { + xx = yy = zz = 1.0; + } + + ImmutableTransform(Transform transform) { + this(transform.getMxx(), transform.getMxy(), transform.getMxz(), + transform.getTx(), + transform.getMyx(), transform.getMyy(), transform.getMyz(), + transform.getTy(), + transform.getMzx(), transform.getMzy(), transform.getMzz(), + transform.getTz()); + } + + ImmutableTransform(double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + xx = mxx; + xy = mxy; + xz = mxz; + xt = tx; + + yx = myx; + yy = myy; + yz = myz; + yt = ty; + + zx = mzx; + zy = mzy; + zz = mzz; + zt = tz; + + updateState(); + } + + // Beware: this is modifying immutable transform! + // It is private and it is there just for the purpose of reusing + // instances not given to users + private void setToTransform(double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) + { + xx = mxx; + xy = mxy; + xz = mxz; + xt = tx; + yx = myx; + yy = myy; + yz = myz; + yt = ty; + zx = mzx; + zy = mzy; + zz = mzz; + zt = tz; + updateState(); + } + + // Beware: this is modifying immutable transform! + // It is private and it is there just for the purpose of reusing + // instances not given to users + private void setToConcatenation(ImmutableTransform left, ImmutableTransform right) { + if (left.state3d == APPLY_NON_3D && right.state3d == APPLY_NON_3D) { + xx = left.xx * right.xx + left.xy * right.yx; + xy = left.xx * right.xy + left.xy * right.yy; + xt = left.xx * right.xt + left.xy * right.yt + left.xt; + yx = left.yx * right.xx + left.yy * right.yx; + yy = left.yx * right.xy + left.yy * right.yy; + yt = left.yx * right.xt + left.yy * right.yt + left.yt; + if (state3d != APPLY_NON_3D) { + xz = yz = zx = zy = zt = 0.0; + zz = 1.0; + state3d = APPLY_NON_3D; + } + updateState2D(); + } else { + xx = left.xx * right.xx + left.xy * right.yx + left.xz * right.zx; + xy = left.xx * right.xy + left.xy * right.yy + left.xz * right.zy; + xz = left.xx * right.xz + left.xy * right.yz + left.xz * right.zz; + xt = left.xx * right.xt + left.xy * right.yt + left.xz * right.zt + left.xt; + yx = left.yx * right.xx + left.yy * right.yx + left.yz * right.zx; + yy = left.yx * right.xy + left.yy * right.yy + left.yz * right.zy; + yz = left.yx * right.xz + left.yy * right.yz + left.yz * right.zz; + yt = left.yx * right.xt + left.yy * right.yt + left.yz * right.zt + left.yt; + zx = left.zx * right.xx + left.zy * right.yx + left.zz * right.zx; + zy = left.zx * right.xy + left.zy * right.yy + left.zz * right.zy; + zz = left.zx * right.xz + left.zy * right.yz + left.zz * right.zz; + zt = left.zx * right.xt + left.zy * right.yt + left.zz * right.zt + left.zt; + updateState(); + } + // could be further optimized using the states, but that would + // require a lot of code (see Affine and all its append* methods) + } + + @Override + public double getMxx() { + return xx; + } + + @Override + public double getMxy() { + return xy; + } + + @Override + public double getMxz() { + return xz; + } + + @Override + public double getTx() { + return xt; + } + + @Override + public double getMyx() { + return yx; + } + + @Override + public double getMyy() { + return yy; + } + + @Override + public double getMyz() { + return yz; + } + + @Override + public double getTy() { + return yt; + } + + @Override + public double getMzx() { + return zx; + } + + @Override + public double getMzy() { + return zy; + } + + @Override + public double getMzz() { + return zz; + } + + @Override + public double getTz() { + return zt; + } + + /* ************************************************************************* + * * + * State getters * + * * + **************************************************************************/ + + @Override + public double determinant() { + switch(state3d) { + default: + stateError(); + // cannot reach + case APPLY_NON_3D: + switch (state2d) { + default: + stateError(); + // cannot reach + case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SHEAR | APPLY_SCALE: + return xx * yy - xy * yx; + case APPLY_SHEAR | APPLY_TRANSLATE: + case APPLY_SHEAR: + return -(xy* yx); + case APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SCALE: + return xx * yy; + case APPLY_TRANSLATE: + case APPLY_IDENTITY: + return 1.0; + } + case APPLY_TRANSLATE: + return 1.0; + case APPLY_SCALE: + case APPLY_SCALE | APPLY_TRANSLATE: + return xx * yy * zz; + case APPLY_3D_COMPLEX: + return (xx* (yy * zz - zy * yz) + + xy* (yz * zx - zz * yx) + + xz* (yx * zy - zx * yy)); + } + } + + @Override + public Transform createConcatenation(Transform transform) { + javafx.scene.transform.Affine a = new Affine(this); + a.append(transform); + return a; + } + + @Override + public javafx.scene.transform.Affine createInverse() throws NonInvertibleTransformException { + javafx.scene.transform.Affine t = new Affine(this); + t.invert(); + return t; + } + + @Override + public Transform clone() { + return new ImmutableTransform(this); + } + + /* ************************************************************************* + * * + * Transform, Inverse Transform * + * * + **************************************************************************/ + + @Override + public Point2D transform(double x, double y) { + ensureCanTransform2DPoint(); + + switch (state2d) { + default: + stateError(); + // cannot reach + case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: + return new Point2D( + xx * x + xy * y + xt, + yx * x + yy * y + yt); + case APPLY_SHEAR | APPLY_SCALE: + return new Point2D( + xx * x + xy * y, + yx * x + yy * y); + case APPLY_SHEAR | APPLY_TRANSLATE: + return new Point2D( + xy * y + xt, + yx * x + yt); + case APPLY_SHEAR: + return new Point2D(xy * y, yx * x); + case APPLY_SCALE | APPLY_TRANSLATE: + return new Point2D( + xx * x + xt, + yy * y + yt); + case APPLY_SCALE: + return new Point2D(xx * x, yy * y); + case APPLY_TRANSLATE: + return new Point2D(x + xt, y + yt); + case APPLY_IDENTITY: + return new Point2D(x, y); + } + } + + @Override + public Point3D transform(double x, double y, double z) { + switch (state3d) { + default: + stateError(); + // cannot reach + case APPLY_NON_3D: + switch (state2d) { + default: + stateError(); + // cannot reach + case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: + return new Point3D( + xx * x + xy * y + xt, + yx * x + yy * y + yt, z); + case APPLY_SHEAR | APPLY_SCALE: + return new Point3D( + xx * x + xy * y, + yx * x + yy * y, z); + case APPLY_SHEAR | APPLY_TRANSLATE: + return new Point3D( + xy * y + xt, yx * x + yt, + z); + case APPLY_SHEAR: + return new Point3D(xy * y, yx * x, z); + case APPLY_SCALE | APPLY_TRANSLATE: + return new Point3D( + xx * x + xt, yy * y + yt, + z); + case APPLY_SCALE: + return new Point3D(xx * x, yy * y, z); + case APPLY_TRANSLATE: + return new Point3D(x + xt, y + yt, z); + case APPLY_IDENTITY: + return new Point3D(x, y, z); + } + case APPLY_TRANSLATE: + return new Point3D(x + xt, y + yt, z + zt); + case APPLY_SCALE: + return new Point3D(xx * x, yy * y, zz * z); + case APPLY_SCALE | APPLY_TRANSLATE: + return new Point3D( + xx * x + xt, + yy * y + yt, + zz * z + zt); + case APPLY_3D_COMPLEX: + return new Point3D( + xx * x + xy * y + xz * z + xt, + yx * x + yy * y + yz * z + yt, + zx * x + zy * y + zz * z + zt); + } + } + + @Override + public Point2D deltaTransform(double x, double y) { + ensureCanTransform2DPoint(); + + switch (state2d) { + default: + stateError(); + // cannot reach + case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SHEAR | APPLY_SCALE: + return new Point2D( + xx * x + xy * y, + yx * x + yy * y); + case APPLY_SHEAR | APPLY_TRANSLATE: + case APPLY_SHEAR: + return new Point2D(xy * y, yx * x); + case APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SCALE: + return new Point2D(xx * x, yy * y); + case APPLY_TRANSLATE: + case APPLY_IDENTITY: + return new Point2D(x, y); + } + } + + @Override + public Point3D deltaTransform(double x, double y, double z) { + switch (state3d) { + default: + stateError(); + // cannot reach + case APPLY_NON_3D: + switch (state2d) { + default: + stateError(); + // cannot reach + case APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SHEAR | APPLY_SCALE: + return new Point3D( + xx * x + xy * y, + yx * x + yy * y, z); + case APPLY_SHEAR | APPLY_TRANSLATE: + case APPLY_SHEAR: + return new Point3D(xy * y, yx * x, z); + case APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SCALE: + return new Point3D(xx * x, yy * y, z); + case APPLY_TRANSLATE: + case APPLY_IDENTITY: + return new Point3D(x, y, z); + } + case APPLY_TRANSLATE: + return new Point3D(x, y, z); + case APPLY_SCALE: + case APPLY_SCALE | APPLY_TRANSLATE: + return new Point3D(xx * x, yy * y, zz * z); + case APPLY_3D_COMPLEX: + return new Point3D( + xx * x + xy * y + xz * z, + yx * x + yy * y + yz * z, + zx * x + zy * y + zz * z); + } + } + + @Override + public Point2D inverseTransform(double x, double y) + throws NonInvertibleTransformException { + ensureCanTransform2DPoint(); + + switch (state2d) { + default: + return super.inverseTransform(x, y); + case APPLY_SHEAR | APPLY_TRANSLATE: + if (xy == 0.0 || yx == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point2D( + (1.0 / yx) * y - yt / yx, + (1.0 / xy) * x - xt / xy); + case APPLY_SHEAR: + if (xy == 0.0 || yx == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point2D((1.0 / yx) * y, (1.0 / xy) * x); + case APPLY_SCALE | APPLY_TRANSLATE: + if (xx == 0.0 || yy == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point2D( + (1.0 / xx) * x - xt / xx, + (1.0 / yy) * y - yt / yy); + case APPLY_SCALE: + if (xx == 0.0 || yy == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point2D((1.0 / xx) * x, (1.0 / yy) * y); + case APPLY_TRANSLATE: + return new Point2D(x - xt, y - yt); + case APPLY_IDENTITY: + return new Point2D(x, y); + } + } + + @Override + public Point3D inverseTransform(double x, double y, double z) + throws NonInvertibleTransformException { + switch(state3d) { + default: + stateError(); + // cannot reach + case APPLY_NON_3D: + switch (state2d) { + default: + return super.inverseTransform(x, y, z); + case APPLY_SHEAR | APPLY_TRANSLATE: + if (xy == 0.0 || yx == 0.0) { + throw new NonInvertibleTransformException( + "Determinant is 0"); + } + return new Point3D( + (1.0 / yx) * y - yt / yx, + (1.0 / xy) * x - xt / xy, z); + case APPLY_SHEAR: + if (xy == 0.0 || yx == 0.0) { + throw new NonInvertibleTransformException( + "Determinant is 0"); + } + return new Point3D( + (1.0 / yx) * y, + (1.0 / xy) * x, z); + case APPLY_SCALE | APPLY_TRANSLATE: + if (xx == 0.0 || yy == 0.0) { + throw new NonInvertibleTransformException( + "Determinant is 0"); + } + return new Point3D( + (1.0 / xx) * x - xt / xx, + (1.0 / yy) * y - yt / yy, z); + case APPLY_SCALE: + if (xx == 0.0 || yy == 0.0) { + throw new NonInvertibleTransformException( + "Determinant is 0"); + } + return new Point3D((1.0 / xx) * x, (1.0 / yy) * y, z); + case APPLY_TRANSLATE: + return new Point3D(x - xt, y - yt, z); + case APPLY_IDENTITY: + return new Point3D(x, y, z); + } + case APPLY_TRANSLATE: + return new Point3D(x - xt, y - yt, z - zt); + case APPLY_SCALE: + if (xx == 0.0 || yy == 0.0 || zz == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point3D( + (1.0 / xx) * x, + (1.0 / yy) * y, + (1.0 / zz) * z); + case APPLY_SCALE | APPLY_TRANSLATE: + if (xx == 0.0 || yy == 0.0 || zz == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point3D( + (1.0 / xx) * x - xt / xx, + (1.0 / yy) * y - yt / yy, + (1.0 / zz) * z - zt / zz); + case APPLY_3D_COMPLEX: + return super.inverseTransform(x, y, z); + } + } + + @Override + public Point2D inverseDeltaTransform(double x, double y) + throws NonInvertibleTransformException { + ensureCanTransform2DPoint(); + + switch (state2d) { + default: + return super.inverseDeltaTransform(x, y); + case APPLY_SHEAR | APPLY_TRANSLATE: + case APPLY_SHEAR: + if (xy == 0.0 || yx == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point2D((1.0 / yx) * y, (1.0 / xy) * x); + case APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SCALE: + if (xx == 0.0 || yy == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point2D((1.0 / xx) * x, (1.0 / yy) * y); + case APPLY_TRANSLATE: + case APPLY_IDENTITY: + return new Point2D(x, y); + } + } + + @Override + public Point3D inverseDeltaTransform(double x, double y, double z) + throws NonInvertibleTransformException { + switch(state3d) { + default: + stateError(); + // cannot reach + case APPLY_NON_3D: + switch (state2d) { + default: + return super.inverseDeltaTransform(x, y, z); + case APPLY_SHEAR | APPLY_TRANSLATE: + case APPLY_SHEAR: + if (xy == 0.0 || yx == 0.0) { + throw new NonInvertibleTransformException( + "Determinant is 0"); + } + return new Point3D( + (1.0 / yx) * y, + (1.0 / xy) * x, z); + case APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SCALE: + if (xx == 0.0 || yy == 0.0) { + throw new NonInvertibleTransformException( + "Determinant is 0"); + } + return new Point3D( + (1.0 / xx) * x, + (1.0 / yy) * y, z); + case APPLY_TRANSLATE: + case APPLY_IDENTITY: + return new Point3D(x, y, z); + } + + case APPLY_TRANSLATE: + return new Point3D(x, y, z); + case APPLY_SCALE | APPLY_TRANSLATE: + case APPLY_SCALE: + if (xx == 0.0 || yy == 0.0 || zz == 0.0) { + throw new NonInvertibleTransformException("Determinant is 0"); + } + return new Point3D( + (1.0 / xx) * x, + (1.0 / yy) * y, + (1.0 / zz) * z); + case APPLY_3D_COMPLEX: + return super.inverseDeltaTransform(x, y, z); + } + } + + /* ************************************************************************* + * * + * Other API * + * * + **************************************************************************/ + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("Transform [\n"); + + sb.append("\t").append(xx); + sb.append(", ").append(xy); + sb.append(", ").append(xz); + sb.append(", ").append(xt); + sb.append('\n'); + sb.append("\t").append(yx); + sb.append(", ").append(yy); + sb.append(", ").append(yz); + sb.append(", ").append(yt); + sb.append('\n'); + sb.append("\t").append(zx); + sb.append(", ").append(zy); + sb.append(", ").append(zz); + sb.append(", ").append(zt); + + return sb.append("\n]").toString(); + } + + /* ************************************************************************* + * * + * Internal implementation stuff * + * * + **************************************************************************/ + + private void updateState() { + updateState2D(); + + state3d = APPLY_NON_3D; + + if (xz != 0.0 || + yz != 0.0 || + zx != 0.0 || + zy != 0.0) + { + state3d = APPLY_3D_COMPLEX; + } else { + if ((state2d & APPLY_SHEAR) == 0) { + if (zt != 0.0) { + state3d |= APPLY_TRANSLATE; + } + if (zz != 1.0) { + state3d |= APPLY_SCALE; + } + if (state3d != APPLY_NON_3D) { + state3d |= (state2d & (APPLY_SCALE | APPLY_TRANSLATE)); + } + } else { + if (zz != 1.0 || zt != 0.0) { + state3d = APPLY_3D_COMPLEX; + } + } + } + } + + private void updateState2D() { + if (xy == 0.0 && yx == 0.0) { + if (xx == 1.0 && yy == 1.0) { + if (xt == 0.0 && yt == 0.0) { + state2d = APPLY_IDENTITY; + } else { + state2d = APPLY_TRANSLATE; + } + } else { + if (xt == 0.0 && yt == 0.0) { + state2d = APPLY_SCALE; + } else { + state2d = (APPLY_SCALE | APPLY_TRANSLATE); + } + } + } else { + if (xx == 0.0 && yy == 0.0) { + if (xt == 0.0 && yt == 0.0) { + state2d = APPLY_SHEAR; + } else { + state2d = (APPLY_SHEAR | APPLY_TRANSLATE); + } + } else { + if (xt == 0.0 && yt == 0.0) { + state2d = (APPLY_SHEAR | APPLY_SCALE); + } else { + state2d = (APPLY_SHEAR | APPLY_SCALE | APPLY_TRANSLATE); + } + } + } + } + + void ensureCanTransform2DPoint() throws IllegalStateException { + if (state3d != APPLY_NON_3D) { + throw new IllegalStateException("Cannot transform 2D point " + + "with a 3D transform"); + } + } + + private static void stateError() { + throw new InternalError("missing case in a switch"); + } + + + @Override + void apply(final Affine3D trans) { + trans.concatenate(xx, xy, xz, xt, + yx, yy, yz, yt, + zx, zy, zz, zt); + } + + @Override + BaseTransform derive(final BaseTransform trans) { + return trans.deriveWithConcatenation(xx, xy, xz, xt, + yx, yy, yz, yt, + zx, zy, zz, zt); + } + + /** + * Used only by tests to check the 2d matrix state + */ + int getState2d() { + return state2d; + } + + /** + * Used only by tests to check the 3d matrix state + */ + int getState3d() { + return state3d; + } + + } + } --- old/modules/graphics/src/main/java/javafx/scene/transform/Translate.java 2016-05-03 23:06:47.000000000 -0700 +++ new/modules/graphics/src/main/java/javafx/scene/transform/Translate.java 2016-05-03 23:06:47.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -517,23 +517,13 @@ * * **************************************************************************/ - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public void impl_apply(final Affine3D trans) { + void apply(final Affine3D trans) { trans.translate(getX(), getY(), getZ()); } - /** - * @treatAsPrivate implementation detail - * @deprecated This is an internal API that is not intended for use and will be removed in the next version - */ - @Deprecated @Override - public BaseTransform impl_derive(final BaseTransform trans) { + BaseTransform derive(final BaseTransform trans) { return trans.deriveWithTranslation(getX(), getY(), getZ()); } --- old/modules/graphics/src/test/java/javafx/scene/transform/TransformShim.java 2016-05-03 23:06:48.000000000 -0700 +++ new/modules/graphics/src/test/java/javafx/scene/transform/TransformShim.java 2016-05-03 23:06:47.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,9 @@ package javafx.scene.transform; +import com.sun.javafx.geom.transform.Affine3D; +import com.sun.javafx.geom.transform.BaseTransform; + public class TransformShim { public static boolean computeIs2D(Transform t) { @@ -35,4 +38,143 @@ t.clearInverseCache(); } + public static class ImmutableTransformShim extends Transform.ImmutableTransform { + + } + + public static Transform getImmutableTransform(Transform transform) { + return new Transform.ImmutableTransform(transform); + } + + public static Transform getImmutableTransform( + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + return new Transform.ImmutableTransform( + mxx, mxy, mxz, tx, + myx, myy, myz, ty, + mzx, mzy, mzz, tz); + } + + public static int getImmutableState2d(Transform t) { + return ((Transform.ImmutableTransform) t).getState2d(); + } + + public static int getImmutableState3d(Transform t) { + return ((Transform.ImmutableTransform) t).getState3d(); + } + + /** + * Creates a raw transformation to test the Transform class. + */ + public static Transform createRawTransform( + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + return new RawTransform( + mxx, mxy, mxz, tx, + myx, myy, myz, ty, + mzx, mzy, mzz, tz); + } + + private static class RawTransform extends Transform { + + private final double mxx, mxy, mxz, tx; + private final double myx, myy, myz, ty; + private final double mzx, mzy, mzz, tz; + + public RawTransform( + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + this.mxx = mxx; + this.mxy = mxy; + this.mxz = mxz; + this.tx = tx; + this.myx = myx; + this.myy = myy; + this.myz = myz; + this.ty = ty; + this.mzx = mzx; + this.mzy = mzy; + this.mzz = mzz; + this.tz = tz; + } + + @Override + public double getMxx() { + return mxx; + } + + @Override + public double getMxy() { + return mxy; + } + + @Override + public double getMxz() { + return mxz; + } + + @Override + public double getTx() { + return tx; + } + + @Override + public double getMyx() { + return myx; + } + + @Override + public double getMyy() { + return myy; + } + + @Override + public double getMyz() { + return myz; + } + + @Override + public double getTy() { + return ty; + } + + @Override + public double getMzx() { + return mzx; + } + + @Override + public double getMzy() { + return mzy; + } + + @Override + public double getMzz() { + return mzz; + } + + @Override + public double getTz() { + return tz; + } + + @Override + void apply(Affine3D t) { + t.concatenate( + getMxx(), getMxy(), getMxz(), getTx(), + getMyx(), getMyy(), getMyz(), getTy(), + getMzx(), getMzy(), getMzz(), getTz()); + } + + @Override + BaseTransform derive(BaseTransform t) { + return t.deriveWithConcatenation( + getMxx(), getMxy(), getMxz(), getTx(), + getMyx(), getMyy(), getMyz(), getTy(), + getMzx(), getMzy(), getMzz(), getTz()); + } + } } --- old/modules/graphics/src/test/java/test/com/sun/javafx/scene/transform/TransformUtilsTest.java 2016-05-03 23:06:48.000000000 -0700 +++ new/modules/graphics/src/test/java/test/com/sun/javafx/scene/transform/TransformUtilsTest.java 2016-05-03 23:06:48.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,9 +29,9 @@ import javafx.scene.transform.Transform; import com.sun.javafx.geom.transform.Affine3D; import com.sun.javafx.scene.transform.TransformUtils; -import com.sun.javafx.scene.transform.TransformUtilsShim; import java.util.LinkedList; import java.util.List; +import javafx.scene.transform.TransformShim; import test.javafx.scene.transform.TransformOperationsTest; import javafx.scene.transform.Translate; import static org.junit.Assert.*; @@ -41,7 +41,7 @@ public class TransformUtilsTest { @Test public void shouldCreateCorrectImmutableTransform() { - Transform t = TransformUtilsShim.getImmutableTransform( + Transform t = TransformShim.getImmutableTransform( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); @@ -57,12 +57,12 @@ Affine3D a = new Affine3D(); a.translate(10, 20); - Transform t = TransformUtilsShim.getImmutableTransform( + Transform t = TransformShim.getImmutableTransform( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); - t.impl_apply(a); + com.sun.javafx.scene.transform.TransformHelper.apply(t,a); TransformHelper.assertMatrix(a, 1, 2, 3, 14, @@ -72,7 +72,7 @@ @Test public void immutableTransformShouldCopyCorrectly() { - Transform src = TransformUtilsShim.getImmutableTransform( + Transform src = TransformShim.getImmutableTransform( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); @@ -86,7 +86,7 @@ } @Test public void testImmutableTransformToString() { - Transform trans = TransformUtilsShim.getImmutableTransform( + Transform trans = TransformShim.getImmutableTransform( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); @@ -101,14 +101,14 @@ int counter = 0; for (Object o : TransformOperationsTest.getParams()) { Object[] arr = (Object[]) o; - if (arr[0] instanceof TransformUtilsShim.ImmutableTransformShim) { - TransformUtilsShim.ImmutableTransformShim t = - (TransformUtilsShim.ImmutableTransformShim) arr[0]; + if (arr[0] instanceof TransformShim.ImmutableTransformShim) { + TransformShim.ImmutableTransformShim t = + (TransformShim.ImmutableTransformShim) arr[0]; TransformHelper.assertStateOk("Checking state of transform #" + (counter++) + " of TransformOperationsTest", t, - TransformUtilsShim.getImmutableState3d(t), - TransformUtilsShim.getImmutableState2d(t)); + TransformShim.getImmutableState3d(t), + TransformShim.getImmutableState2d(t)); } } } @@ -117,7 +117,7 @@ int counter = 0; for (Object o : TransformOperationsTest.getParams()) { Object[] arr = (Object[]) o; - if (arr[0] instanceof TransformUtilsShim.ImmutableTransformShim) { + if (arr[0] instanceof TransformShim.ImmutableTransformShim) { Transform t = (Transform) arr[0]; @@ -135,8 +135,8 @@ "Checking reusing immutable transform to values of #" + counter + " of TransformOperationsTest", returned, - (TransformUtilsShim.getImmutableState3d(returned)), - (TransformUtilsShim.getImmutableState2d(returned))); + (TransformShim.getImmutableState3d(returned)), + (TransformShim.getImmutableState2d(returned))); TransformHelper.assertMatrix("Checking reusing immutable " + "transform to values of #" + counter @@ -152,8 +152,8 @@ "Checking reusing immutable transform to values of #" + counter + " of TransformOperationsTest", returned2, - TransformUtilsShim.getImmutableState3d(returned), - TransformUtilsShim.getImmutableState2d(returned)); + TransformShim.getImmutableState3d(returned), + TransformShim.getImmutableState2d(returned)); TransformHelper.assertMatrix("Checking reusing immutable " + "transform to values of #" + counter @@ -166,21 +166,21 @@ @Test public void testConcatenatedImmutableTransform() { - List ts = new LinkedList<>(); + List ts = new LinkedList<>(); for (Object o : TransformOperationsTest.getParams()) { Object[] arr = (Object[]) o; - if (arr[0] instanceof TransformUtilsShim.ImmutableTransformShim) { - ts.add((TransformUtilsShim.ImmutableTransformShim) arr[0]); + if (arr[0] instanceof TransformShim.ImmutableTransformShim) { + ts.add((TransformShim.ImmutableTransformShim) arr[0]); } } int outer = 0; - for (TransformUtilsShim.ImmutableTransformShim t1 : ts) { + for (TransformShim.ImmutableTransformShim t1 : ts) { int inner = 0; - for (TransformUtilsShim.ImmutableTransformShim t2 : ts) { + for (TransformShim.ImmutableTransformShim t2 : ts) { int orig = 0; // reusing - for (TransformUtilsShim.ImmutableTransformShim t3 : ts) { + for (TransformShim.ImmutableTransformShim t3 : ts) { Transform clone = t3.clone(); Transform conc = TransformUtils.immutableTransform( clone, t1, t2); @@ -194,9 +194,9 @@ + "transform #" + outer + " and #" + inner + " reusing #" + orig + " of TransformOperationsTest", - (TransformUtilsShim.ImmutableTransformShim) conc, - TransformUtilsShim.getImmutableState3d(conc), - TransformUtilsShim.getImmutableState2d(conc)); + (TransformShim.ImmutableTransformShim) conc, + TransformShim.getImmutableState3d(conc), + TransformShim.getImmutableState2d(conc)); TransformHelper.assertMatrix( "Checking state of concatenation of " + "transform #" + outer + " and #" + inner + @@ -220,9 +220,9 @@ "Checking state of concatenation of " + "transform #" + outer + " and #" + inner + " of TransformOperationsTest", - (TransformUtilsShim.ImmutableTransformShim) conc2, - TransformUtilsShim.getImmutableState3d(conc2), - TransformUtilsShim.getImmutableState2d(conc2)); + (TransformShim.ImmutableTransformShim) conc2, + TransformShim.getImmutableState3d(conc2), + TransformShim.getImmutableState2d(conc2)); TransformHelper.assertMatrix( "Checking state of concatenation of " + "transform #" + outer + " and #" + inner + --- old/modules/graphics/src/test/java/test/com/sun/javafx/test/TransformHelper.java 2016-05-03 23:06:49.000000000 -0700 +++ new/modules/graphics/src/test/java/test/com/sun/javafx/test/TransformHelper.java 2016-05-03 23:06:49.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -650,117 +650,4 @@ myx, myy, 0.0, ty, 0.0, 0.0, 1.0, 0.0); } - - /** - * Creates a raw transformation to test the Transform class. - */ - public static Transform rawTransform( - double mxx, double mxy, double mxz, double tx, - double myx, double myy, double myz, double ty, - double mzx, double mzy, double mzz, double tz) { - return new RawTransform( - mxx, mxy, mxz, tx, - myx, myy, myz, ty, - mzx, mzy, mzz, tz); - } - - private static class RawTransform extends Transform { - private final double mxx, mxy, mxz, tx; - private final double myx, myy, myz, ty; - private final double mzx, mzy, mzz, tz; - - public RawTransform( - double mxx, double mxy, double mxz, double tx, - double myx, double myy, double myz, double ty, - double mzx, double mzy, double mzz, double tz) { - this.mxx = mxx; - this.mxy = mxy; - this.mxz = mxz; - this.tx = tx; - this.myx = myx; - this.myy = myy; - this.myz = myz; - this.ty = ty; - this.mzx = mzx; - this.mzy = mzy; - this.mzz = mzz; - this.tz = tz; - } - - @Override - public double getMxx() { - return mxx; - } - - @Override - public double getMxy() { - return mxy; - } - - @Override - public double getMxz() { - return mxz; - } - - @Override - public double getTx() { - return tx; - } - - @Override - public double getMyx() { - return myx; - } - - @Override - public double getMyy() { - return myy; - } - - @Override - public double getMyz() { - return myz; - } - - @Override - public double getTy() { - return ty; - } - - @Override - public double getMzx() { - return mzx; - } - - @Override - public double getMzy() { - return mzy; - } - - @Override - public double getMzz() { - return mzz; - } - - @Override - public double getTz() { - return tz; - } - - @Override - public void impl_apply(Affine3D t) { - t.concatenate( - getMxx(), getMxy(), getMxz(), getTx(), - getMyx(), getMyy(), getMyz(), getTy(), - getMzx(), getMzy(), getMzz(), getTz()); - } - - @Override - public BaseTransform impl_derive(BaseTransform t) { - return t.deriveWithConcatenation( - getMxx(), getMxy(), getMxz(), getTx(), - getMyx(), getMyy(), getMyz(), getTy(), - getMzx(), getMzy(), getMzz(), getTz()); - } - } } --- old/modules/graphics/src/test/java/test/javafx/scene/CameraTest.java 2016-05-03 23:06:50.000000000 -0700 +++ new/modules/graphics/src/test/java/test/javafx/scene/CameraTest.java 2016-05-03 23:06:50.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -144,7 +144,8 @@ camera.getParent().setTranslateY(100); Affine3D expected = new Affine3D(); try { - camera.getLocalToSceneTransform().createInverse().impl_apply(expected); + com.sun.javafx.scene.transform.TransformHelper.apply( + camera.getLocalToSceneTransform().createInverse(), expected); } catch (NonInvertibleTransformException ex) { fail("NonInvertibleTransformException when compute sceneToLocalTx."); } @@ -154,7 +155,8 @@ camera.setScaleX(10); expected.setToIdentity(); try { - camera.getLocalToSceneTransform().createInverse().impl_apply(expected); + com.sun.javafx.scene.transform.TransformHelper.apply( + camera.getLocalToSceneTransform().createInverse(), expected); } catch (NonInvertibleTransformException ex) { fail("NonInvertibleTransformException when compute sceneToLocalTx."); } @@ -171,7 +173,8 @@ assertEquals(expected, CameraShim.getSceneToLocalTransform(camera)); try { - camera.getLocalToSceneTransform().createInverse().impl_apply(expected); + com.sun.javafx.scene.transform.TransformHelper.apply( + camera.getLocalToSceneTransform().createInverse(), expected); } catch (NonInvertibleTransformException ex) { fail("NonInvertibleTransformException when compute sceneToLocalTx."); } @@ -181,7 +184,8 @@ camera.setScaleX(10); expected.setToIdentity(); try { - camera.getLocalToSceneTransform().createInverse().impl_apply(expected); + com.sun.javafx.scene.transform.TransformHelper.apply( + camera.getLocalToSceneTransform().createInverse(), expected); } catch (NonInvertibleTransformException ex) { fail("NonInvertibleTransformException when compute sceneToLocalTx."); } --- old/modules/graphics/src/test/java/test/javafx/scene/transform/TransformDeriveTest.java 2016-05-03 23:06:51.000000000 -0700 +++ new/modules/graphics/src/test/java/test/javafx/scene/transform/TransformDeriveTest.java 2016-05-03 23:06:51.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -215,7 +215,7 @@ @Test public void testDerive() { Transform conc = TransformHelper.concatenate(from, deriver); - BaseTransform res = deriver.impl_derive(from); + BaseTransform res = com.sun.javafx.scene.transform.TransformHelper.derive(deriver, from); assertSame(deriveType, res.getClass()); TransformHelper.assertMatrix(res, --- old/modules/graphics/src/test/java/test/javafx/scene/transform/TransformOperationsTest.java 2016-05-03 23:06:52.000000000 -0700 +++ new/modules/graphics/src/test/java/test/javafx/scene/transform/TransformOperationsTest.java 2016-05-03 23:06:51.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -265,25 +265,25 @@ private static final Transform immutable_nonInv_sc_tr_y = TransformHelper.immutableTransform(0, 0, 0, 0, 2, 7); private static final Transform raw_arbitrary_nonInvertible = - TransformHelper.rawTransform( 5, 6, 7, 8, - 10, 11, 12, 13, - 15, 16, 17, 18); + TransformShim.createRawTransform(5, 6, 7, 8, + 10, 11, 12, 13, + 15, 16, 17, 18); private static final Transform raw_arbitrary = - TransformHelper.rawTransform( 5, 6, 13, 8, - 10, 4, 12, 13, - 15, 16, 26, 18); + TransformShim.createRawTransform(5, 6, 13, 8, + 10, 4, 12, 13, + 15, 16, 26, 18); private static final Transform raw_empty = - TransformHelper.rawTransform(0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0); + TransformShim.createRawTransform(0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0); private static final Transform raw_emptyZ = - TransformHelper.rawTransform(1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 0, 0); + TransformShim.createRawTransform(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 0, 0); private static final Transform raw_emptyXY = - TransformHelper.rawTransform(0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 1, 0); + TransformShim.createRawTransform(0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 1, 0); private boolean listenerCalled; private int eventCounter; --- old/modules/graphics/src/test/java/test/javafx/scene/transform/TransformTest.java 2016-05-03 23:06:52.000000000 -0700 +++ new/modules/graphics/src/test/java/test/javafx/scene/transform/TransformTest.java 2016-05-03 23:06:52.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -48,6 +48,7 @@ import javafx.scene.transform.Rotate; import javafx.scene.transform.Scale; import javafx.scene.transform.Transform; +import javafx.scene.transform.TransformShim; import static org.junit.Assert.*; @@ -155,13 +156,10 @@ @Test public void defaultTransformShouldBeIdentity() { - final Transform t = new Transform() { - @Override - public void impl_apply(com.sun.javafx.geom.transform.Affine3D ad) {} - - @Override - public BaseTransform impl_derive(BaseTransform ad) { return null; } - }; + final Transform t = TransformShim.createRawTransform( + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0); TransformHelper.assertMatrix(t, 1, 0, 0, 0, --- /dev/null 2016-05-03 23:06:53.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/javafx/scene/transform/TransformHelper.java 2016-05-03 23:06:53.000000000 -0700 @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.javafx.scene.transform; + +import com.sun.javafx.geom.transform.Affine3D; +import com.sun.javafx.geom.transform.BaseTransform; +import javafx.scene.Node; +import javafx.scene.transform.Transform; + +/** + * Used to access internal methods of Transform. + */ +public class TransformHelper { + + private static TransformAccessor transformAccessor; + + static { + forceInit(Transform.class); + } + + private TransformHelper() { + } + + public static void add(Transform transform, Node node) { + transformAccessor.add(transform, node); + } + + public static void remove(Transform transform, Node node) { + transformAccessor.remove(transform, node); + } + + public static void apply(Transform transform, Affine3D affine3D) { + transformAccessor.apply(transform, affine3D); + } + + public static BaseTransform derive(Transform transform, BaseTransform baseTransform) { + return transformAccessor.derive(transform, baseTransform); + } + + public static Transform createImmutableTransform() { + return transformAccessor.createImmutableTransform(); + } + + public static Transform createImmutableTransform( + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + return transformAccessor.createImmutableTransform(mxx, mxy, mxz, tx, + myx, myy, myz, ty, mzx, mzy, mzz, tz); + } + + public static Transform createImmutableTransform(Transform transform, + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz) { + return transformAccessor.createImmutableTransform(transform, mxx, mxy, mxz, tx, + myx, myy, myz, ty, mzx, mzy, mzz, tz); + } + + public static Transform createImmutableTransform(Transform transform, + Transform left, Transform right) { + return transformAccessor.createImmutableTransform(transform, left, right); + } + + public static void setTransformAccessor(final TransformAccessor newAccessor) { + if (transformAccessor != null) { + throw new IllegalStateException(); + } + + transformAccessor = newAccessor; + } + + public interface TransformAccessor { + + void add(Transform transform, Node node); + + void remove(Transform transform, Node node); + + void apply(Transform transform, Affine3D affine3D); + + BaseTransform derive(Transform transform, BaseTransform baseTransform); + + Transform createImmutableTransform(); + + Transform createImmutableTransform(double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz); + + Transform createImmutableTransform(Transform transform, + double mxx, double mxy, double mxz, double tx, + double myx, double myy, double myz, double ty, + double mzx, double mzy, double mzz, double tz); + + Transform createImmutableTransform(Transform transform, + Transform left, Transform right); + } + + private static void forceInit(final Class classToInit) { + try { + Class.forName(classToInit.getName(), true, + classToInit.getClassLoader()); + } catch (final ClassNotFoundException e) { + throw new AssertionError(e); // Can't happen + } + } + +} --- old/modules/graphics/src/test/java/com/sun/javafx/scene/transform/TransformUtilsShim.java 2016-05-03 23:06:54.000000000 -0700 +++ /dev/null 2016-05-03 23:06:54.000000000 -0700 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.javafx.scene.transform; - -import com.sun.javafx.scene.transform.TransformUtils.ImmutableTransform; -import javafx.scene.transform.Transform; - -public class TransformUtilsShim { - - public static Transform getImmutableTransform(Transform transform) { - return new TransformUtils.ImmutableTransform(transform); - } - - public static Transform getImmutableTransform( - double mxx, double mxy, double mxz, double tx, - double myx, double myy, double myz, double ty, - double mzx, double mzy, double mzz, double tz) { - return new TransformUtils.ImmutableTransform( - mxx, mxy, mxz, tx, - myx, myy, myz, ty, - mzx, mzy, mzz, tz); - } - - public static int getImmutableState2d(Transform t) { - return ((TransformUtils.ImmutableTransform) t).getState2d(); - } - - public static int getImmutableState3d(Transform t) { - return ((TransformUtils.ImmutableTransform) t).getState3d(); - } - - public static class ImmutableTransformShim extends ImmutableTransform { - - } - -}