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

jsorel 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 133d1e5b49 feat(Geometry): replace Affine.toMatrix(buffer) by 
Matrix.setFromAffine(affine)
133d1e5b49 is described below

commit 133d1e5b49d940a2dfc351d06ceb95a7f83ea92f
Author: jsorel <[email protected]>
AuthorDate: Mon Mar 9 16:45:05 2026 +0100

    feat(Geometry): replace Affine.toMatrix(buffer) by 
Matrix.setFromAffine(affine)
---
 .../org/apache/sis/geometries/math/Affine1D.java   | 12 +-------
 .../org/apache/sis/geometries/math/Affine2D.java   | 17 +----------
 .../org/apache/sis/geometries/math/Affine3D.java   | 25 ----------------
 .../org/apache/sis/geometries/math/Affine4D.java   | 35 ----------------------
 .../org/apache/sis/geometries/math/AffineND.java   | 19 +++++-------
 .../main/org/apache/sis/geometries/math/Array.java |  2 +-
 .../sis/geometries/math/ArraySpliterator.java      |  6 ++--
 .../org/apache/sis/geometries/math/Matrix.java     |  8 +++++
 .../org/apache/sis/geometries/math/Matrix2D.java   |  9 ++++++
 .../org/apache/sis/geometries/math/Matrix3D.java   | 14 +++++++++
 .../org/apache/sis/geometries/math/Matrix4D.java   | 24 +++++++++++++++
 .../org/apache/sis/geometries/math/MatrixND.java   | 12 ++++++++
 .../org/apache/sis/geometries/math/NDArray.java    |  2 +-
 .../org/apache/sis/geometries/math/ReadOnly.java   |  9 ------
 .../operation/triangulate/EarClipping.java         |  2 +-
 .../apache/sis/geometries/math/NDArraysTest.java   |  4 +--
 16 files changed, 84 insertions(+), 116 deletions(-)

diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine1D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine1D.java
index 7669e32561..66d09bf495 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine1D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine1D.java
@@ -149,20 +149,10 @@ public final class Affine1D extends 
AbstractAffine<Affine1D> implements Transfor
     }
 
     @Override
