Merge branch 'refs/heads/master' of ssh://jvonpilgrim@git.eclipse.org/gitroot/gef3d/org.eclipse.gef3d.git
diff --git a/plugins/org.eclipse.draw3d.geometry/src/java/org/eclipse/draw3d/geometry/Math3DMatrix4f.java b/plugins/org.eclipse.draw3d.geometry/src/java/org/eclipse/draw3d/geometry/Math3DMatrix4f.java
index 0700ca1..c76fa3e 100644
--- a/plugins/org.eclipse.draw3d.geometry/src/java/org/eclipse/draw3d/geometry/Math3DMatrix4f.java
+++ b/plugins/org.eclipse.draw3d.geometry/src/java/org/eclipse/draw3d/geometry/Math3DMatrix4f.java
@@ -330,7 +330,7 @@
 	 * </p>
 	 * 
 	 * @param i_source must not be null
-	 * @param o_result may be null
+	 * @param o_result may be null, if matrix cannot be inverted 
 	 * @return o_result (if not null), or a new instance
 	 * @see http://en.wikipedia.org/wiki/Invertible_matrix
 	 */
@@ -362,58 +362,52 @@
 
 		// A^{-1}
 		Matrix2fImpl Ainv = new Matrix2fImpl();
-		if (Ainv != null) {
-			invert(A, Ainv);
 
-			// CA^{-1}
-			Matrix2fImpl C_Ainv = new Matrix2fImpl();
-			mul(C, Ainv, C_Ainv);
+		invert(A, Ainv);
 
-			// D−CA^{-1}B
-			Matrix2fImpl SchurInv = new Matrix2fImpl();
-			mul(C_Ainv, B, SchurInv);
-			sub(D, SchurInv, SchurInv);
-			invert(SchurInv, SchurInv);
-			if (SchurInv != null) {
+		// CA^{-1}
+		Matrix2fImpl C_Ainv = new Matrix2fImpl();
+		mul(C, Ainv, C_Ainv);
 
-				// A^{-1}B
-				Matrix2fImpl Ainv_B = new Matrix2fImpl();
-				mul(Ainv, B, Ainv_B);
+		// D−CA^{-1}B
+		Matrix2fImpl SchurInv = new Matrix2fImpl();
+		mul(C_Ainv, B, SchurInv);
+		sub(D, SchurInv, SchurInv);
+		invert(SchurInv, SchurInv);
 
-				// calculate result blocks:
-				mul(Ainv_B, SchurInv, A);
-				negate(A, B); // this is B
-				mul(A, C_Ainv, A);
-				add(Ainv, A, A); // this is A
-				mul(SchurInv, C_Ainv, C);
-				negate(C, C); // this is C
-				D = SchurInv; // this is D
+		// A^{-1}B
+		Matrix2fImpl Ainv_B = new Matrix2fImpl();
+		mul(Ainv, B, Ainv_B);
 
-				result.a11 = A.a11;
-				result.a12 = A.a12;
-				result.a21 = A.a21;
-				result.a22 = A.a22;
+		// calculate result blocks:
+		mul(Ainv_B, SchurInv, A);
+		negate(A, B); // this is B
+		mul(A, C_Ainv, A);
+		add(Ainv, A, A); // this is A
+		mul(SchurInv, C_Ainv, C);
+		negate(C, C); // this is C
+		D = SchurInv; // this is D
 
-				result.a13 = B.a11;
-				result.a14 = B.a12;
-				result.a23 = B.a21;
-				result.a24 = B.a22;
+		result.a11 = A.a11;
+		result.a12 = A.a12;
+		result.a21 = A.a21;
+		result.a22 = A.a22;
 
-				result.a31 = C.a11;
-				result.a32 = C.a12;
-				result.a41 = C.a21;
-				result.a42 = C.a22;
+		result.a13 = B.a11;
+		result.a14 = B.a12;
+		result.a23 = B.a21;
+		result.a24 = B.a22;
 
-				result.a33 = D.a11;
-				result.a34 = D.a12;
-				result.a43 = D.a21;
-				result.a44 = D.a22;
-			} else {
-				invert2(detSource, m, result);
-			}
-		} else {
-			invert2(detSource, m, result);
-		}
+		result.a31 = C.a11;
+		result.a32 = C.a12;
+		result.a41 = C.a21;
+		result.a42 = C.a22;
+
+		result.a33 = D.a11;
+		result.a34 = D.a12;
+		result.a43 = D.a21;
+		result.a44 = D.a22;
+
 		if (o_result != result)
 			o_result.set(result);
 
