YAC 3.12.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_latcxlatc.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_latcxlatc(
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 unsigned const q_between_cd = 1 << 3;
24 unsigned const circles_are_identically = 1 << 4;
25 double lon_middle_ab, lat_middle_ab, lon_middle_cd, lat_middle_cd;
26
27 // two circles of latitude on the same plane that intersect
28
29 for (int i = 0; i < 2; ++i) {
30
31 double lon_coords[2][2] = {{-10, 5}, {-5, 10}};
32 utest_latcxlatc(lon_coords[i][0], 30, // point a
33 lon_coords[i][1], 30, // point b
34 lon_coords[i^1][0], 30, // point c
35 lon_coords[i^1][1], 30, // point d
36 -5, 30, // reference point p
37 5, 30, // reference point q
38 p_between_ab + p_between_cd + q_between_ab + q_between_cd +
39 circles_are_identically); // reference return value
40 }
41
42 for (int i = 0; i < 2; ++i) {
43
44 double lon_coords[2][2] = {{20, 25}, {30, 10}};
45 utest_latcxlatc(lon_coords[i][0], -15, // point a
46 lon_coords[i][1], -15, // point b
47 lon_coords[i^1][0], -15, // point c
48 lon_coords[i^1][1], -15, // point d
49 20, -15, // reference point p
50 25, -15, // reference point q
51 p_between_ab + p_between_cd + q_between_ab + q_between_cd +
52 circles_are_identically); // reference return value
53 }
54
55 // two circles of latitude on the same plane that do not intersect
56
57 for (int i = 0; i < 2; ++i) {
58
59 double lon_coords[2][2] = {{-80, -70}, {20, 30}};
61 YAC_LAT_CIRCLE_EDGE, lon_coords[i][0], 10, lon_coords[i][1], 10,
62 &lon_middle_ab, &lat_middle_ab);
64 YAC_LAT_CIRCLE_EDGE, lon_coords[i^1][0], 10, lon_coords[i^1][1], 10,
65 &lon_middle_cd, &lat_middle_cd);
66 utest_latcxlatc(lon_coords[i][0], 10, // point a
67 lon_coords[i][1], 10, // point b
68 lon_coords[i^1][0], 10, // point c
69 lon_coords[i^1][1], 10, // point d
70 lon_middle_ab, 10, // reference point p
71 lon_middle_cd, 10, // reference point q
72 p_between_ab + q_between_cd +
73 circles_are_identically); // reference return value
74 }
75
76 // two circles of latitude on different planes that do not intersect
77
78 for (int i = 0; i < 2; ++i) {
79
80 double lat_coords[2] = {0, 5};
81 utest_latcxlatc(20, lat_coords[i], // point a
82 30, lat_coords[i], // point b
83 20, lat_coords[i^1], // point c
84 30, lat_coords[i^1], // point d
85 -1, -1, // reference point p
86 -1, -1, // reference point q
87 -1); // reference return value
88
89 utest_latcxlatc(-80, lat_coords[i], // point a
90 -70, lat_coords[i], // point b
91 20, lat_coords[i^1], // point c
92 30, lat_coords[i^1], // point d
93 -1, -1, // reference point p
94 -1, -1, // reference point q
95 -1); // reference return value
96 }
97
98 // two circles of latitude on the pole
99
100 for (int i = 0; i < 2; ++i) {
101
102 double lat_coords[2] = {90, -90};
103 utest_latcxlatc( 0, lat_coords[i], // point a
104 10, lat_coords[i], // point b
105 180, lat_coords[i], // point c
106 190, lat_coords[i], // point d
107 0, lat_coords[i], // reference point p
108 0, lat_coords[i^1], // reference point q
109 p_between_ab + p_between_cd); // reference return value
110 }
111
112 for (int i = 0; i < 2; ++i) {
113
114 double lat_coords[2] = {90, -90};
115 utest_latcxlatc( 0, lat_coords[i], // point a
116 10, lat_coords[i], // point b
117 5, lat_coords[i], // point c
118 15, lat_coords[i], // point d
119 0, lat_coords[i], // reference point p
120 0, lat_coords[i^1], // reference point q
121 p_between_ab + p_between_cd); // reference return value
122 }
123
124 // two circles of latitude on different planes with length zero
125
126 for (int i = 0; i < 2; ++i) {
127
128 double lat_coords[2] = {-10, 10};
129 utest_latcxlatc(45 , lat_coords[i], // point a
130 45 , lat_coords[i], // point b
131 90 , lat_coords[i^1], // point c
132 90 , lat_coords[i^1], // point d
133 -1 , -1, // reference point p
134 -1 , -1, // reference point q
135 -1); // reference return value
136 }
137
138 // two circles of latitude on the same plane that do not intersect
139 // with length zero
140
141 utest_latcxlatc(45, 10, // point a
142 46, 10, // point b
143 90, 10, // point c
144 91, 10, // point d
145 45.5, 10, // reference point p
146 90.5, 10, // reference point q
147 p_between_ab + q_between_cd +
148 circles_are_identically); // reference return value
149
150 // two circles of latitude on the same plane that do intersect
151 // with length zero
152
153 utest_latcxlatc( 90, 10, // point a
154 90, 10, // point b
155 90, 10, // point c
156 90, 10, // point d
157 90, 10, // reference point p
158 -90, -10, // reference point q
159 p_between_ab + p_between_cd); // reference return value
160
161 // two circles of latitude on the same plane, one has the length zero and
162 // intersects with the other
163
164 utest_latcxlatc( 0, 10, // point a
165 0, 10, // point b
166 -5, 10, // point c
167 5, 10, // point d
168 0, 10, // reference point p
169 180, 10, // reference point q
170 p_between_ab + p_between_cd); // reference return value
171
172 // two circles of latitude on the same plane, one has the length zero and
173 // does not intersects with the other
174
175 utest_latcxlatc(180, 10, // point a
176 180, 10, // point b
177 -5, 10, // point c
178 5, 10, // point d
179 180, 10, // reference point p
180 0, 10, // reference point q
181 p_between_ab + q_between_cd); // reference return value
182
183 utest_latcxlatc( 90, 10, // point a
184 90, 10, // point b
185 -5, 10, // point c
186 5, 10, // point d
187 90, 10, // reference point p
188 -90, 10, // reference point q
189 p_between_ab); // reference return value
190
191 return TEST_EXIT_CODE;
192}
193
194static void utest_latcxlatc(double lon_a, double lat_a, double lon_b, double lat_b,
195 double lon_c, double lat_c, double lon_d, double lat_d,
196 double lon_ref_p, double lat_ref_p,
197 double lon_ref_q, double lat_ref_q, int ref_ret_val) {
198
199 test_cxc(lon_a, lat_a, lon_b, lat_b, lon_c, lat_c, lon_d, lat_d,
201 lon_ref_p, lat_ref_p, lon_ref_q, lat_ref_q, ref_ret_val);
202}
203
@ YAC_LAT_CIRCLE_EDGE
latitude circle
Definition grid_cell.h:14
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