15#define YAC_RAD (0.01745329251994329576923690768489)
36 PUT_ERR(
"error in point_in_cell (simple inside test)\n")
46 PUT_ERR(
"error in point_in_cell (simple outside test)\n")
55 PUT_ERR(
"error in point_in_cell (test point on edge)\n")
65 PUT_ERR(
"error in point_in_cell (lon-lat cell near the pole)\n")
72 (
double[]){85,85,88,88},
gc_edges, 4);
75 PUT_ERR(
"error in point_in_cell (great circle cell near the pole)\n")
82 (
double[]){88,88,88,88},
88 PUT_ERR(
"error in point_in_cell (lon-lat cell on the pole)\n")
95 (
double[]){88,88,88,88},
gc_edges, 4);
98 PUT_ERR(
"error in point_in_cell (great circle cell on the pole)\n")
103 for (
int i = -1; i <= 1; i += 2) {
104 for (
int j = -1; j <= 1; j += 2) {
106 double lat_coords[5] = {88.0, 88.0, 88.0, 88.0, 88.0};
107 for (
int k = 0; k < 5; ++k) lat_coords[k] *= (
double)j;
112 PUT_ERR(
"error in point_in_cell (great circle cell on the pole)\n")
124 PUT_ERR(
"error in point_in_cell (point on corner of lon-lat cell)\n")
129 PUT_ERR(
"error in point_in_cell (point on edge of lon-lat cell)\n")
139 PUT_ERR(
"error in point_in_cell (point on corner of great circle cell)\n")
144 PUT_ERR(
"error in point_in_cell (point on corner of great circle cell)\n")
149 PUT_ERR(
"error in point_in_cell (point in cell)\n")
154 PUT_ERR(
"error in point_in_cell (point in cell)\n")
164 PUT_ERR(
"error in point_in_cell\n")
171 for (
unsigned i = 0; i < 2; ++i) {
172 for (
int j = 0; j < 3; ++j) {
178 double point_lat[3] = {40, 45, 50};
185 PUT_ERR(
"error in point_in_cell\n")
193 for (
unsigned i = 0; i < 2; ++i) {
196 double y_coords[2][3] = {{10,10,15}, {10,10,5}};
203 PUT_ERR(
"error in point_in_cell\n")
210 for (
unsigned i = 0; i < 2; ++i) {
213 double y_coords[2][3] = {{0,0,5}, {0,0,-5}};
218 PUT_ERR(
"error in point_in_cell\n")
226 for (
unsigned i = 0; i < 2; ++i) {
237 PUT_ERR(
"error in point_in_cell\n")
244 for (
unsigned i = 0; i < 2; ++i) {
253 (
double[]){0, 5, 10, 10},
257 PUT_ERR(
"error in point_in_cell\n")
264 for (
unsigned i = 0; i < 2; ++i) {
273 (
double[]){0, 5, 10, 10},
277 PUT_ERR(
"error in point_in_cell\n")
284 double x_coords[] = { 0.0, 0.5, 0.0,-0.5};
285 double y_coords[] = {-0.5, 0.0, 0.5, 0.0};
288 for (
unsigned i = 0; i < 4; ++i) {
291 PUT_ERR(
"error in point_in_cell\n")
300 -2.5742124622891822},
301 (
double[]){-0.8955349680874743,
303 -0.8955349680874748},
306 LLtoXYZ(-2.5132741229357842, -0.8511807007280388, point_3d);
308 PUT_ERR(
"error in point_in_cell\n");
315 -1.4373158006630782e-09,
316 -0.19351146472502487},
317 {-0.98296571213463857,
318 -0.016290939681434788,
319 -0.18306560040580719},
320 {-0.98550150905720235,
321 -0.016447047624685553,
322 -0.16886761166786302},
323 {-0.98739170499602125,
324 -1.9584538881393463e-09,
325 -0.15829599143708675},
326 {-0.98550150905854683,
327 0.016447044383749162,
328 -0.16886761197567171},
329 {-0.98296571214686901,
330 0.016290936203869018,
331 -0.18306560064960375}},
335 -1.2055152618042087e-16,
336 -0.17606851504603632}, cell))
337 PUT_ERR(
"error in point_in_cell\n");
344 double lat[3] = {0,0,1};
346 double lon, lat, xyz[3];
349 {{.lon = lon[0], .lat = lat[0], .is_inside = 1},
350 {.lon = lon[1], .lat = lat[1], .is_inside = 1},
351 {.lon = lon[2], .lat = lat[2], .is_inside = 1},
354 {.lon = -0.01, .lat = 0, .is_inside = 0},
355 {.lon = 0.01, .lat = 0, .is_inside = 0},
356 {.lon = 0, .lat = 1.001, .is_inside = 0},
357 {.lon = -0.01, .lat = 0.5, .is_inside = 0}};
358 enum{num_test_points =
sizeof(test_points) /
sizeof(test_points[0])};
359 for (
size_t i = 0; i < num_test_points; ++i)
360 LLtoXYZ_deg(test_points[i].lon, test_points[i].lat, test_points[i].xyz);
367 bnd_circle.
sq_crd = DBL_MAX;
369 for (
int direction = -1; direction <= 1; direction += 2) {
371 for (
int start = 0; start < 3; ++start) {
373 double temp_lon[3], temp_lat[3];
374 for (
int edge_idx = start, i = 0; i < 3; ++i, edge_idx += direction) {
375 temp_lon[i] = lon[(edge_idx + 3) % 3];
376 temp_lat[i] = lat[(edge_idx + 3) % 3];
380 for (
size_t i = 0; i < num_test_points; ++i) {
382 test_points[i].is_inside)
383 PUT_ERR(
"error in point_in_cell\n")
385 test_points[i].is_inside)
386 PUT_ERR(
"error in point_in_cell2\n")
399 double lon, lat, xyz[3];
402 {{.lon = lon[0], .lat = lat[0], .is_inside = 1},
403 {.lon = lon[1], .lat = lat[1], .is_inside = 1},
404 {.lon = lon[2], .lat = lat[2], .is_inside = 1},
408 {.lon = -0.001, .lat = 0, .is_inside = 0},
409 {.lon = 0.001, .lat = 0, .is_inside = 0},
410 {.lon = 0, .lat = 0.001, .is_inside = 0},
411 {.lon = 0, .lat = -0.001, .is_inside = 0}};
412 size_t num_test_points =
sizeof(test_points) /
sizeof(test_points[0]);
413 for (
size_t i = 0; i < num_test_points; ++i)
414 LLtoXYZ_deg(test_points[i].lon, test_points[i].lat, test_points[i].xyz);
421 bnd_circle.
sq_crd = DBL_MAX;
423 for (
int direction = -1; direction <= 1; direction += 2) {
425 for (
int start = 0; start < 3; ++start) {
427 double temp_lon[3], temp_lat[3];
428 for (
int edge_idx = start, i = 0; i < 3; ++i, edge_idx += direction) {
429 temp_lon[i] = lon[(edge_idx + 3) % 3];
430 temp_lat[i] = lat[(edge_idx + 3) % 3];
434 for (
size_t i = 0; i < num_test_points; ++i) {
436 test_points[i].is_inside)
437 PUT_ERR(
"error in point_in_cell\n")
439 test_points[i].is_inside)
440 PUT_ERR(
"error in point_in_cell2\n")
452 0.78079400915120067},
453 {0.39106981008544894,
455 0.78079400915120067},
456 {0.39178019297633498,
458 0.77988448312789571},
459 {0.39248974712806789,
461 0.77988448312789571}},
466 0.77988448309288172}, cell))
467 PUT_ERR(
"error in point_in_cell\n");
int yac_point_in_cell(double point_coords[3], struct yac_grid_cell cell)
int yac_point_in_cell2(double point_coords[3], struct yac_grid_cell cell, struct bounding_circle bnd_circle)
static void LLtoXYZ_deg(double lon, double lat, double p_out[])
static struct sin_cos_angle sin_cos_angle_new(double sin, double cos)
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
enum yac_edge_type * edge_type
struct yac_grid_cell generate_cell_rad(double *lon, double *lat, enum yac_edge_type *edge_type, size_t num_corners)
struct yac_grid_cell generate_cell_3d(yac_coordinate_pointer coords, enum yac_edge_type *edge_type, size_t num_corners)
struct yac_grid_cell generate_cell_deg(double *lon, double *lat, enum yac_edge_type *edge_type, size_t num_corners)
static enum yac_edge_type gc_edges[]
static enum yac_edge_type latlon_edges[4]
static void LLtoXYZ(double lon, double lat, double p_out[])