Commit in GeomConverter/test/org/lcsim/detector on MAIN
CoordinateTransformation3DTest.java+108-671.3 -> 1.4
Improvements to basic test cases for transformations.

GeomConverter/test/org/lcsim/detector
CoordinateTransformation3DTest.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- CoordinateTransformation3DTest.java	27 Feb 2007 01:18:37 -0000	1.3
+++ CoordinateTransformation3DTest.java	27 Feb 2007 19:56:49 -0000	1.4
@@ -7,6 +7,7 @@
 import hep.physics.vec.Hep3Vector;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import java.util.Random;
 
 public class CoordinateTransformation3DTest extends TestCase
 {		
@@ -27,69 +28,31 @@
     {
     	System.out.println("CoordinateTransformation3DTest.testIdentityTransformation");
     	
-    	CoordinateTransformation3D transform = new CoordinateTransformation3D();     
-    	CoordinateTransformation3D point = new CoordinateTransformation3D(new BasicHep3Vector(1.0,0.0,0.0), new Rotation3D());
-    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
-    	
-    	Hep3Vector translation = result.getTranslation();
-    	assert(translation.x() == 1.0);
-    	assert(translation.y() == 0);
-    	assert(translation.y() == 0);
+    	CoordinateTransformation3D transformation = new CoordinateTransformation3D();     
+    	Hep3Vector point = new BasicHep3Vector(1.0,2.0,3.0);
     	
-    	Rotation3D rotation = result.getRotation();
-    	assert(rotation.getRotationMatrix().trace() == 3.0);    	
+    	Hep3Vector transformed_point = transformation.transform(point);
+    	assert(transformed_point.x() == point.x());
+    	assert(transformed_point.y() == point.y());
+    	assert(transformed_point.z() == point.z());
     }    
     
-    public void testSimpleTranslationX()
-    {
-    	System.out.println("CoordinateTransformation3DTest.testSimpleTranslationX");
-    	
-    	CoordinateTransformation3D transform = new CoordinateTransformation3D(new BasicHep3Vector(1.0,0.0,0.0));
-    	CoordinateTransformation3D point = new CoordinateTransformation3D();
-    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
-    	Hep3Vector translation = result.getTranslation();
-    	assert(translation.x() == 1.0);
-    	assert(translation.y() == 0.0);
-    	assert(translation.z() == 0.0);
-    }
-    
-    public void testSimpleTranslationY()
-    {
-    	System.out.println("CoordinateTransformation3DTest.testSimpleTranslationY");
-    	
-    	CoordinateTransformation3D transform = new CoordinateTransformation3D(new BasicHep3Vector(0.0,1.0,0.0));
-    	CoordinateTransformation3D point = new CoordinateTransformation3D();
-    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
-    	Hep3Vector translation = result.getTranslation();
-    	assert(translation.x() == 0.0);
-    	assert(translation.y() == 1.0);
-    	assert(translation.z() == 0.0);
-    }
-    
-    public void testSimpleTranslationZ()
-    {
-    	System.out.println("CoordinateTransformation3DTest.testSimpleTranslationZ");
-    	
-    	CoordinateTransformation3D transform = new CoordinateTransformation3D(new BasicHep3Vector(0.0,0.0,1.0));
-    	CoordinateTransformation3D point = new CoordinateTransformation3D();
-    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
-    	Hep3Vector translation = result.getTranslation();
-    	assert(translation.x() == 0.0);
-    	assert(translation.y() == 0.0);
-    	assert(translation.z() == 1.0);
-    }
-    
     public void testSimpleTranslationXYZ()
     {
     	System.out.println("CoordinateTransformation3DTest.testSimpleTranslationXYZ");
     	
-    	CoordinateTransformation3D transform = new CoordinateTransformation3D(new BasicHep3Vector(1.0,1.0,1.0));
-    	CoordinateTransformation3D point = new CoordinateTransformation3D();
-    	CoordinateTransformation3D result = CoordinateTransformation3D.mult(point, transform);
-    	Hep3Vector translation = result.getTranslation();
-    	assert(translation.x() == 1.0);
-    	assert(translation.y() == 1.0);
-    	assert(translation.z() == 1.0);
+        Random random = new Random();
+        double random_x = random.nextDouble();
+        double random_y = random.nextDouble();
+        double random_z = random.nextDouble();
+        
+    	CoordinateTransformation3D transformation = new CoordinateTransformation3D(new BasicHep3Vector(random_x,random_y,random_z));
+    	Hep3Vector point = new BasicHep3Vector(1.0,2.0,3.0);
+
+    	Hep3Vector transformed_point = transformation.transform(point);
+    	assert(transformed_point.x() == point.x()+random_x);
+    	assert(transformed_point.y() == point.y()+random_y);
+    	assert(transformed_point.z() == point.z()+random_z);
     }
     
     public void testSimpleRotationX()
@@ -97,13 +60,15 @@
     	System.out.println("CoordinateTransformation3DTest.testSimpleRotationX");
     	
     	Rotation3D rotateX = new Rotation3D();
-    	rotateX.setPassiveXYZ(Math.PI / 4, 0, 0);
-    	CoordinateTransformation3D transform = new CoordinateTransformation3D(rotateX);
-    	//CoordinateTransformation3D point = new CoordinateTransformation3D();
-    	Hep3Vector point = new BasicHep3Vector(1.0,0.0,0.0);
-    	Hep3Vector result = transform.rotate(point);
+        
+    	rotateX.setPassiveXYZ(Math.PI / 2, 0, 0);
+    	CoordinateTransformation3D transformation = new CoordinateTransformation3D(rotateX);
+
+    	Hep3Vector point = new BasicHep3Vector(0.0,0.0,1.0);
+    	Hep3Vector result = transformation.rotate(point);
+
     	System.out.println("Transform");
-    	transform.getRotation().printOut(System.out);
+    	transformation.getRotation().printOut(System.out);
     	System.out.printf("new point = ( %.4f %.4f %.4f )\n",result.x(),result.y(),result.z());
     	//CoordinateTransformation3D.mult(point, transform);
     	//Hep3Rotation rotation = result.getRotation();    	
@@ -118,13 +83,89 @@
     	
     }
     
