ext/h3/src/src/apps/testapps/testGeoCoord.c in h3-3.6.2 vs ext/h3/src/src/apps/testapps/testGeoCoord.c in h3-3.7.1
- old
+ new
@@ -1,7 +1,7 @@
/*
- * Copyright 2017-2019 Uber Technologies, Inc.
+ * Copyright 2017-2020 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -17,24 +17,28 @@
* @brief Tests geographic coordinate functions
*
* usage: `testGeoCoord`
*/
+#include <float.h>
#include <math.h>
+
#include "constants.h"
#include "geoCoord.h"
#include "h3api.h"
#include "test.h"
+#include "utility.h"
/**
* Test a function for all resolutions, where the value should be decreasing as
* resolution increases.
*
* @param function
* @param message
*/
-void testDecreasingFunction(double (*function)(int), const char* message) {
+static void testDecreasingFunction(double (*function)(int),
+ const char* message) {
double last = 0;
double next;
for (int i = MAX_H3_RES; i >= 0; i--) {
next = function(i);
t_assert(next > last, message);
@@ -49,24 +53,45 @@
double rads = H3_EXPORT(degsToRads)(degs);
t_assert(fabs(rads - originalRads) < EPSILON_RAD,
"radsToDegs/degsToRads invertible");
}
- TEST(_geoDistRads) {
+ TEST(pointDistRads) {
GeoCoord p1;
setGeoDegs(&p1, 10, 10);
GeoCoord p2;
setGeoDegs(&p2, 0, 10);
// TODO: Epsilon is relatively large
- t_assert(_geoDistRads(&p1, &p1) < EPSILON_RAD * 1000,
+ t_assert(H3_EXPORT(pointDistRads)(&p1, &p1) < EPSILON_RAD * 1000,
"0 distance as expected");
- t_assert(fabs(_geoDistRads(&p1, &p2) - H3_EXPORT(degsToRads)(10)) <
- EPSILON_RAD * 1000,
+ t_assert(fabs(H3_EXPORT(pointDistRads)(&p1, &p2) -
+ H3_EXPORT(degsToRads)(10)) < EPSILON_RAD * 1000,
"distance along longitude as expected");
}
+ TEST(geoAlmostEqualThreshold) {
+ GeoCoord a = {15, 10};
+ GeoCoord b = {15, 10};
+ t_assert(geoAlmostEqualThreshold(&a, &b, DBL_EPSILON), "same point");
+
+ b.lat = 15.00001;
+ b.lon = 10.00002;
+ t_assert(geoAlmostEqualThreshold(&a, &b, 0.0001),
+ "differences under threshold");
+
+ b.lat = 15.00001;
+ b.lon = 10;
+ t_assert(!geoAlmostEqualThreshold(&a, &b, 0.000001),
+ "lat over threshold");
+
+ b.lat = 15;
+ b.lon = 10.00001;
+ t_assert(!geoAlmostEqualThreshold(&a, &b, 0.000001),
+ "lon over threshold");
+ }
+
TEST(constrainLatLng) {
t_assert(constrainLat(0) == 0, "lat 0");
t_assert(constrainLat(1) == 1, "lat 1");
t_assert(constrainLat(M_PI_2) == M_PI_2, "lat pi/2");
t_assert(constrainLat(M_PI) == 0, "lat pi");
@@ -157,27 +182,29 @@
double azimuth = H3_EXPORT(degsToRads)(20);
double degrees180 = H3_EXPORT(degsToRads)(180);
double distance = H3_EXPORT(degsToRads)(15);
_geoAzDistanceRads(&start, azimuth, distance, &out);
- t_assert(fabs(_geoDistRads(&start, &out) - distance) < EPSILON_RAD,
+ t_assert(fabs(H3_EXPORT(pointDistRads)(&start, &out) - distance) <
+ EPSILON_RAD,
"moved distance is as expected");
GeoCoord start2 = out;
_geoAzDistanceRads(&start2, azimuth + degrees180, distance, &out);
// TODO: Epsilon is relatively large
- t_assert(_geoDistRads(&start, &out) < 0.01, "moved back to origin");
+ t_assert(H3_EXPORT(pointDistRads)(&start, &out) < 0.01,
+ "moved back to origin");
}
- TEST(_geoDistRads_wrappedLongitude) {
+ TEST(pointDistRads_wrappedLongitude) {
const GeoCoord negativeLongitude = {.lat = 0, .lon = -(M_PI + M_PI_2)};
const GeoCoord zero = {.lat = 0, .lon = 0};
- t_assert(fabs(M_PI_2 - _geoDistRads(&negativeLongitude, &zero)) <
- EPSILON_RAD,
+ t_assert(fabs(M_PI_2 - H3_EXPORT(pointDistRads)(&negativeLongitude,
+ &zero)) < EPSILON_RAD,
"Distance with wrapped longitude");
- t_assert(fabs(M_PI_2 - _geoDistRads(&zero, &negativeLongitude)) <
- EPSILON_RAD,
+ t_assert(fabs(M_PI_2 - H3_EXPORT(pointDistRads)(
+ &zero, &negativeLongitude)) < EPSILON_RAD,
"Distance with wrapped longitude and swapped arguments");
}
TEST(doubleConstants) {
// Simple checks for ordering of values