-    public Matrix<?> toMatrix() {
+    public Matrix2D toMatrix() {
         return new Matrix2D(m00, m01, 0, 1);
     }
 
-    @Override
-    public Matrix<?> toMatrix(Matrix<?> buffer) {
-        if (buffer==null) return toMatrix();
-        buffer.set(0, 0, m00);
-        buffer.set(0, 1, m01);
-        buffer.set(1, 0, 0);
-        buffer.set(1, 1, 1);
-        return buffer;
-    }
-
     @Override
     public Affine1D copy() {
         return new Affine1D(m00, m01);
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine2D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine2D.java
index 981349312d..a6f6297535 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine2D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine2D.java
@@ -207,25 +207,10 @@ public final class Affine2D extends 
AbstractAffine<Affine2D> {
     }
 
     @Override
-    public Matrix<?> toMatrix() {
+    public Matrix3D toMatrix() {
         return new Matrix3D(m00, m01, m02, m10, m11, m12, 0, 0, 1);
     }
 
-    @Override
-    public Matrix<?> toMatrix(Matrix<?> buffer) {
-        if (buffer == null) return toMatrix();
-        buffer.set(0, 0, m00);
-        buffer.set(0, 1, m01);
-        buffer.set(0, 2, m02);
-        buffer.set(1, 0, m10);
-        buffer.set(1, 1, m11);
-        buffer.set(1, 2, m12);
-        buffer.set(2, 0, 0);
-        buffer.set(2, 1, 0);
-        buffer.set(2, 2, 1);
-        return buffer;
-    }
-
     public Matrix4D toMatrix4() {
         return new Matrix4D(
                 m00, m01,   0, m02,
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine3D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine3D.java
index 24ca3939fc..6e6c4f666a 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine3D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine3D.java
@@ -330,31 +330,6 @@ public final class Affine3D extends 
AbstractAffine<Affine3D> {
                   0,   0,   0,   1);
     }
 
-    @Override
-    public Matrix<?> toMatrix(Matrix<?> buffer) {
-        if (buffer == null) return toMatrix();
-        buffer.set(0, 0, m00);
-        buffer.set(0, 1, m01);
-        buffer.set(0, 2, m02);
-        buffer.set(0, 3, m03);
-
-        buffer.set(1, 0, m10);
-        buffer.set(1, 1, m11);
-        buffer.set(1, 2, m12);
-        buffer.set(1, 3, m13);
-
-        buffer.set(2, 0, m20);
-        buffer.set(2, 1, m21);
-        buffer.set(2, 2, m22);
-        buffer.set(2, 3, m23);
-
-        buffer.set(3, 0, 0);
-        buffer.set(3, 1, 0);
-        buffer.set(3, 2, 0);
-        buffer.set(3, 3, 1);
-        return buffer;
-    }
-
     /**
      * Create a rotation matrix from given angle and axis.
      *
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine4D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine4D.java
index 5688e90e6a..e233a0843d 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine4D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Affine4D.java
@@ -475,41 +475,6 @@ public final class Affine4D extends 
AbstractAffine<Affine4D> {
         return m;
     }
 
-    @Override
-    public Matrix<?> toMatrix(Matrix<?> buffer) {
-        if (buffer == null) return toMatrix();
-        buffer.set(0, 0, m00);
-        buffer.set(0, 1, m01);
-        buffer.set(0, 2, m02);
-        buffer.set(0, 3, m03);
-        buffer.set(0, 4, m04);
-
-        buffer.set(1, 0, m10);
-        buffer.set(1, 1, m11);
-        buffer.set(1, 2, m12);
-        buffer.set(1, 3, m13);
-        buffer.set(1, 4, m14);
-
-        buffer.set(2, 0, m20);
-        buffer.set(2, 1, m21);
-        buffer.set(2, 2, m22);
-        buffer.set(2, 3, m23);
-        buffer.set(2, 4, m24);
-
-        buffer.set(3, 0, m30);
-        buffer.set(3, 1, m31);
-        buffer.set(3, 2, m32);
-        buffer.set(3, 3, m33);
-        buffer.set(3, 4, m34);
-
-        buffer.set(4, 0, 0);
-        buffer.set(4, 1, 0);
-        buffer.set(4, 2, 0);
-        buffer.set(4, 3, 0);
-        buffer.set(4, 4, 1);
-        return buffer;
-    }
-
     @Override
     public Affine4D copy() {
         return new Affine4D(m00, m01, m02, m03, m04, m10, m11, m12, m13, m14, 
m20, m21, m22, m23, m24, m30, m31, m32, m33, m34);
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/AffineND.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/AffineND.java
index dcd0cfc9f5..921b9a469b 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/AffineND.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/AffineND.java
@@ -50,7 +50,13 @@ public final class AffineND extends AbstractAffine<AffineND> 
{
 
     @Override
     public Matrix<?> toMatrix() {
-        throw new UnsupportedOperationException("Not supported yet.");
+        final Matrix<?> buffer = MatrixND.create(dim+1, +1);
+        for (int y=0;y<dim;y++) {
+            for (int x=0;x<=dim;x++) {
+                buffer.set(y, x, values[y][x]);
+            }
+        }
+        return buffer;
     }
 
     @Override
@@ -84,17 +90,6 @@ public final class AffineND extends AbstractAffine<AffineND> 
{
         throw new UnsupportedOperationException("Not supported yet.");
     }
 
-    @Override
-    public Matrix<?> toMatrix(Matrix<?> buffer) {
-        if (buffer == null) buffer = MatrixND.create(dim+1, +1);
-        for (int y=0;y<dim;y++) {
-            for (int x=0;x<=dim;x++) {
-                buffer.set(y, x, values[y][x]);
-            }
-        }
-        return buffer;
-    }
-
     @Override
     public AffineND copy() {
         final AffineND aff = new AffineND(dim);
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Array.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Array.java
index 2f986aceed..75a77dd290 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Array.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Array.java
@@ -360,7 +360,7 @@ public interface Array extends NDArray {
      * @return tuple stream over this array.
      */
     @Override
-    default Stream<Tuple> stream(boolean parallel) {
+    default Stream<Tuple<?>> stream(boolean parallel) {
         return StreamSupport.stream(new ArraySpliterator(this), parallel);
     }
 
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/ArraySpliterator.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/ArraySpliterator.java
index d089d2a83f..e1a1aa3407 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/ArraySpliterator.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/ArraySpliterator.java
@@ -24,7 +24,7 @@ import java.util.function.Consumer;
  *
  * @author Johann Sorel (Geomatys)
  */
-final class ArraySpliterator implements Spliterator<Tuple>{
+final class ArraySpliterator implements Spliterator<Tuple<?>>{
 
     private final Array array;
     /**
@@ -52,7 +52,7 @@ final class ArraySpliterator implements Spliterator<Tuple>{
     }
 
     @Override
-    public boolean tryAdvance(Consumer<? super Tuple> action) {
+    public boolean tryAdvance(Consumer<? super Tuple<?>> action) {
         if (rangeStart >= rangeEnd) return false;
         if (cursor == null) cursor = array.cursor();
         cursor.moveTo(rangeStart);
@@ -62,7 +62,7 @@ final class ArraySpliterator implements Spliterator<Tuple>{
     }
 
     @Override
-    public Spliterator<Tuple> trySplit() {
+    public Spliterator<Tuple<?>> trySplit() {
         long remaining = rangeEnd - rangeStart;
         if (remaining < 5) {
             //too few elements to split it
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix.java
index fd1a207123..89739a39e0 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix.java
@@ -50,6 +50,14 @@ public interface Matrix<T extends Matrix<T>> extends 
ReadOnly.Matrix<T>, org.ope
 
     T setFromGeoapi(org.opengis.referencing.operation.Matrix matrix);
 
+    /**
+     * set to ad square matrix of size dimensions+1
+     * The last matrix line will be [0,...,1]
+     *
+     * @return this matrix
+     */
+    T setFromAffine(ReadOnly.Affine<?> affine);
+
     T set(double[] values, boolean rowOrder);
 
     T set(double[][] values, boolean rowOrder);
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix2D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix2D.java
index 7aa4258f20..3c8482b9fa 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix2D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix2D.java
@@ -132,6 +132,15 @@ public class Matrix2D extends AbstractMatrix<Matrix2D> {
         return this;
     }
 
+    @Override
+    public Matrix2D setFromAffine(ReadOnly.Affine<?> affine) {
+        m00 = affine.get(0, 0);
+        m01 = affine.get(0, 1);
+        m10 = 0;
+        m11 = 1;
+        return this;
+    }
+
     @Override
     public boolean isIdentity() {
         return m00==1.0 && m01==0.0
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix3D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix3D.java
index abfc1f6d5a..2c522a8f40 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix3D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix3D.java
@@ -411,6 +411,20 @@ public class Matrix3D extends AbstractMatrix<Matrix3D> {
         return this;
     }
 
+    @Override
+    public Matrix3D setFromAffine(ReadOnly.Affine<?> affine) {
+        m00 = affine.get(0, 0);
+        m01 = affine.get(0, 1);
+        m02 = affine.get(0, 2);
+        m10 = affine.get(1, 0);
+        m11 = affine.get(1, 1);
+        m12 = affine.get(1, 2);
+        m20 = 0;
+        m21 = 0;
+        m22 = 1;
+        return this;
+    }
+
     @Override
     public Matrix3D copy() {
         return new Matrix3D(this);
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix4D.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix4D.java
index 50dace9706..ac07075edd 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix4D.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/Matrix4D.java
@@ -392,6 +392,30 @@ public class Matrix4D extends AbstractMatrix<Matrix4D> {
         return set(m, ROW_ORDER);
     }
 
+    @Override
+    public Matrix4D setFromAffine(ReadOnly.Affine<?> affine) {
+        m00 = affine.get(0, 0);
+        m01 = affine.get(0, 1);
+        m02 = affine.get(0, 2);
+        m03 = affine.get(0, 3);
+
+        m10 = affine.get(1, 0);
+        m11 = affine.get(1, 1);
+        m12 = affine.get(1, 2);
+        m13 = affine.get(1, 3);
+
+        m20 = affine.get(2, 0);
+        m21 = affine.get(2, 1);
+        m22 = affine.get(2, 2);
+        m23 = affine.get(2, 3);
+
+        m30 = 0;
+        m31 = 0;
+        m32 = 0;
+        m33 = 1;
+        return this;
+    }
+
     // 
/////////////////////////////////////////////////////////////////////////////
     // compute cofactor of 3x3 minor matrix without sign
     // input params are 9 elements of the minor matrix
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/MatrixND.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/MatrixND.java
index b54c7375cc..e7eff9f878 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/MatrixND.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/MatrixND.java
@@ -317,6 +317,18 @@ public class MatrixND extends AbstractMatrix<MatrixND>{
         return this;
     }
 
+    @Override
+    public MatrixND setFromAffine(ReadOnly.Affine<?> affine) {
+        setToIdentity();
+        final int dim = affine.getInputDimensions();
+        for (int y=0;y<dim;y++) {
+            for (int x=0;x<=dim;x++) {
+                set(y, x, affine.get(y, x));
+            }
+        }
+        return this;
+    }
+
     @Override
     public boolean isIdentity(){
         return Matrices.isIdentity(values);
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/NDArray.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/NDArray.java
index bd9593b5ce..665c3ff51f 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/NDArray.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/NDArray.java
@@ -184,6 +184,6 @@ public interface NDArray {
     /**
      * @return tuple stream over this array.
      */
-    Stream<Tuple> stream(boolean parallel);
+    Stream<Tuple<?>> stream(boolean parallel);
 
 }
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/ReadOnly.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/ReadOnly.java
index b73d63facd..ccbe79890d 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/ReadOnly.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/ReadOnly.java
@@ -384,15 +384,6 @@ public final class ReadOnly {
          */
         org.apache.sis.geometries.math.Matrix<?> toMatrix();
 
-        /**
-         * Create a square matrix of size dimensions+1
-         * The last matrix line will be [0,...,1]
-         *
-         * @param buffer to store matrix values in
-         * @return matrix
-         */
-        org.apache.sis.geometries.math.Matrix<?> 
toMatrix(org.apache.sis.geometries.math.Matrix<?> buffer);
-
         /**
          * Create a copy of this Affine.
          *
diff --git 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/EarClipping.java
 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/EarClipping.java
index 701f6bf8b0..d8e3278b55 100644
--- 
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/EarClipping.java
+++ 
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/EarClipping.java
@@ -155,7 +155,7 @@ public class EarClipping {
         //attach holes to the main geometry
         for(int i=0,n=part.inners.size();i<n;i++){
             //we must find the minimum x coordinate in the inner loop
-            final List<Tuple> loop = 
part.inners.get(i).getPoints().getAttributeArray(AttributesType.ATT_POSITION).stream(false).toList();
+            final List<Tuple<?>> loop = 
part.inners.get(i).getPoints().getAttributeArray(AttributesType.ATT_POSITION).stream(false).toList();
             int index = 0;
             Tuple min = loop.get(index);
             for(int k=1,p=loop.size();k<p;k++){
diff --git 
a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/math/NDArraysTest.java
 
b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/math/NDArraysTest.java
index d75bd773a5..87b24328ce 100644
--- 
a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/math/NDArraysTest.java
+++ 
b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/math/NDArraysTest.java
@@ -127,8 +127,8 @@ public class NDArraysTest {
         }
         final Array array = NDArrays.of(SampleSystem.ofSize(1), arr);
 
-        final Set<Tuple> distinct = Collections.synchronizedSet(new 
HashSet<>());
-        Stream<Tuple> stream = array.stream(true);
+        final Set<Tuple<?>> distinct = Collections.synchronizedSet(new 
HashSet<>());
+        Stream<Tuple<?>> stream = array.stream(true);
         stream.forEach((Tuple t) -> {
             distinct.add(new Vector1D.Double(t));
         });

Reply via email to