aboutsummaryrefslogblamecommitdiffstats
path: root/libtellurian_azimuth.c
blob: c39596a90ad793bf62a96460f5f73bcc3262910c (plain) (tree)
1
2
3

                                                         
            
















                                                                                                               


     



































                                                                              
      
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


void
libtellurian_azimuth(double latitude1, double longitude1,
                     double latitude2, double longitude2,
                     double *azimuth1_out, double *azimuth2_out)
{
	latitude1 = radians(latitude1);
	longitude1 = radians(longitude1);
	latitude2 = radians(latitude2);
	longitude2 = radians(longitude2);
	libtellurian_azimuth_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);
}


#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;

	libtellurian_azimuth_radians(ra, rb, rc, rd, &az1_ref, &az2_ref);
	az1_ref *= 180 / M_PI;
	az2_ref *= 180 / M_PI;

	libtellurian_azimuth(da, db, dc, dd, &az1, &az2);
	libtellurian_azimuth(da, db, dc, dd, &az1b, NULL);
	libtellurian_azimuth(da, db, dc, dd, NULL, &az2b);
	libtellurian_azimuth(da, db, dc, dd, NULL, NULL);
	return az1 == az1_ref && az2 == az2_ref && az1 == az1b && az2 == az2b;
}

int
main(void)
{
	double a1 = 1, a2 = 2;

	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));

	libtellurian_azimuth(0, 0, 0, 90, &a1, &a2);
	ASSERT(a1 == a2);
	ASSERT(a1 == 90);
	return 0;
}


#endif