YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_loncxlonc.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include "test_cxc.h"
6
12static void utest_loncxlonc(
13 double lon_a, double lat_a, double lon_b, double lat_b,
14 double lon_c, double lat_c, double lon_d, double lat_d,
15 double lon_ref_p, double lat_ref_p,
16 double lon_ref_q, double lat_ref_q, int ref_ret_val);
17
18int main (void) {
19
20 int const p_between_ab = 1 << 0;
21 int const q_between_ab = 1 << 1;
22 int const p_between_cd = 1 << 2;
23 int const q_between_cd = 1 << 3;
24 int const circles_are_identically = 1 << 4;
25
26 // two circles of longitude on the same plane that intersect
27
28 for (int i = 0; i < 2; ++i) {
29
30 double lat_coords[2][2] = {{-10, 5}, {-5, 10}};
31 utest_loncxlonc(0, lat_coords[i][0], // point a
32 0, lat_coords[i][1], // point b
33 0, lat_coords[i^1][0], // point c
34 0, lat_coords[i^1][1], // point d
35 0, -5, // reference point p
36 0, 5, // reference point q
37 p_between_ab + p_between_cd + q_between_ab + q_between_cd +
38 circles_are_identically); // reference return value
39 }
40
41 for (int i = 0; i < 2; ++i) {
42
43 double lat_coords[2][2] = {{20, 25}, {30, 10}};
44 utest_loncxlonc(10, lat_coords[i][0], // point a
45 10, lat_coords[i][1], // point b
46 10, lat_coords[i^1][0], // point c
47 10, lat_coords[i^1][1], // point d
48 10, 20, // reference point p
49 10, 25, // reference point q
50 p_between_ab + p_between_cd + q_between_ab + q_between_cd +
51 circles_are_identically); // reference return value
52 }
53
54 // two circles of longitude on the same plane that do not intersect
55
56 for (int i = 0; i < 2; ++i) {
57
58 double lat_coords[2][2] = {{-80, -70}, {20, 30}};
59 utest_loncxlonc(30, lat_coords[i][0], // point a
60 30, lat_coords[i][1], // point b
61 30, lat_coords[i^1][0], // point c
62 30, lat_coords[i^1][1], // point d
63 30, (lat_coords[i][0] +
64 lat_coords[i][1])*0.5, // reference point p
65 30, (lat_coords[i^1][0] +
66 lat_coords[i^1][1])*0.5, // reference point q
67 p_between_ab + q_between_cd +
68 circles_are_identically); // reference return value
69 }
70
71 // two circles of longitude on different planes that do not intersect
72
73 for (int i = 0; i < 2; ++i) {
74
75 double lat_coords[2][2] = {{-80, -70}, {20, 30}};
76 utest_loncxlonc(-30, lat_coords[i][0], // point a
77 -30, lat_coords[i][1], // point b
78 30, lat_coords[i^1][0], // point c
79 30, lat_coords[i^1][1], // point d
80 0, 90, // reference point p
81 0, -90, // reference point q
82 0); // reference return value
83 }
84
85 // two circles of longitude on different planes that do not intersect
86 // and one edge goes across the north pole
87
88 for (int i = 0; i < 2; ++i) {
89
90 double lat_coords[2][2] = {{80, 85}, {70, 75}};
91 utest_loncxlonc(-45 , lat_coords[i][0], // point a
92 -45+180, lat_coords[i][1], // point b
93 50 , lat_coords[i^1][0], // point c
94 50 , lat_coords[i^1][1], // point d
95 0 , 90, // reference point p
96 0 , -90, // reference point q
97 p_between_ab); // reference return value
98 }
99
100 // two circles of longitude on different planes that do not intersect
101 // and one circle touches the north pole
102
103 for (int i = 0; i < 2; ++i) {
104
105 double lat_coords[2][2] = {{90, 80}, {-40, -30}};
106 int ret_val[2] = {p_between_ab, p_between_cd};
107 utest_loncxlonc(60, lat_coords[i][0], // point a
108 60, lat_coords[i][1], // point b
109 90, lat_coords[i^1][0], // point c
110 90, lat_coords[i^1][1], // point d
111 0, 90, // reference point p
112 0, -90, // reference point q
113 ret_val[i]); // reference return value
114 }
115
116 // two circles of longitude on different planes that intersect at the
117 // north pole
118
119 for (int i = 0; i < 2; ++i) {
120
121 double lat_coords[2][2] = {{75, 80},{60, 85}};
122 utest_loncxlonc(60 , lat_coords[i][0], // point a
123 60-180, lat_coords[i][1], // point b
124 90 , lat_coords[i^1][0], // point c
125 90-180, lat_coords[i^1][1], // point d
126 0 , 90, // reference point p
127 0 , -90, // reference point q
128 p_between_ab + p_between_cd); // reference return value
129 }
130
131 // two circles of longitude on different planes that intersect at the
132 // south pole
133
134 for (int i = 0; i < 2; ++i) {
135
136 double lat_coords[2][2] = {{-75, -80},{-60, -85}};
137 utest_loncxlonc(60 , lat_coords[i][0], // point a
138 60-180, lat_coords[i][1], // point b
139 90 , lat_coords[i^1][0], // point c
140 90-180, lat_coords[i^1][1], // point d
141 0 , 90, // reference point p
142 0 , -90, // reference point q
143 q_between_ab + q_between_cd); // reference return value
144 }
145
146 for (int i = 0; i < 2; ++i) {
147
148 double lat_coords[2][2] = {{-75, -80},{-60, -90}};
149 utest_loncxlonc(60 , lat_coords[i][0], // point a
150 60-180, lat_coords[i][1], // point b
151 90 , lat_coords[i^1][0], // point c
152 90-180, lat_coords[i^1][1], // point d
153 0 , 90, // reference point p
154 0 , -90, // reference point q
155 q_between_ab + q_between_cd); // reference return value
156 }
157
158 // two circles of longitude on different planes that do not intersect
159 // one of the circles has length zero
160
161 utest_loncxlonc( 0, -10, // point a
162 0, 10, // point b
163 10, 0, // point c
164 10, 0, // point d
165 -1, -1, // reference point p
166 -1, -1, // reference point q
167 -1); // reference return value
168
169 utest_loncxlonc(10, -10, // point a
170 10, 10, // point b
171 0, 0, // point c
172 0, 0, // point d
173 -1, -1, // reference point p
174 -1, -1, // reference point q
175 -1); // reference return value
176
177 utest_loncxlonc( 0, 10, // point a
178 0, 10, // point b
179 10, 0, // point c
180 10, 0, // point d
181 -1, -1, // reference point p
182 -1, -1, // reference point q
183 -1); // reference return value
184
185 utest_loncxlonc( 0, 0, // point a
186 0, 0, // point b
187 10, 10, // point c
188 10, 10, // point d
189 -1, -1, // reference point p
190 -1, -1, // reference point q
191 -1); // reference return value
192
193 // two circles of longitude on the same planes but do not intersect
194 // both circles have length zero
195
196 utest_loncxlonc( 0, 10, // point a
197 0, 10, // point b
198 0, 0, // point c
199 0, 0, // point d
200 -1, -1, // reference point p
201 -1, -1, // reference point q
202 -1); // reference return value
203
204 // two circles of longitude on the same planes
205 // both circles have length zero and are at the same location
206
207 utest_loncxlonc( 0, 0, // point a
208 0, 0, // point b
209 0, 0, // point c
210 0, 0, // point d
211 0, 0, // reference point p
212 180, 0, // reference point q
213 p_between_ab + p_between_cd); // reference return value
214
215 // two circles of longitude, both have length zero and are on the poles
216
217 for (int i = 0; i < 8; ++i) {
218 double lon_coords[2] = {0 , 90};
219 double lat_coords[2] = {-90, 90};
220
221 utest_loncxlonc(lon_coords[i>>2], lat_coords[i&1], // point a
222 lon_coords[i>>2], lat_coords[i&1], // point b
223 lon_coords[(i>>2)^1], lat_coords[(i>>1)&1], // point c
224 lon_coords[(i>>2)^1], lat_coords[(i>>1)&1], // point d
225 0, lat_coords[i&1], // reference point p
226 0, -lat_coords[i&1], // reference point q
227 (((i&1)==((i>>1)&1))?
228 (p_between_ab+p_between_cd):
229 (-1))); // reference return value
230 }
231
232 // two circles of longitude, one has length zero and is on the pole
233
234 for (int j = 0; j < 2; ++j) {
235 double lat_coords[2][2] = {{90, 90}, {-10, 10}};
236 int ref_ret_val[2] = {p_between_ab, p_between_cd};
237 for (int i = 0; i < 2; ++i) {
238 double lon_coords[2] = {0, 10};
239 utest_loncxlonc(lon_coords[i], lat_coords[j][0], // point a
240 lon_coords[i], lat_coords[j][1], // point b
241 lon_coords[i^1], lat_coords[j^1][0], // point c
242 lon_coords[i^1], lat_coords[j^1][1], // point d
243 0, 90, // reference point p
244 0, -90, // reference point q
245 ref_ret_val[j]); // reference return value
246 }
247 }
248
249 // two circles that intersect at the pole
250
251 for (int i = 0; i < 4; ++i) {
252 double lat_coords[2][2] = {{-89, 89},{-90, 90}};
253 int ret_val[2] = {p_between_ab+q_between_cd,
254 p_between_ab+p_between_cd};
255 utest_loncxlonc( 0, lat_coords[0][i&1], // point a
256 180, lat_coords[0][i&1], // point b
257 45, lat_coords[0][i>>1], // point c
258 225, lat_coords[0][i>>1], // point d
259 0, lat_coords[1][i&1], // reference point p
260 0, -lat_coords[1][i&1], // reference point q
261 ret_val[(i&1)==(i>>1)]);
262 }
263
264 for (int i = 0; i < 4; ++i) {
265 double lat_coords[2][2] = {{-85, 85}, {-90, 90}};
266 int ret_val[2] = {p_between_ab + q_between_cd,
267 p_between_ab + p_between_cd};
268 utest_loncxlonc( 0, lat_coords[0][i&1], // point a
269 180, lat_coords[0][i&1], // point b
270 45, lat_coords[0][i>>1], // point c
271 225, lat_coords[0][i>>1], // point d
272 0, lat_coords[1][i&1], // reference point p
273 0, lat_coords[1][(i&1)^1], // reference point q
274 ret_val[(i&1)==(i>>1)]);
275 }
276
277 // two edges on identical circles that cross different poles
278
279 for (int j = 0; j < 4; ++j) {
280 double lon_coords[2] = {0, 180};
281 for (int i = 0; i < 2; ++i) {
282 double lat_coords[2][2] = {{-85, 85}, {-90, 90}};
283 utest_loncxlonc(lon_coords[j&1], lat_coords[0][i&1], // point a
284 lon_coords[(j&1)^1], lat_coords[0][i&1], // point b
285 lon_coords[j>>1], lat_coords[0][(i&1)^1], // point c
286 lon_coords[(j>>1)^1], lat_coords[0][(i&1)^1], // point d
287 0, lat_coords[1][i&1], // reference point p
288 0, lat_coords[1][(i&1)^1], // reference point q
289 p_between_ab + q_between_cd + circles_are_identically);
290 }
291 }
292
293 // two edges on different circles that touch at the poles
294
295 for (int j = 0; j < 2; ++j) {
296 double lon_coords[2] = {0, 60};
297 for (int i = 0; i < 2; ++i) {
298 double lat_coords[2][2] = {{-85, -90}, {85, 90}};
299 utest_loncxlonc(lon_coords[j], lat_coords[i][0], // point a
300 lon_coords[j], lat_coords[i][1], // point b
301 lon_coords[j^1], lat_coords[i][0], // point c
302 lon_coords[j^1], lat_coords[i][1], // point d
303 0, lat_coords[i][1], // reference point p
304 0, lat_coords[i^1][1], // reference point q
305 p_between_ab + p_between_cd);
306 }
307 }
308
309 // two edges on identical circles that touch at the poles
310
311 for (int i = 0; i < 2; ++i) {
312 double lat_coords[2][2] = {{-85, -90}, {85, 90}};
313 utest_loncxlonc(60, lat_coords[i][0], // point a
314 60, lat_coords[i][1], // point b
315 60+180, lat_coords[i][0], // point c
316 60+180, lat_coords[i][1], // point d
317 0, lat_coords[i][1], // reference point p
318 0, lat_coords[i][1], // reference point q
319 p_between_ab + p_between_cd +
320 q_between_ab + q_between_cd +
321 circles_are_identically);
322 }
323
324 // two edges on identical circles that overlap on the poles
325
326 for (int i = 0; i < 2; ++i) {
327 double lat_coords[2][2] = {{-85, -80}, {85, 80}};
328 utest_loncxlonc(60, lat_coords[i][0], // point a
329 60+180, lat_coords[i][1], // point b
330 60+180, lat_coords[i][0], // point c
331 60, lat_coords[i][1], // point d
332 60, lat_coords[i][0], // reference point p
333 60+180, lat_coords[i][0], // reference point q
334 p_between_ab + p_between_cd +
335 q_between_ab + q_between_cd + circles_are_identically);
336 }
337
338 for (int i = 0; i < 2; ++i) {
339 for (int j = 0; j < 2; ++j) {
340 double lat_coords[2][2] = {{-85, -80}, {85, 80}};
341 utest_loncxlonc(60, lat_coords[i][j], // point a
342 60+180, lat_coords[i][j], // point b
343 60+180, lat_coords[i][j^1], // point c
344 60, lat_coords[i][j^1], // point d
345 60, lat_coords[i][0], // reference point p
346 60+180, lat_coords[i][0], // reference point q
347 p_between_ab + p_between_cd +
348 q_between_ab + q_between_cd + circles_are_identically);
349 }
350 }
351
352 for (int i = 0; i < 2; ++i) {
353 for (int j = 0; j < 2; ++j) {
354 double lat_coords[2][3] = {{-80, -85, -90}, {80, 85, 90}};
355 utest_loncxlonc(60, lat_coords[i][j], // point a
356 60, lat_coords[i][2], // point b
357 60, lat_coords[i][j^1], // point c
358 60, lat_coords[i][2], // point d
359 60, lat_coords[i][1], // reference point p
360 60, lat_coords[i][2], // reference point q
361 p_between_ab + p_between_cd +
362 q_between_ab + q_between_cd + circles_are_identically);
363 }
364 }
365
366 for (int i = 0; i < 2; ++i) {
367 double lat_coords[2][2] = {{-85, -90}, {85, 90}};
368 utest_loncxlonc(60, lat_coords[i][0], // point a
369 60, lat_coords[i][1], // point b
370 60, lat_coords[i][0], // point c
371 60, lat_coords[i][1], // point d
372 60, lat_coords[i][0], // reference point p
373 60, lat_coords[i][1], // reference point q
374 p_between_ab + p_between_cd +
375 q_between_ab + q_between_cd + circles_are_identically);
376 }
377
378 return TEST_EXIT_CODE;
379}
380
381static void utest_loncxlonc(double lon_a, double lat_a, double lon_b, double lat_b,
382 double lon_c, double lat_c, double lon_d, double lat_d,
383 double lon_ref_p, double lat_ref_p,
384 double lon_ref_q, double lat_ref_q, int ref_ret_val) {
385
386 test_cxc(lon_a, lat_a, lon_b, lat_b, lon_c, lat_c, lon_d, lat_d,
388 lon_ref_p, lat_ref_p, lon_ref_q, lat_ref_q, ref_ret_val);
389}
@ YAC_LON_CIRCLE_EDGE
longitude circle
Definition grid_cell.h:15
void test_cxc(double lon_a, double lat_a, double lon_b, double lat_b, double lon_c, double lat_c, double lon_d, double lat_d, enum yac_edge_type edge_type_a, enum yac_edge_type edge_type_b, double lon_ref_p, double lat_ref_p, double lon_ref_q, double lat_ref_q, int ref_ret_val)
Definition test_cxc.c:141
#define TEST_EXIT_CODE
Definition tests.h:14