20static void utest_random_test(
size_t count);
21static void utest_random_test_big(
size_t count);
22static void utest_empty_test();
23static void utest_zero_balance_point();
24static void utest_mean_point_test();
30 for (
size_t i = 0;
i < 10; ++
i) {
32 utest_random_test(10);
33 utest_random_test(100);
34 utest_random_test(650);
35 utest_random_test_big(50);
38 utest_zero_balance_point();
39 utest_mean_point_test();
46 double x_coordinate = 2.0 * M_PI * (((double)rand()) / ((
double)RAND_MAX));
47 double y_coordinate = M_PI * (((double)rand()) / ((
double)RAND_MAX)) - M_PI_2;
48 LLtoXYZ(x_coordinate, y_coordinate, point);
54 double angle = M_PI_2 * (((double)rand()) / ((
double)RAND_MAX));
62 double angle = 3.0 * M_PI_2 * (((double)rand()) / ((
double)RAND_MAX));
69 (*(
size_t const *)a > *(
size_t const *)b) -
70 (*(
size_t const *)a < *(
size_t const *)b);
74 size_t * list,
size_t list_size,
size_t * sorted_indices,
size_t count) {
78 size_t match_count = 0;
79 for (
size_t i = 0, j = 0; i < count; ++i) {
80 while ((j < list_size) && (list[j] < sorted_indices[i])) ++j;
81 if ((j < list_size) && (list[j] == sorted_indices[i])) ++match_count;
83 return match_count != count;
86static void utest_random_test(
size_t count) {
89 xmalloc(2 * count *
sizeof(*bnd_circles));
92 double (*point_coords)[3] =
xmalloc(count *
sizeof(*point_coords));
94 for (
size_t i = 0;
i < count; ++
i) {
106 size_t * num_results =
xmalloc(count *
sizeof(*num_results));
108 search, point_coords, count, &results, num_results);
110 size_t * ref_results =
xmalloc(count *
sizeof(*ref_results));
111 for (
size_t i = 0, offset = 0;
i < count; ++
i) {
112 size_t ref_num_results = 0;
113 for (
size_t j = 0; j < count; ++j)
115 point_coords[i], bnd_circles_a + j))
116 ref_results[ref_num_results++] = j;
118 if ((ref_num_results > num_results[i]) ||
120 results + offset, num_results[i], ref_results, ref_num_results))
121 PUT_ERR(
"ERROR in yac_bnd_sphere_part_search_do_point_search");
123 offset += num_results[
i];
132 size_t * num_results =
xmalloc(count *
sizeof(*num_results));
134 search, bnd_circles_b, count, &results, num_results);
136 size_t * ref_results =
xmalloc(count *
sizeof(*ref_results));
137 for (
size_t i = 0, offset = 0;
i < count; ++
i) {
138 size_t ref_num_results = 0;
139 for (
size_t j = 0; j < count; ++j)
141 bnd_circles_b + i, bnd_circles_a + j))
142 ref_results[ref_num_results++] = j;
144 if ((ref_num_results > num_results[i]) ||
146 results + offset, num_results[i], ref_results, ref_num_results))
147 PUT_ERR(
"ERROR in yac_bnd_sphere_part_search_do_bnd_circle_search");
149 offset += num_results[
i];
161static void utest_random_test_big(
size_t count) {
164 xmalloc(2 * count *
sizeof(*bnd_circles));
167 double (*point_coords)[3] =
xmalloc(count *
sizeof(*point_coords));
169 for (
size_t i = 0;
i < count; ++
i) {
181 size_t * num_results =
xmalloc(count *
sizeof(*num_results));
183 search, bnd_circles_b, count, &results, num_results);
185 size_t * ref_results =
xmalloc(count *
sizeof(*ref_results));
186 for (
size_t i = 0, offset = 0;
i < count; ++
i) {
187 size_t ref_num_results = 0;
188 for (
size_t j = 0; j < count; ++j)
190 bnd_circles_b + i, bnd_circles_a + j))
191 ref_results[ref_num_results++] = j;
193 if ((ref_num_results > num_results[i]) ||
195 results + offset, num_results[i], ref_results, ref_num_results))
196 PUT_ERR(
"ERROR in yac_bnd_sphere_part_search_do_bnd_circle_search");
198 offset += num_results[
i];
210static void utest_empty_test() {
214 xmalloc(count *
sizeof(*bnd_circles));
215 double (*point_coords)[3] =
xmalloc(count *
sizeof(*point_coords));
217 for (
size_t i = 0;
i < count; ++
i) {
228 size_t * num_results =
xmalloc(count *
sizeof(*num_results));
230 search, point_coords, count, &results, num_results);
232 for (
size_t i = 0;
i < count; ++
i)
233 if (num_results[i] != 0)
234 PUT_ERR(
"ERROR in yac_bnd_sphere_part_search_do_point_search");
242 size_t * num_results =
xmalloc(count *
sizeof(*num_results));
244 search, bnd_circles, count, &results, num_results);
246 for (
size_t i = 0;
i < count; ++
i)
247 if (num_results[i] != 0)
248 PUT_ERR(
"ERROR in yac_bnd_sphere_part_search_do_bnd_circle_search");
259static void utest_zero_balance_point() {
263 {.base_vector = {-1,0,0}, .inc_angle =
SIN_COS_ZERO, .sq_crd = DBL_MAX},
264 {.base_vector = {0,1,0}, .inc_angle =
SIN_COS_ZERO, .sq_crd = DBL_MAX},
265 {.base_vector = {0,-1,0}, .inc_angle =
SIN_COS_ZERO, .sq_crd = DBL_MAX},
266 {.base_vector = {0,0,1}, .inc_angle =
SIN_COS_ZERO, .sq_crd = DBL_MAX},
267 {.base_vector = {0,0,-1}, .inc_angle =
SIN_COS_ZERO, .sq_crd = DBL_MAX}};
271 utest_zero_balance_point_bnd_circles,
272 sizeof(utest_zero_balance_point_bnd_circles)/
273 sizeof(utest_zero_balance_point_bnd_circles[0]));
278static void utest_mean_point_test() {
282 {.base_vector = {-1,0,0}, .inc_angle =
SIN_COS_M_PI_2, .sq_crd = DBL_MAX},
283 {.base_vector = {0,1,0}, .inc_angle =
SIN_COS_M_PI_2, .sq_crd = DBL_MAX},
284 {.base_vector = {0,-1,0}, .inc_angle =
SIN_COS_M_PI_2, .sq_crd = DBL_MAX},
285 {.base_vector = {0,0,1}, .inc_angle =
SIN_COS_M_PI_2, .sq_crd = DBL_MAX}};
287 double search_points[6][3] =
288 {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
292 pole_balance_point_bnd_circles,
293 sizeof(pole_balance_point_bnd_circles)/
294 sizeof(pole_balance_point_bnd_circles[0]));
296 size_t num_points =
sizeof(search_points)/
sizeof(search_points[0]);
300 search, search_points,
num_points, &results, num_results);
302 size_t ref_results[6][5] =
303 {{0,2,3,4},{1,2,3,4},{0,1,3,4},{0,1,2,4},{0,1,2,3,4},{0,1,2,3}};
304 size_t ref_num_results[6] = {4,4,4,4,5,4};
306 for (
size_t i = 0, offset = 0;
i <
num_points; offset += num_results[
i++])
307 if ((ref_num_results[i] > num_results[i]) ||
309 results + offset, num_results[i], ref_results[i], ref_num_results[i]))
310 PUT_ERR(
"ERROR in yac_bnd_sphere_part_search_do_point_search");
int yac_extents_overlap(struct bounding_circle *extent_a, struct bounding_circle *extent_b)
static const struct sin_cos_angle SIN_COS_ZERO
static int yac_point_in_bounding_circle_vec(double point_vector[3], struct bounding_circle *bnd_circle)
static const struct sin_cos_angle SIN_COS_M_PI_2
static struct sin_cos_angle sin_cos_angle_new(double sin, double cos)
void yac_bnd_sphere_part_search_do_bnd_circle_search(struct bnd_sphere_part_search *search, struct bounding_circle *bnd_circles, size_t count, size_t **cells, size_t *num_cells_per_bnd_circle)
struct bnd_sphere_part_search * yac_bnd_sphere_part_search_new(struct bounding_circle *circles, size_t num_circles)
void yac_bnd_sphere_part_search_delete(struct bnd_sphere_part_search *search)
void yac_bnd_sphere_part_search_do_point_search(struct bnd_sphere_part_search *search, yac_coordinate_pointer coordinates_xyz, size_t count, size_t **cells, size_t *num_cells_per_coordinate)
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 int compare_size_t(void const *a, void const *b)
static void gen_random_bnd_circle(struct bounding_circle *circle)
static void gen_random_point(double *point)
static int check_results(size_t *list, size_t list_size, size_t *sorted_indices, size_t count)
static void gen_random_bnd_circle_big(struct bounding_circle *circle)
static void LLtoXYZ(double lon, double lat, double p_out[])