sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1600698 - in /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis: internal/referencing/j2d/ referencing/operation/transform/
Date Thu, 05 Jun 2014 16:54:47 GMT
Author: desruisseaux
Date: Thu Jun  5 16:54:46 2014
New Revision: 1600698

URL: http://svn.apache.org/r1600698
Log:
Moved AffineTransform2D to the "j2d" internal package, for making clearer its dependency toward
Java2D
and for allowing reuse by other packages than org.apache.sis.referencing.operation.transform.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
      - copied, changed from r1600683, sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java
Removed:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java

Copied: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
(from r1600683, sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java?p2=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java&p1=sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java&r1=1600683&r2=1600698&rev=1600698&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
[UTF-8] Thu Jun  5 16:54:46 2014
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.referencing.operation.transform;
+package org.apache.sis.internal.referencing.j2d;
 
 import java.awt.Shape;
 import java.awt.geom.Point2D;
@@ -30,9 +30,9 @@ import org.apache.sis.parameter.Paramete
 import org.apache.sis.parameter.TensorParameters;
 import org.apache.sis.referencing.operation.matrix.Matrix2;
 import org.apache.sis.referencing.operation.matrix.AffineTransforms2D;
+import org.apache.sis.referencing.operation.transform.LinearTransform;
 import org.apache.sis.referencing.operation.provider.Affine;
 import org.apache.sis.io.wkt.Formatter;
-import org.apache.sis.internal.referencing.j2d.ImmutableAffineTransform;
 import org.apache.sis.util.LenientComparable;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Workaround;
@@ -53,8 +53,8 @@ import static org.apache.sis.util.Argume
  *
  * @see ProjectiveTransform
  */
-final class AffineTransform2D extends ImmutableAffineTransform implements MathTransform2D,
LinearTransform,
-        LenientComparable, Parameterized, Cloneable
+public class AffineTransform2D extends ImmutableAffineTransform implements MathTransform2D,
+        LinearTransform, LenientComparable, Parameterized, Cloneable
 {
     /**
      * Serial number for inter-operability with different versions.
@@ -69,21 +69,36 @@ final class AffineTransform2D extends Im
     /**
      * {@code true} if this transform is mutable. This field may be temporarily set
      * to {@code true} during construction, but <strong>must</strong> be reset
to
-     * {@code false} before a reference to {@link AffineTransform2D} is made public.
+     * {@code false} before an {@link AffineTransform2D} instance is published.
+     *
+     * @see #freeze()
      */
-    transient boolean mutable;
+    private transient boolean mutable;
 
     /**
-     * Constructs an identity affine transform.  This constructor is reserved to code that
-     * temporarily set the {@linkplain #mutable} flag to {@code true} for initializing the
-     * affine transform.
+     * Constructs a <strong>temporarily mutable</strong> identity affine transform.
+     * Callers shall initializing the affine transform to the desired final values,
+     * then invoke {@link #freeze()}.
      */
-    AffineTransform2D() {
+    public AffineTransform2D() {
         super();
+        mutable = true;
+    }
+
+    /**
+     * Constructs a new affine transform with the same coefficients than the specified transform.
+     *
+     * @param transform The affine transform to copy.
+     * @param mutable {@code true} if this affine transform needs to be <strong>temporarily</strong>
mutable.
+     *        If {@code true}, then caller shall invoke {@link #freeze()} after they completed
initialization.
+     */
+    public AffineTransform2D(final AffineTransform transform, final boolean mutable) {
+        super(transform);
+        this.mutable = mutable;
     }
 
     /**
-     * Constructs a new affine transform with the same coefficient than the specified transform.
+     * Constructs a new affine transform with the same coefficients than the specified transform.
      *
      * @param transform The affine transform to copy.
      */
@@ -112,11 +127,14 @@ final class AffineTransform2D extends Im
     }
 
     /**
-     * Makes sure that the zero is positive. We do that in order to workaround a JDK 6 bug,
-     * where AffineTransform.hashCode() is inconsistent with AffineTransform.equals(Object)
+     * Makes sure that the zero is positive. We do that in order to workaround a JDK 6 to
8 bug, where
+     * {@link AffineTransform#hashCode()} is inconsistent with {@link AffineTransform#equals(Object)}
      * if there is zeros of opposite sign.
+     *
+     * <p>The inconsistency is in the use of {@link Double#doubleToLongBits(double)}
for hash code and
+     * {@code ==} for testing equality. The former is sensitive to the sign of 0 while the
later is not.</p>
      */
-    @Workaround(library="JDK", version="6")
+    @Workaround(library="JDK", version="8") // Last verified in 1.8.0_05.
     private static double pz(final double value) {
         return (value != 0) ? value : 0;
     }
@@ -124,13 +142,20 @@ final class AffineTransform2D extends Im
     /**
      * Ensures that this transform contains only positive zeros.
      */
-    final void forcePositiveZeros() {
+    public final void forcePositiveZeros() {
         super.setTransform(pz(super.getScaleX()),     pz(super.getShearY()),
                            pz(super.getShearX()),     pz(super.getScaleY()),
                            pz(super.getTranslateX()), pz(super.getTranslateY()));
     }
 
     /**
+     * Makes this {@code AffineTransform2D} immutable.
+     */
+    public final void freeze() {
+        mutable = false;
+    }
+
+    /**
      * Throws an {@link UnsupportedOperationException} when a mutable method
      * is invoked, since {@code AffineTransform2D} must be immutable.
      *
@@ -181,7 +206,7 @@ final class AffineTransform2D extends Im
      * Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}.
      */
     @Override
-    public DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst) {
+    public final DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst)
{
         ensureDimensionMatches("ptSrc", 2, ptSrc);
         /*
          * Try to write directly in the destination point if possible. Following
@@ -227,7 +252,7 @@ final class AffineTransform2D extends Im
      * @return Transformed shape, or {@code shape} if this transform is the identity transform.
      */
     @Override
-    public Shape createTransformedShape(final Shape shape) {
+    public final Shape createTransformedShape(final Shape shape) {
         return AffineTransforms2D.transform(this, shape, false);
     }
 
@@ -235,7 +260,7 @@ final class AffineTransform2D extends Im
      * Returns this transform as an affine transform matrix.
      */
     @Override
-    public Matrix getMatrix() {
+    public final Matrix getMatrix() {
         return AffineTransforms2D.toMatrix(this);
     }
 
@@ -244,7 +269,7 @@ final class AffineTransform2D extends Im
      * For an affine transform, the derivative is the same everywhere.
      */
     @Override
-    public Matrix derivative(final Point2D point) {
+    public final Matrix derivative(final Point2D point) {
         return new Matrix2(getScaleX(), getShearX(),
                            getShearY(), getScaleY());
     }
@@ -254,7 +279,7 @@ final class AffineTransform2D extends Im
      * For an affine transform, the derivative is the same everywhere.
      */
     @Override
-    public Matrix derivative(final DirectPosition point) {
+    public final Matrix derivative(final DirectPosition point) {
         return derivative((Point2D) null);
     }
 
@@ -264,7 +289,7 @@ final class AffineTransform2D extends Im
      * @throws NoninvertibleTransformException if this transform can not be inverted.
      */
     @Override
-    public MathTransform2D inverse() throws NoninvertibleTransformException {
+    public final MathTransform2D inverse() throws NoninvertibleTransformException {
         if (inverse == null) {
             if (super.isIdentity()) {
                 inverse = this;
@@ -275,11 +300,10 @@ final class AffineTransform2D extends Im
                  * declared volatile (Joshua Bloch, "Effective Java" second edition).
                  */
                 if (inverse == null) try {
-                    final AffineTransform2D work = new AffineTransform2D(this);
-                    work.mutable = true;
+                    final AffineTransform2D work = new AffineTransform2D(this, true);
                     work.invert();
                     work.forcePositiveZeros();
-                    work.mutable = false;
+                    work.freeze();
                     work.inverse = this;
                     inverse = work; // Set only on success.
                 } catch (java.awt.geom.NoninvertibleTransformException exception) {
@@ -303,10 +327,17 @@ final class AffineTransform2D extends Im
      */
     @Override
     public boolean equals(final Object object, final ComparisonMode mode) {
+        if (object == this) { // Slight optimization
+            return true;
+        }
         if (mode == ComparisonMode.STRICT) {
             return equals(object);
         }
-        return (object == this) || AbstractMathTransform.equals(this, object, mode);
+        if (object instanceof LinearTransform) {
+            final Matrix m2 = ((LinearTransform) object).getMatrix();
+            return AffineTransforms2D.toMatrix(this).equals(m2, mode);
+        }
+        return false;
     }
 
     /**
@@ -365,6 +396,8 @@ final class AffineTransform2D extends Im
      * Returns a new affine transform which is a modifiable copy of this transform. This
implementation always
      * returns an instance of {@link AffineTransform}, <strong>not</strong> {@code
AffineTransform2D}, because
      * the later is unmodifiable and cloning it make little sense.
+     *
+     * @return A modifiable copy of this affine transform.
      */
     @Override
     public AffineTransform clone() {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java?rev=1600698&r1=1600697&r2=1600698&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java
[UTF-8] Thu Jun  5 16:54:46 2014
@@ -31,7 +31,7 @@ import org.apache.sis.util.resources.Err
  * @version 0.5
  * @module
  */
-public class ImmutableAffineTransform extends AffineTransform {
+class ImmutableAffineTransform extends AffineTransform {
     /**
      * Serial number for inter-operability with different versions.
      */

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java?rev=1600698&r1=1600697&r2=1600698&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
[UTF-8] Thu Jun  5 16:54:46 2014
@@ -28,6 +28,7 @@ import org.apache.sis.geometry.GeneralDi
 import org.apache.sis.parameter.TensorParameters;
 import org.apache.sis.referencing.operation.provider.Affine;
 import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
 
 
 /**
@@ -91,9 +92,11 @@ final class IdentityTransform extends Ab
                 }
             }
             switch (dimension) {
-                case 1:  candidate = IdentityTransform1D.INSTANCE;     break;
-                case 2:  candidate = new AffineTransform2D();          break;
                 default: candidate = new IdentityTransform(dimension); break;
+                case 1:  candidate = IdentityTransform1D.INSTANCE;     break;
+                case 2:  candidate = new AffineTransform2D();
+                         ((AffineTransform2D) candidate).freeze();
+                         break;
             }
             if (dimension < IDENTITIES.length) {
                 IDENTITIES[dimension] = candidate;



Mime
View raw message