21static void utest_random_test(
size_t const num_points);
22static void utest_zero_point_test();
23static void utest_single_point_test();
24static void utest_empty_branch_test(
size_t num_points);
25static void utest_zero_balance_point();
26static void utest_duplicated_point_test();
27static void utest_bnd_circle_search();
28static void utest_bnd_circle_random_test(
size_t num_points,
size_t num_circles);
34 for (
size_t i = 0;
i < 10; ++
i) {
36 utest_random_test(10);
37 utest_random_test(100);
38 utest_random_test(650);
40 utest_zero_point_test();
41 utest_single_point_test();
42 utest_empty_branch_test(4);
43 utest_empty_branch_test(128);
44 utest_zero_balance_point();
45 utest_duplicated_point_test();
46 utest_bnd_circle_search();
47 for (
size_t i = 0;
i < 10; ++
i) {
48 utest_bnd_circle_random_test(10, 5);
49 utest_bnd_circle_random_test(100, 20);
50 utest_bnd_circle_random_test(500, 50);
61static int utest_compare_distance_index(
const void * a,
const void * b) {
76static void utest_point_sphere_test_NNN(
78 double (*sphere_part_coordinates_xyz)[3],
79 double (*search_coordinates_xyz)[3],
size_t num_points,
80 size_t ** local_point_ids,
size_t * local_point_ids_array_size,
83 for (
int with_result_coords = 0; with_result_coords < 2;
84 ++with_result_coords) {
86 double (*result_coordinates_xyz)[3] = NULL;
87 size_t result_coordinates_xyz_array_size = 0;
90 search, num_points, search_coordinates_xyz, n, NULL, NULL,
91 with_result_coords?&result_coordinates_xyz:NULL,
92 with_result_coords?&result_coordinates_xyz_array_size:NULL,
93 local_point_ids, local_point_ids_array_size, num_local_point_ids);
96 for (
size_t j = 0, offset = 0; j < num_points; ++j) {
98 struct distance_index * curr_distances = distances + j * num_points;
100 size_t ref_num_local_points = 1,
m = 0;
101 for (; (ref_num_local_points < num_points); ++ref_num_local_points)
102 if (utest_double_are_unequal(
103 curr_distances[ref_num_local_points-1].
distance,
104 curr_distances[ref_num_local_points].
distance))
107 if (num_local_point_ids[j] != ref_num_local_points) {
108 PUT_ERR(
"wrong number of local points found\n");
112 size_t num_matching_points = 0;
113 for (
size_t k = 0; k < ref_num_local_points; ++k) {
114 for (
size_t l = 0; l < ref_num_local_points; ++l) {
115 if ((curr_distances[k].
index == (*local_point_ids)[offset+l]) &&
116 (!with_result_coords ||
118 sphere_part_coordinates_xyz[curr_distances[k].
index],
119 result_coordinates_xyz[offset+l])))) {
120 ++num_matching_points;
125 if (num_matching_points != ref_num_local_points)
128 offset += ref_num_local_points;
131 free(result_coordinates_xyz);
135static void utest_point_sphere_test_NNN_ubound(
143 search, num_points, xyz_coordinates, n, angles);
145 for (
size_t i = 0;
i < num_points; ++
i) {
156static void utest_point_sphere_test_NNN_bnd_circle(
165 size_t cut_off =
n / 2;
167 for (
size_t i = 0;
i < num_points; ++
i) {
171 sizeof(*xyz_coordinates));
174 i * num_points + ((
i < num_points / 2)?cut_off:(
n-1))].distance +
176 bnd_circles[
i].inc_angle =
180 size_t * local_point_ids = NULL;
181 size_t local_point_ids_array_size = 0;
182 size_t * num_local_point_ids =
183 malloc(num_points *
sizeof(*num_local_point_ids));
186 search, num_points, bnd_circles, n, &local_point_ids,
187 &local_point_ids_array_size, num_local_point_ids);
190 for (
size_t i = 0;
i < num_points; ++
i) {
192 size_t ref_num_local_point_ids = (
i < num_points / 2)?(n / 2 + 1):
n;
193 double ref_distance =
194 distances[
i * num_points + ref_num_local_point_ids - 1].
distance;
195 for (; (ref_num_local_point_ids <
MIN(n, num_points)) &&
197 i * num_points + ref_num_local_point_ids].distance == ref_distance);
198 ++ref_num_local_point_ids);
200 if (ref_num_local_point_ids != num_local_point_ids[i])
203 for (
size_t j = 0; j < num_local_point_ids[
i]; ++j) {
205 for (
size_t k = 0; (k < num_local_point_ids[
i]) && !match_flag; ++k)
207 distances[i * num_points + k].index == local_point_ids[offset + j];
208 if (!match_flag)
PUT_ERR(
"wrong result");
210 offset += num_local_point_ids[
i];
213 free(local_point_ids);
214 free(num_local_point_ids);
217static void utest_gen_random_point(
double * point) {
219 double x_coordinate = 2.0 * M_PI * (((double)rand()) / ((
double)RAND_MAX));
220 double y_coordinate = M_PI * (((double)rand()) / ((
double)RAND_MAX)) - M_PI_2;
221 LLtoXYZ(x_coordinate, y_coordinate, point);
224static void utest_gen_random_bnd_circle(
struct bounding_circle * circle) {
227 double angle = M_PI_2 * (((double)rand()) / ((
double)RAND_MAX));
232static void utest_random_test(
size_t const num_points) {
234 double (*coordinates_xyz)[3];
235 double (*coordinates_xyz_a)[3];
236 double (*coordinates_xyz_b)[3];
238 xmalloc(num_points *
sizeof(*bnd_circles));
241 coordinates_xyz =
xmalloc(2 * num_points *
sizeof(*coordinates_xyz));
242 coordinates_xyz_a = coordinates_xyz;
243 coordinates_xyz_b = coordinates_xyz + num_points;
245 size_t * local_point_ids = NULL;
246 size_t local_point_ids_array_size = 0;
247 size_t * num_local_point_ids =
248 xmalloc(num_points *
sizeof(*num_local_point_ids));
250 xmalloc(num_points * num_points *
sizeof(*distances));
252 for (
size_t i = 0;
i < num_points; ++
i) {
253 utest_gen_random_bnd_circle(bnd_circles + i);
256 for (
size_t k = 0; k < 2 * num_points; ++k)
257 utest_gen_random_point(coordinates_xyz[k]);
259 for (
size_t j = 0; j < num_points; ++j) {
260 for (
size_t k = 0; k < num_points; ++k) {
262 distances[j * num_points + k].
distance =
264 distances[j * num_points + k].
index = k;
267 distances + j * num_points, num_points,
sizeof(*distances),
268 utest_compare_distance_index);
276 for (
size_t n = 1;
n < 16; ++
n)
277 utest_point_sphere_test_NNN(
278 search, n, coordinates_xyz_a, coordinates_xyz_b, num_points,
279 &local_point_ids, &local_point_ids_array_size, num_local_point_ids,
282 for (
size_t n = 1;
n <
MIN(num_points,16); ++
n)
283 utest_point_sphere_test_NNN_ubound(
284 search, num_points, coordinates_xyz_b, n, distances);
286 for (
size_t n = 1;
n <
MIN(num_points,16); ++
n)
287 utest_point_sphere_test_NNN_bnd_circle(
288 search, num_points, coordinates_xyz_b, n, distances);
293 free(local_point_ids);
294 free(num_local_point_ids);
297 free(coordinates_xyz);
300static void utest_single_point_test() {
303 double xyz_coordinate[1][3];
305 double x_coordinate = 0, y_coordinate = 0;
307 LLtoXYZ(x_coordinate, y_coordinate, xyz_coordinate[0]);
313 double x_coordinates[] = {0.0,90.0,180.0,-90.0, 0.0, 0.0};
314 double y_coordinates[] = {0.0, 0.0, 0.0, 0.0,90.0,-90.0};
315 size_t num_points =
sizeof(x_coordinates) /
sizeof(x_coordinates[0]);
316 double xyz_coordinates[num_points][3];
317 for (
size_t i = 0;
i < num_points; ++
i)
318 LLtoXYZ_deg(x_coordinates[i], y_coordinates[i], xyz_coordinates[i]);
320 size_t * local_point_ids = NULL;
321 size_t local_point_ids_array_size = 0;
322 size_t * num_local_point_ids =
323 xmalloc(num_points *
sizeof(*num_local_point_ids));
326 search, num_points, xyz_coordinates, NULL, NULL, NULL, &local_point_ids,
327 &local_point_ids_array_size, num_local_point_ids);
329 for (
size_t i = 0;
i < num_points; ++
i)
330 if ((num_local_point_ids[i] != 1) || (local_point_ids[i] != 0))
331 PUT_ERR(
"utest_single_point_test: wrong result\n");
335 search, num_points, xyz_coordinates, 1, angles);
337 for (
size_t i = 0;
i < num_points; ++
i)
341 xyz_coordinate[0], xyz_coordinates[i])) != 0)
344 free(local_point_ids);
345 free(num_local_point_ids);
349static void utest_zero_point_test() {
354 double x_coordinates[] = {0.0,90.0,180.0,-90.0, 0.0, 0.0};
355 double y_coordinates[] = {0.0, 0.0, 0.0, 0.0,90.0,-90.0};
356 enum {
NUM_POINTS =
sizeof(x_coordinates) /
sizeof(x_coordinates[0])};
359 LLtoXYZ_deg(x_coordinates[i], y_coordinates[i], xyz_coordinates[i]);
364 x_coordinates[i], y_coordinates[i], bnd_circles[i].
base_vector);
368 size_t * local_point_ids = NULL;
369 size_t local_point_ids_array_size = 0;
373 num_local_point_ids[i] = (
size_t)-1;
375 search,
NUM_POINTS, xyz_coordinates, NULL, NULL, NULL, &local_point_ids,
376 &local_point_ids_array_size, num_local_point_ids);
379 if (num_local_point_ids[i] != 0)
PUT_ERR(
"utest_zero_point_test: wrong result\n");
382 num_local_point_ids[i] = (
size_t)-1;
384 search,
NUM_POINTS, xyz_coordinates, 16, NULL, NULL, NULL, NULL,
385 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
388 if (num_local_point_ids[i] != 0)
PUT_ERR(
"utest_zero_point_test: wrong result\n");
391 num_local_point_ids[i] = (
size_t)-1;
393 search,
NUM_POINTS, bnd_circles, 1, &local_point_ids,
394 &local_point_ids_array_size, num_local_point_ids);
397 if (num_local_point_ids[i] != 0)
PUT_ERR(
"utest_zero_point_test: wrong result\n");
399 free(local_point_ids);
403static void utest_empty_branch_test(
size_t num_points_a) {
406 malloc(num_points_a *
sizeof(*xyz_coordinates_a));
407 yac_int * global_ids = malloc(num_points_a *
sizeof(*global_ids));
408 for (
size_t i = 0;
i < num_points_a; ++
i) {
409 LLtoXYZ_deg(0.0, -5.0 + (10.0 / (
double)num_points_a) * (
double)i,
410 xyz_coordinates_a[i]);
420 double x_coordinates_b[] = {-1.0,-1.0, 1.0,1.0};
421 double y_coordinates_b[] = {-1.0, 1.0,-1.0,1.0};
422 size_t num_points_b =
sizeof(x_coordinates_b) /
sizeof(x_coordinates_b[0]);
423 double xyz_coordinates_b[num_points_b][3];
424 for (
size_t i = 0;
i < num_points_b; ++
i)
425 LLtoXYZ_deg(x_coordinates_b[i], y_coordinates_b[i], xyz_coordinates_b[i]);
427 size_t * local_point_ids = NULL;
428 size_t local_point_ids_array_size = 0;
429 size_t * num_local_point_ids =
430 xmalloc(num_points_b *
sizeof(*num_local_point_ids));
434 for (
size_t i = 0;
i < num_points_b; ++
i) {
436 for (
size_t j = 0; j < num_points_a; ++j) {
438 distances[
i * num_points_a + j].
distance =
440 distances[
i * num_points_a + j].
index = j;
442 qsort(distances + i * num_points_a, num_points_a,
sizeof(*distances),
443 utest_compare_distance_index);
446 for (
size_t i = 0;
i < num_points_b; ++
i)
447 num_local_point_ids[i] = (
size_t)-1;
449 search, num_points_b, xyz_coordinates_b, NULL, NULL, NULL,
450 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
453 for (
size_t j = 0, offset = 0; j < num_points_b; ++j) {
455 struct distance_index * curr_distances = distances + j * num_points_a;
457 size_t ref_num_local_points;
458 for (ref_num_local_points = 1;
459 (ref_num_local_points < num_points_a); ++ref_num_local_points)
460 if (utest_double_are_unequal(
461 curr_distances[ref_num_local_points-1].
distance,
462 curr_distances[ref_num_local_points].
distance))
break;
464 if (num_local_point_ids[j] != ref_num_local_points) {
465 PUT_ERR(
"wrong number of local points found\n");
469 size_t num_matching_points = 0;
470 for (
size_t k = 0; k < ref_num_local_points; ++k)
471 for (
size_t l = 0; l < ref_num_local_points; ++l)
472 if (curr_distances[k].
index == local_point_ids[offset+l])
473 ++num_matching_points;
475 if (num_matching_points != ref_num_local_points)
478 offset += ref_num_local_points;
480 free(local_point_ids);
481 free(num_local_point_ids);
486 search, num_points_b, xyz_coordinates_b, 1, angles);
489 for (
size_t j = 0; j < num_points_b; ++j) {
493 for (
size_t i = 0;
i < num_points_a; ++
i) {
497 xyz_coordinates_a[i], xyz_coordinates_b[j]);
500 min_angle = curr_angle;
507 free(xyz_coordinates_a);
512static void utest_zero_balance_point() {
516 double x_coordinate = 0, y_coordinate = 0;
517 double xyz_coordinate[6][3] =
521 yac_int global_ids[6] = {0,1,2,3,4,5};
522 LLtoXYZ(x_coordinate, y_coordinate, xyz_coordinate[0]);
530static void utest_duplicated_point_test() {
534 double x_coordinates[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
535 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
536 2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,
537 3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,
538 4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0,
540 double y_coordinates[] = {0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,
541 0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,
542 0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,
543 0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,
544 0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,
546 enum {
NUM_POINTS =
sizeof(x_coordinates) /
sizeof(x_coordinates[0])};
549 0,1,2,3,4,5,6,7,8,9,
550 10,11,12,13,14,15,16,17,18,19,
551 20,21,22,23,24,25,26,27,28,29,
552 30,31,32,33,34,35,36,37,38,39,
553 40,41,42,43,44,45,46,47,48,49,
556 LLtoXYZ_deg(x_coordinates[i], y_coordinates[i], xyz_coordinates[i]);
564 double x_coordinates[] = {1.0,1.0,2.0,2.0,2.0,3.0,3.0,2.1,0.1,2.5};
565 double y_coordinates[] = {1.0,8.0,3.0,4.0,5.0,1.0,8.0,4.0,0.0,3.0};
567 NUM_POINTS =
sizeof(x_coordinates) /
sizeof(x_coordinates[0]),
568 MAX_NUM_RESULTS = 2};
571 LLtoXYZ_deg(x_coordinates[i], y_coordinates[i], xyz_coordinates[i]);
573 size_t * local_point_ids = NULL;
574 size_t local_point_ids_array_size = 0;
577 double (*result_coordinates_xyz)[3] = NULL;
578 size_t result_coordinates_xyz_array_size = 0;
582 &result_coordinates_xyz, &result_coordinates_xyz_array_size,
583 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
585 size_t ref_local_point_ids[
NUM_POINTS][MAX_NUM_RESULTS] =
586 {{11}, {18}, {23}, {52}, {25}, {31}, {38}, {52}, {0}, {23,33}};
587 size_t ref_num_local_point_ids[
NUM_POINTS] = {1,1,1,1,1,1,1,1,1,2};
588 double ref_x_coordinates[
NUM_POINTS][MAX_NUM_RESULTS] =
589 {{1.0},{1.0},{2.0},{2.0},{2.0},{3.0},{3.0},{2.0},{0.0},{2.0,3.0}};
590 double ref_y_coordinates[
NUM_POINTS][MAX_NUM_RESULTS] =
591 {{1.0},{8.0},{3.0},{4.0},{5.0},{1.0},{8.0},{4.0},{0.0},{3.0,3.0}};
592 double ref_result_coordinates_xyz[
NUM_POINTS][MAX_NUM_RESULTS][3];
595 for (
size_t j = 0; j < ref_num_local_point_ids[
i]; ++j)
597 ref_x_coordinates[i][j], ref_y_coordinates[i][j],
598 ref_result_coordinates_xyz[i][j]);
601 offset += num_local_point_ids[
i++]) {
603 if (num_local_point_ids[i] != ref_num_local_point_ids[i]) {
604 PUT_ERR(
"ERROR in yac_point_sphere_part_search_NN (num_local_point_ids)");
607 int match_flag[ref_num_local_point_ids[
i]];
608 size_t match_count = 0;
609 memset(match_flag, 0, ref_num_local_point_ids[i] *
sizeof(match_flag[0]));
611 for (
size_t j = 0; j < ref_num_local_point_ids[
i]; ++j) {
613 for (
size_t k = 0; k < ref_num_local_point_ids[
i]; ++k) {
616 result_coordinates_xyz[offset+j],
617 ref_result_coordinates_xyz[i][k]) &&
618 (local_point_ids[offset+j] == ref_local_point_ids[i][k])) {
621 PUT_ERR(
"ERROR in yac_point_sphere_part_search_NN "
622 "duplicated result");
630 if (match_count != ref_num_local_point_ids[i]) {
631 PUT_ERR(
"ERROR in yac_point_sphere_part_search_NN result mismatch");
636 free(local_point_ids);
637 free(result_coordinates_xyz);
641static void utest_bnd_circle_search() {
645 double x_coordinates[] = {0.0, 10.0, 20.0, 30.0, 40.0};
646 double y_coordinates[] = {0.0, 0.0, 0.0, 0.0, 0.0};
647 enum {
NUM_POINTS =
sizeof(x_coordinates) /
sizeof(x_coordinates[0])};
651 LLtoXYZ_deg(x_coordinates[i], y_coordinates[i], xyz_coordinates[i]);
666 bnd_circles[0].
sq_crd = DBL_MAX;
670 bnd_circles[1].
sq_crd = DBL_MAX;
672 size_t * local_point_ids = NULL;
673 size_t local_point_ids_array_size = 0;
674 size_t num_local_point_ids[2];
678 search, 2, bnd_circles,
679 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
685 {{.count = 2, .ids = (
size_t[]){1,2}},
686 {.count = 2, .ids = (
size_t[]){3,4}}};
689 for (
size_t i = 0, offset = 0;
i < 2; ++
i) {
691 if (num_local_point_ids[i] != ref_results[i].count){
692 PUT_ERR(
"utest_bnd_circle_search: wrong number of points");
695 int match_flag[ref_results[
i].count];
696 size_t match_count = 0;
697 memset(match_flag, 0, ref_results[i].count *
sizeof(match_flag[0]));
699 size_t * curr_local_point_ids = local_point_ids + offset;
700 for (
size_t j = 0; j < num_local_point_ids[
i]; ++j) {
701 for (
size_t k = 0; k < ref_results[
i].count; ++k) {
702 if (curr_local_point_ids[j] == ref_results[i].ids[k]) {
705 PUT_ERR(
"utest_bnd_circle_search: multiple matches");
713 if (match_count != ref_results[i].count) {
714 PUT_ERR(
"utest_bnd_circle_search: wrong points");
717 offset += num_local_point_ids[
i];
720 free(local_point_ids);
733 bnd_circle.sq_crd = DBL_MAX;
735 size_t * local_point_ids = NULL;
736 size_t local_point_ids_array_size = 0;
737 size_t num_local_point_ids[1] = {(size_t)-1};
740 search, 1, &bnd_circle,
741 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
743 if (num_local_point_ids[0] != 0)
744 PUT_ERR(
"utest_bnd_circle_search: empty search should find 0 points");
746 free(local_point_ids);
752 double xyz_coordinates[3][3] = {{1,0,0}, {0,1,0}, {0,0,1}};
753 yac_int global_ids[3] = {0, 1, 2};
759 size_t * local_point_ids = NULL;
760 size_t local_point_ids_array_size = 0;
765 &local_point_ids, &local_point_ids_array_size, NULL);
767 free(local_point_ids);
773 double xyz_coordinate[1][3];
783 memcpy(bnd_circle.base_vector, xyz_coordinate[0],
sizeof(xyz_coordinate[0]));
786 bnd_circle.sq_crd = DBL_MAX;
788 size_t * local_point_ids = NULL;
789 size_t local_point_ids_array_size = 0;
790 size_t num_local_point_ids[1];
793 search, 1, &bnd_circle,
794 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
796 if (num_local_point_ids[0] != 1)
797 PUT_ERR(
"utest_bnd_circle_search: single point search failed (count)");
798 if (local_point_ids[0] != 0)
799 PUT_ERR(
"utest_bnd_circle_search: single point search failed (id)");
801 free(local_point_ids);
807 double x_coordinates[] = {0.0, 90.0, 180.0, -90.0};
808 double y_coordinates[] = {0.0, 0.0, 0.0, 0.0};
809 enum {
NUM_POINTS =
sizeof(x_coordinates) /
sizeof(x_coordinates[0])};
813 LLtoXYZ_deg(x_coordinates[i], y_coordinates[i], xyz_coordinates[i]);
826 bnd_circle.sq_crd = DBL_MAX;
828 size_t * local_point_ids = NULL;
829 size_t local_point_ids_array_size = 0;
830 size_t num_local_point_ids[1];
833 search, 1, &bnd_circle,
834 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
836 if (num_local_point_ids[0] != 0)
837 PUT_ERR(
"utest_bnd_circle_search: should find 0 points");
839 free(local_point_ids);
845 double x_coordinates[] = {0.0, 1.0, 2.0, 3.0, 4.0};
846 double y_coordinates[] = {0.0, 0.0, 0.0, 0.0, 0.0};
847 enum {
NUM_POINTS =
sizeof(x_coordinates) /
sizeof(x_coordinates[0])};
851 LLtoXYZ_deg(x_coordinates[i], y_coordinates[i], xyz_coordinates[i]);
864 bnd_circle.sq_crd = DBL_MAX;
866 size_t * local_point_ids = NULL;
867 size_t local_point_ids_array_size = 0;
868 size_t num_local_point_ids[1];
871 search, 1, &bnd_circle,
872 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
875 PUT_ERR(
"utest_bnd_circle_search: should find all points");
877 free(local_point_ids);
882static void utest_bnd_circle_random_test(
883 size_t num_points,
size_t num_circles) {
885 double (*xyz_coordinates)[3] =
xmalloc(num_points *
sizeof(*xyz_coordinates));
888 xmalloc(num_circles *
sizeof(*bnd_circles));
891 for (
size_t i = 0;
i < num_points; ++
i) {
892 utest_gen_random_point(xyz_coordinates[i]);
897 for (
size_t i = 0;
i < num_circles; ++
i)
898 utest_gen_random_bnd_circle(&bnd_circles[i]);
904 size_t * local_point_ids = NULL;
905 size_t local_point_ids_array_size = 0;
906 size_t * num_local_point_ids =
xmalloc(num_circles *
sizeof(*num_local_point_ids));
909 search, num_circles, bnd_circles,
910 &local_point_ids, &local_point_ids_array_size, num_local_point_ids);
914 for (
size_t i = 0;
i < num_circles; ++
i) {
917 size_t ref_count = 0;
918 size_t * ref_ids =
xmalloc(num_points *
sizeof(*ref_ids));
920 for (
size_t j = 0; j < num_points; ++j) {
923 if (
compare_angles(angle_to_point, bnd_circles[i].inc_angle) <= 0) {
924 ref_ids[ref_count++] = j;
929 if (num_local_point_ids[i] != ref_count) {
930 PUT_ERR(
"utest_bnd_circle_random_test: wrong number of points found");
933 for (
size_t j = 0; j < num_local_point_ids[
i]; ++j) {
935 for (
size_t k = 0; k < ref_count; ++k) {
936 if (local_point_ids[offset + j] == ref_ids[k]) {
942 PUT_ERR(
"utest_bnd_circle_random_test: unexpected point in result");
946 for (
size_t k = 0; k < ref_count; ++k) {
948 for (
size_t j = 0; j < num_local_point_ids[
i]; ++j) {
949 if (local_point_ids[offset + j] == ref_ids[k]) {
955 PUT_ERR(
"utest_bnd_circle_random_test: missing point in result");
959 offset += num_local_point_ids[
i];
963 free(local_point_ids);
964 free(num_local_point_ids);
967 free(xyz_coordinates);
static struct sin_cos_angle get_vector_angle_2(double const a[3], double const b[3])
static int points_are_identically(double const *a, double const *b)
static const struct sin_cos_angle SIN_COS_M_PI
static void LLtoXYZ_deg(double lon, double lat, double p_out[])
static int compare_angles(struct sin_cos_angle a, struct sin_cos_angle b)
static double get_vector_angle(double const a[3], double const b[3])
static struct sin_cos_angle sin_cos_angle_new(double sin, double cos)
void yac_point_sphere_part_search_NNN_ubound(struct point_sphere_part_search *search, size_t num_points, yac_coordinate_pointer coordinates_xyz, size_t n, struct sin_cos_angle *angles)
void yac_point_sphere_part_search_NNN_bnd_circle(struct point_sphere_part_search *search, size_t num_bnd_circles, struct bounding_circle *bnd_circles, size_t n, size_t **local_point_ids, size_t *local_point_ids_array_size, size_t *num_local_point_ids)
void yac_delete_point_sphere_part_search(struct point_sphere_part_search *search)
struct point_sphere_part_search * yac_point_sphere_part_search_new(size_t num_points, yac_const_coordinate_pointer coordinates_xyz, yac_int const *ids)
void yac_point_sphere_part_search_bnd_circle(struct point_sphere_part_search *search, size_t num_bnd_circles, const_bounding_circle_pointer bnd_circles, size_t **local_point_ids, size_t *local_point_ids_array_size, size_t *num_local_point_ids)
void yac_point_sphere_part_search_NN(struct point_sphere_part_search *search, size_t num_points, double(*coordinates_xyz)[3], double *cos_angles, double(**result_coordinates_xyz)[3], size_t *result_coordinates_xyz_array_size, size_t **local_point_ids, size_t *local_point_ids_array_size, size_t *num_local_point_ids)
void yac_point_sphere_part_search_NNN(struct point_sphere_part_search *search, size_t num_points, double(*coordinates_xyz)[3], size_t n, double **cos_angles, size_t *cos_angles_array_size, double(**result_coordinates_xyz)[3], size_t *result_coordinates_xyz_array_size, size_t **local_point_ids, size_t *local_point_ids_array_size, size_t *num_local_point_ids)
algorithm for searching cells and points on a grid
struct sin_cos_angle inc_angle
angle between the middle point and the boundary of the spherical cap
static void LLtoXYZ(double lon, double lat, double p_out[])
double const (* yac_const_coordinate_pointer)[3]
double(* yac_coordinate_pointer)[3]