diff --git a/tests/org.eclipse.draw3d.geometry.test/src/java/org/eclipse/draw3d/geometry/Math3DTest.java b/tests/org.eclipse.draw3d.geometry.test/src/java/org/eclipse/draw3d/geometry/Math3DTest.java
index edad7c4..aeb14ba 100644
--- a/tests/org.eclipse.draw3d.geometry.test/src/java/org/eclipse/draw3d/geometry/Math3DTest.java
+++ b/tests/org.eclipse.draw3d.geometry.test/src/java/org/eclipse/draw3d/geometry/Math3DTest.java
@@ -11,8 +11,6 @@
 

 package org.eclipse.draw3d.geometry;

 

-import java.util.Random;

-

 import junit.framework.TestCase;

 

 /**

@@ -25,7 +23,11 @@
  */

 public class Math3DTest extends TestCase {

 

-	public static float PREC = 0.0001f;

+	/**

+	 * Precision used in {@link Math3D#equals(float, float, float)}

+	 * @todo increase precision (i.e., reduce this value)

+	 */

+	public static float PREC = 0.0002f;

 

 	/**

 	 * {@inheritDoc}

@@ -1225,7 +1227,7 @@
 	 * {@link org.eclipse.draw3d.geometryext.Math3D#determinant(org.eclipse.draw3d.geometryext.IMatrix4f)}

 	 * .

 	 */

-	public void testDeterminantIMatrix4f() {

+	public void testDeterminantIMatrix4fRandom() {

 		Matrix4fImpl m0 = GeometryTests.getRandomMatrix4f();

 		Matrix4fImpl m1 = GeometryTests.getRandomMatrix4f();

 

@@ -1252,7 +1254,40 @@
 			fail("testDeterminantIMatrix4f - Test with transposed matrix failed: detA "

 				+ detA + ", detB " + detB + m0.toString());

 		}

+	}

 

+	public void testDeterminantIMatrix4fFixed() {

+

+		Matrix4fImpl m0 =

+			new Matrix4fImpl(0.641808f, 0.6173171f, 0.3888759f, 0.3780973f,

+				0.6113494f, 0.33735108f, 0.5189923f, 0.44364285f, 0.8764232f,

+				0.17627525f, 0.6259386f, 0.8142215f, 0.2934872f, 0.98154485f,

+				0.86022735f, 0.0f);

+		Matrix4fImpl m1 = GeometryTests.getRandomMatrix4f();

+

+		float detA = Math3D.determinant(m0) * Math3D.determinant(m1);

+		float detB = Math3D.determinant(Math3D.mul(m0, m1, null));

+

+		if (!Math3D.equals(detA, detB, PREC)) {

+			fail("testDeterminantIMatrix4f - Test for multiplicative transformation failed: detA "

+				+ detA + ", detB " + detB + m0.toString() + m1.toString());

+		}

+

+		detA = Math3D.determinant(Math3D.invert(m0, null));

+		detB = (float) Math.pow(Math3D.determinant(m0), -1);

+

+		if (!Math3D.equals(detA, detB, PREC)) {

+			fail("testDeterminantIMatrix4f - Test with inverted matrix failed: detA "

+				+ detA + ", detB " + detB + m0.toString());

+		}

+

+		detA = Math3D.determinant(m0);

+		detB = Math3D.determinant(Math3D.transpose(m0, null));

+

+		if (!Math3D.equals(detA, detB, PREC)) {

+			fail("testDeterminantIMatrix4f - Test with transposed matrix failed: detA "

+				+ detA + ", detB " + detB + m0.toString());

+		}

 	}

 

 	/**

diff --git a/tests/org.eclipse.draw3d.geometry.test/src/java/org/eclipse/draw3d/geometry/PerformanceTest.java b/tests/org.eclipse.draw3d.geometry.test/src/java/org/eclipse/draw3d/geometry/PerformanceTest.java
index c97d1e8..40131f3 100644
--- a/tests/org.eclipse.draw3d.geometry.test/src/java/org/eclipse/draw3d/geometry/PerformanceTest.java
+++ b/tests/org.eclipse.draw3d.geometry.test/src/java/org/eclipse/draw3d/geometry/PerformanceTest.java
@@ -35,7 +35,10 @@
 	
 	static String message = "%20s, Field: %8d, Array: %8d, Buffer: %8d";
 
-	public void testFieldsVsArrayMatrix() {
+	/**
+	 * No real test, only a console output test for manual evaluation.
+	 */
+	public void runFieldsVsArrayMatrix() {
 
 		Matrix3fImpl fieldMatrix;
 		Matrix3fAsArray arrayMatrix;
@@ -170,9 +173,9 @@
 
 	long doTestDeterminant(IMatrix3f matrix) {
 		start();
-		float f;
+		
 		for (int i = 0; i < LOOPCOUNT; i++) {
-			f = Math3D.determinant(matrix);
+			Math3D.determinant(matrix);
 		}
 		return stop();
 	}