YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_pxgc.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_gcxgc(
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 enum {
21 p_between_ab = 1,
22 q_between_ab = 2,
23 p_between_cd = 4,
24 q_between_cd = 8,
25 circles_are_identically = 16
26 };
27
28 double lon_middle_ab, lat_middle_ab, lon_middle_cd, lat_middle_cd;
29
30 // simple example
31
32 utest_gcxgc(-10, 0, // point a
33 10, 0, // point b
34 0, 10, // point c
35 0, -10, // point d
36 0, 0, // reference point p
37 180, 0, // reference point q
38 p_between_ab + p_between_cd); // reference return value
39
40 // d at north pole
41
42 utest_gcxgc(-10, 0, // point a
43 10, 0, // point b
44 0, -20, // point c
45 0, 90, // point d
46 0, 0, // reference point p
47 180, 0, // reference point q
48 p_between_ab + p_between_cd); // reference return value
49
50 // edge_a == edge_b
51
52 utest_gcxgc(-10, 0, // point a
53 10, 0, // point b
54 -10, 0, // point c
55 10, 0, // point d
56 -10, 0, // reference point p
57 10, 0, // reference point q
58 p_between_ab + p_between_cd + q_between_ab + q_between_cd +
59 circles_are_identically); // reference return value
60
61 // both circles on the same plane but no intersection
62
64 YAC_GREAT_CIRCLE_EDGE, -45, 45, 0, 0, &lon_middle_ab, &lat_middle_ab);
66 YAC_GREAT_CIRCLE_EDGE, 225, 45, 135, -45, &lon_middle_cd, &lat_middle_cd);
67 utest_gcxgc(-45, 45, // point a
68 0, 0, // point b
69 225, 45, // point c
70 135, -45, // point d
71 lon_middle_ab, lat_middle_ab, // reference point p
72 lon_middle_cd, lat_middle_cd, // reference point q
73 p_between_ab + q_between_cd +
74 circles_are_identically); // reference return value
75
76 // normal case + some cyclic stuff
77
78 utest_gcxgc( 45, 3, // point a
79 45, -10, // point b
80 -45, 0, // point c
81 -135, -45, // point d
82 45, 45, // reference point p
83 -135, -45, // reference point q
84 q_between_cd); // reference return value
85
86 // normal case + some heavier cyclic stuff
87
88 utest_gcxgc( 67.5, 40, // point a
89 67.5, -13, // point b
90 405, 0, // point c
91 450, 0, // point d
92 -112.5, 0, // reference point p
93 67.5, 0, // reference point q
94 q_between_ab + q_between_cd); // reference return value
95
96
97 // normal case + some heavier cyclic stuff + shifted end of edge b
98
99 utest_gcxgc( 67.5, 40, // point a
100 67.5, -13, // point b
101 45, 0, // point c
102 450, 0, // point d
103 -112.5, 0, // reference point p
104 67.5, 0, // reference point q
105 q_between_ab + q_between_cd); // reference return value
106
107 // one of the two edge has length zero and is not on the other plane
108
109 utest_gcxgc( 10, 10, // point a
110 10, 10, // point b
111 -10, -10, // point c
112 10, 11, // point d
113 -1, -1, // reference point p
114 -1, -1, // reference point q
115 -1); // reference return value
116
117 utest_gcxgc(-10, -10, // point a
118 10, 11, // point b
119 10, 10, // point c
120 10, 10, // point d
121 -1, -1, // reference point p
122 -1, -1, // reference point q
123 -1); // reference return value
124
125 // one of the two edge has length zero, is not on the other edge, but on the other plane
126
127 utest_gcxgc( 10, 10, // point a
128 10, 10, // point b
129 -10, -10, // point c
130 0, 0, // point d
131 10, 10, // reference point p
132 190, -10, // reference point q
133 p_between_ab); // reference return value
134
135 utest_gcxgc(-10, -10, // point a
136 0, 0, // point b
137 10, 10, // point c
138 10, 10, // point d
139 10, 10, // reference point p
140 190, -10, // reference point q
141 p_between_cd); // reference return value
142
143 utest_gcxgc( 10, 10, // point a
144 10, 10, // point b
145 190, -10, // point c
146 170, 10, // point d
147 10, 10, // reference point p
148 190, -10, // reference point q
149 p_between_ab + q_between_cd); // reference return value
150
151 utest_gcxgc(190, -10, // point a
152 170, 10, // point b
153 10, 10, // point c
154 10, 10, // point d
155 10, 10, // reference point p
156 190, -10, // reference point q
157 p_between_cd + q_between_ab); // reference return value
158
159 // one of the two edge has length zero and touches the other edge
160
161 utest_gcxgc( 10, 10, // point a
162 10, 10, // point b
163 -10, -10, // point c
164 10, 10, // point d
165 10, 10, // reference point p
166 190, -10, // reference point q
167 p_between_ab + p_between_cd); // reference return value
168
169 utest_gcxgc( 10, 10, // point a
170 10, 10, // point b
171 -10, -10, // point c
172 10, 10, // point d
173 10, 10, // reference point p
174 190, -10, // reference point q
175 p_between_ab + p_between_cd); // reference return value
176
177 // one of the two edge has length zero and is on the other edge
178
179 utest_gcxgc( 0, 0, // point a
180 0, 0, // point b
181 -10, -10, // point c
182 10, 10, // point d
183 0, 0, // reference point p
184 180, 0, // reference point q
185 p_between_ab + p_between_cd); // reference return value
186
187 utest_gcxgc(-10, -10, // point a
188 10, 10, // point b
189 0, 0, // point c
190 0, 0, // point d
191 0, 0, // reference point p
192 180, 0, // reference point q
193 p_between_ab + p_between_cd); // reference return value
194
195 // both edges have length zero and do not match
196
197 utest_gcxgc(-10, -10, // point a
198 -10, -10, // point b
199 10, 10, // point c
200 10, 10, // point d
201 -1, -1, // reference point p
202 -1, -1, // reference point q
203 -1); // reference return value
204
205 utest_gcxgc( 10, 10, // point a
206 10, 10, // point b
207 -10, -10, // point c
208 -10, -10, // point d
209 -1, -1, // reference point p
210 -1, -1, // reference point q
211 -1); // reference return value
212
213 // both edges have length zero and do not match, but are directly opposite
214 // of each other
215
216 utest_gcxgc(-10, -10, // point a
217 -10, -10, // point b
218 170, 10, // point c
219 170, 10, // point d
220 -1, -1, // reference point p
221 -1, -1, // reference point q
222 -1); // reference return value
223
224 utest_gcxgc(170, 10, // point a
225 170, 10, // point b
226 -10, -10, // point c
227 -10, -10, // point d
228 -1, -1, // reference point p
229 -1, -1, // reference point q
230 -1); // reference return value
231
232 // both edges have length zero and match
233
234 utest_gcxgc(-10, -10, // point a
235 -10, -10, // point b
236 -10, -10, // point c
237 -10, -10, // point d
238 -10, -10, // reference point p
239 170, 10, // reference point q
240 p_between_ab + p_between_cd); // reference return value
241
242 return TEST_EXIT_CODE;
243}
244
245static void utest_gcxgc(double lon_a, double lat_a, double lon_b, double lat_b,
246 double lon_c, double lat_c, double lon_d, double lat_d,
247 double lon_ref_p, double lat_ref_p,
248 double lon_ref_q, double lat_ref_q, int ref_ret_val) {
249
250 test_cxc(lon_a, lat_a, lon_b, lat_b, lon_c, lat_c, lon_d, lat_d,
252 lon_ref_p, lat_ref_p, lon_ref_q, lat_ref_q, ref_ret_val);
253}
254
@ YAC_GREAT_CIRCLE_EDGE
great circle
Definition grid_cell.h:13
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
void get_edge_middle_point(enum yac_edge_type edge_type, double lon_a, double lat_a, double lon_b, double lat_b, double *lon_middle, double *lat_middle)
Definition test_cxc.c:159
#define TEST_EXIT_CODE
Definition tests.h:14