OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
vincenty.c
Go to the documentation of this file.
1 
2 #include <vincenty.h>
3 
4 #include <check.h>
5 #include <float.h>
6 #include <math.h>
7 #include <stdbool.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 
11 
12 // https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
13 bool dbl_equal_eps(double A, double B, double maxRelDiff){
14  // Calculate the difference.
15  double diff = fabs(A - B);
16  A = fabs(A);
17  B = fabs(B);
18  // Find the largest
19  double largest = (B > A) ? B : A;
20 
21  if (diff <= largest * maxRelDiff)
22  return true;
23  return false;
24 }
25 bool dbl_equal(double A, double B){
26  return dbl_equal_eps(A, B, DBL_EPSILON);
27 }
28 
29 START_TEST(edge_cases){
30  ck_assert(dbl_equal(vincenty_distance(0.000000, 0.000000, 0.000000, 0.000000), 0.000000));
31  ck_assert(dbl_equal_eps(vincenty_distance(0.000000, 0.000000, 0.000000, -2.000000), 222639, 0.0000001));
32  ck_assert(dbl_equal_eps(vincenty_distance(0.000000, 0.000000, 0.000000, -1.000000), 111319.5, 0.0000001));
33  ck_assert(dbl_equal_eps(vincenty_distance(0.000000, 0.000000, 0.000000, 1.000000), 111319.5, 0.0000001));
34  ck_assert(dbl_equal_eps(vincenty_distance(0.000000, 0.000000, 0.000000, 2.000000), 222639, 0.0000001));
35 }
36 END_TEST
37 
38 Suite* stub_suite(void){
39  Suite *s = suite_create("Stub");
40 
41  TCase *tc_core = tcase_create("Core");
42  tcase_add_test(tc_core, edge_cases);
43  suite_add_tcase(s, tc_core);
44 
45  return s;
46 }
47 
48 int main(int argc, char **argv){
49  int number_failed;
50 
51  Suite *s = stub_suite();
52  SRunner *sr = srunner_create(s);
53 
54  srunner_run_all(sr, CK_VERBOSE);
55  number_failed = srunner_ntests_failed(sr);
56  srunner_free(sr);
57  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
58 }
#define EXIT_SUCCESS
Definition: GEO_basic.h:72
Provides a single function to calculate geographical distances.
double vincenty_distance(double lat1, double lon1, double lat2, double lon2)
Calculate geographical distances using Vincenty's algorithm.
Definition: vincenty.c:47
bool dbl_equal_eps(double A, double B, double maxRelDiff)
Definition: vincenty.c:13
END_TEST Suite * stub_suite(void)
Definition: vincenty.c:38
subroutine diff(x, conec, n, dconecno, dn, dconecmk, units, u, inno, i, outno, o, input, deriv)
Definition: ffnet.f:205
bool dbl_equal(double A, double B)
Definition: vincenty.c:25
#define fabs(a)
Definition: misc.h:93
data_t s[NROOTS]
Definition: decode_rs.h:75
START_TEST(edge_cases)
Definition: vincenty.c:29
int main(int argc, char **argv)
Definition: vincenty.c:48