PageRenderTime 18ms CodeModel.GetById 7ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/org/mt4j/test/util/math/Vector3DTest.java

http://mt4j.googlecode.com/
Java | 33 lines | 24 code | 9 blank | 0 comment | 1 complexity | d1b7b48393515815f9abfc604c8f09ea MD5 | raw file
 1package org.mt4j.test.util.math;
 2
 3import org.mt4j.util.math.ToolsMath;
 4import org.mt4j.util.math.Vector3D;
 5
 6import junit.framework.TestCase;
 7
 8public class Vector3DTest extends TestCase {
 9	
10	public void testVector3D(){
11		Vector3D a = new Vector3D(1,2,3);
12		Vector3D b = new Vector3D(3,2,1);
13		Vector3D c = new Vector3D(1,0,0);
14		Vector3D d = new Vector3D(0,1,0);
15		
16		assertTrue(new Vector3D(5,6,7).equalsVector(new Vector3D(5,6,7)));
17		assertTrue(new Vector3D(5,6,7).equalsVectorWithTolerance(new Vector3D(4.8f, 6,6.9f), 0.2f));
18		
19		assertTrue("Vector3D getAdded test" , a.getAdded(b).equalsVector(new Vector3D(4,4,4)));
20		assertTrue("Vector3D getAdded test" , a.getSubtracted(b).equalsVector(new Vector3D(-2,0,2)));
21		assertTrue("Vector3D addLocal(), subtractLocal() test" , new Vector3D(a).subtractLocal(b).addLocal(b).equalsVector(a));
22		assertTrue(a.equalsVectorWithTolerance(new Vector3D(0.8f, 2,2.9f), 0.2f));
23		
24		System.out.println(c.angleBetween(d) * ToolsMath.RAD_TO_DEG);
25		assertTrue(c.angleBetween(d) * ToolsMath.RAD_TO_DEG == 90 );
26		
27		Vector3D e = new Vector3D(c);
28		e.rotateZ(90 * ToolsMath.DEG_TO_RAD);
29		e.rotateZ(-90 * ToolsMath.DEG_TO_RAD);
30		assertTrue(e.equalsVector(c));
31	}
32
33}