sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1521922 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix: Matrix2.java Matrix3.java Matrix4.java MatrixSIS.java
Date Wed, 11 Sep 2013 16:24:58 GMT
Author: desruisseaux
Date: Wed Sep 11 16:24:58 2013
New Revision: 1521922

URL: http://svn.apache.org/r1521922
Log:
Check matrix indices explicitely.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java?rev=1521922&r1=1521921&r2=1521922&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
[UTF-8] Wed Sep 11 16:24:58 2013
@@ -138,13 +138,15 @@ public final class Matrix2 extends Matri
      */
     @Override
     public double getElement(final int row, final int column) {
-        switch (row*SIZE + column) {
-            case 0:  return m00;
-            case 1:  return m01;
-            case 2:  return m10;
-            case 3:  return m11;
-            default: throw indexOutOfBounds(row, column);
+        if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
+            switch (row*SIZE + column) {
+                case 0: return m00;
+                case 1: return m01;
+                case 2: return m10;
+                case 3: return m11;
+            }
         }
+        throw indexOutOfBounds(row, column);
     }
 
     /**
@@ -159,13 +161,15 @@ public final class Matrix2 extends Matri
      */
     @Override
     public void setElement(final int row, final int column, final double value) {
-        switch (row*SIZE + column) {
-            case 0:  m00 = value; break;
-            case 1:  m01 = value; break;
-            case 2:  m10 = value; break;
-            case 3:  m11 = value; break;
-            default: throw indexOutOfBounds(row, column);
+        if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
+            switch (row*SIZE + column) {
+                case 0: m00 = value; return;
+                case 1: m01 = value; return;
+                case 2: m10 = value; return;
+                case 3: m11 = value; return;
+            }
         }
+        throw indexOutOfBounds(row, column);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java?rev=1521922&r1=1521921&r2=1521922&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] Wed Sep 11 16:24:58 2013
@@ -162,18 +162,20 @@ public final class Matrix3 extends Matri
      */
     @Override
     public double getElement(final int row, final int column) {
-        switch (row*SIZE + column) {
-            case 0:  return m00;
-            case 1:  return m01;
-            case 2:  return m02;
-            case 3:  return m10;
-            case 4:  return m11;
-            case 5:  return m12;
-            case 6:  return m20;
-            case 7:  return m21;
-            case 8:  return m22;
-            default: throw indexOutOfBounds(row, column);
+        if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
+            switch (row*SIZE + column) {
+                case 0: return m00;
+                case 1: return m01;
+                case 2: return m02;
+                case 3: return m10;
+                case 4: return m11;
+                case 5: return m12;
+                case 6: return m20;
+                case 7: return m21;
+                case 8: return m22;
+            }
         }
+        throw indexOutOfBounds(row, column);
     }
 
     /**
@@ -188,18 +190,20 @@ public final class Matrix3 extends Matri
      */
     @Override
     public void setElement(final int row, final int column, final double value) {
-        switch (row*SIZE + column) {
-            case 0:  m00 = value; break;
-            case 1:  m01 = value; break;
-            case 2:  m02 = value; break;
-            case 3:  m10 = value; break;
-            case 4:  m11 = value; break;
-            case 5:  m12 = value; break;
-            case 6:  m20 = value; break;
-            case 7:  m21 = value; break;
-            case 8:  m22 = value; break;
-            default: throw indexOutOfBounds(row, column);
+        if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
+            switch (row*SIZE + column) {
+                case 0: m00 = value; return;
+                case 1: m01 = value; return;
+                case 2: m02 = value; return;
+                case 3: m10 = value; return;
+                case 4: m11 = value; return;
+                case 5: m12 = value; return;
+                case 6: m20 = value; return;
+                case 7: m21 = value; return;
+                case 8: m22 = value; return;
+            }
         }
+        throw indexOutOfBounds(row, column);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java?rev=1521922&r1=1521921&r2=1521922&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] Wed Sep 11 16:24:58 2013
@@ -186,25 +186,27 @@ public final class Matrix4 extends Matri
      */
     @Override
     public double getElement(final int row, final int column) {
-        switch (row*SIZE + column) {
-            case  0: return m00;
-            case  1: return m01;
-            case  2: return m02;
-            case  3: return m03;
-            case  4: return m10;
-            case  5: return m11;
-            case  6: return m12;
-            case  7: return m13;
-            case  8: return m20;
-            case  9: return m21;
-            case 10: return m22;
-            case 11: return m23;
-            case 12: return m30;
-            case 13: return m31;
-            case 14: return m32;
-            case 15: return m33;
-            default: throw indexOutOfBounds(row, column);
+        if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
+            switch (row*SIZE + column) {
+                case  0: return m00;
+                case  1: return m01;
+                case  2: return m02;
+                case  3: return m03;
+                case  4: return m10;
+                case  5: return m11;
+                case  6: return m12;
+                case  7: return m13;
+                case  8: return m20;
+                case  9: return m21;
+                case 10: return m22;
+                case 11: return m23;
+                case 12: return m30;
+                case 13: return m31;
+                case 14: return m32;
+                case 15: return m33;
+            }
         }
+        throw indexOutOfBounds(row, column);
     }
 
     /**
@@ -219,25 +221,27 @@ public final class Matrix4 extends Matri
      */
     @Override
     public void setElement(final int row, final int column, final double value) {
-        switch (row*SIZE + column) {
-            case  0: m00 = value; break;
-            case  1: m01 = value; break;
-            case  2: m02 = value; break;
-            case  3: m03 = value; break;
-            case  4: m10 = value; break;
-            case  5: m11 = value; break;
-            case  6: m12 = value; break;
-            case  7: m13 = value; break;
-            case  8: m20 = value; break;
-            case  9: m21 = value; break;
-            case 10: m22 = value; break;
-            case 11: m23 = value; break;
-            case 12: m30 = value; break;
-            case 13: m31 = value; break;
-            case 14: m32 = value; break;
-            case 15: m33 = value; break;
-            default: throw indexOutOfBounds(row, column);
+        if (row >= 0 && row < SIZE && column >= 0 && column
< SIZE) {
+            switch (row*SIZE + column) {
+                case  0: m00 = value; return;
+                case  1: m01 = value; return;
+                case  2: m02 = value; return;
+                case  3: m03 = value; return;
+                case  4: m10 = value; return;
+                case  5: m11 = value; return;
+                case  6: m12 = value; return;
+                case  7: m13 = value; return;
+                case  8: m20 = value; return;
+                case  9: m21 = value; return;
+                case 10: m22 = value; return;
+                case 11: m23 = value; return;
+                case 12: m30 = value; return;
+                case 13: m31 = value; return;
+                case 14: m32 = value; return;
+                case 15: m33 = value; return;
+            }
         }
+        throw indexOutOfBounds(row, column);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java?rev=1521922&r1=1521921&r2=1521922&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
(original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
Wed Sep 11 16:24:58 2013
@@ -90,10 +90,10 @@ public abstract class MatrixSIS implemen
     }
 
     /**
-     * Returns all matrix elements in a flat, row-major (column indices vary fastest) array.
+     * Returns a copy of all matrix elements in a flat, row-major (column indices vary fastest)
array.
      * The array length is <code>{@linkplain #getNumRow()} * {@linkplain #getNumCol()}</code>.
      *
-     * @return The current matrix elements in a row-major array.
+     * @return A copy of all current matrix elements in a row-major array.
      */
     public abstract double[] getElements();
 



Mime
View raw message