-    public void testRotationIdentity()
+    public void testMultiplication()
     {
-    	System.out.println("CoordinateTransformation3DTest.testRotationIdentity");
-    	Rotation3D rotation = new Rotation3D();
-    	System.out.println("This should be the identity matrix.");
-    	rotation.printOut(System.out);
+        
+        System.out.println("CoordinateTransformation3DTest.testMultiplication");
+    	
+        Random random = new Random();
+
+        Rotation3D rotation_1 = new Rotation3D();
+        rotation_1.setPassiveXYZ(random.nextDouble(),random.nextDouble(),random.nextDouble());
+        Hep3Vector translation_1 = new BasicHep3Vector(random.nextDouble(),random.nextDouble(),random.nextDouble());
+
+        Rotation3D rotation_2 = new Rotation3D();
+        rotation_2.setPassiveXYZ(random.nextDouble(),random.nextDouble(),random.nextDouble());
+        Hep3Vector translation_2 = new BasicHep3Vector(random.nextDouble(),random.nextDouble(),random.nextDouble());
+
+    	CoordinateTransformation3D transformation_1 = new CoordinateTransformation3D(translation_1,rotation_1);
+    	CoordinateTransformation3D transformation_2 = new CoordinateTransformation3D(translation_2,rotation_2);
+        
+     	CoordinateTransformation3D transformation_product = CoordinateTransformation3D.mult(transformation_2,transformation_1);
+        
+        Hep3Vector point = new BasicHep3Vector(1.0,2.0,3.0);
+        
+        Hep3Vector transformed_point_1 = transformation_1.transform(point);
+        transformed_point_1 = transformation_2.transform(transformed_point_1);
+        
+        Hep3Vector transformed_point_2 = transformation_product.transform(point);
+        
+    	assert(transformed_point_2.x() == transformed_point_1.x());
+    	assert(transformed_point_2.y() == transformed_point_1.y());
+    	assert(transformed_point_2.z() == transformed_point_1.z());
+        
+    }
+
+    
+    public void testInvert()
+    {
+        
+        System.out.println("CoordinateTransformation3DTest.testInvert");
+    	
+        Random random = new Random();
+
+        Rotation3D rotation = new Rotation3D();
+        rotation.setPassiveXYZ(random.nextDouble(),random.nextDouble(),random.nextDouble());
+        Hep3Vector translation = new BasicHep3Vector(random.nextDouble(),random.nextDouble(),random.nextDouble());
+
+    	CoordinateTransformation3D transformation = new CoordinateTransformation3D(translation,rotation);  
+        Hep3Vector point = new BasicHep3Vector(1.0,2.0,3.0);        
+        Hep3Vector transformed_point = transformation.transform(point);
+        
+        transformation.invert();
+        transformed_point = transformation.transform(transformed_point);
+        
+    	assert(transformed_point.x() == point.x());
+    	assert(transformed_point.y() == point.y());
+    	assert(transformed_point.z() == point.z());
+        
     }
+
+    
+    public void testInverse()
+    {
+        
+        System.out.println("CoordinateTransformation3DTest.testInverse");
+    	
+        Random random = new Random();
+
+        Rotation3D rotation = new Rotation3D();
+        rotation.setPassiveXYZ(random.nextDouble(),random.nextDouble(),random.nextDouble());
+        Hep3Vector translation = new BasicHep3Vector(random.nextDouble(),random.nextDouble(),random.nextDouble());
+
+    	CoordinateTransformation3D transformation = new CoordinateTransformation3D(translation,rotation);  
+        Hep3Vector point = new BasicHep3Vector(1.0,2.0,3.0);        
+        Hep3Vector transformed_point = transformation.transform(point);
+        
+        CoordinateTransformation3D transformation_inverted = transformation.inverse();
+        transformed_point = transformation_inverted.transform(transformed_point);
+        
+    	assert(transformed_point.x() == point.x());
+    	assert(transformed_point.y() == point.y());
+    	assert(transformed_point.z() == point.z());
+        
+    } 
+    
     
     private static final void assertStrictEquals(Rotation3D rotate1, Rotation3D rotate2)
     {
CVSspam 0.2.8