/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
double
libtellurian_distance(double latitude1, double longitude1,
double latitude2, double longitude2,
double *azimuth1_out, double *azimuth2_out)
{
double r;
latitude1 = radians(latitude1);
longitude1 = radians(longitude1);
latitude2 = radians(latitude2);
longitude2 = radians(longitude2);
r = libtellurian_distance_radians(latitude1, longitude1, latitude2, longitude2, azimuth1_out, azimuth2_out);
if (azimuth1_out)
*azimuth1_out = degrees(*azimuth1_out);
if (azimuth2_out)
*azimuth2_out = degrees(*azimuth2_out);
return r;
}
#else
static int
check(double da, double db, double dc, double dd,
double ra, double rb, double rc, double rd)
{
double az1_ref = 1, az2_ref = 2, az1 = 3, az2 = 4, az1b = 5, az2b = 6;
double s_ref, s1, s2, s3, s4;
s_ref = libtellurian_distance_radians(ra, rb, rc, rd, &az1_ref, &az2_ref);
az1_ref *= 180 / M_PI;
az2_ref *= 180 / M_PI;
s1 = libtellurian_distance(da, db, dc, dd, &az1, &az2);
s2 = libtellurian_distance(da, db, dc, dd, &az1b, NULL);
s3 = libtellurian_distance(da, db, dc, dd, NULL, &az2b);
s4 = libtellurian_distance(da, db, dc, dd, NULL, NULL);
ASSERT(s1 == s_ref);
ASSERT(s2 == s_ref);
ASSERT(s3 == s_ref);
ASSERT(s4 == s_ref);
return az1 == az1_ref && az2 == az2_ref && az1 == az1b && az2 == az2b;
}
int
main(void)
{
double a1 = 1, a2 = 2, s;
ASSERT(check(30, 45, 60, 90, D30, D45, D60, D90));
ASSERT(check(30, 45, 60, 45, D30, D45, D60, D45));
ASSERT(check(45, 30, 60, 45, D45, D30, D60, D45));
ASSERT(check(45, 30, 30, 45, D45, D30, D30, D45));
s = libtellurian_distance(0, 0, 0, 90, &a1, &a2);
fprintf(stderr, "%lg\n", s);
fprintf(stderr, "%lg\n", s / LIBTELLURIAN_MERIDIONAL_CIRCUMFERENCE);
(void) s;
ASSERT(a1 == a2);
ASSERT(a1 == 90);
return 0;
}
#endif