#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "tests.h"
#include "test_common.h"
double const tol = 1.0e-10;
static void check_latlon_cell(double * coordinates_x, double * coordinates_y);
static void check_gc_triangle(double * coordinates_x, double * coordinates_y);
static void check_gc_quad(double * coordinates_x, double * coordinates_y);
static unsigned point_in_circle(
double point[3],
struct bounding_circle circle);
{
double coordinates_x[] = {-1.0, 1.0, 1.0, -1.0};
double coordinates_y[] = {-1.0, -1.0, 1.0, 1.0};
check_latlon_cell(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {40.0, 45.0, 45.0, 40.0};
double coordinates_y[] = {20.0, 20.0, 25.0, 25.0};
check_latlon_cell(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = { 175.0, -175.0, -175.0, 175.0};
double coordinates_y[] = {-5.0, -5.0, 5.0, 5.0};
check_latlon_cell(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {30.0, 40.0, 40.0, 30.0};
double coordinates_y[] = {80.0, 80.0, 85.0, 85.0};
check_latlon_cell(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {30.0, 40.0, 40.0, 30.0};
double coordinates_y[] = {80.0, 80.0, 90.0, 90.0};
check_latlon_cell(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {-5.0, 5.0, 0.0};
double coordinates_y[] = {-5.0, 5.0, -5.0};
check_gc_triangle(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {0.0, 120.0, -120.0};
double coordinates_y[] = {85.0, 85.0, 85.0};
check_gc_triangle(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {0.0, 120.0, -120.0};
double coordinates_y[] = {-85.0, -85.0, -85.0};
check_gc_triangle(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {-5.0, 5.0, 1.0};
double coordinates_y[] = {0.0, 0.0, 1.0};
check_gc_triangle(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {0.0, 170.0, 260.0};
double coordinates_y[] = {85.0, 85.0, 89.0};
check_gc_triangle(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {-1.0, 1.0, 1.0, -1.0};
double coordinates_y[] = {-1.0, -1.0, 1.0, 1.0};
check_gc_quad(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {0.0, 90.0, 180.0, 270.0};
double coordinates_y[] = {85.0, 85.0, 85.0, 85.0};
check_gc_quad(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {0.0, 90.0, 180.0, 270.0};
double coordinates_y[] = {-85.0, -85.0, -85.0, -85.0};
check_gc_quad(coordinates_x, coordinates_y);
}
{
double coordinates_x[] = {0.0, 10.0, 0.0, -10.0};
double coordinates_y[] = {-10.0, 0.0, 10.0, 0.0};
check_gc_quad(coordinates_x, coordinates_y);
}
return TEST_EXIT_CODE;
}
static void check_gc_triangle(double * coordinates_x, double * coordinates_y) {
for (int order = -1; order <= 1; order += 2) {
for (int start = 0; start < 3; ++start) {
double temp_coordinates_x[3];
double temp_coordinates_y[3];
double coords[3][3];
for (int i = 0; i < 3; ++i) {
temp_coordinates_x[i] = coordinates_x[(3+i*order+start)%3];
temp_coordinates_y[i] = coordinates_y[(3+i*order+start)%3];
temp_coordinates_y[i]*
YAC_RAD, coords[i]);
}
generate_cell_deg(temp_coordinates_x, temp_coordinates_y, edges, 3);
coords[0], coords[1], coords[2], bnd_circle+1);
coords[0], coords[1], coords[2], bnd_circle+2);
PUT_ERR("get_cell_bounding_circle_unstruct_triangle did not "
"compute smallest bounding circle\n");
test_circle(cell, bnd_circle[0]);
test_circle(cell, bnd_circle[1]);
test_circle(cell, bnd_circle[2]);
test_cirumscribe_circle(cell, bnd_circle[2]);
}
}
}
static void check_gc_quad(double * coordinates_x, double * coordinates_y) {
for (unsigned i = 0; i < 4; ++i) {
}
for (int order = -1; order <= 1; order += 2) {
for (int start = 0; start < 4; ++start) {
double temp_coordinates_x[4];
double temp_coordinates_y[4];
for (int i = 0; i < 4; ++i) {
temp_coordinates_x[i] = coordinates_x[(4+i*order+start)%4];
temp_coordinates_y[i] = coordinates_y[(4+i*order+start)%4];
}
generate_cell_deg(temp_coordinates_x, temp_coordinates_y, edges, 4);
test_circle(cell, bnd_circle);
}
}
}
static void check_latlon_cell(double * coordinates_x, double * coordinates_y) {
for (int order = -1; order <= 1; order += 2) {
for (int start = 0; start < 4; ++start) {
double temp_coordinates_x[4];
double temp_coordinates_y[4];
double coords[4][3];
for (int i = 0; i < 4; ++i) {
temp_coordinates_x[i] = coordinates_x[(4+i*order+start)%4];
temp_coordinates_y[i] = coordinates_y[(4+i*order+start)%4];
temp_coordinates_y[i]*
YAC_RAD, coords[i]);
}
for (int i = 0; i < 4; ++i) {
int temp[2] =
{fabs(temp_coordinates_x[i] - temp_coordinates_x[(i+3)%4]) > 0.0,
fabs(temp_coordinates_y[i] - temp_coordinates_y[(i+3)%4]) > 0.0};
}
generate_cell_deg(temp_coordinates_x, temp_coordinates_y, edges, 4);
coords[2], bnd_circle+1);
coords[2], bnd_circle+2);
PUT_ERR("get_cell_bounding_circle_reg_quad did not "
"compute smallest bounding circle\n");
test_circle(cell, bnd_circle[0]);
test_circle(cell, bnd_circle[1]);
test_circle(cell, bnd_circle[2]);
test_cirumscribe_circle(cell, bnd_circle[2]);
}
}
}
for (size_t i = 0; i < cell.num_corners; ++i)
if (!point_in_circle(cell.coordinates_xyz[i], circle))
PUT_ERR("point is not in bounding circle\n");
}
static void test_cirumscribe_circle(
int neg =
sub_angles(inc_angle, angle, &diff_angle);
if (neg) PUT_ERR("not all points are on the circumscribe circle\n");
}
}
static unsigned point_in_circle(
double point[3],
struct bounding_circle circle) {
return
}
void yac_get_cell_circumscribe_circle_reg_quad(double a[3], double b[3], double c[3], struct bounding_circle *bnd_circle)
void yac_get_cell_circumscribe_circle_unstruct_triangle(double a[3], double b[3], double c[3], struct bounding_circle *bnd_circle)
void yac_get_cell_bounding_circle_unstruct_triangle(double a[3], double b[3], double c[3], struct bounding_circle *bnd_circle)
void yac_get_cell_bounding_circle_reg_quad(double a[3], double b[3], double c[3], struct bounding_circle *bnd_circle)
void yac_get_cell_bounding_circle(struct yac_grid_cell cell, struct bounding_circle *bnd_circle)
int main(int argc, char **argv)
static struct sin_cos_angle get_vector_angle_2(double const a[3], double const b[3])
static const struct sin_cos_angle SIN_COS_M_PI
static struct sin_cos_angle sum_angles_no_check(struct sin_cos_angle a, struct sin_cos_angle b)
static const struct sin_cos_angle SIN_COS_TOL
static int compare_angles(struct sin_cos_angle a, struct sin_cos_angle b)
static int sub_angles(struct sin_cos_angle a, struct sin_cos_angle b, struct sin_cos_angle *restrict sub)
static void LLtoXYZ(double lon, double lat, double p_out[])
void yac_free_grid_cell(struct yac_grid_cell *cell)
@ YAC_GREAT_CIRCLE_EDGE
great circle
@ YAC_LAT_CIRCLE_EDGE
latitude circle
@ YAC_LON_CIRCLE_EDGE
longitude circle
struct sin_cos_angle inc_angle
angle between the middle point and the boundary of the spherical cap
double(* coordinates_xyz)[3]
#define YAC_ASSERT(exp, msg)