Skip to content

Commit

Permalink
WWMath unit test (NASAWorldWind#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
markpet49 authored Jul 10, 2020
1 parent 6a2726b commit 11f79cc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/gov/nasa/worldwind/util/WWMathTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/

package gov.nasa.worldwind.util;

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import gov.nasa.worldwind.geom.Vec4;

@RunWith(JUnit4.class)
public class WWMathTest {

private static final double DELTA = 1e-9;

/**
* Test triangle normal computation
*/
@Test
public void testParseTimeString() {
Vec4 v1 = new Vec4(26, 2, 1);
Vec4 v2 = new Vec4(26, 2, 13);
Vec4 v3 = new Vec4(12, -23, 13);
Vec4 expectedNormal = new Vec4(0.8725060159497201, -0.48860336893184325, 0.0);
Vec4 normal = WWMath.computeTriangleNormal(v1, v2, v3);
assertEquals("Normal computation 1 X", expectedNormal.x, normal.x, DELTA);
assertEquals("Normal computation 1 Y", expectedNormal.y, normal.y, DELTA);
assertEquals("Normal computation 1 Z", expectedNormal.z, normal.z, DELTA);

v1 = new Vec4(-12, 12, 26);
v2 = new Vec4(23, -23, 2);
v3 = new Vec4(13, 13, 13);
expectedNormal = new Vec4(0.4612242682795252, -0.1396190373706287, 0.8762298207398077);
normal = WWMath.computeTriangleNormal(v1, v2, v3);
assertEquals("Normal computation 2 X", expectedNormal.x, normal.x, DELTA);
assertEquals("Normal computation 2 Y", expectedNormal.y, normal.y, DELTA);
assertEquals("Normal computation 2 Z", expectedNormal.z, normal.z, DELTA);
}
}

0 comments on commit 11f79cc

Please sign in to comment.