/*-
 *  Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
 * 
 *  This file is part of CityDoctor2.
 *
 *  CityDoctor2 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  CityDoctor2 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 CityDoctor2.  If not, see <https://www.gnu.org/licenses/>.
 */
package de.hft.stuttgart.citydoctor2.math;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
 * 
 * @author Matthias Betz
 *
 */
public class QuaternionTest {

	@Test
	public void testFromToRotation() {
		Vector3d v0 = new Vector3d(1, 164, 4);
		Vector3d v1 = new Vector3d(1, 5, 10);
		Vector3d v2 = new Vector3d(3, 3, 4);
		
		Vector3d d0 = v1.minus(v0);
		Vector3d d1 = v2.minus(v0);
		
		Vector3d normal = d0.cross(d1);
		normal.normalize();
		
		Vector3d zAxis = new Vector3d(0, 0, 1);
		
		Quaternion quad = Quaternion.fromToRotation(normal, zAxis);
		Matrix3x3d rota2 = quad.toRotationMatrix();
		
		Vector3d newV0 = rota2.mult(v0);
		Vector3d newV1 = rota2.mult(v1);
		Vector3d newV2 = rota2.mult(v2);
		
		Vector3d newd0 = newV1.minus(newV0);
		Vector3d newd1 = newV2.minus(newV0);

		assertEquals(d0.getLength(), newd0.getLength(), 0.00001);
		assertEquals(d1.getLength(), newd1.getLength(), 0.00001);
		
		assertEquals(newV1.getZ(), newV0.getZ(), 0.00001);
		assertEquals(newV2.getZ(), newV0.getZ(), 0.00001);
		assertEquals(newV1.getZ(), newV2.getZ(), 0.00001);
		
	}

}
