YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_loncxlatc.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_loncxlatc(
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 unsigned const p_between_ab = 1 << 0;
21 unsigned const q_between_ab = 1 << 1;
22 unsigned const p_between_cd = 1 << 2;
23
24 // circles that intersect
25
26 utest_loncxlatc( 0, 10, // point a
27 0, -10, // point b
28 10, 0, // point c
29 -10, 0, // point d
30 0, 0, // reference point p
31 180, 0, // reference point q
32 p_between_ab + p_between_cd); // reference return value
33
34 // circles that intersect
35
36 utest_loncxlatc(65, 35, // point a
37 65, 45, // point b
38 60, 40, // point c
39 70, 40, // point d
40 65, 40, // reference point p
41 65+180, 40, // reference point q
42 p_between_ab + p_between_cd); // reference return value
43
44 // circles that intersect but the edges not
45
46 utest_loncxlatc(-30, -60, // point a
47 -30, -70, // point b
48 -31, -65, // point c
49 -40, -65, // point d
50 -30, -65, // reference point p
51 -30+180, -65, // reference point q
52 p_between_ab); // reference return value
53
54 // circles that intersect and the edges touch
55
56 utest_loncxlatc(-30, -60, // point a
57 -30, -70, // point b
58 -30, -65, // point c
59 -40, -65, // point d
60 -30, -65, // reference point p
61 -30+180, -65, // reference point q
62 p_between_ab + p_between_cd); // reference return value
63
64 // circles that intersect but the edges not
65
66 utest_loncxlatc(-45, 80, // point a
67 -45, 90, // point b
68 -40, 70, // point c
69 -50, 70, // point d
70 -45, 70, // reference point p
71 -45+180, 70, // reference point q
72 p_between_cd); // reference return value
73
74 // circles that intersect and the edges touch
75
76 utest_loncxlatc(-45, 70, // point a
77 -45, 90, // point b
78 -40, 70, // point c
79 -50, 70, // point d
80 -45, 70, // reference point p
81 -45+180, 70, // reference point q
82 p_between_ab + p_between_cd); // reference return value
83
84 // circles that intersect at the north pole and the lon
85 // edge crosses the north pole
86
87 utest_loncxlatc(-45, 80, // point a
88 -45+180, 80, // point b
89 20, 90, // point c
90 30, 90, // point d
91 0, 90, // reference point p
92 0, -90, // reference point q
93 p_between_ab + p_between_cd); // reference return value
94
95 // circles that intersect at the south pole and the lon
96 // edge crosses the south pole
97
98 utest_loncxlatc(-45, -80, // point a
99 -45+180, -80, // point b
100 20, -90, // point c
101 30, -90, // point d
102 0, -90, // reference point p
103 0, 90, // reference point q
104 p_between_ab + p_between_cd); // reference return value
105
106 // circles that intersect at the north pole and the lon
107 // edge does not cross the north pole
108
109 utest_loncxlatc(-45, 80, // point a
110 -45, 85, // point b
111 20, 90, // point c
112 30, 90, // point d
113 0, 90, // reference point p
114 0, -90, // reference point q
115 p_between_cd); // reference return value
116
117 // circles that intersect at the south pole and the lon
118 // edge does not cross the south pole
119
120 utest_loncxlatc(-45, -80, // point a
121 -45, -85, // point b
122 20, -90, // point c
123 30, -90, // point d
124 0, -90, // reference point p
125 0, 90, // reference point q
126 p_between_cd); // reference return value
127
128 // circles that intersect at the south pole and the lon
129 // edge touches the south pole
130
131 utest_loncxlatc(-45, -80, // point a
132 -45, -90, // point b
133 20, -90, // point c
134 30, -90, // point d
135 0, -90, // reference point p
136 0, 90, // reference point q
137 p_between_ab + p_between_cd); // reference return value
138
139
140 // circles that intersect close to the south pole and the lon
141 // edge intersects the lat circle twice
142
143 utest_loncxlatc( 0, -80, // point a
144 180, -80, // point b
145 50, -89, // point c
146 60, -89, // point d
147 0, -89, // reference point p
148 180, -89, // reference point q
149 p_between_ab + q_between_ab); // reference return value
150
151 utest_loncxlatc( 0, -80, // point a
152 180, -80, // point b
153 -10, -89, // point c
154 10, -89, // point d
155 0, -89, // reference point p
156 180, -89, // reference point q
157 p_between_ab + p_between_cd + q_between_ab); // reference return value
158
159 // longitude circle consists of two identical points and is not on
160 // the latitude circle
161
162 utest_loncxlatc( 0, 0, // point a
163 0, 0, // point b
164 5, 10, // point c
165 5, 10, // point d
166 -1, -1, // reference point p
167 -1, -1, // reference point q
168 -1); // reference return value
169
170 utest_loncxlatc( 0, 0, // point a
171 0, 0, // point b
172 5, 10, // point c
173 10, 10, // point d
174 -1, -1, // reference point p
175 -1, -1, // reference point q
176 -1); // reference return value
177
178 // longitude circle consists of two identical points and is on the
179 // latitude circle
180
181 utest_loncxlatc( 0, 0, // point a
182 0, 0, // point b
183 5, 0, // point c
184 -5, 0, // point d
185 0, 0, // reference point p
186 180, 0, // reference point q
187 p_between_ab + p_between_cd); // reference return value
188
189 // latitude circle consists of two identical points and is not on
190 // the longitude circle
191
192 utest_loncxlatc( 0, -5, // point a
193 0, 5, // point b
194 5, 0, // point c
195 5, 0, // point d
196 -1, -1, // reference point p
197 -1, -1, // reference point q
198 -1); // reference return value
199
200 utest_loncxlatc( 0, -5, // point a
201 0, 5, // point b
202 5, 10, // point c
203 5, 10, // point d
204 -1, -1, // reference point p
205 -1, -1, // reference point q
206 -1); // reference return value
207
208 // longitude circle consists of two identical points and is on the
209 // latitude circle
210
211 utest_loncxlatc( 0, -5, // point a
212 0, 5, // point b
213 0, 0, // point c
214 0, 0, // point d
215 0, 0, // reference point p
216 180, 0, // reference point q
217 p_between_ab + p_between_cd); // reference return value
218
219 utest_loncxlatc( 0, 90, // point a
220 140, 60, // point b
221 90, -45, // point c
222 39, -45, // point d
223 140, -45, // reference point p
224 -40, -45, // reference point q
225 0); // reference return value
226
227 // both edges have length zero and are on a pole
228
229 for (int i = 0; i < 4; ++i) {
230
231 double lat_coords[2] = {90, -90};
232 int ret_val[2] = {-1, p_between_ab + p_between_cd};
233 utest_loncxlatc( 20, lat_coords[i&1], // point a
234 200, lat_coords[i&1], // point b
235 10, lat_coords[i>>1], // point c
236 20, lat_coords[i>>1], // point d
237 0, lat_coords[i>>1], // reference point p
238 0, -lat_coords[i>>1], // reference point q
239 ret_val[(i&1)==(i>>1)]); // reference return value
240 }
241
242 {
243
244 double a[3] = {-0.01728256081754178,
245 -0.0024289055230921597,
246 0.99984769515639127};
247 double b[3] = {-0.034559857199638548,
248 -0.0048570711780326408,
249 0.99939082701909576};
250 double c[3] = {-0.017298289573378096,
251 -0.0023142316840916847,
252 0.99984769515639127};
253 double d[3] = { 0.01732231884620395,
254 0.0021269133133512588,
255 0.99984769515639127};
256
257 double a_lon, a_lat, b_lon, b_lat, c_lon, c_lat, d_lon, d_lat;
258
259 XYZtoLL(a, &a_lon, &a_lat);
260 XYZtoLL(b, &b_lon, &b_lat);
261 XYZtoLL(c, &c_lon, &c_lat);
262 XYZtoLL(d, &d_lon, &d_lat);
263
264 utest_loncxlatc(a_lon/YAC_RAD, a_lat/YAC_RAD, // point a
265 b_lon/YAC_RAD, b_lat/YAC_RAD, // point b
266 c_lon/YAC_RAD, c_lat/YAC_RAD, // point c
267 d_lon/YAC_RAD, d_lat/YAC_RAD, // point d
268 a_lon/YAC_RAD, c_lat/YAC_RAD, // reference point p
269 a_lon/YAC_RAD+180.0, c_lat/YAC_RAD, // reference point q
270 p_between_ab + p_between_cd); // reference return value
271 }
272
273 return TEST_EXIT_CODE;
274}
275
276static void utest_loncxlatc(double lon_a, double lat_a, double lon_b, double lat_b,
277 double lon_c, double lat_c, double lon_d, double lat_d,
278 double lon_ref_p, double lat_ref_p,
279 double lon_ref_q, double lat_ref_q, int ref_ret_val) {
280
281 test_cxc(lon_a, lat_a, lon_b, lat_b, lon_c, lat_c, lon_d, lat_d,
283 lon_ref_p, lat_ref_p, lon_ref_q, lat_ref_q, ref_ret_val);
284}
285
#define YAC_RAD
@ YAC_LAT_CIRCLE_EDGE
latitude circle
Definition grid_cell.h:14
@ YAC_LON_CIRCLE_EDGE
longitude circle
Definition grid_cell.h:15
static void XYZtoLL(double const p_in[], double *lon, double *lat)
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