YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_gcxlatc.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 <stdlib.h>
6#include <stdio.h>
7#include <math.h>
8#include "test_cxc.h"
9#include "geometry.h"
10
16static void utest_test_gcxlatc(
17 double lon_a, double lat_a, double lon_b, double lat_b,
18 double lon_c, double lat_c, double lon_d, double lat_d,
19 double lon_ref_p, double lat_ref_p,
20 double lon_ref_q, double lat_ref_q, int ref_ret_val);
21
22int main (void) {
23
24 enum {
26 p_between_ab = 1,
27 q_between_ab = 2,
28 p_between_cd = 4,
29 q_between_cd = 8,
30 circles_are_identically = 16
31 };
32
33 // simple example
34
35 utest_test_gcxlatc(-10, 10, // point a
36 10, 10, // point b
37 -10, 0, // point c
38 10, 0, // point d
39 90, 0, // reference point p
40 -90, 0, // reference point q
41 no_intersection); // reference return value
42
43 // simple example
44
45 utest_test_gcxlatc(-10, 10, // point a
46 10, -10, // point b
47 -10, 0, // point c
48 10, 0, // point d
49 180, 0, // reference point p
50 0, 0, // reference point q
51 q_between_ab + q_between_cd); // reference return value
52
53 // example from test program
54
55 utest_test_gcxlatc( 0, 90, // point a
56 140, 60, // point b
57 90, -45, // point c
58 39, -45, // point d
59 140, -45, // reference point p
60 -40, -45, // reference point q
61 no_intersection); // reference return value
62
63 // both circles do not intersect
64
65 utest_test_gcxlatc(-10, 10, // point a
66 10, 9, // point b
67 -10, 70, // point c
68 10, 70, // point d
69 -10, 70, // reference point p
70 10, 70, // reference point q
71 -1); // reference return value
72
73 utest_test_gcxlatc(-10, 9, // point a
74 10, 10, // point b
75 -10, 70, // point c
76 10, 70, // point d
77 -10, 70, // reference point p
78 10, 70, // reference point q
79 -1); // reference return value
80
81 // the great circle only touches the circle of latitude
82
83 utest_test_gcxlatc(-90, 0, // point a
84 0, 45, // point b
85 -10, 45, // point c
86 10, 45, // point d
87 0, 45, // reference point p
88 0, 45, // reference point q
89 p_between_ab + p_between_cd +
90 q_between_ab + q_between_cd); // reference return value
91
92 // the circle of latitude is on the pole and does not intersect the great circle
93
94 utest_test_gcxlatc(-90, 0, // point a
95 0, 45, // point b
96 10, 90, // point c
97 20, 90, // point d
98 10, 90, // reference point p
99 20, 90, // reference point q
100 -1); // reference return value
101
102 // the circle of latitude is on the pole and does intersect the great circle
103
104 utest_test_gcxlatc(15 , 85, // point a
105 180 + 15, 85, // point b
106 10 , 90, // point c
107 20 , 90, // point d
108 0, 90, // reference point p
109 0, -90, // reference point q
110 p_between_ab + p_between_cd); // reference return value
111
112 // the circle of latitude is on the pole and does intersect the great circle
113
114 utest_test_gcxlatc(30, 90, // point a
115 30, 70, // point b
116 10, 90, // point c
117 20, 90, // point d
118 0, 90, // reference point p
119 0, -90, // reference point q
120 p_between_ab + p_between_cd); // reference return value
121
122 // the great circle edge has a length of zero and has no intersection with
123 // the circle of latitude
124
125 utest_test_gcxlatc(30, 70, // point a
126 30, 70, // point b
127 10, 60, // point c
128 20, 60, // point d
129 -1, -1, // reference point p
130 -1, -1, // reference point q
131 -1); // reference return value
132
133 // the great circle edge has a length of zero and an intersection with
134 // the circle of latitude
135 utest_test_gcxlatc( 15, 10, // point a
136 15, 10, // point b
137 10, 10, // point c
138 20, 10, // point d
139 15, 10, // reference point p
140 195, 10, // reference point q
141 p_between_ab + p_between_cd); // reference return value
142
143 // the latitude circle edge has a length of zero and has no intersection with
144 // the great circle edge
145
146 utest_test_gcxlatc(-5, -5, // point a
147 5, 5, // point b
148 10, 89, // point c
149 10, 89, // point d
150 -1, -1, // reference point p
151 -1, -1, // reference point q
152 -1); // reference return value
153
154 // the latitude circle edge has a length of zero and has no intersection with
155 // the great circle edge
156
157 utest_test_gcxlatc(-5, -5, // point a
158 5, 5, // point b
159 10, 0, // point c
160 10, 0, // point d
161 -1, -1, // reference point p
162 -1, -1, // reference point q
163 -1); // reference return value
164
165 // the latitude circle edge has a length of zero and has an intersection with
166 // the great circle edge
167
168 utest_test_gcxlatc( -5, -5, // point a
169 5, 5, // point b
170 0, 0, // point c
171 0, 0, // point d
172 0, 0, // reference point p
173 0+180, 0, // reference point q
174 p_between_ab + p_between_cd); // reference return value
175
176 {
177 // example taken from a toy...caused a crash
178
179 double a[3] = {-0.18125814883147034, -0.5578552203226167, -0.80990310324198245};
180 double b[3] = {-0.18125814875183416, -0.557855220392383, -0.80990310321175063};
181 double c[3] = {-0.18673822182292288, -0.54232717509597339, -0.8191520442889918};
182 double d[3] = {-0.1772448664054937, -0.5455036073850148, -0.8191520442889918};
183 double p[3], q[3];
184
186 }
187
188 {
189 // example taken from a toy...caused a crash
190
191 double a[3] = {0.049067638730680319, 0.0012045429209767452, -0.99879473161693588};
192 double b[3] = {0.049067674327417689, 0, -0.99879545620517241};
193 double c[3] = {0.049067674327418126, 0, -0.99879545620517241};
194 double d[3] = {0.049052896061289972, 0.0012041810087570048, -0.99879545620517241};
195 double p[3], q[3];
196
198 }
199
200 // both circles are on the equator and they do intersect
201
202 utest_test_gcxlatc(-10, 0, // point a
203 10, 0, // point b
204 -10, 0, // point c
205 10, 0, // point d
206 -10, 0, // reference point p
207 10, 0, // reference point q
208 p_between_ab + p_between_cd +
209 q_between_ab + q_between_cd +
210 circles_are_identically); // reference return value
211
212 utest_test_gcxlatc( 0, 0, // point a
213 10, 0, // point b
214 -10, 0, // point c
215 10, 0, // point d
216 0, 0, // reference point p
217 10, 0, // reference point q
218 p_between_ab + p_between_cd +
219 q_between_ab + q_between_cd +
220 circles_are_identically); // reference return value
221
222 utest_test_gcxlatc( -5, 0, // point a
223 5, 0, // point b
224 -10, 0, // point c
225 10, 0, // point d
226 -5, 0, // reference point p
227 5, 0, // reference point q
228 p_between_ab + p_between_cd +
229 q_between_ab + q_between_cd +
230 circles_are_identically); // reference return value
231
232 utest_test_gcxlatc(-10, 0, // point a
233 10, 0, // point b
234 -5, 0, // point c
235 5, 0, // point d
236 -5, 0, // reference point p
237 5, 0, // reference point q
238 p_between_ab + p_between_cd +
239 q_between_ab + q_between_cd +
240 circles_are_identically); // reference return value
241
242 // both circles are on the equator and they do not intersect
243
244 utest_test_gcxlatc(170, 0, // point a
245 190, 0, // point b
246 -10, 0, // point c
247 10, 0, // point d
248 180, 0, // reference point p
249 0, 0, // reference point q
250 p_between_ab + q_between_cd +
251 circles_are_identically); // reference return value
252
253 return TEST_EXIT_CODE;
254}
255
256static void utest_test_gcxlatc(double lon_a, double lat_a, double lon_b, double lat_b,
257 double lon_c, double lat_c, double lon_d, double lat_d,
258 double lon_ref_p, double lat_ref_p,
259 double lon_ref_q, double lat_ref_q, int ref_ret_val) {
260
261 test_cxc(lon_a, lat_a, lon_b, lat_b, lon_c, lat_c, lon_d, lat_d,
263 lon_ref_p, lat_ref_p, lon_ref_q, lat_ref_q, ref_ret_val);
264}
265
int yac_intersect_vec(enum yac_edge_type edge_type_a, double const a[3], double const b[3], enum yac_edge_type edge_type_b, double const c[3], double const d[3], double p[3], double q[3])
@ YAC_GREAT_CIRCLE_EDGE
great circle
Definition grid_cell.h:13
@ YAC_LAT_CIRCLE_EDGE
latitude circle
Definition grid_cell.h:14
@ no_intersection
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
double(* p)(double lon, double lat)
Definition toy_scrip.c:119