diff -Naur /users/iupisi/isi2g0/TP_JUnit/Depot/Opale/src/units/m3d/TestPoint3D.java Opale/src/units/m3d/TestPoint3D.java --- /users/iupisi/isi2g0/TP_JUnit/Depot/Opale/src/units/m3d/TestPoint3D.java +++ Opale/src/units/m3d/TestPoint3D.java Fri Feb 20 15:38:11 2004 @@ -0,0 +1,191 @@ +/* + * OPALE is a scientific library under LGPL. Its main goal is to + * develop mathematical tools for any scientist. + * + * Copyright (C) 2002 Opale Group + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * You can visit the web site http://opale.tuxfamily.org to obtain more + * informations about this program and/or to contact the authors by mail + * developers@opale.tuxfamily.org. + */ +package m3d; + +import junit.framework.TestCase; +import opale.m3d.Point3D; +import opale.m3d.OIJK; +import opale.m3d.OIJKException; +import opale.mathtools.Precision; + + +public class TestPoint3D extends TestCase +{ + + public void testConstructors() + { + Point3D p1 = new Point3D(); + + assertTrue(p1.getOIJK() == OIJK.OIJK_ABSOLUTE); + + try + { + OIJK cs1 = new OIJK(8,1,1,0,0,1,2,1,3,4,1,3); + Point3D p3 = new Point3D(cs1); + + assertTrue(p3.getOIJK().equals(cs1)); + } + catch(OIJKException e) {} + + Point3D p3 = new Point3D(5.0,6.0,7.0); + Point3D p4 = new Point3D(p3); + assertTrue(p4.getOIJK() == OIJK.OIJK_ABSOLUTE); + assertTrue(p4.getX() == 5.0); + assertTrue(p4.getY() == 6.0); + assertTrue(p4.getZ() == 7.0); + assertTrue(p3.getX() == 5.0); + assertTrue(p3.getY() == 6.0); + assertTrue(p3.getZ() == 7.0); + } + + + public void testEquals() + { + Point3D p1 = new Point3D(); + Point3D p2 = new Point3D(3.0,5.0,6.0); + assertTrue(p1.equals(p1)); + assertTrue(p2.equals(p2)); + assertTrue(p2.equals(p1) == false); + } + + public void testClone() + { + Point3D p1 = new Point3D(4.0,7.0,9.0); + Point3D p2 = (Point3D) p1.clone(); + + assertTrue(p1.equals(p2)); + } + + public void testSet() + { + Point3D p3 = new Point3D(5.0,6.0,7.0); + p3.setX(4.0); + assertTrue(p3.getX() == 4.0); + + p3.setY(-50.0); + assertTrue(p3.getY() == -50.0); + + p3.setZ(10.0); + assertTrue(p3.getZ() == 10.0); + } + +/* public void testScale() + { + Point2D p3 = new Point2D(2.0,6.0); + Point2D a = new Point2D(1.0,0.0); + + p3.scale(a,1); + assertTrue(p3.getX() == 2.0); + assertTrue(p3.getY() == 6.0); + + p3.scale(a, 0.5); + assertTrue(Precision.isEqual(p3.getX(), (0.5 * (2.0 - a.getX()) + a.getX()))); + assertTrue(Precision.isEqual(p3.getY(), (0.5 * (6.0 - a.getY()) + a.getY()))); + + p3.scale(a,0); + assertTrue(p3.equals(a)); + + a.scale(a,2.0); + assertTrue(Precision.isEqual(a.getX(), 1.0)); + assertTrue(Precision.isEqual(a.getY(), 0.0)); + } + + public void testRotation() + { + Point2D origin = new Point2D(); + final double racine2 = Math.sqrt(2); + final double racine22 = racine2/2; + final double pi4 = Math.PI / 4.0; + final double pi2 = Math.PI / 2.0; + + origin.rotate(pi4); + assertTrue(origin.getX() == 0); + assertTrue(origin.getY() == 0); + + Point2D p1 = new Point2D(1.0,0.0); + p1.rotate(pi4); + //assertTrue(p1.getX() == racine22); + //assertTrue(p1.getY() == racine22); + p1.rotate(pi4); + assertTrue(Precision.isEqual(p1.getX(),0.0)); + assertTrue(Precision.isEqual(p1.getY(),1.0)); + + p1.rotate(pi2); + assertTrue(Precision.isEqual(p1.getX(),-1.0)); + assertTrue(Precision.isEqual(p1.getY(),0.0)); + } + + public void testRotationWithOtherCenter() + { + Point2D p1 = new Point2D(1.0,0.0); + Point2D p2 = new Point2D(1.0,1.0); + final double pi = Math.PI; + + p1.rotate(p2.getX(), p2.getY(),pi); + + assertTrue(Precision.isEqual(p1.getX(),1.0)); + assertTrue(Precision.isEqual(p1.getY(), 2.0)); + + p1.setLocation(1.0,0.0); + p1.rotate(p2,pi); + + assertTrue(Precision.isEqual(p1.getX(),1.0)); + assertTrue(Precision.isEqual(p1.getY(), 2.0)); + } +*/ + public void testTranslation() + { + Point3D p1 = new Point3D(1.0,10.0,5.0); + Point3D p2 = new Point3D(4.0,1.0,6.0); + + p1.translate(3.0,-9,1); + assertTrue(p1.equals(p2)); + + Point3D p3 = new Point3D(1.0,1.0,1.0) ; + + p1.translate(p3) ; + assertTrue(p1.getX() == 5.0); + assertTrue(p1.getY() == 2.0); + assertTrue(p1.getZ() == 7.0); + } + + public void testRotation() + { + Point3D p1 = new Point3D(); + + p1.rotateXAxis(Math.PI/4.0) ; + p1.rotateYAxis(Math.PI/2.0) ; + p1.rotateZAxis(-Math.PI/3.0) ; + assertTrue(p1.getX() == 0); + assertTrue(p1.getY() == 0); + assertTrue(p1.getZ() == 0); + + Point3D p2 = new Point3D(1.0,0.0,0.0) ; + p2.rotateYAxis(Math.PI/4.0) ; + assertTrue(p2.getX() == 0); + assertTrue(p2.getY() == 0); + assertTrue(p2.getZ() == 1); + } +}