This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 1084046ff4 Correction in `transform(MathTransform)` method contract: 
CRS is null. Avoid copying the shape in `toJava2D()`.
1084046ff4 is described below

commit 1084046ff466aa99f682933595d526b90a3ee115
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Mon Jan 29 11:13:31 2024 +0100

    Correction in `transform(MathTransform)` method contract: CRS is null.
    Avoid copying the shape in `toJava2D()`.
---
 .../org/apache/sis/geometry/wrapper/GeometryWrapper.java  | 15 +++++++++------
 .../main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java |  6 +++---
 .../main/org/apache/sis/geometry/wrapper/jts/Wrapper.java | 10 ++++++----
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java
index 319ca1672f..882fa1e96d 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java
@@ -475,16 +475,17 @@ public abstract class GeometryWrapper extends 
AbstractGeometry implements Geomet
     /**
      * Transforms this geometry using the given transform.
      * If the transform is {@code null}, then the geometry is returned 
unchanged.
-     * The geometry CRS remains unchanged.
+     * Otherwise, a new geometry is returned without CRS.
      *
      * @param  transform  the math transform to apply, or {@code null}.
      * @return the transformed geometry (may be the same geometry instance, 
but never {@code null}).
      * @throws UnsupportedOperationException if this operation is not 
supported for current implementation.
      * @throws TransformException if the geometry cannot be transformed.
      */
-    public GeometryWrapper transform(MathTransform transform)
-            throws TransformException
-    {
+    public GeometryWrapper transform(MathTransform transform) throws 
TransformException {
+        if (transform == null || transform.isIdentity()) {
+            return this;
+        }
         throw new 
UnsupportedOperationException(Geometries.unsupported("transform"));
     }
 
@@ -542,9 +543,11 @@ public abstract class GeometryWrapper extends 
AbstractGeometry implements Geomet
 
     /**
      * Returns a Java2D shape made from this geometry.
+     * The returned shape may be a view backed by the {@linkplain 
#implementation() geometry implementation},
+     * or may be an internal object returned directly. Caller should not 
attempt to modify the returned shape.
+     * Changes in the geometry implementation may or may not be reflected in 
the returned Java2D shape.
      *
-     * @param  geometry  the geometry as a shape, not {@code null}.
-     * @return the Java2D shape.
+     * @return a view, copy or direct reference to the geometry as a Java2D 
shape.
      * @throws UnsupportedOperationException if this operation is not 
supported for current implementation.
      */
     public Shape toJava2D() {
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java
index 8ca25c929c..b03fe61104 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/j2d/Wrapper.java
@@ -22,7 +22,6 @@ import java.util.Iterator;
 import java.util.function.BiPredicate;
 import java.awt.Shape;
 import java.awt.geom.Area;
-import java.awt.geom.GeneralPath;
 import java.awt.geom.Path2D;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
@@ -199,11 +198,12 @@ add:    for (;;) {
     }
 
     /**
-     * @return shape copy.
+     * {@return directly the underlying Java2D geometry}. This method does not 
copy the shape.
+     * Caller should not modify the returned shape (by casting to an 
implementation class).
      */
     @Override
     public Shape toJava2D() {
-        return new GeneralPath(geometry);
+        return geometry;
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java
index 882e9106df..aeede8b8a3 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/jts/Wrapper.java
@@ -17,7 +17,6 @@
 package org.apache.sis.geometry.wrapper.jts;
 
 import java.awt.Shape;
-import java.awt.geom.GeneralPath;
 import java.util.List;
 import java.util.Arrays;
 import java.util.ArrayList;
@@ -733,7 +732,7 @@ add:    for (Geometry next = geometry;;) {
     /**
      * Transforms this geometry using the given transform.
      * If the transform is {@code null}, then the geometry is returned 
unchanged.
-     * The geometry CRS remains unchanged.
+     * Otherwise, a new geometry is returned without CRS.
      *
      * @param  transform  the math transform to apply, or {@code null}.
      * @return the transformed geometry (may be the same geometry instance, 
but never {@code null}).
@@ -745,11 +744,14 @@ add:    for (Geometry next = geometry;;) {
     }
 
     /**
-     * @return GeneralPath from current JTS Geometry.
+     * Returns a view over the JTS geometry as a Java2D shape. Changes in the 
JTS geometry
+     * after this method call may be reflected in the returned shape in an 
unspecified way.
+     *
+     * @return a view over the geometry as a Java2D shape.
      */
     @Override
     public Shape toJava2D() {
-        return new GeneralPath(JTS.asShape(geometry));
+        return JTS.asShape(geometry);
     }
 
     /**

Reply via email to