Skip to content

Commit

Permalink
Merge pull request #28 from open-dis/coordinate-tests
Browse files Browse the repository at this point in the history
Coordinate tests
  • Loading branch information
mcgredonps authored Dec 9, 2016
2 parents 644caa2 + 1f4d3cc commit d06b6c4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public static double[] xyzToLatLonDegrees(double[] xyz)
{
double degrees[] = CoordinateConversions.xyzToLatLonRadians(xyz);

degrees[0] = degrees[0] * 180.0 / Math.PI;
degrees[1] = degrees[1] * 180.0 / Math.PI;
degrees[0] = degrees[0] * CoordinateConversions.RADIANS_TO_DEGREES;
degrees[1] = degrees[1] * CoordinateConversions.RADIANS_TO_DEGREES;

return degrees;

Expand Down
39 changes: 39 additions & 0 deletions src/test/java/edu/nps/moves/disutil/CoordinateConversionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package edu.nps.moves.disutil;

import org.junit.Assert;
import org.junit.Test;

public class CoordinateConversionsTest {

final double DELTA = 0.1; // acceptable amount of error

double[] xyz = {1071401.9738714, -4450059.11156203, 4427050.83344532};
double[] latlonheightDegrees = {44.2368804, -76.4630307, 91};
double[] latlonheightRadians;

public CoordinateConversionsTest() {
latlonheightRadians = latlonheightDegrees.clone();
latlonheightRadians[0] *= CoordinateConversions.DEGREES_TO_RADIANS;
latlonheightRadians[1] *= CoordinateConversions.DEGREES_TO_RADIANS;
}

@Test
public void xyzToLatLonRadiansTest() {
Assert.assertArrayEquals(latlonheightRadians, CoordinateConversions.xyzToLatLonRadians(xyz), DELTA);
}

@Test
public void xyzToLatLonDegreesTest() {
Assert.assertArrayEquals(latlonheightDegrees, CoordinateConversions.xyzToLatLonDegrees(xyz), DELTA);
}

@Test
public void getXYZfromLatLonDegreesTest() {
Assert.assertArrayEquals(xyz, CoordinateConversions.getXYZfromLatLonDegrees(latlonheightDegrees[0], latlonheightDegrees[1], latlonheightDegrees[2]), DELTA);
}

@Test
public void getXYZfromLatLonRadiansTest() {
Assert.assertArrayEquals(xyz, CoordinateConversions.getXYZfromLatLonRadians(latlonheightRadians[0], latlonheightRadians[1], latlonheightRadians[2]), DELTA);
}
}

0 comments on commit d06b6c4

Please sign in to comment.