Debian Codegraph @

lib/geo.c

raw symbols SCIP
1 /*
2 Copyright (C) 2009-2017 Brazil
3 Copyright (C) 2020-2025 Sutou Kouhei <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "grn_geo.h"cxx . . $ `<file>/lib/grn_geo.h`/
21 #include "grn_pat.h"cxx . . $ `<file>/lib/grn_pat.h`/
22 #include "grn_util.h"cxx . . $ `<file>/lib/grn_util.h`/
23 #include "grn_posting.h"cxx . . $ `<file>/lib/grn_posting.h`/
24
25 #include <math.h>
26 #include <string.h>
27 #include <stdlib.h>
28
29 #ifndef MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!
30 # define MAX(a, b) ((a) > (b) ? (a) : (b))
31 #endif
32
33 #ifndef MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!
34 # define MIN(a, b) ((a) < (b) ? (a) : (b))
35 #endif
36
37 #define GRN_GEO_POINT_IN_NORTH_EASTcxx . . $ `lib/geo.c:37:9`!(point) \
38 ((point)->latitude >= 0 && (point)->longitude >= 0)
39 #define GRN_GEO_POINT_IN_NORTH_WESTcxx . . $ `lib/geo.c:39:9`!(point) \
40 ((point)->latitude >= 0 && (point)->longitude < 0)
41 #define GRN_GEO_POINT_IN_SOUTH_WESTcxx . . $ `lib/geo.c:41:9`!(point) \
42 ((point)->latitude < 0 && (point)->longitude < 0)
43 #define GRN_GEO_POINT_IN_SOUTH_EASTcxx . . $ `lib/geo.c:43:9`!(point) \
44 ((point)->latitude < 0 && (point)->longitude >= 0)
45
46 #define GRN_GEO_LONGITUDE_IS_WRAPPEDcxx . . $ `lib/geo.c:46:9`!(top_left, bottom_right) \
47 ((top_left)->longitude > 0 && (bottom_right)->longitude < 0)
48
49 typedef structcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0# {
50 grn_idcxx . . $ grn_id# idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id.;
51 double dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d.;
52 } geo_entrycxx . . $ geo_entry#;
53
54 typedef structcxx . . $ $anonymous_type_a6dd5fd738c9bb15_1# {
55 grn_geo_pointcxx . . $ grn_geo_point# keycxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key.;
56 int key_sizecxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key_size.;
57 } mesh_entrycxx . . $ mesh_entry#;
58
59 typedef structcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2# {
60 grn_objcxx . . $ grn_obj# *patcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#pat.;
61 grn_objcxx . . $ grn_obj# top_left_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left_point_buffer.;
62 grn_objcxx . . $ grn_obj# bottom_right_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right_point_buffer.;
63 grn_geo_pointcxx . . $ grn_geo_point# *top_leftcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left.;
64 grn_geo_pointcxx . . $ grn_geo_point# *bottom_rightcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right.;
65 grn_geo_pointcxx . . $ grn_geo_point# centercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#center.;
66 } in_rectangle_datacxx . . $ in_rectangle_data#;
67
68 typedef structcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3# {
69 grn_geo_pointcxx . . $ grn_geo_point# mincxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#min.;
70 grn_geo_pointcxx . . $ grn_geo_point# maxcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#max.;
71 uint8_tcxx . . $ uint8_t# rectangle_common_bitcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#rectangle_common_bit.;
72 uint8_tcxx . . $ uint8_t# rectangle_common_keycxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#rectangle_common_key.[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
73 } in_rectangle_area_datacxx . . $ in_rectangle_area_data#;
74
75 static uint8_tcxx . . $ uint8_t#
76 compute_diff_bitcxx . . $ compute_diff_bit(c6d1befd7368f101).(uint8_tcxx . . $ uint8_t# *geo_key1, uint8_tcxx . . $ uint8_t# *geo_key2)
77 {
78 uint8_tcxx . . $ uint8_t# i;
79 uint8_tcxx . . $ uint8_t# j;
80 uint8_tcxx . . $ uint8_t# diff_bit = 0;
81
82 for (i = 0; i < sizeof(grn_geo_pointcxx . . $ grn_geo_point#); i++) {
83 if (geo_key1[i] != geo_key2[i]) {
84 diff_bit = 8;
85 for (j = 0; j < 8; j++) {
86 if ((geo_key1[i] & (1 << (7 - j))) != (geo_key2[i] & (1 << (7 - j)))) {
87 diff_bit = j;
88 break;
89 }
90 }
91 break;
92 }
93 }
94
95 uint8_tcxx . . $ uint8_t# n_bits_per_byte = 8;
96 return (uint8_tcxx . . $ uint8_t#)(i * n_bits_per_byte) + diff_bit;
97 }
98
99 static void
100 compute_min_and_max_keycxx . . $ compute_min_and_max_key(9da651c5f357079e).(uint8_tcxx . . $ uint8_t# *key_base,
101 uint8_tcxx . . $ uint8_t# diff_bit,
102 uint8_tcxx . . $ uint8_t# *key_min,
103 uint8_tcxx . . $ uint8_t# *key_max)
104 {
105 uint8_tcxx . . $ uint8_t# diff_byte, diff_bit_mask;
106
107 diff_byte = diff_bit / 8;
108 diff_bit_mask = 0xff >> (diff_bit % 8);
109
110 if (diff_byte == sizeof(grn_geo_pointcxx . . $ grn_geo_point#)) {
111 if (key_min) {
112 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(key_min, key_base, diff_byte);
113 }
114 if (key_max) {
115 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(key_max, key_base, diff_byte);
116 }
117 } else {
118 if (key_min) {
119 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(key_min, key_base, diff_byte + 1);
120 key_min[diff_byte] &= ~diff_bit_mask;
121 memsetcxx . . $ memset(d1de1e4fb215f1c6).(key_min + diff_byte + 1, 0, sizeof(grn_geo_pointcxx . . $ grn_geo_point#) - diff_byte - 1);
122 }
123
124 if (key_max) {
125 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(key_max, key_base, diff_byte + 1);
126 key_max[diff_byte] |= diff_bit_mask;
127 memsetcxx . . $ memset(d1de1e4fb215f1c6).(key_max + diff_byte + 1,
128 0xff,
129 sizeof(grn_geo_pointcxx . . $ grn_geo_point#) - diff_byte - 1);
130 }
131 }
132 }
133
134 static void
135 compute_min_and_maxcxx . . $ compute_min_and_max(7aa427f80ae4eb27).(grn_geo_pointcxx . . $ grn_geo_point# *base_point,
136 uint8_tcxx . . $ uint8_t# diff_bit,
137 grn_geo_pointcxx . . $ grn_geo_point# *geo_min,
138 grn_geo_pointcxx . . $ grn_geo_point# *geo_max)
139 {
140 uint8_tcxx . . $ uint8_t# geo_key_base[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
141 uint8_tcxx . . $ uint8_t# geo_key_min[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
142 uint8_tcxx . . $ uint8_t# geo_key_max[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
143
144 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key_base, base_point, sizeof(grn_geo_point));
145 compute_min_and_max_keycxx . . $ compute_min_and_max_key(9da651c5f357079e).(geo_key_base,
146 diff_bit,
147 geo_min ? geo_key_min : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
148 geo_max ? geo_key_max : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
149 if (geo_min) {
150 grn_ntogcxx . . $ `lib/grn.h:669:9`!((uint8_t *)geo_min, geo_key_min, sizeof(grn_geo_point));
151 }
152 if (geo_max) {
153 grn_ntogcxx . . $ `lib/grn.h:669:9`!((uint8_t *)geo_max, geo_key_max, sizeof(grn_geo_point));
154 }
155 }
156
157 /* #define GEO_DEBUG */
158
159 #ifdef GEO_DEBUG
160 # include <stdio.h>
161
162 static void
163 inspect_mesh(grn_ctx *ctx, grn_geo_point *key, int key_size, int n)
164 {
165 grn_geo_point min, max;
166
167 printf("mesh: %d:%d\n", n, key_size);
168
169 printf("key: ");
170 grn_p_geo_point(ctx, key);
171
172 compute_min_and_max(key, key_size, &min, &max);
173 printf("min: ");
174 grn_p_geo_point(ctx, &min);
175 printf("max: ");
176 grn_p_geo_point(ctx, &max);
177 }
178
179 static void
180 inspect_mesh_entry(grn_ctx *ctx, mesh_entry *entries, int n)
181 {
182 mesh_entry *entry;
183
184 entry = entries + n;
185 inspect_mesh(ctx, &(entry->key), entry->key_size, n);
186 }
187
188 static void
189 inspect_tid(grn_ctx *ctx, grn_id tid, grn_geo_point *point, double d)
190 {
191 printf("tid: %d:%g", tid, d);
192 grn_p_geo_point(ctx, point);
193 }
194
195 static void
196 inspect_key(grn_ctx *ctx, uint8_t *key)
197 {
198 int i;
199 for (i = 0; i < 8; i++) {
200 int j;
201 for (j = 0; j < 8; j++) {
202 printf("%d", (key[i] & (1 << (7 - j))) >> (7 - j));
203 }
204 printf(" ");
205 }
206 printf("\n");
207 }
208
209 static void
210 print_key_mark(grn_ctx *ctx, int target_bit)
211 {
212 int i;
213
214 for (i = 0; i < target_bit; i++) {
215 printf(" ");
216 if (i > 0 && i % 8 == 0) {
217 printf(" ");
218 }
219 }
220 if (i > 0 && i % 8 == 0) {
221 printf(" ");
222 }
223 printf("^\n");
224 }
225
226 static void
227 inspect_cursor_entry(grn_ctx *ctx, grn_geo_cursor_entry *entry)
228 {
229 grn_geo_point point;
230
231 printf("entry: ");
232 grn_ntog((uint8_t *)&point, entry->key, sizeof(grn_geo_point));
233 grn_p_geo_point(ctx, &point);
234 inspect_key(ctx, entry->key);
235 print_key_mark(ctx, entry->target_bit);
236
237 printf(" target bit: %d\n", entry->target_bit);
238
239 # define INSPECT_STATUS_FLAG(name) \
240 ((entry->status_flags & GRN_GEO_CURSOR_ENTRY_STATUS_##name) ? "true" \
241 : "false")
242
243 printf(" top included: %s\n", INSPECT_STATUS_FLAG(TOP_INCLUDED));
244 printf("bottom included: %s\n", INSPECT_STATUS_FLAG(BOTTOM_INCLUDED));
245 printf(" left included: %s\n", INSPECT_STATUS_FLAG(LEFT_INCLUDED));
246 printf(" right included: %s\n", INSPECT_STATUS_FLAG(RIGHT_INCLUDED));
247 printf(" latitude inner: %s\n", INSPECT_STATUS_FLAG(LATITUDE_INNER));
248 printf("longitude inner: %s\n", INSPECT_STATUS_FLAG(LONGITUDE_INNER));
249
250 # undef INSPECT_STATUS_FLAG
251 }
252
253 static void
254 inspect_cursor_entry_targets(grn_ctx *ctx,
255 grn_geo_cursor_entry *entry,
256 uint8_t *top_left_key,
257 uint8_t *bottom_right_key,
258 grn_geo_cursor_entry *next_entry0,
259 grn_geo_cursor_entry *next_entry1)
260 {
261 printf("entry: ");
262 inspect_key(ctx, entry->key);
263 printf("top-left: ");
264 inspect_key(ctx, top_left_key);
265 printf("bottom-right: ");
266 inspect_key(ctx, bottom_right_key);
267 printf("next-entry-0: ");
268 inspect_key(ctx, next_entry0->key);
269 printf("next-entry-1: ");
270 inspect_key(ctx, next_entry1->key);
271 printf(" ");
272 print_key_mark(ctx, entry->target_bit + 1);
273 }
274 #else
275 # define inspect_meshcxx . . $ `lib/geo.c:275:11`!(...)
276 # define inspect_mesh_entrycxx . . $ `lib/geo.c:276:11`!(...)
277 # define inspect_tidcxx . . $ `lib/geo.c:277:11`!(...)
278 # define inspect_keycxx . . $ `lib/geo.c:278:11`!(...)
279 # define print_key_markcxx . . $ `lib/geo.c:279:11`!(...)
280 # define inspect_cursor_entrycxx . . $ `lib/geo.c:280:11`!(...)
281 # define inspect_cursor_entry_targetscxx . . $ `lib/geo.c:281:11`!(...)
282 #endif
283
284 static int
285 grn_geo_table_sort_detect_far_pointcxx . . $ grn_geo_table_sort_detect_far_point(9c3b664d5bd75633).(grn_ctxcxx . . $ grn_ctx# *ctx,
286 grn_objcxx . . $ grn_obj# *table,
287 grn_objcxx . . $ grn_obj# *index,
288 grn_patcxx . . $ grn_pat# *pat,
289 geo_entrycxx . . $ geo_entry# *entries,
290 grn_pat_cursorcxx . . $ grn_pat_cursor# *pc,
291 int n,
292 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! accessorp,
293 grn_geo_pointcxx . . $ grn_geo_point# *base_point,
294 double *d_far,
295 uint8_tcxx . . $ uint8_t# *diff_bit)
296 {
297 int i = 0;
298 uint8_tcxx . . $ uint8_t# diff_bit_prev;
299 uint8_tcxx . . $ uint8_t# diff_bit_current;
300 grn_idcxx . . $ grn_id# tid;
301 geo_entrycxx . . $ geo_entry# *ep, *p;
302 double d;
303 uint8_tcxx . . $ uint8_t# geo_key_prev[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
304 uint8_tcxx . . $ uint8_t# geo_key_curr[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
305 grn_geo_pointcxx . . $ grn_geo_point# point;
306
307 *d_far = 0.0;
308 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key_curr, base_point, sizeof(grn_geo_point));
309 *diff_bit = sizeof(grn_geo_pointcxx . . $ grn_geo_point#) * 8;
310 diff_bit_current = sizeof(grn_geo_pointcxx . . $ grn_geo_point#) * 8;
311 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(&point, base_point, sizeof(grn_geo_point));
312 ep = entries;
313 inspect_meshcxx . . $ `lib/geo.c:275:11`!(ctx, &point, *diff_bit, -1);
314 while ((tid = grn_pat_cursor_nextcxx . . $ grn_pat_cursor_next(5452c9aa69698298).(ctx, pc))) {
315 grn_ii_cursorcxx . . $ grn_ii_cursor# *ic =
316 grn_ii_cursor_opencxx . . $ grn_ii_cursor_open(5e1f33d5cbef52bd).(ctx, (grn_iicxx . . $ grn_ii# *)index, tid, 0, 0, 1, 0);
317 if (ic) {
318 grn_postingcxx . . $ grn_posting# *posting;
319 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key_prev, &point, sizeof(grn_geo_point));
320 grn_pat_get_keycxx . . $ grn_pat_get_key(52cd598958564ca7).(ctx, pat, tid, &point, sizeof(grn_geo_pointcxx . . $ grn_geo_point#));
321 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key_curr, &point, sizeof(grn_geo_point));
322 d = grn_geo_distance_rectangle_rawcxx . . $ grn_geo_distance_rectangle_raw(efce70e58f1fe0a0).(ctx, base_point, &point);
323 inspect_tidcxx . . $ `lib/geo.c:277:11`!(ctx, tid, &point, d);
324
325 diff_bit_prev = diff_bit_current;
326 diff_bit_current = compute_diff_bitcxx . . $ compute_diff_bit(c6d1befd7368f101).(geo_key_curr, geo_key_prev);
327 #ifdef GEO_DEBUG
328 printf("diff: %d:%d:%d\n", *diff_bit, diff_bit_prev, diff_bit_current);
329 #endif
330 if ((diff_bit_current % 2) == 1) {
331 diff_bit_current--;
332 }
333 if (diff_bit_current < diff_bit_prev && *diff_bit > diff_bit_current) {
334 if (i == n) {
335 grn_ii_cursor_closecxx . . $ grn_ii_cursor_close(9f30b86a43abe2c6).(ctx, ic);
336 break;
337 }
338 *diff_bit = diff_bit_current;
339 }
340
341 if (d > *d_far) {
342 *d_far = d;
343 }
344 while ((posting = grn_ii_cursor_nextcxx . . $ grn_ii_cursor_next(2ca859fa2305fa5c).(ctx, ic))) {
345 grn_idcxx . . $ grn_id# rid =
346 accessorp ? grn_table_getcxx . . $ grn_table_get(5676c91e20172100).(ctx, table, &posting->ridcxx . . $ $anonymous_type_abfcd92361d8c963_0#rid., sizeof(grn_idcxx . . $ grn_id#))
347 : posting->ridcxx . . $ $anonymous_type_abfcd92361d8c963_0#rid.;
348 if (rid) {
349 for (p = ep; entries < p && p[-1].dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d. > d; p--) {
350 p->idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id. = p[-1].idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id.;
351 p->dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d. = p[-1].dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d.;
352 }
353 p->idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id. = rid;
354 p->dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d. = d;
355 if (i < n) {
356 ep++;
357 i++;
358 }
359 }
360 }
361 grn_ii_cursor_closecxx . . $ grn_ii_cursor_close(9f30b86a43abe2c6).(ctx, ic);
362 }
363 }
364
365 return i;
366 }
367
368 typedef enumcxx . . $ $anonymous_type_a6dd5fd738c9bb15_4# {
369 MESH_LEFT_TOPcxx . . $ MESH_LEFT_TOP.,
370 MESH_RIGHT_TOPcxx . . $ MESH_RIGHT_TOP.,
371 MESH_RIGHT_BOTTOMcxx . . $ MESH_RIGHT_BOTTOM.,
372 MESH_LEFT_BOTTOMcxx . . $ MESH_LEFT_BOTTOM.
373 } mesh_positioncxx . . $ mesh_position#;
374
375 /*
376 meshes should have
377 86 >= spaces when include_base_point_hash == false,
378 87 >= spaces when include_base_point_hash == true.
379 */
380 static int
381 grn_geo_get_meshes_for_circlecxx . . $ grn_geo_get_meshes_for_circle(7e0e8b911d5720fb).(grn_ctxcxx . . $ grn_ctx# *ctx,
382 grn_geo_pointcxx . . $ grn_geo_point# *base_point,
383 double d_far,
384 uint8_tcxx . . $ uint8_t# diff_bit,
385 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! include_base_point_mesh,
386 mesh_entrycxx . . $ mesh_entry# *meshes)
387 {
388 double d;
389 int n_meshes;
390 int lat_diff, lng_diff;
391 mesh_positioncxx . . $ mesh_position# position;
392 grn_geo_pointcxx . . $ grn_geo_point# geo_base, geo_min, geo_max;
393
394 compute_min_and_maxcxx . . $ compute_min_and_max(7aa427f80ae4eb27).(base_point, diff_bit - 2, &geo_min, &geo_max);
395
396 lat_diff = (geo_max.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. - geo_min.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + 1) / 2;
397 lng_diff = (geo_max.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. - geo_min.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. + 1) / 2;
398 geo_base.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = geo_min.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + lat_diff;
399 geo_base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = geo_min.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. + lng_diff;
400 if (base_point->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. >= geo_base.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.) {
401 if (base_point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= geo_base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) {
402 position = MESH_RIGHT_TOPcxx . . $ MESH_RIGHT_TOP.;
403 } else {
404 position = MESH_LEFT_TOPcxx . . $ MESH_LEFT_TOP.;
405 }
406 } else {
407 if (base_point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= geo_base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) {
408 position = MESH_RIGHT_BOTTOMcxx . . $ MESH_RIGHT_BOTTOM.;
409 } else {
410 position = MESH_LEFT_BOTTOMcxx . . $ MESH_LEFT_BOTTOM.;
411 }
412 }
413 /*
414 base_point: b
415 geo_min: i
416 geo_max: a
417 geo_base: x: must be at the left bottom in the top right mesh.
418
419 e.g.: base_point is at the left bottom mesh case:
420 +------+------+
421 | | a|
422 | |x |
423 ^+------+------+
424 || | |
425 lng_diff || b | |
426 \/i------+------+
427 <------>
428 lat_diff
429
430 grn_min + lat_diff -> the right mesh.
431 grn_min + lng_diff -> the top mesh.
432 */
433 #ifdef GEO_DEBUG
434 grn_p_geo_point(ctx, base_point);
435 printf("base: ");
436 grn_p_geo_point(ctx, &geo_base);
437 printf("min: ");
438 grn_p_geo_point(ctx, &geo_min);
439 printf("max: ");
440 grn_p_geo_point(ctx, &geo_max);
441 printf("diff: %d (%d, %d)\n", diff_bit, lat_diff, lng_diff);
442 switch (position) {
443 case MESH_LEFT_TOP:
444 printf("position: left-top\n");
445 break;
446 case MESH_RIGHT_TOP:
447 printf("position: right-top\n");
448 break;
449 case MESH_RIGHT_BOTTOM:
450 printf("position: right-bottom\n");
451 break;
452 case MESH_LEFT_BOTTOM:
453 printf("position: left-bottom\n");
454 break;
455 }
456 #endif
457
458 n_meshes = 0;
459
460 #define add_meshcxx . . $ `lib/geo.c:460:9`!(lat_diff_, lng_diff_, key_size_) \
461 do { \
462 meshes[n_meshes].key.latitude = geo_base.latitude + (lat_diff_); \
463 meshes[n_meshes].key.longitude = geo_base.longitude + (lng_diff_); \
464 meshes[n_meshes].key_size = key_size_; \
465 n_meshes++; \
466 } while (0)
467
468 if (include_base_point_mesh || position != MESH_LEFT_TOPcxx . . $ MESH_LEFT_TOP.) {
469 add_meshcxx . . $ `lib/geo.c:460:9`!(0, -lng_diff, diff_bit);
470 }
471 if (include_base_point_mesh || position != MESH_RIGHT_TOPcxx . . $ MESH_RIGHT_TOP.) {
472 add_meshcxx . . $ `lib/geo.c:460:9`!(0, 0, diff_bit);
473 }
474 if (include_base_point_mesh || position != MESH_RIGHT_BOTTOMcxx . . $ MESH_RIGHT_BOTTOM.) {
475 add_meshcxx . . $ `lib/geo.c:460:9`!(-lat_diff, 0, diff_bit);
476 }
477 if (include_base_point_mesh || position != MESH_LEFT_BOTTOMcxx . . $ MESH_LEFT_BOTTOM.) {
478 add_meshcxx . . $ `lib/geo.c:460:9`!(-lat_diff, -lng_diff, diff_bit);
479 }
480
481 /*
482 b: base_point
483 x: geo_base
484 0-83: sub meshes. 0-83 are added order.
485
486 j: -5 -4 -3 -2 -1 0 1 2 3 4
487 +---+---+---+---+---+---+---+---+---+---+
488 |74 |75 |76 |77 |78 |79 |80 |81 |82 |83 | 4
489 +---+---+---+---+---+---+---+---+---+---+
490 |64 |65 |66 |67 |68 |69 |70 |71 |72 |73 | 3
491 +---+---+---+---+---+---+---+---+---+---+
492 |54 |55 |56 |57 |58 |59 |60 |61 |62 |63 | 2
493 +---+---+---+---+---+---+---+---+---+---+
494 |48 |49 |50 | b | |51 |52 |53 | 1
495 +---+---+---+ | +---+---+---+
496 |42 |43 |44 | |x |45 |46 |47 | 0
497 +---+---+---+-------+-------+---+---+---+
498 |36 |37 |38 | | |39 |40 |41 | -1
499 +---+---+---+ base meshes +---+---+---+
500 |30 |31 |32 | | |33 |34 |35 | -2
501 +---+---+---+---+---+---+---+---+---+---+
502 |20 |21 |22 |23 |24 |25 |26 |27 |28 |29 | -3
503 +---+---+---+---+---+---+---+---+---+---+
504 |10 |11 |12 |13 |14 |15 |16 |17 |18 |19 | -4
505 +---+---+---+---+---+---+---+---+---+---+
506 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -5
507 +---+---+---+---+---+---+---+---+---+---+
508 i
509 */
510 {
511 int i, j, n_sub_meshes, lat, lat_min, lat_max, lng, lng_min, lng_max;
512 n_sub_meshes = 0;
513 for (i = -5; i < 5; i++) {
514 lat_min = ((lat_diff + 1) / 2) * i;
515 lat_max = ((lat_diff + 1) / 2) * (i + 1) - 1;
516 for (j = -5; j < 5; j++) {
517 if (-3 < i && i < 2 && -3 < j && j < 2) {
518 continue;
519 }
520 lng_min = ((lng_diff + 1) / 2) * j;
521 lng_max = ((lng_diff + 1) / 2) * (j + 1) - 1;
522 if (base_point->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. <= geo_base.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + lat_min) {
523 lat = geo_base.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + lat_min;
524 } else if (geo_base.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + lat_max < base_point->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.) {
525 lat = geo_base.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + lat_max;
526 } else {
527 lat = base_point->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.;
528 }
529 if (base_point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= geo_base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. + lng_min) {
530 lng = geo_base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. + lng_min;
531 } else if (geo_base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. + lng_max < base_point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) {
532 lng = geo_base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. + lng_max;
533 } else {
534 lng = base_point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
535 }
536 meshes[n_meshes].keycxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key..latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = lat;
537 meshes[n_meshes].keycxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key..longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = lng;
538 d = grn_geo_distance_rectangle_rawcxx . . $ grn_geo_distance_rectangle_raw(efce70e58f1fe0a0).(ctx,
539 base_point,
540 &(meshes[n_meshes].keycxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key.));
541 if (d < d_far) {
542 #ifdef GEO_DEBUG
543 printf("sub-mesh: %d: (%d,%d): (%d,%d;%d,%d)\n",
544 n_sub_meshes,
545 base_point->latitude,
546 base_point->longitude,
547 geo_base.latitude + lat_min,
548 geo_base.latitude + lat_max,
549 geo_base.longitude + lng_min,
550 geo_base.longitude + lng_max);
551 grn_p_geo_point(ctx, &(meshes[n_meshes].key));
552 #endif
553 meshes[n_meshes].key_sizecxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key_size. = diff_bit + 2;
554 n_meshes++;
555 }
556 n_sub_meshes++;
557 }
558 }
559 }
560
561 #undef add_meshcxx . . $ `lib/geo.c:460:9`!
562
563 return n_meshes;
564 }
565
566 static int
567 grn_geo_table_sort_collect_pointscxx . . $ grn_geo_table_sort_collect_points(ec0ffdbdc42f186a).(grn_ctxcxx . . $ grn_ctx# *ctx,
568 grn_objcxx . . $ grn_obj# *table,
569 grn_objcxx . . $ grn_obj# *index,
570 grn_patcxx . . $ grn_pat# *pat,
571 geo_entrycxx . . $ geo_entry# *entries,
572 int n_entries,
573 int n,
574 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! accessorp,
575 grn_geo_pointcxx . . $ grn_geo_point# *base_point,
576 double d_far,
577 uint8_tcxx . . $ uint8_t# diff_bit)
578 {
579 int n_meshes;
580 mesh_entrycxx . . $ mesh_entry# meshes[86];
581 geo_entrycxx . . $ geo_entry# *ep, *p;
582
583 n_meshes = grn_geo_get_meshes_for_circlecxx . . $ grn_geo_get_meshes_for_circle(7e0e8b911d5720fb).(ctx,
584 base_point,
585 d_far,
586 diff_bit,
587 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!,
588 meshes);
589
590 ep = entries + n_entries;
591 while (n_meshes--) {
592 grn_idcxx . . $ grn_id# tid;
593 grn_pat_cursorcxx . . $ grn_pat_cursor# *pc =
594 grn_pat_cursor_opencxx . . $ grn_pat_cursor_open(b2668de89fd2b39a).(ctx,
595 pat,
596 &(meshes[n_meshes].keycxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key.),
597 (uint32_tcxx . . $ uint32_t#)(meshes[n_meshes].key_sizecxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key_size.),
598 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
599 0,
600 0,
601 -1,
602 GRN_CURSOR_PREFIXcxx . . $ `include/groonga/table.h:281:9`! | GRN_CURSOR_SIZE_BY_BITcxx . . $ `include/groonga/table.h:282:9`!);
603 inspect_mesh_entrycxx . . $ `lib/geo.c:276:11`!(ctx, meshes, n_meshes);
604 if (pc) {
605 while ((tid = grn_pat_cursor_nextcxx . . $ grn_pat_cursor_next(5452c9aa69698298).(ctx, pc))) {
606 grn_ii_cursorcxx . . $ grn_ii_cursor# *ic =
607 grn_ii_cursor_opencxx . . $ grn_ii_cursor_open(5e1f33d5cbef52bd).(ctx, (grn_iicxx . . $ grn_ii# *)index, tid, 0, 0, 1, 0);
608 if (ic) {
609 double d;
610 grn_geo_pointcxx . . $ grn_geo_point# pos;
611 grn_postingcxx . . $ grn_posting# *posting;
612 grn_pat_get_keycxx . . $ grn_pat_get_key(52cd598958564ca7).(ctx, pat, tid, &pos, sizeof(grn_geo_pointcxx . . $ grn_geo_point#));
613 d = grn_geo_distance_rectangle_rawcxx . . $ grn_geo_distance_rectangle_raw(efce70e58f1fe0a0).(ctx, base_point, &pos);
614 inspect_tidcxx . . $ `lib/geo.c:277:11`!(ctx, tid, &pos, d);
615 while ((posting = grn_ii_cursor_nextcxx . . $ grn_ii_cursor_next(2ca859fa2305fa5c).(ctx, ic))) {
616 grn_idcxx . . $ grn_id# rid =
617 accessorp
618 ? grn_table_getcxx . . $ grn_table_get(5676c91e20172100).(ctx, table, &posting->ridcxx . . $ $anonymous_type_abfcd92361d8c963_0#rid., sizeof(grn_idcxx . . $ grn_id#))
619 : posting->ridcxx . . $ $anonymous_type_abfcd92361d8c963_0#rid.;
620 if (rid) {
621 for (p = ep; entries < p && p[-1].dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d. > d; p--) {
622 p->idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id. = p[-1].idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id.;
623 p->dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d. = p[-1].dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d.;
624 }
625 p->idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id. = rid;
626 p->dcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#d. = d;
627 if (n_entries < n) {
628 ep++;
629 n_entries++;
630 }
631 }
632 }
633 grn_ii_cursor_closecxx . . $ grn_ii_cursor_close(9f30b86a43abe2c6).(ctx, ic);
634 }
635 }
636 grn_pat_cursor_closecxx . . $ grn_pat_cursor_close(e6719157d7b0b236).(ctx, pc);
637 }
638 }
639 return n_entries;
640 }
641
642 static inline grn_objcxx . . $ grn_obj# *
643 find_geo_sort_indexcxx . . $ find_geo_sort_index(e9f40e4080908c1e).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *key)
644 {
645 grn_objcxx . . $ grn_obj# *index = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
646
647 if (GRN_ACCESSORPcxx . . $ `lib/grn_db.h:627:9`!(key)) {
648 grn_accessorcxx . . $ grn_accessor# *accessor = (grn_accessorcxx . . $ grn_accessor# *)key;
649 if (accessor->actioncxx . . $ _grn_accessor#action. != GRN_ACCESSOR_GET_KEYcxx . . $ GRN_ACCESSOR_GET_KEY.) {
650 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
651 }
652 if (!(DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(accessor->obj)->idcxx . . $ $anonymous_type_4a7c1014017e4c5d_0#id. & GRN_OBJ_TMP_OBJECTcxx . . $ `lib/grn_db.h:368:9`!)) {
653 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
654 }
655 if (accessor->objcxx . . $ _grn_accessor#obj.->headercxx . . $ _grn_obj#header..typecxx . . $ _grn_obj_header#type. != GRN_TABLE_HASH_KEYcxx . . $ `include/groonga/groonga.h:895:9`!) {
656 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
657 }
658 if (!accessor->nextcxx . . $ _grn_accessor#next.) {
659 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
660 }
661 grn_column_indexcxx . . $ grn_column_index(9c241c95d0832080).(ctx, accessor->nextcxx . . $ _grn_accessor#next.->objcxx . . $ _grn_accessor#obj., GRN_OP_LESScxx . . $ GRN_OP_LESS., &index, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
662 } else {
663 grn_column_indexcxx . . $ grn_column_index(9c241c95d0832080).(ctx, key, GRN_OP_LESScxx . . $ GRN_OP_LESS., &index, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
664 }
665
666 return index;
667 }
668
669 static inline int
670 grn_geo_table_sort_by_distancecxx . . $ grn_geo_table_sort_by_distance(93e460646055a0c5).(grn_ctxcxx . . $ grn_ctx# *ctx,
671 grn_objcxx . . $ grn_obj# *table,
672 grn_objcxx . . $ grn_obj# *index,
673 grn_patcxx . . $ grn_pat# *pat,
674 grn_pat_cursorcxx . . $ grn_pat_cursor# *pc,
675 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! accessorp,
676 grn_geo_pointcxx . . $ grn_geo_point# *base_point,
677 int offset,
678 int limit,
679 grn_objcxx . . $ grn_obj# *result)
680 {
681 int n_entries = 0, e = offset + limit;
682 geo_entrycxx . . $ geo_entry# *entries;
683
684 if ((entries = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(sizeof(geo_entry) * (size_t)(e + 1)))) {
685 int n;
686 uint8_tcxx . . $ uint8_t# diff_bit;
687 double d_far;
688 geo_entrycxx . . $ geo_entry# *ep;
689 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! need_not_indexed_records;
690 grn_hashcxx . . $ grn_hash# *indexed_records = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
691
692 n = grn_geo_table_sort_detect_far_pointcxx . . $ grn_geo_table_sort_detect_far_point(9c3b664d5bd75633).(ctx,
693 table,
694 index,
695 pat,
696 entries,
697 pc,
698 e,
699 accessorp,
700 base_point,
701 &d_far,
702 &diff_bit);
703 if (diff_bit > 0) {
704 n = grn_geo_table_sort_collect_pointscxx . . $ grn_geo_table_sort_collect_points(ec0ffdbdc42f186a).(ctx,
705 table,
706 index,
707 pat,
708 entries,
709 n,
710 e,
711 accessorp,
712 base_point,
713 d_far,
714 diff_bit);
715 }
716 need_not_indexed_records = offset + limit > n;
717 if (need_not_indexed_records) {
718 indexed_records = grn_hash_createcxx . . $ grn_hash_create(db1bba7e0d64660).(ctx,
719 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
720 sizeof(grn_idcxx . . $ grn_id#),
721 0,
722 GRN_OBJ_TABLE_HASH_KEYcxx . . $ `include/groonga/groonga.h:688:9`! | GRN_HASH_TINYcxx . . $ `include/groonga/hash.h:26:9`!);
723 }
724 for (ep = entries + offset; n_entries < limit && ep < entries + n;
725 n_entries++, ep++) {
726 grn_idcxx . . $ grn_id# *sorted_id;
727 if (!grn_array_addcxx . . $ grn_array_add(16402fe2a15257f6).(ctx, (grn_arraycxx . . $ grn_array# *)result, (void **)&sorted_id)) {
728 if (indexed_records) {
729 grn_hash_closecxx . . $ grn_hash_close(c005d027d163fb0b).(ctx, indexed_records);
730 indexed_records = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
731 }
732 break;
733 }
734 *sorted_id = ep->idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id.;
735 if (indexed_records) {
736 grn_hash_addcxx . . $ grn_hash_add(251a256fc515235e).(ctx,
737 indexed_records,
738 &(ep->idcxx . . $ $anonymous_type_a6dd5fd738c9bb15_0#id.),
739 sizeof(grn_idcxx . . $ grn_id#),
740 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
741 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
742 }
743 }
744 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(entries);
745 if (indexed_records) {
746 GRN_TABLE_EACHcxx . . $ `include/groonga/table.h:551:9`!(ctx, table, GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!, GRN_ID_MAXcxx . . $ `include/groonga/groonga.h:56:9`!, id, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, {
747 if (!grn_hash_get(ctx, indexed_records, &id, sizeof(grn_id), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)) {
748 grn_id *sorted_id;
749 if (grn_array_add(ctx, (grn_array *)result, (void **)&sorted_id)) {
750 *sorted_id = id;
751 }
752 n_entries++;
753 if (n_entries == limit) {
754 break;
755 }
756 };
757 });
758 grn_hash_closecxx . . $ grn_hash_close(c005d027d163fb0b).(ctx, indexed_records);
759 }
760 }
761
762 return n_entries;
763 }
764
765 int
766 grn_geo_table_sortcxx . . $ grn_geo_table_sort(2f9441c09e3051fc).(grn_ctxcxx . . $ grn_ctx# *ctx,
767 grn_objcxx . . $ grn_obj# *table,
768 int offset,
769 int limit,
770 grn_objcxx . . $ grn_obj# *result,
771 grn_objcxx . . $ grn_obj# *column,
772 grn_objcxx . . $ grn_obj# *geo_point)
773 {
774 grn_objcxx . . $ grn_obj# *index;
775 int i = 0;
776
777 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
778
779 if (offset < 0 || limit < 0) {
780 unsigned int size;
781 grn_rccxx . . $ grn_rc# rc;
782 size = grn_table_sizecxx . . $ grn_table_size(8dd58acc9865e889).(ctx, table);
783 rc = grn_output_range_normalizecxx . . $ grn_output_range_normalize(6acf1ea4c3517c62).(ctx, (int)size, &offset, &limit);
784 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
785 ERRcxx . . $ `lib/grn_error.h:156:9`!(rc,
786 "[sort][geo] failed to normalize offset and limit: "
787 "offset:%d limit:%d table-size:%u",
788 offset,
789 limit,
790 size);
791 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(i);
792 }
793 }
794
795 if ((index = find_geo_sort_indexcxx . . $ find_geo_sort_index(e9f40e4080908c1e).(ctx, column))) {
796 grn_idcxx . . $ grn_id# tid;
797 grn_patcxx . . $ grn_pat# *pat = (grn_patcxx . . $ grn_pat# *)grn_ctx_atcxx . . $ grn_ctx_at(ac4544c8400954c9).(ctx, index->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.);
798 if (!pat) {
799 char index_name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
800 int index_name_size;
801 char lexicon_name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
802 int lexicon_name_size;
803 index_name_size =
804 grn_obj_namecxx . . $ grn_obj_name(a51d1bff955f2f21).(ctx, index, index_name, GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!);
805 lexicon_name_size = grn_table_get_keycxx . . $ grn_table_get_key(2c24f49dad267d35).(ctx,
806 grn_ctx_dbcxx . . $ grn_ctx_db(ddec8e3b1327ceae).(ctx),
807 index->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.,
808 lexicon_name,
809 GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!);
810 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OBJECT_CORRUPT,
811 "[sort][geo] lexicon is broken: <%.*s>: <%.*s>(%d)",
812 index_name_size,
813 index_name,
814 lexicon_name_size,
815 lexicon_name,
816 index->header.domain);
817 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(i);
818 }
819 grn_idcxx . . $ grn_id# domain = pat->objcxx . . $ _grn_pat#obj..headercxx . . $ $anonymous_type_4a7c1014017e4c5d_0#header..domaincxx . . $ _grn_obj_header#domain.;
820 grn_pat_cursorcxx . . $ grn_pat_cursor# *pc =
821 grn_pat_cursor_opencxx . . $ grn_pat_cursor_open(b2668de89fd2b39a).(ctx,
822 pat,
823 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
824 0,
825 GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(geo_point),
826 (uint32_tcxx . . $ uint32_t#)GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(geo_point),
827 0,
828 -1,
829 GRN_CURSOR_PREFIXcxx . . $ `include/groonga/table.h:281:9`!);
830 if (pc) {
831 if (domain != GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. &&
832 domain != GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
833 int e = offset + limit;
834 while (i < e && (tid = grn_pat_cursor_nextcxx . . $ grn_pat_cursor_next(5452c9aa69698298).(ctx, pc))) {
835 grn_ii_cursorcxx . . $ grn_ii_cursor# *ic =
836 grn_ii_cursor_opencxx . . $ grn_ii_cursor_open(5e1f33d5cbef52bd).(ctx, (grn_iicxx . . $ grn_ii# *)index, tid, 0, 0, 1, 0);
837 if (ic) {
838 grn_postingcxx . . $ grn_posting# *posting;
839 while (i < e && (posting = grn_ii_cursor_nextcxx . . $ grn_ii_cursor_next(2ca859fa2305fa5c).(ctx, ic))) {
840 if (offset <= i) {
841 grn_idcxx . . $ grn_id# *v;
842 if (!grn_array_addcxx . . $ grn_array_add(16402fe2a15257f6).(ctx, (grn_arraycxx . . $ grn_array# *)result, (void **)&v)) {
843 break;
844 }
845 *v = posting->ridcxx . . $ $anonymous_type_abfcd92361d8c963_0#rid.;
846 }
847 i++;
848 }
849 grn_ii_cursor_closecxx . . $ grn_ii_cursor_close(9f30b86a43abe2c6).(ctx, ic);
850 }
851 }
852 } else {
853 grn_geo_pointcxx . . $ grn_geo_point# *base_point = (grn_geo_pointcxx . . $ grn_geo_point# *)GRN_BULK_HEADcxx . . $ `include/groonga/groonga.h:2648:9`!(geo_point);
854 i = grn_geo_table_sort_by_distancecxx . . $ grn_geo_table_sort_by_distance(93e460646055a0c5).(ctx,
855 table,
856 index,
857 pat,
858 pc,
859 GRN_ACCESSORPcxx . . $ `lib/grn_db.h:627:9`!(column),
860 base_point,
861 offset,
862 limit,
863 result);
864 }
865 grn_pat_cursor_closecxx . . $ grn_pat_cursor_close(e6719157d7b0b236).(ctx, pc);
866 }
867 }
868 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(i);
869 }
870
871 grn_rccxx . . $ grn_rc#
872 grn_geo_resolve_approximate_typecxx . . $ grn_geo_resolve_approximate_type(86997f310e277b98).(grn_ctxcxx . . $ grn_ctx# *ctx,
873 grn_objcxx . . $ grn_obj# *type_name,
874 grn_geo_approximate_typecxx . . $ grn_geo_approximate_type# *type)
875 {
876 grn_rccxx . . $ grn_rc# rc;
877 grn_objcxx . . $ grn_obj# approximate_type;
878
879 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&approximate_type, 0);
880 rc = grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, type_name, &approximate_type, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
881 if (rc == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
882 const char *name;
883 size_t size;
884 name = GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&approximate_type);
885 size = GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&approximate_type);
886 if ((strncmpcxx . . $ strncmp(fd278af2f295fa2e).("rectangle", name, size) == 0) ||
887 (strncmpcxx . . $ strncmp(fd278af2f295fa2e).("rect", name, size) == 0)) {
888 *type = GRN_GEO_APPROXIMATE_RECTANGLEcxx . . $ GRN_GEO_APPROXIMATE_RECTANGLE.;
889 } else if ((strncmpcxx . . $ strncmp(fd278af2f295fa2e).("sphere", name, size) == 0) ||
890 (strncmpcxx . . $ strncmp(fd278af2f295fa2e).("sphr", name, size) == 0)) {
891 *type = GRN_GEO_APPROXIMATE_SPHEREcxx . . $ GRN_GEO_APPROXIMATE_SPHERE.;
892 } else if ((strncmpcxx . . $ strncmp(fd278af2f295fa2e).("ellipsoid", name, size) == 0) ||
893 (strncmpcxx . . $ strncmp(fd278af2f295fa2e).("ellip", name, size) == 0)) {
894 *type = GRN_GEO_APPROXIMATE_ELLIPSOIDcxx . . $ GRN_GEO_APPROXIMATE_ELLIPSOID.;
895 } else {
896 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
897 "geo distance approximate type must be one of "
898 "[rectangle, rect, sphere, sphr, ellipsoid, ellip]"
899 ": <%.*s>",
900 (int)size,
901 name);
902 }
903 }
904 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &approximate_type);
905
906 return rc;
907 }
908
909 typedef double (*grn_geo_distance_raw_funccxx . . $ grn_geo_distance_raw_func#)(grn_ctxcxx . . $ grn_ctx# *ctx,
910 grn_geo_pointcxx . . $ grn_geo_point# *point1,
911 grn_geo_pointcxx . . $ grn_geo_point# *point2);
912
913 grn_rccxx . . $ grn_rc#
914 grn_selector_geo_in_circlecxx . . $ grn_selector_geo_in_circle(2267fc2522c8e143).(grn_ctxcxx . . $ grn_ctx# *ctx,
915 grn_objcxx . . $ grn_obj# *table,
916 grn_objcxx . . $ grn_obj# *index,
917 int nargs,
918 grn_objcxx . . $ grn_obj# **args,
919 grn_objcxx . . $ grn_obj# *res,
920 grn_operatorcxx . . $ grn_operator# op)
921 {
922 const char *tag = "[geo-in-circle]";
923 grn_selector_datacxx . . $ grn_selector_data# *data = grn_selector_data_getcxx . . $ grn_selector_data_get(e834f84f98eef4a5).(ctx);
924 grn_geo_approximate_typecxx . . $ grn_geo_approximate_type# type = GRN_GEO_APPROXIMATE_RECTANGLEcxx . . $ GRN_GEO_APPROXIMATE_RECTANGLE.;
925
926 if (!(nargs == 4 || nargs == 5)) {
927 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
928 "%s requires 3 or 4 arguments but was <%d> arguments",
929 tag,
930 nargs - 1);
931 return ctx->rccxx . . $ _grn_ctx#rc.;
932 }
933
934 if (nargs == 5) {
935 grn_objcxx . . $ grn_obj# *type_name = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
936 if (args[4]->headercxx . . $ _grn_obj#header..typecxx . . $ _grn_obj_header#type. == GRN_TABLE_HASH_KEYcxx . . $ `include/groonga/groonga.h:895:9`!) {
937 grn_objcxx . . $ grn_obj# *options = args[4];
938 grn_rccxx . . $ grn_rc# rc = grn_selector_data_parse_optionscxx . . $ `include/groonga/selector.h:98:9`!(ctx,
939 data,
940 options,
941 tag,
942 "type",
943 GRN_PROC_OPTION_VALUE_RAW,
944 &type_name,
945 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
946 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
947 return rc;
948 }
949 } else {
950 type_name = args[4];
951 }
952 if (type_name) {
953 grn_rccxx . . $ grn_rc# rc = grn_geo_resolve_approximate_typecxx . . $ grn_geo_resolve_approximate_type(86997f310e277b98).(ctx, type_name, &type);
954 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
955 return rc;
956 }
957 }
958 }
959
960 {
961 grn_objcxx . . $ grn_obj# *center_point, *distance;
962 center_point = args[2];
963 distance = args[3];
964 grn_geo_select_in_circlecxx . . $ grn_geo_select_in_circle(4c21f20e11d439c3).(ctx, index, center_point, distance, type, res, op);
965 }
966
967 return ctx->rccxx . . $ _grn_ctx#rc.;
968 }
969
970 static grn_geo_distance_raw_funccxx . . $ grn_geo_distance_raw_func#
971 grn_geo_resolve_distance_raw_funccxx . . $ grn_geo_resolve_distance_raw_func(8b468ae8ff6c91db).(grn_ctxcxx . . $ grn_ctx# *ctx,
972 grn_geo_approximate_typecxx . . $ grn_geo_approximate_type# approximate_type,
973 grn_idcxx . . $ grn_id# domain)
974 {
975 grn_geo_distance_raw_funccxx . . $ grn_geo_distance_raw_func# distance_raw_func = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
976
977 switch (approximate_type) {
978 case GRN_GEO_APPROXIMATE_RECTANGLEcxx . . $ GRN_GEO_APPROXIMATE_RECTANGLE.:
979 distance_raw_func = grn_geo_distance_rectangle_rawcxx . . $ grn_geo_distance_rectangle_raw(efce70e58f1fe0a0).;
980 break;
981 case GRN_GEO_APPROXIMATE_SPHEREcxx . . $ GRN_GEO_APPROXIMATE_SPHERE.:
982 distance_raw_func = grn_geo_distance_sphere_rawcxx . . $ grn_geo_distance_sphere_raw(efce70e58f1fe0a0).;
983 break;
984 case GRN_GEO_APPROXIMATE_ELLIPSOIDcxx . . $ GRN_GEO_APPROXIMATE_ELLIPSOID.:
985 if (domain == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
986 distance_raw_func = grn_geo_distance_ellipsoid_raw_wgs84cxx . . $ grn_geo_distance_ellipsoid_raw_wgs84(efce70e58f1fe0a0).;
987 } else {
988 distance_raw_func = grn_geo_distance_ellipsoid_raw_tokyocxx . . $ grn_geo_distance_ellipsoid_raw_tokyo(efce70e58f1fe0a0).;
989 }
990 break;
991 default:
992 break;
993 }
994
995 return distance_raw_func;
996 }
997
998 grn_rccxx . . $ grn_rc#
999 grn_geo_select_in_circlecxx . . $ grn_geo_select_in_circle(4c21f20e11d439c3).(grn_ctxcxx . . $ grn_ctx# *ctx,
1000 grn_objcxx . . $ grn_obj# *index,
1001 grn_objcxx . . $ grn_obj# *center_point,
1002 grn_objcxx . . $ grn_obj# *distance,
1003 grn_geo_approximate_typecxx . . $ grn_geo_approximate_type# approximate_type,
1004 grn_objcxx . . $ grn_obj# *res,
1005 grn_operatorcxx . . $ grn_operator# op)
1006 {
1007 grn_idcxx . . $ grn_id# domain;
1008 double center_longitude, center_latitude;
1009 double d;
1010 grn_objcxx . . $ grn_obj# *pat, *point_on_circle = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, center_point_, point_on_circle_;
1011 grn_geo_pointcxx . . $ grn_geo_point# *center, on_circle;
1012 grn_geo_distance_raw_funccxx . . $ grn_geo_distance_raw_func# distance_raw_func;
1013 pat = grn_ctx_atcxx . . $ grn_ctx_at(ac4544c8400954c9).(ctx, index->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.);
1014 if (!pat) {
1015 char index_name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
1016 int index_name_size;
1017 char lexicon_name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
1018 int lexicon_name_size;
1019 index_name_size =
1020 grn_obj_namecxx . . $ grn_obj_name(a51d1bff955f2f21).(ctx, index, index_name, GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!);
1021 lexicon_name_size = grn_table_get_keycxx . . $ grn_table_get_key(2c24f49dad267d35).(ctx,
1022 grn_ctx_dbcxx . . $ grn_ctx_db(ddec8e3b1327ceae).(ctx),
1023 index->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.,
1024 lexicon_name,
1025 GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!);
1026 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OBJECT_CORRUPT,
1027 "geo_in_circle(): lexicon is broken: <%.*s>: <%.*s>(%d)",
1028 index_name_size,
1029 index_name,
1030 lexicon_name_size,
1031 lexicon_name,
1032 index->header.domain);
1033 goto exit;
1034 }
1035 domain = pat->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.;
1036 if (domain != GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. && domain != GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
1037 char name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
1038 int name_size = 0;
1039 grn_objcxx . . $ grn_obj# *domain_object;
1040 domain_object = grn_ctx_atcxx . . $ grn_ctx_at(ac4544c8400954c9).(ctx, domain);
1041 if (domain_object) {
1042 name_size =
1043 grn_obj_namecxx . . $ grn_obj_name(a51d1bff955f2f21).(ctx, domain_object, name, GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!);
1044 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, domain_object);
1045 } else {
1046 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(name, GRN_TABLE_MAX_KEY_SIZE, "(null)");
1047 name_size = (int)strlencxx . . $ strlen(751346f8406fd082).(name);
1048 }
1049 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1050 "geo_in_circle(): index table must be "
1051 "TokyoGeoPoint or WGS84GeoPoint key type table: <%.*s>",
1052 name_size,
1053 name);
1054 goto exit;
1055 }
1056
1057 if (center_point->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. != domain) {
1058 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&center_point_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain);
1059 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, center_point, &center_point_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
1060 goto exit;
1061 }
1062 center_point = &center_point_;
1063 }
1064 center = GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(center_point);
1065 center_longitude = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(center->longitude);
1066 center_latitude = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(center->latitude);
1067
1068 distance_raw_func =
1069 grn_geo_resolve_distance_raw_funccxx . . $ grn_geo_resolve_distance_raw_func(8b468ae8ff6c91db).(ctx, approximate_type, domain);
1070 if (!distance_raw_func) {
1071 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1072 "unknown approximate type: <%d>",
1073 approximate_type);
1074 goto exit;
1075 }
1076
1077 switch (distance->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.) {
1078 case GRN_DB_INT32cxx . . $ GRN_DB_INT32.:
1079 d = GRN_INT32_VALUEcxx . . $ `include/groonga/groonga.h:3102:9`!(distance);
1080 on_circle.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. =
1081 center->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + GRN_GEO_RADIAN2MSECcxx . . $ `include/groonga/groonga.h:2956:9`!(d / (double)GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!);
1082 on_circle.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = center->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1083 break;
1084 case GRN_DB_UINT32cxx . . $ GRN_DB_UINT32.:
1085 d = GRN_UINT32_VALUEcxx . . $ `include/groonga/groonga.h:3103:9`!(distance);
1086 on_circle.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. =
1087 center->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + GRN_GEO_RADIAN2MSECcxx . . $ `include/groonga/groonga.h:2956:9`!(d / (double)GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!);
1088 on_circle.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = center->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1089 break;
1090 case GRN_DB_INT64cxx . . $ GRN_DB_INT64.:
1091 d = (double)GRN_INT64_VALUEcxx . . $ `include/groonga/groonga.h:3104:9`!(distance);
1092 on_circle.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. =
1093 center->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + GRN_GEO_RADIAN2MSECcxx . . $ `include/groonga/groonga.h:2956:9`!(d / (double)GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!);
1094 on_circle.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = center->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1095 break;
1096 case GRN_DB_UINT64cxx . . $ GRN_DB_UINT64.:
1097 d = (double)GRN_UINT64_VALUEcxx . . $ `include/groonga/groonga.h:3105:9`!(distance);
1098 on_circle.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. =
1099 center->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + GRN_GEO_RADIAN2MSECcxx . . $ `include/groonga/groonga.h:2956:9`!(d / (double)GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!);
1100 on_circle.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = center->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1101 break;
1102 case GRN_DB_FLOAT32cxx . . $ GRN_DB_FLOAT32.:
1103 d = GRN_FLOAT32_VALUEcxx . . $ `include/groonga/groonga.h:3107:9`!(distance);
1104 on_circle.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. =
1105 center->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + GRN_GEO_RADIAN2MSECcxx . . $ `include/groonga/groonga.h:2956:9`!(d / (double)GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!);
1106 on_circle.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = center->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1107 break;
1108 case GRN_DB_FLOATcxx . . $ GRN_DB_FLOAT.:
1109 d = GRN_FLOAT_VALUEcxx . . $ `include/groonga/groonga.h:3108:9`!(distance);
1110 on_circle.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. =
1111 center->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. + GRN_GEO_RADIAN2MSECcxx . . $ `include/groonga/groonga.h:2956:9`!(d / (double)GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!);
1112 on_circle.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = center->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1113 break;
1114 case GRN_DB_SHORT_TEXTcxx . . $ GRN_DB_SHORT_TEXT.:
1115 case GRN_DB_TEXTcxx . . $ GRN_DB_TEXT.:
1116 case GRN_DB_LONG_TEXTcxx . . $ GRN_DB_LONG_TEXT.:
1117 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&point_on_circle_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain);
1118 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, distance, &point_on_circle_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
1119 goto exit;
1120 }
1121 point_on_circle = &point_on_circle_;
1122 /* fallthru */
1123 case GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT.:
1124 case GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.:
1125 if (!point_on_circle) {
1126 if (domain != distance->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.) { /* todo */
1127 goto exit;
1128 }
1129 point_on_circle = distance;
1130 }
1131 GRN_GEO_POINT_VALUEcxx . . $ `include/groonga/groonga.h:3113:9`!(point_on_circle,
1132 on_circle.latitude,
1133 on_circle.longitude);
1134 d = distance_raw_func(ctx, center, &on_circle);
1135 if (point_on_circle == &point_on_circle_) {
1136 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, point_on_circle);
1137 }
1138 break;
1139 default:
1140 goto exit;
1141 }
1142 {
1143 grn_selector_datacxx . . $ grn_selector_data# *data = grn_selector_data_getcxx . . $ grn_selector_data_get(e834f84f98eef4a5).(ctx);
1144 const boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! use_selector_data =
1145 (data && (grn_selector_data_have_score_columncxx . . $ grn_selector_data_have_score_column(87993b14c3eb9c5f).(ctx, data) ||
1146 grn_selector_data_have_tags_columncxx . . $ grn_selector_data_have_tags_column(87993b14c3eb9c5f).(ctx, data)));
1147
1148 int n_meshes;
1149 uint8_tcxx . . $ uint8_t# diff_bit;
1150 double d_far;
1151 mesh_entrycxx . . $ mesh_entry# meshes[87];
1152 uint8_tcxx . . $ uint8_t# geo_key1[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
1153 uint8_tcxx . . $ uint8_t# geo_key2[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
1154
1155 d_far = grn_geo_distance_rectangle_rawcxx . . $ grn_geo_distance_rectangle_raw(efce70e58f1fe0a0).(ctx, center, &on_circle);
1156 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key1, center, sizeof(grn_geo_point));
1157 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key2, &on_circle, sizeof(grn_geo_point));
1158 diff_bit = compute_diff_bitcxx . . $ compute_diff_bit(c6d1befd7368f101).(geo_key1, geo_key2);
1159 #ifdef GEO_DEBUG
1160 printf("center point: ");
1161 grn_p_geo_point(ctx, center);
1162 printf("point on circle: ");
1163 grn_p_geo_point(ctx, &on_circle);
1164 printf("diff: %d\n", diff_bit);
1165 #endif
1166 if ((diff_bit % 2) == 1) {
1167 diff_bit--;
1168 }
1169 n_meshes =
1170 grn_geo_get_meshes_for_circlecxx . . $ grn_geo_get_meshes_for_circle(7e0e8b911d5720fb).(ctx, center, d_far, diff_bit, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!, meshes);
1171 while (n_meshes--) {
1172 grn_table_cursorcxx . . $ grn_table_cursor# *tc;
1173 tc = grn_table_cursor_opencxx . . $ grn_table_cursor_open(a4cddc3087c69e91).(ctx,
1174 pat,
1175 &(meshes[n_meshes].keycxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key.),
1176 (unsigned int)(meshes[n_meshes].key_sizecxx . . $ $anonymous_type_a6dd5fd738c9bb15_1#key_size.),
1177 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
1178 0,
1179 0,
1180 -1,
1181 GRN_CURSOR_PREFIXcxx . . $ `include/groonga/table.h:281:9`! | GRN_CURSOR_SIZE_BY_BITcxx . . $ `include/groonga/table.h:282:9`!);
1182 inspect_mesh_entrycxx . . $ `lib/geo.c:276:11`!(ctx, meshes, n_meshes);
1183 if (tc) {
1184 grn_idcxx . . $ grn_id# tid;
1185 grn_geo_pointcxx . . $ grn_geo_point# point;
1186 while ((tid = grn_table_cursor_nextcxx . . $ grn_table_cursor_next(8dd58acc9865e889).(ctx, tc))) {
1187 double point_distance;
1188 grn_table_get_keycxx . . $ grn_table_get_key(2c24f49dad267d35).(ctx, pat, tid, &point, sizeof(grn_geo_pointcxx . . $ grn_geo_point#));
1189 point_distance = distance_raw_func(ctx, &point, center);
1190 if (point_distance <= d) {
1191 inspect_tidcxx . . $ `lib/geo.c:277:11`!(ctx, tid, &point, point_distance);
1192 if (use_selector_data) {
1193 grn_selector_data_on_token_foundcxx . . $ grn_selector_data_on_token_found(63aa34676b426ba5).(ctx,
1194 data,
1195 index,
1196 tid,
1197 point_distance);
1198 } else {
1199 grn_ii_atcxx . . $ grn_ii_at(c699eb785099329f).(ctx, (grn_iicxx . . $ grn_ii# *)index, tid, (grn_hashcxx . . $ grn_hash# *)res, op);
1200 }
1201 }
1202 }
1203 grn_table_cursor_closecxx . . $ grn_table_cursor_close(4865d068a46d0f83).(ctx, tc);
1204 }
1205 }
1206 }
1207 exit:
1208 grn_ii_resolve_sel_andcxx . . $ grn_ii_resolve_sel_and(8582dd5db79648f2).(ctx, (grn_hashcxx . . $ grn_hash# *)res, op);
1209 return ctx->rccxx . . $ _grn_ctx#rc.;
1210 }
1211
1212 grn_rccxx . . $ grn_rc#
1213 grn_selector_geo_in_rectanglecxx . . $ grn_selector_geo_in_rectangle(2267fc2522c8e143).(grn_ctxcxx . . $ grn_ctx# *ctx,
1214 grn_objcxx . . $ grn_obj# *table,
1215 grn_objcxx . . $ grn_obj# *index,
1216 int nargs,
1217 grn_objcxx . . $ grn_obj# **args,
1218 grn_objcxx . . $ grn_obj# *res,
1219 grn_operatorcxx . . $ grn_operator# op)
1220 {
1221 const char *tag = "[geo-in-rectangle]";
1222 grn_selector_datacxx . . $ grn_selector_data# *data = grn_selector_data_getcxx . . $ grn_selector_data_get(e834f84f98eef4a5).(ctx);
1223
1224 if (!(nargs == 4 || nargs == 5)) {
1225 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1226 "%s requires 3 or 4 arguments but was <%d> arguments",
1227 tag,
1228 nargs - 1);
1229 return ctx->rccxx . . $ _grn_ctx#rc.;
1230 }
1231
1232 if (nargs == 5) {
1233 if (args[4]->headercxx . . $ _grn_obj#header..typecxx . . $ _grn_obj_header#type. != GRN_TABLE_HASH_KEYcxx . . $ `include/groonga/groonga.h:895:9`!) {
1234 grn_objcxx . . $ grn_obj# inspected;
1235 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
1236 grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, args[4]);
1237 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1238 "%s the 4th argument must be options: %.*s",
1239 tag,
1240 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
1241 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
1242 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
1243 return ctx->rccxx . . $ _grn_ctx#rc.;
1244 }
1245 grn_objcxx . . $ grn_obj# *options = args[4];
1246 grn_rccxx . . $ grn_rc# rc = grn_selector_data_parse_optionscxx . . $ `include/groonga/selector.h:98:9`!(ctx, data, options, tag, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
1247 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
1248 return rc;
1249 }
1250 }
1251
1252 grn_objcxx . . $ grn_obj# *top_left_point, *bottom_right_point;
1253 top_left_point = args[2];
1254 bottom_right_point = args[3];
1255 grn_geo_select_in_rectanglecxx . . $ grn_geo_select_in_rectangle(e0babf7a429da9d6).(ctx,
1256 index,
1257 top_left_point,
1258 bottom_right_point,
1259 res,
1260 op);
1261 return ctx->rccxx . . $ _grn_ctx#rc.;
1262 }
1263
1264 static void
1265 in_rectangle_data_fillcxx . . $ in_rectangle_data_fill(c1bed27aa0eca08b).(grn_ctxcxx . . $ grn_ctx# *ctx,
1266 grn_objcxx . . $ grn_obj# *index,
1267 grn_objcxx . . $ grn_obj# *top_left_point,
1268 grn_objcxx . . $ grn_obj# *bottom_right_point,
1269 const char *process_name,
1270 in_rectangle_datacxx . . $ in_rectangle_data# *data)
1271 {
1272 grn_idcxx . . $ grn_id# domain;
1273 const char *domain_name;
1274
1275 data->patcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#pat. = grn_ctx_atcxx . . $ grn_ctx_at(ac4544c8400954c9).(ctx, index->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.);
1276 if (!data->patcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#pat.) {
1277 char index_name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
1278 int index_name_size;
1279 char lexicon_name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
1280 int lexicon_name_size;
1281 index_name_size =
1282 grn_obj_namecxx . . $ grn_obj_name(a51d1bff955f2f21).(ctx, index, index_name, GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!);
1283 lexicon_name_size = grn_table_get_keycxx . . $ grn_table_get_key(2c24f49dad267d35).(ctx,
1284 grn_ctx_dbcxx . . $ grn_ctx_db(ddec8e3b1327ceae).(ctx),
1285 index->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.,
1286 lexicon_name,
1287 GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!);
1288 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OBJECT_CORRUPT,
1289 "%s: lexicon lexicon is broken: <%.*s>: <%.*s>(%d)",
1290 process_name,
1291 index_name_size,
1292 index_name,
1293 lexicon_name_size,
1294 lexicon_name,
1295 index->header.domain);
1296 return;
1297 }
1298
1299 domain = data->patcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#pat.->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.;
1300 if (domain != GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. && domain != GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
1301 char name[GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!];
1302 int name_size = 0;
1303 grn_objcxx . . $ grn_obj# *domain_object;
1304 domain_object = grn_ctx_atcxx . . $ grn_ctx_at(ac4544c8400954c9).(ctx, domain);
1305 if (domain_object) {
1306 name_size =
1307 grn_obj_namecxx . . $ grn_obj_name(a51d1bff955f2f21).(ctx, domain_object, name, GRN_TABLE_MAX_KEY_SIZEcxx . . $ `include/groonga/table.h:26:9`!);
1308 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, domain_object);
1309 } else {
1310 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(name, GRN_TABLE_MAX_KEY_SIZE, "(null)");
1311 name_size = (int)strlencxx . . $ strlen(751346f8406fd082).(name);
1312 }
1313 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1314 "%s: index table must be "
1315 "TokyoGeoPoint or WGS84GeoPoint key type table: <%.*s>",
1316 process_name,
1317 name_size,
1318 name);
1319 return;
1320 }
1321
1322 if (domain == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT.) {
1323 domain_name = "TokyoGeoPoint";
1324 } else {
1325 domain_name = "WGS84GeoPoint";
1326 }
1327
1328 if (top_left_point->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. != domain) {
1329 grn_obj_reinitcxx . . $ grn_obj_reinit(fc9ea836325dd1d2).(ctx, &(data->top_left_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left_point_buffer.), domain, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!);
1330 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx,
1331 top_left_point,
1332 &(data->top_left_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left_point_buffer.),
1333 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
1334 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1335 "%s: failed to cast to %s: <%.*s>",
1336 process_name,
1337 domain_name,
1338 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(top_left_point),
1339 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(top_left_point));
1340 return;
1341 }
1342 top_left_point = &(data->top_left_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left_point_buffer.);
1343 }
1344 data->top_leftcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left. = GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(top_left_point);
1345
1346 if (bottom_right_point->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. != domain) {
1347 grn_obj_reinitcxx . . $ grn_obj_reinit(fc9ea836325dd1d2).(ctx, &(data->bottom_right_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right_point_buffer.), domain, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!);
1348 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx,
1349 bottom_right_point,
1350 &(data->bottom_right_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right_point_buffer.),
1351 falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
1352 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1353 "%s: failed to cast to %s: <%.*s>",
1354 process_name,
1355 domain_name,
1356 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(bottom_right_point),
1357 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(bottom_right_point));
1358 return;
1359 }
1360 bottom_right_point = &(data->bottom_right_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right_point_buffer.);
1361 }
1362 data->bottom_rightcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right. = GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(bottom_right_point);
1363
1364 data->centercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#center..latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. =
1365 data->top_leftcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left.->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. -
1366 (abscxx . . $ abs(7864480464b09eea).(data->top_leftcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left.->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. - data->bottom_rightcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right.->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.) / 2);
1367 data->centercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#center..longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. =
1368 data->bottom_rightcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right.->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. -
1369 (abscxx . . $ abs(7864480464b09eea).(data->bottom_rightcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right.->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. - data->top_leftcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left.->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) / 2);
1370 }
1371
1372 static void
1373 in_rectangle_data_validatecxx . . $ in_rectangle_data_validate(634a7bbc1c6caab9).(grn_ctxcxx . . $ grn_ctx# *ctx,
1374 const char *process_name,
1375 in_rectangle_datacxx . . $ in_rectangle_data# *data)
1376 {
1377 grn_geo_pointcxx . . $ grn_geo_point# *top_left, *bottom_right;
1378
1379 top_left = data->top_leftcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left.;
1380 bottom_right = data->bottom_rightcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right.;
1381
1382 if (top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. >= GRN_GEO_MAX_LATITUDEcxx . . $ `lib/grn_geo.h:38:9`!) {
1383 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1384 "%s: top left point's latitude is too big: "
1385 "<%d>(max:%d): (%d,%d) (%d,%d)",
1386 process_name,
1387 GRN_GEO_MAX_LATITUDEcxx . . $ `lib/grn_geo.h:38:9`!,
1388 top_left->latitude,
1389 top_left->latitude,
1390 top_left->longitude,
1391 bottom_right->latitude,
1392 bottom_right->longitude);
1393 return;
1394 }
1395
1396 if (top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. <= GRN_GEO_MIN_LATITUDEcxx . . $ `lib/grn_geo.h:40:9`!) {
1397 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1398 "%s: top left point's latitude is too small: "
1399 "<%d>(min:%d): (%d,%d) (%d,%d)",
1400 process_name,
1401 GRN_GEO_MIN_LATITUDEcxx . . $ `lib/grn_geo.h:40:9`!,
1402 top_left->latitude,
1403 top_left->latitude,
1404 top_left->longitude,
1405 bottom_right->latitude,
1406 bottom_right->longitude);
1407 return;
1408 }
1409
1410 if (top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= GRN_GEO_MAX_LONGITUDEcxx . . $ `lib/grn_geo.h:39:9`!) {
1411 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1412 "%s: top left point's longitude is too big: "
1413 "<%d>(max:%d): (%d,%d) (%d,%d)",
1414 process_name,
1415 GRN_GEO_MAX_LONGITUDEcxx . . $ `lib/grn_geo.h:39:9`!,
1416 top_left->longitude,
1417 top_left->latitude,
1418 top_left->longitude,
1419 bottom_right->latitude,
1420 bottom_right->longitude);
1421 return;
1422 }
1423
1424 if (top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= GRN_GEO_MIN_LONGITUDEcxx . . $ `lib/grn_geo.h:41:9`!) {
1425 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1426 "%s: top left point's longitude is too small: "
1427 "<%d>(min:%d): (%d,%d) (%d,%d)",
1428 process_name,
1429 GRN_GEO_MIN_LONGITUDEcxx . . $ `lib/grn_geo.h:41:9`!,
1430 top_left->longitude,
1431 top_left->latitude,
1432 top_left->longitude,
1433 bottom_right->latitude,
1434 bottom_right->longitude);
1435 return;
1436 }
1437
1438 if (bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. >= GRN_GEO_MAX_LATITUDEcxx . . $ `lib/grn_geo.h:38:9`!) {
1439 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1440 "%s: bottom right point's latitude is too big: "
1441 "<%d>(max:%d): (%d,%d) (%d,%d)",
1442 process_name,
1443 GRN_GEO_MAX_LATITUDEcxx . . $ `lib/grn_geo.h:38:9`!,
1444 bottom_right->latitude,
1445 top_left->latitude,
1446 top_left->longitude,
1447 bottom_right->latitude,
1448 bottom_right->longitude);
1449 return;
1450 }
1451
1452 if (bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. <= GRN_GEO_MIN_LATITUDEcxx . . $ `lib/grn_geo.h:40:9`!) {
1453 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1454 "%s: bottom right point's latitude is too small: "
1455 "<%d>(min:%d): (%d,%d) (%d,%d)",
1456 process_name,
1457 GRN_GEO_MIN_LATITUDEcxx . . $ `lib/grn_geo.h:40:9`!,
1458 bottom_right->latitude,
1459 top_left->latitude,
1460 top_left->longitude,
1461 bottom_right->latitude,
1462 bottom_right->longitude);
1463 return;
1464 }
1465
1466 if (bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= GRN_GEO_MAX_LONGITUDEcxx . . $ `lib/grn_geo.h:39:9`!) {
1467 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1468 "%s: bottom right point's longitude is too big: "
1469 "<%d>(max:%d): (%d,%d) (%d,%d)",
1470 process_name,
1471 GRN_GEO_MAX_LONGITUDEcxx . . $ `lib/grn_geo.h:39:9`!,
1472 bottom_right->longitude,
1473 top_left->latitude,
1474 top_left->longitude,
1475 bottom_right->latitude,
1476 bottom_right->longitude);
1477 return;
1478 }
1479
1480 if (bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= GRN_GEO_MIN_LONGITUDEcxx . . $ `lib/grn_geo.h:41:9`!) {
1481 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
1482 "%s: bottom right point's longitude is too small: "
1483 "<%d>(min:%d): (%d,%d) (%d,%d)",
1484 process_name,
1485 GRN_GEO_MIN_LONGITUDEcxx . . $ `lib/grn_geo.h:41:9`!,
1486 bottom_right->longitude,
1487 top_left->latitude,
1488 top_left->longitude,
1489 bottom_right->latitude,
1490 bottom_right->longitude);
1491 return;
1492 }
1493 }
1494
1495 static void
1496 in_rectangle_area_data_computecxx . . $ in_rectangle_area_data_compute(ede52f6bc8216).(grn_ctxcxx . . $ grn_ctx# *ctx,
1497 grn_geo_pointcxx . . $ grn_geo_point# *top_left,
1498 grn_geo_pointcxx . . $ grn_geo_point# *bottom_right,
1499 in_rectangle_area_datacxx . . $ in_rectangle_area_data# *data)
1500 {
1501 int latitude_distance, longitude_distance;
1502 uint8_tcxx . . $ uint8_t# diff_bit;
1503 grn_geo_pointcxx . . $ grn_geo_point# base;
1504 grn_geo_pointcxx . . $ grn_geo_point# *geo_point_input;
1505 uint8_tcxx . . $ uint8_t# geo_key_input[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
1506 uint8_tcxx . . $ uint8_t# geo_key_base[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
1507 uint8_tcxx . . $ uint8_t# geo_key_top_left[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
1508 uint8_tcxx . . $ uint8_t# geo_key_bottom_right[sizeof(grn_geo_pointcxx . . $ grn_geo_point#)];
1509
1510 latitude_distance = top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. - bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.;
1511 longitude_distance = bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. - top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1512 if (latitude_distance > longitude_distance) {
1513 geo_point_input = bottom_right;
1514 base.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.;
1515 base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. - longitude_distance;
1516 } else {
1517 geo_point_input = top_left;
1518 base.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. - latitude_distance;
1519 base.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1520 }
1521 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key_input, geo_point_input, sizeof(grn_geo_point));
1522 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key_base, &base, sizeof(grn_geo_point));
1523 diff_bit = compute_diff_bitcxx . . $ compute_diff_bit(c6d1befd7368f101).(geo_key_input, geo_key_base);
1524 compute_min_and_maxcxx . . $ compute_min_and_max(7aa427f80ae4eb27).(&base, diff_bit, &(data->mincxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#min.), &(data->maxcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#max.));
1525
1526 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key_top_left, top_left, sizeof(grn_geo_point));
1527 grn_gtoncxx . . $ `lib/grn.h:648:9`!(geo_key_bottom_right, bottom_right, sizeof(grn_geo_point));
1528 data->rectangle_common_bitcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#rectangle_common_bit. =
1529 compute_diff_bitcxx . . $ compute_diff_bit(c6d1befd7368f101).(geo_key_top_left, geo_key_bottom_right) - 1;
1530 compute_min_and_max_keycxx . . $ compute_min_and_max_key(9da651c5f357079e).(geo_key_top_left,
1531 data->rectangle_common_bitcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#rectangle_common_bit. + 1,
1532 data->rectangle_common_keycxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#rectangle_common_key.,
1533 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
1534
1535 #ifdef GEO_DEBUG
1536 printf("base: ");
1537 grn_p_geo_point(ctx, &base);
1538 printf("min: ");
1539 grn_p_geo_point(ctx, &(data->min));
1540 printf("max: ");
1541 grn_p_geo_point(ctx, &(data->max));
1542 printf("top-left: ");
1543 grn_p_geo_point(ctx, top_left);
1544 printf("bottom-right: ");
1545 grn_p_geo_point(ctx, bottom_right);
1546 printf("rectangle-common-bit:%10d\n", data->rectangle_common_bit);
1547 printf("distance(latitude): %10d\n", latitude_distance);
1548 printf("distance(longitude): %10d\n", longitude_distance);
1549 #endif
1550 }
1551
1552 static grn_rccxx . . $ grn_rc#
1553 in_rectangle_data_preparecxx . . $ in_rectangle_data_prepare(a3c4f2a05ab419c2).(grn_ctxcxx . . $ grn_ctx# *ctx,
1554 grn_objcxx . . $ grn_obj# *index,
1555 grn_objcxx . . $ grn_obj# *top_left_point,
1556 grn_objcxx . . $ grn_obj# *bottom_right_point,
1557 const char *process_name,
1558 in_rectangle_datacxx . . $ in_rectangle_data# *data)
1559 {
1560 in_rectangle_data_fillcxx . . $ in_rectangle_data_fill(c1bed27aa0eca08b).(ctx,
1561 index,
1562 top_left_point,
1563 bottom_right_point,
1564 process_name,
1565 data);
1566 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
1567 goto exit;
1568 }
1569
1570 in_rectangle_data_validatecxx . . $ in_rectangle_data_validate(634a7bbc1c6caab9).(ctx, process_name, data);
1571 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
1572 goto exit;
1573 }
1574
1575 exit:
1576 return ctx->rccxx . . $ _grn_ctx#rc.;
1577 }
1578
1579 #define SAME_BIT_Pcxx . . $ `lib/geo.c:1579:9`!(a, b, n_bit) \
1580 ((((uint8_t *)(a))[(n_bit) / 8] & (1 << (7 - ((n_bit) % 8)))) == \
1581 (((uint8_t *)(b))[(n_bit) / 8] & (1 << (7 - ((n_bit) % 8)))))
1582
1583 #define CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(entry, name, other_key) \
1584 do { \
1585 if (SAME_BIT_Pcxx . . $ `lib/geo.c:1579:9`!((entry)->key, (other_key), (entry)->target_bit)) { \
1586 (entry)->status_flags |= GRN_GEO_CURSOR_ENTRY_STATUS_##name; \
1587 } else { \
1588 (entry)->status_flags &= ~GRN_GEO_CURSOR_ENTRY_STATUS_##name; \
1589 } \
1590 } while (0)
1591
1592 #define CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, name) \
1593 ((entry)->status_flags & GRN_GEO_CURSOR_ENTRY_STATUS_##name)
1594 #define CURSOR_ENTRY_IS_INNERcxx . . $ `lib/geo.c:1594:9`!(entry) \
1595 (((entry)->status_flags & (GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNER | \
1596 GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNER)) == \
1597 (GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNER | \
1598 GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNER))
1599 #define CURSOR_ENTRY_INCLUDED_IN_LATITUDE_DIRECTIONcxx . . $ `lib/geo.c:1599:9`!(entry) \
1600 ((entry)->status_flags & (GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNER | \
1601 GRN_GEO_CURSOR_ENTRY_STATUS_TOP_INCLUDED | \
1602 GRN_GEO_CURSOR_ENTRY_STATUS_BOTTOM_INCLUDED))
1603 #define CURSOR_ENTRY_INCLUDED_IN_LONGITUDE_DIRECTIONcxx . . $ `lib/geo.c:1603:9`!(entry) \
1604 ((entry)->status_flags & (GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNER | \
1605 GRN_GEO_CURSOR_ENTRY_STATUS_LEFT_INCLUDED | \
1606 GRN_GEO_CURSOR_ENTRY_STATUS_RIGHT_INCLUDED))
1607
1608 #define SET_N_BITcxx . . $ `lib/geo.c:1608:9`!(a, n_bit) \
1609 (((uint8_t *)(a))[((n_bit) / 8)] ^= (1 << (7 - ((n_bit) % 8))))
1610
1611 #define N_BITcxx . . $ `lib/geo.c:1611:9`!(a, n_bit) \
1612 ((((uint8_t *)(a))[((n_bit) / 8)] & (1 << (7 - ((n_bit) % 8)))) >> \
1613 (1 << (7 - ((n_bit) % 8))))
1614
1615 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
1616 extract_rectangle_in_areacxx . . $ extract_rectangle_in_area(a408629daf1df873).(grn_ctxcxx . . $ grn_ctx# *ctx,
1617 grn_geo_area_typecxx . . $ grn_geo_area_type# area_type,
1618 const grn_geo_pointcxx . . $ grn_geo_point# *top_left,
1619 const grn_geo_pointcxx . . $ grn_geo_point# *bottom_right,
1620 grn_geo_pointcxx . . $ grn_geo_point# *area_top_left,
1621 grn_geo_pointcxx . . $ grn_geo_point# *area_bottom_right)
1622 {
1623 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! out_of_area = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
1624 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! cover_all_areas = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
1625
1626 if ((GRN_GEO_POINT_IN_NORTH_WESTcxx . . $ `lib/geo.c:39:9`!(top_left) &&
1627 GRN_GEO_POINT_IN_SOUTH_EASTcxx . . $ `lib/geo.c:43:9`!(bottom_right)) ||
1628 (GRN_GEO_POINT_IN_NORTH_EASTcxx . . $ `lib/geo.c:37:9`!(top_left) &&
1629 GRN_GEO_POINT_IN_SOUTH_WESTcxx . . $ `lib/geo.c:41:9`!(bottom_right))) {
1630 cover_all_areas = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1631 }
1632
1633 switch (area_type) {
1634 case GRN_GEO_AREA_NORTH_EASTcxx . . $ GRN_GEO_AREA_NORTH_EAST.:
1635 if (cover_all_areas || GRN_GEO_POINT_IN_NORTH_EASTcxx . . $ `lib/geo.c:37:9`!(top_left) ||
1636 GRN_GEO_POINT_IN_NORTH_EASTcxx . . $ `lib/geo.c:37:9`!(bottom_right)) {
1637 area_top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(top_left->latitude, 0);
1638 area_bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(bottom_right->latitude, 0);
1639 if (GRN_GEO_LONGITUDE_IS_WRAPPEDcxx . . $ `lib/geo.c:46:9`!(top_left, bottom_right)) {
1640 area_top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1641 area_bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = GRN_GEO_MAX_LONGITUDEcxx . . $ `lib/grn_geo.h:39:9`!;
1642 } else {
1643 area_top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(top_left->longitude, 0);
1644 area_bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(bottom_right->longitude, 0);
1645 }
1646 } else {
1647 out_of_area = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1648 }
1649 break;
1650 case GRN_GEO_AREA_NORTH_WESTcxx . . $ GRN_GEO_AREA_NORTH_WEST.:
1651 if (cover_all_areas || GRN_GEO_POINT_IN_NORTH_WESTcxx . . $ `lib/geo.c:39:9`!(top_left) ||
1652 GRN_GEO_POINT_IN_NORTH_WESTcxx . . $ `lib/geo.c:39:9`!(bottom_right)) {
1653 area_top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(top_left->latitude, 0);
1654 area_bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(bottom_right->latitude, 0);
1655 if (GRN_GEO_LONGITUDE_IS_WRAPPEDcxx . . $ `lib/geo.c:46:9`!(top_left, bottom_right)) {
1656 area_top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = GRN_GEO_MIN_LONGITUDEcxx . . $ `lib/grn_geo.h:41:9`!;
1657 area_bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1658 } else {
1659 area_top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(top_left->longitude, -1);
1660 area_bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(bottom_right->longitude, -1);
1661 }
1662 } else {
1663 out_of_area = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1664 }
1665 break;
1666 case GRN_GEO_AREA_SOUTH_WESTcxx . . $ GRN_GEO_AREA_SOUTH_WEST.:
1667 if (cover_all_areas || GRN_GEO_POINT_IN_SOUTH_WESTcxx . . $ `lib/geo.c:41:9`!(top_left) ||
1668 GRN_GEO_POINT_IN_SOUTH_WESTcxx . . $ `lib/geo.c:41:9`!(bottom_right)) {
1669 area_top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(top_left->latitude, -1);
1670 area_bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(bottom_right->latitude, -1);
1671 if (GRN_GEO_LONGITUDE_IS_WRAPPEDcxx . . $ `lib/geo.c:46:9`!(top_left, bottom_right)) {
1672 area_top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = GRN_GEO_MIN_LONGITUDEcxx . . $ `lib/grn_geo.h:41:9`!;
1673 area_bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1674 } else {
1675 area_top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(top_left->longitude, -1);
1676 area_bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(bottom_right->longitude, -1);
1677 }
1678 } else {
1679 out_of_area = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1680 }
1681 break;
1682 case GRN_GEO_AREA_SOUTH_EASTcxx . . $ GRN_GEO_AREA_SOUTH_EAST.:
1683 if (cover_all_areas || GRN_GEO_POINT_IN_SOUTH_EASTcxx . . $ `lib/geo.c:43:9`!(top_left) ||
1684 GRN_GEO_POINT_IN_SOUTH_EASTcxx . . $ `lib/geo.c:43:9`!(bottom_right)) {
1685 area_top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(top_left->latitude, -1);
1686 area_bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(bottom_right->latitude, -1);
1687 if (GRN_GEO_LONGITUDE_IS_WRAPPEDcxx . . $ `lib/geo.c:46:9`!(top_left, bottom_right)) {
1688 area_top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.;
1689 area_bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = GRN_GEO_MAX_LONGITUDEcxx . . $ `lib/grn_geo.h:39:9`!;
1690 } else {
1691 area_top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(top_left->longitude, 0);
1692 area_bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. = MAXcxx . . $ `<external>/1231830743887005719/param.h:103:9`!(bottom_right->longitude, 0);
1693 }
1694 } else {
1695 out_of_area = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1696 }
1697 break;
1698 default:
1699 out_of_area = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1700 break;
1701 }
1702
1703 return out_of_area;
1704 }
1705
1706 static void
1707 grn_geo_cursor_area_initcxx . . $ grn_geo_cursor_area_init(fa50d0d737ad479b).(grn_ctxcxx . . $ grn_ctx# *ctx,
1708 grn_geo_cursor_areacxx . . $ grn_geo_cursor_area# *area,
1709 grn_geo_area_typecxx . . $ grn_geo_area_type# area_type,
1710 const grn_geo_pointcxx . . $ grn_geo_point# *top_left,
1711 const grn_geo_pointcxx . . $ grn_geo_point# *bottom_right)
1712 {
1713 grn_geo_pointcxx . . $ grn_geo_point# area_top_left, area_bottom_right;
1714 in_rectangle_area_datacxx . . $ in_rectangle_area_data# data;
1715 grn_geo_cursor_entrycxx . . $ grn_geo_cursor_entry# *entry;
1716 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! out_of_area;
1717
1718 out_of_area = extract_rectangle_in_areacxx . . $ extract_rectangle_in_area(a408629daf1df873).(ctx,
1719 area_type,
1720 top_left,
1721 bottom_right,
1722 &area_top_left,
1723 &area_bottom_right);
1724 if (out_of_area) {
1725 area->current_entrycxx . . $ $anonymous_type_7c56213e446f27c4_4#current_entry. = -1;
1726 return;
1727 }
1728
1729 area->current_entrycxx . . $ $anonymous_type_7c56213e446f27c4_4#current_entry. = 0;
1730 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(&(area->top_left), &area_top_left, sizeof(grn_geo_point));
1731 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(&(area->bottom_right), &area_bottom_right, sizeof(grn_geo_point));
1732 grn_gtoncxx . . $ `lib/grn.h:648:9`!(area->top_left_key, &area_top_left, sizeof(grn_geo_point));
1733 grn_gtoncxx . . $ `lib/grn.h:648:9`!(area->bottom_right_key, &area_bottom_right, sizeof(grn_geo_point));
1734
1735 entry = &(area->entriescxx . . $ $anonymous_type_7c56213e446f27c4_4#entries.[area->current_entrycxx . . $ $anonymous_type_7c56213e446f27c4_4#current_entry.]);
1736 in_rectangle_area_data_computecxx . . $ in_rectangle_area_data_compute(ede52f6bc8216).(ctx,
1737 &area_top_left,
1738 &area_bottom_right,
1739 &data);
1740 entry->target_bitcxx . . $ $anonymous_type_7c56213e446f27c4_3#target_bit. = data.rectangle_common_bitcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#rectangle_common_bit.;
1741 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(entry->key, data.rectangle_common_key, sizeof(grn_geo_point));
1742 entry->status_flagscxx . . $ $anonymous_type_7c56213e446f27c4_3#status_flags. = GRN_GEO_CURSOR_ENTRY_STATUS_TOP_INCLUDEDcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_TOP_INCLUDED. |
1743 GRN_GEO_CURSOR_ENTRY_STATUS_BOTTOM_INCLUDEDcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_BOTTOM_INCLUDED. |
1744 GRN_GEO_CURSOR_ENTRY_STATUS_LEFT_INCLUDEDcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_LEFT_INCLUDED. |
1745 GRN_GEO_CURSOR_ENTRY_STATUS_RIGHT_INCLUDEDcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_RIGHT_INCLUDED.;
1746 if (data.mincxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#min..latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. == area_bottom_right.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. &&
1747 data.maxcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#max..latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. == area_top_left.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.) {
1748 entry->status_flagscxx . . $ $anonymous_type_7c56213e446f27c4_3#status_flags. |= GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNERcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNER.;
1749 }
1750 if (data.mincxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#min..longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. == area_top_left.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. &&
1751 data.maxcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#max..longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. == area_bottom_right.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) {
1752 entry->status_flagscxx . . $ $anonymous_type_7c56213e446f27c4_3#status_flags. |= GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNERcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNER.;
1753 }
1754 }
1755
1756 grn_objcxx . . $ grn_obj# *
1757 grn_geo_cursor_open_in_rectanglecxx . . $ grn_geo_cursor_open_in_rectangle(97e994abda2a4247).(grn_ctxcxx . . $ grn_ctx# *ctx,
1758 grn_objcxx . . $ grn_obj# *index,
1759 grn_objcxx . . $ grn_obj# *top_left_point,
1760 grn_objcxx . . $ grn_obj# *bottom_right_point,
1761 int offset,
1762 int limit)
1763 {
1764 grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *cursor = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1765 in_rectangle_datacxx . . $ in_rectangle_data# data;
1766
1767 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
1768 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&(data.top_left_point_buffer));
1769 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&(data.bottom_right_point_buffer));
1770 if (in_rectangle_data_preparecxx . . $ in_rectangle_data_prepare(a3c4f2a05ab419c2).(ctx,
1771 index,
1772 top_left_point,
1773 bottom_right_point,
1774 "geo_in_rectangle()",
1775 &data)) {
1776 goto exit;
1777 }
1778
1779 cursor = GRN_CALLOCcxx . . $ `lib/grn_alloc.h:42:9`!(sizeof(grn_geo_cursor_in_rectangle));
1780 if (!cursor) {
1781 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_NO_MEMORY_AVAILABLE,
1782 "[geo][cursor][in-rectangle] failed to allocate memory for geo cursor");
1783 goto exit;
1784 }
1785
1786 cursor->patcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat. = data.patcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#pat.;
1787 grn_obj_refercxx . . $ grn_obj_refer(4865d068a46d0f83).(ctx, cursor->patcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat.);
1788 cursor->indexcxx . . $ $anonymous_type_7c56213e446f27c4_5#index. = index;
1789 grn_obj_refercxx . . $ grn_obj_refer(4865d068a46d0f83).(ctx, cursor->indexcxx . . $ $anonymous_type_7c56213e446f27c4_5#index.);
1790 cursor->top_leftcxx . . $ $anonymous_type_7c56213e446f27c4_5#top_left. = *(data.top_leftcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left.);
1791 cursor->bottom_rightcxx . . $ $anonymous_type_7c56213e446f27c4_5#bottom_right. = *(data.bottom_rightcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right.);
1792 cursor->centercxx . . $ $anonymous_type_7c56213e446f27c4_5#center. = data.centercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#center.;
1793 cursor->need_distancecxx . . $ $anonymous_type_7c56213e446f27c4_5#need_distance. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
1794 cursor->pat_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat_cursor. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1795 cursor->ii_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#ii_cursor. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1796 cursor->offsetcxx . . $ $anonymous_type_7c56213e446f27c4_5#offset. = offset;
1797 cursor->restcxx . . $ $anonymous_type_7c56213e446f27c4_5#rest. = limit;
1798
1799 cursor->current_areacxx . . $ $anonymous_type_7c56213e446f27c4_5#current_area. = GRN_GEO_AREA_NORTH_EASTcxx . . $ GRN_GEO_AREA_NORTH_EAST.;
1800 {
1801 grn_geo_area_typecxx . . $ grn_geo_area_type# area_type;
1802 const grn_geo_pointcxx . . $ grn_geo_point# *top_left = &(cursor->top_leftcxx . . $ $anonymous_type_7c56213e446f27c4_5#top_left.);
1803 const grn_geo_pointcxx . . $ grn_geo_point# *bottom_right = &(cursor->bottom_rightcxx . . $ $anonymous_type_7c56213e446f27c4_5#bottom_right.);
1804 for (area_type = GRN_GEO_AREA_NORTH_EASTcxx . . $ GRN_GEO_AREA_NORTH_EAST.; area_type < GRN_GEO_AREA_LASTcxx . . $ GRN_GEO_AREA_LAST.;
1805 area_type++) {
1806 grn_geo_cursor_area_initcxx . . $ grn_geo_cursor_area_init(fa50d0d737ad479b).(ctx,
1807 &(cursor->areascxx . . $ $anonymous_type_7c56213e446f27c4_5#areas.[area_type]),
1808 area_type,
1809 top_left,
1810 bottom_right);
1811 }
1812 }
1813 {
1814 char minimum_reduce_bit_env[GRN_ENV_BUFFER_SIZEcxx . . $ `include/groonga/portability.h:42:9`!];
1815 cursor->minimum_reduce_bitcxx . . $ $anonymous_type_7c56213e446f27c4_5#minimum_reduce_bit. = 0;
1816 grn_getenvcxx . . $ `include/groonga/portability.h:58:11`!("GRN_GEO_IN_RECTANGLE_MINIMUM_REDUCE_BIT",
1817 minimum_reduce_bit_env,
1818 GRN_ENV_BUFFER_SIZEcxx . . $ `include/groonga/portability.h:42:9`!);
1819 if (minimum_reduce_bit_env[0]) {
1820 cursor->minimum_reduce_bitcxx . . $ $anonymous_type_7c56213e446f27c4_5#minimum_reduce_bit. = atoicxx . . $ atoi(5c4306d8553b3696).(minimum_reduce_bit_env);
1821 }
1822 if (cursor->minimum_reduce_bitcxx . . $ $anonymous_type_7c56213e446f27c4_5#minimum_reduce_bit. < 1) {
1823 cursor->minimum_reduce_bitcxx . . $ $anonymous_type_7c56213e446f27c4_5#minimum_reduce_bit. = 1;
1824 }
1825 }
1826 GRN_DB_OBJ_SET_TYPEcxx . . $ `lib/grn_ctx.h:195:9`!(cursor, GRN_CURSOR_COLUMN_GEO_INDEXcxx . . $ `include/groonga/groonga.h:890:9`!);
1827 {
1828 grn_objcxx . . $ grn_obj# *db;
1829 grn_idcxx . . $ grn_id# id;
1830 db = grn_ctx_dbcxx . . $ grn_ctx_db(ddec8e3b1327ceae).(ctx);
1831 id = grn_obj_registercxx . . $ grn_obj_register(5739ee2245199e94).(ctx, db, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0);
1832 DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(cursor)->headercxx . . $ $anonymous_type_4a7c1014017e4c5d_0#header..domaincxx . . $ _grn_obj_header#domain. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
1833 DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(cursor)->rangecxx . . $ $anonymous_type_4a7c1014017e4c5d_0#range. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
1834 grn_db_obj_initcxx . . $ grn_db_obj_init(e57fea19a9dd2af9).(ctx, db, id, DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(cursor));
1835 }
1836
1837 exit:
1838 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, &(data.top_left_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left_point_buffer.));
1839 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, &(data.bottom_right_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right_point_buffer.));
1840 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!((grn_obj *)cursor);
1841 }
1842
1843 static void
1844 grn_geo_cursor_in_rectangle_set_need_distancecxx . . $ grn_geo_cursor_in_rectangle_set_need_distance(23cfc0d55e38b6dc).(grn_ctxcxx . . $ grn_ctx# *ctx,
1845 grn_objcxx . . $ grn_obj# *cursor,
1846 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! need_distance)
1847 {
1848 grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *cursor_in_rectangle =
1849 (grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *)cursor;
1850 cursor_in_rectangle->need_distancecxx . . $ $anonymous_type_7c56213e446f27c4_5#need_distance. = need_distance;
1851 }
1852
1853 static inline boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
1854 grn_geo_cursor_entry_next_pushcxx . . $ grn_geo_cursor_entry_next_push(986e405ba0aaa297).(grn_ctxcxx . . $ grn_ctx# *ctx,
1855 grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *cursor,
1856 grn_geo_cursor_entrycxx . . $ grn_geo_cursor_entry# *entry)
1857 {
1858 grn_geo_cursor_entrycxx . . $ grn_geo_cursor_entry# *next_entry;
1859 grn_geo_pointcxx . . $ grn_geo_point# entry_base;
1860 grn_table_cursorcxx . . $ grn_table_cursor# *pat_cursor;
1861 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! pushed = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
1862
1863 grn_ntogcxx . . $ `lib/grn.h:669:9`!((uint8_t *)(&entry_base), entry->key, sizeof(grn_geo_point));
1864 pat_cursor =
1865 grn_table_cursor_opencxx . . $ grn_table_cursor_open(a4cddc3087c69e91).(ctx,
1866 cursor->patcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat.,
1867 &entry_base,
1868 (unsigned int)(entry->target_bitcxx . . $ $anonymous_type_7c56213e446f27c4_3#target_bit. + 1),
1869 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
1870 0,
1871 0,
1872 -1,
1873 GRN_CURSOR_PREFIXcxx . . $ `include/groonga/table.h:281:9`! | GRN_CURSOR_SIZE_BY_BITcxx . . $ `include/groonga/table.h:282:9`!);
1874 if (pat_cursor) {
1875 if (grn_table_cursor_nextcxx . . $ grn_table_cursor_next(8dd58acc9865e889).(ctx, pat_cursor)) {
1876 grn_geo_cursor_areacxx . . $ grn_geo_cursor_area# *area;
1877 area = &(cursor->areascxx . . $ $anonymous_type_7c56213e446f27c4_5#areas.[cursor->current_areacxx . . $ $anonymous_type_7c56213e446f27c4_5#current_area.]);
1878 next_entry = &(area->entriescxx . . $ $anonymous_type_7c56213e446f27c4_4#entries.[++area->current_entrycxx . . $ $anonymous_type_7c56213e446f27c4_4#current_entry.]);
1879 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(next_entry, entry, sizeof(grn_geo_cursor_entry));
1880 pushed = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1881 }
1882 grn_table_cursor_closecxx . . $ grn_table_cursor_close(4865d068a46d0f83).(ctx, pat_cursor);
1883 }
1884
1885 return pushed;
1886 }
1887
1888 static inline boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
1889 grn_geo_cursor_entry_nextcxx . . $ grn_geo_cursor_entry_next(986e405ba0aaa297).(grn_ctxcxx . . $ grn_ctx# *ctx,
1890 grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *cursor,
1891 grn_geo_cursor_entrycxx . . $ grn_geo_cursor_entry# *entry)
1892 {
1893 uint8_tcxx . . $ uint8_t# *top_left_key;
1894 uint8_tcxx . . $ uint8_t# *bottom_right_key;
1895 int max_target_bit = GRN_GEO_KEY_MAX_BITScxx . . $ `lib/grn_geo.h:43:9`! - cursor->minimum_reduce_bitcxx . . $ $anonymous_type_7c56213e446f27c4_5#minimum_reduce_bit.;
1896 grn_geo_cursor_areacxx . . $ grn_geo_cursor_area# *area = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1897
1898 while (cursor->current_areacxx . . $ $anonymous_type_7c56213e446f27c4_5#current_area. < GRN_GEO_AREA_LASTcxx . . $ GRN_GEO_AREA_LAST.) {
1899 area = &(cursor->areascxx . . $ $anonymous_type_7c56213e446f27c4_5#areas.[cursor->current_areacxx . . $ $anonymous_type_7c56213e446f27c4_5#current_area.]);
1900 if (area->current_entrycxx . . $ $anonymous_type_7c56213e446f27c4_4#current_entry. >= 0) {
1901 break;
1902 }
1903 cursor->current_areacxx . . $ $anonymous_type_7c56213e446f27c4_5#current_area.++;
1904 area = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1905 }
1906
1907 if (!area) {
1908 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
1909 }
1910
1911 top_left_key = area->top_left_keycxx . . $ $anonymous_type_7c56213e446f27c4_4#top_left_key.;
1912 bottom_right_key = area->bottom_right_keycxx . . $ $anonymous_type_7c56213e446f27c4_4#bottom_right_key.;
1913 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(entry,
1914 &(area->entries[area->current_entry--]),
1915 sizeof(grn_geo_cursor_entry));
1916 while (truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!) {
1917 grn_geo_cursor_entrycxx . . $ grn_geo_cursor_entry# next_entry0, next_entry1;
1918 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! pushed = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
1919
1920 /*
1921 top_left_key: tl
1922 bottom_right_key: br
1923
1924 e.g.: top_left_key is at the top left sub mesh and
1925 bottom_right_key is at the bottom right sub mesh.
1926 top_left_key is also at the top left - bottom right
1927 sub-sub mesh and
1928 bottom_right_key is at the bottom right - bottom left
1929 sub-sub mesh.
1930
1931 ^latitude +----+----+----+----+
1932 | 1 |1010|1011|1110|1111|
1933 | | | | | |
1934 | 1 +----+----+----+----+
1935 \/ 0 |1000|1001|1100|1101|
1936 | | tl | | |
1937 +----+----+----+----+
1938 1 |0010|0011|0110|0111|
1939 | | | | |
1940 0 +----+----+----+----+
1941 0 |0000|0001|0100|0101|
1942 | | | br | |
1943 +----+----+----+----+
1944 0 1 0 1
1945 |-------| |-------|
1946 0 1
1947 <------>
1948 longitude
1949
1950 entry.target_bit + 1 -> next_entry0
1951 entry.target_bit + 1 and entry.key ^ (entry.target_bit + 1) in bit
1952 -> next_entry1
1953
1954 entry: represents the biggest mesh.
1955 (1010, 1011, 1110, 1111,
1956 1000, 1001, 1100, 1101,
1957 0010, 0011, 0110, 0111,
1958 0000, 0001, 0100, 0101)
1959 next_entry0: represents bottom sub-mesh.
1960 (0010, 0011, 0110, 0111,
1961 0000, 0001, 0100, 0101)
1962 next_entry1: represents top sub-mesh.
1963 (1010, 1011, 1110, 1111,
1964 1000, 1001, 1100, 1101)
1965
1966 entry->status_flags = TOP_INCLUDED |
1967 BOTTOM_INCLUDED |
1968 LEFT_INCLUDED |
1969 RIGHT_INCLUDED
1970 next_entry0->status_flags = BOTTOM_INCLUDED |
1971 LEFT_INCLUDED |
1972 RIGHT_INCLUDED
1973 next_entry1->status_flags = TOP_INCLUDED |
1974 LEFT_INCLUDED |
1975 RIGHT_INCLUDED
1976
1977 Both next_entry1 and next_entry0 are pushed to the stack in cursor.
1978 */
1979
1980 #ifdef GEO_DEBUG
1981 inspect_cursor_entry(ctx, entry);
1982 #endif
1983
1984 if (entry->target_bitcxx . . $ $anonymous_type_7c56213e446f27c4_3#target_bit. >= max_target_bit) {
1985 #ifdef GEO_DEBUG
1986 printf("%d: force stopping to reduce a mesh\n", entry->target_bit);
1987 #endif
1988 break;
1989 }
1990
1991 if (CURSOR_ENTRY_IS_INNERcxx . . $ `lib/geo.c:1594:9`!(entry)) {
1992 #ifdef GEO_DEBUG
1993 printf("%d: inner entries\n", entry->target_bit);
1994 #endif
1995 break;
1996 }
1997
1998 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(&next_entry0, entry, sizeof(grn_geo_cursor_entry));
1999 next_entry0.target_bitcxx . . $ $anonymous_type_7c56213e446f27c4_3#target_bit.++;
2000 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(&next_entry1, entry, sizeof(grn_geo_cursor_entry));
2001 next_entry1.target_bitcxx . . $ $anonymous_type_7c56213e446f27c4_3#target_bit.++;
2002 SET_N_BITcxx . . $ `lib/geo.c:1608:9`!(next_entry1.key, next_entry1.target_bit);
2003
2004 #ifdef GEO_DEBUG
2005 inspect_cursor_entry_targets(ctx,
2006 entry,
2007 top_left_key,
2008 bottom_right_key,
2009 &next_entry0,
2010 &next_entry1);
2011 #endif
2012
2013 if ((entry->target_bitcxx . . $ $anonymous_type_7c56213e446f27c4_3#target_bit. + 1) % 2 == 0) {
2014 if (CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, TOP_INCLUDED)) {
2015 CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(&next_entry0, TOP_INCLUDED, top_left_key);
2016 CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(&next_entry1, TOP_INCLUDED, top_left_key);
2017 }
2018 if (CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, BOTTOM_INCLUDED)) {
2019 CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(&next_entry0,
2020 BOTTOM_INCLUDED,
2021 bottom_right_key);
2022 CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(&next_entry1,
2023 BOTTOM_INCLUDED,
2024 bottom_right_key);
2025 }
2026
2027 if (CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, TOP_INCLUDED) &&
2028 !CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, BOTTOM_INCLUDED) &&
2029 CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(&next_entry1, TOP_INCLUDED)) {
2030 next_entry0.status_flagscxx . . $ $anonymous_type_7c56213e446f27c4_3#status_flags. |= GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNERcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNER.;
2031 } else if (!CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, TOP_INCLUDED) &&
2032 CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, BOTTOM_INCLUDED) &&
2033 CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(&next_entry0, BOTTOM_INCLUDED)) {
2034 next_entry1.status_flagscxx . . $ $anonymous_type_7c56213e446f27c4_3#status_flags. |= GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNERcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_LATITUDE_INNER.;
2035 }
2036
2037 if (CURSOR_ENTRY_INCLUDED_IN_LATITUDE_DIRECTIONcxx . . $ `lib/geo.c:1599:9`!(&next_entry1)) {
2038 if (grn_geo_cursor_entry_next_pushcxx . . $ grn_geo_cursor_entry_next_push(986e405ba0aaa297).(ctx, cursor, &next_entry1)) {
2039 pushed = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2040 #ifdef GEO_DEBUG
2041 printf("%d: latitude: push 1\n", next_entry1.target_bit);
2042 #endif
2043 }
2044 }
2045 if (CURSOR_ENTRY_INCLUDED_IN_LATITUDE_DIRECTIONcxx . . $ `lib/geo.c:1599:9`!(&next_entry0)) {
2046 if (grn_geo_cursor_entry_next_pushcxx . . $ grn_geo_cursor_entry_next_push(986e405ba0aaa297).(ctx, cursor, &next_entry0)) {
2047 pushed = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2048 #ifdef GEO_DEBUG
2049 printf("%d: latitude: push 0\n", next_entry0.target_bit);
2050 #endif
2051 }
2052 }
2053 } else {
2054 if (CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, RIGHT_INCLUDED)) {
2055 CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(&next_entry0,
2056 RIGHT_INCLUDED,
2057 bottom_right_key);
2058 CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(&next_entry1,
2059 RIGHT_INCLUDED,
2060 bottom_right_key);
2061 }
2062 if (CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, LEFT_INCLUDED)) {
2063 CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(&next_entry0, LEFT_INCLUDED, top_left_key);
2064 CURSOR_ENTRY_UPDATE_STATUScxx . . $ `lib/geo.c:1583:9`!(&next_entry1, LEFT_INCLUDED, top_left_key);
2065 }
2066
2067 if (CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, LEFT_INCLUDED) &&
2068 !CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, RIGHT_INCLUDED) &&
2069 CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(&next_entry0, LEFT_INCLUDED)) {
2070 next_entry1.status_flagscxx . . $ $anonymous_type_7c56213e446f27c4_3#status_flags. |= GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNERcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNER.;
2071 } else if (!CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, LEFT_INCLUDED) &&
2072 CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(entry, RIGHT_INCLUDED) &&
2073 CURSOR_ENTRY_CHECK_STATUScxx . . $ `lib/geo.c:1592:9`!(&next_entry1, RIGHT_INCLUDED)) {
2074 next_entry0.status_flagscxx . . $ $anonymous_type_7c56213e446f27c4_3#status_flags. |= GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNERcxx . . $ GRN_GEO_CURSOR_ENTRY_STATUS_LONGITUDE_INNER.;
2075 }
2076
2077 if (CURSOR_ENTRY_INCLUDED_IN_LONGITUDE_DIRECTIONcxx . . $ `lib/geo.c:1603:9`!(&next_entry1)) {
2078 if (grn_geo_cursor_entry_next_pushcxx . . $ grn_geo_cursor_entry_next_push(986e405ba0aaa297).(ctx, cursor, &next_entry1)) {
2079 pushed = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2080 #ifdef GEO_DEBUG
2081 printf("%d: longitude: push 1\n", next_entry1.target_bit);
2082 #endif
2083 }
2084 }
2085 if (CURSOR_ENTRY_INCLUDED_IN_LONGITUDE_DIRECTIONcxx . . $ `lib/geo.c:1603:9`!(&next_entry0)) {
2086 if (grn_geo_cursor_entry_next_pushcxx . . $ grn_geo_cursor_entry_next_push(986e405ba0aaa297).(ctx, cursor, &next_entry0)) {
2087 pushed = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2088 #ifdef GEO_DEBUG
2089 printf("%d: longitude: push 0\n", next_entry0.target_bit);
2090 #endif
2091 }
2092 }
2093 }
2094
2095 if (pushed) {
2096 #ifdef GEO_DEBUG
2097 int i;
2098
2099 printf("%d: pushed\n", entry->target_bit);
2100 printf("stack:\n");
2101 for (i = area->current_entry; i >= 0; i--) {
2102 grn_geo_cursor_entry *stack_entry;
2103 stack_entry = &(area->entries[i]);
2104 printf("%2d: ", i);
2105 inspect_key(ctx, stack_entry->key);
2106 printf(" ");
2107 print_key_mark(ctx, stack_entry->target_bit);
2108 }
2109 #endif
2110 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(entry,
2111 &(area->entries[area->current_entry--]),
2112 sizeof(grn_geo_cursor_entry));
2113 #ifdef GEO_DEBUG
2114 printf("%d: pop entry\n", entry->target_bit);
2115 #endif
2116 } else {
2117 break;
2118 }
2119 }
2120
2121 #ifdef GEO_DEBUG
2122 printf("found:\n");
2123 inspect_cursor_entry(ctx, entry);
2124 #endif
2125
2126 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2127 }
2128
2129 typedef boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! (*grn_geo_cursor_callbackcxx . . $ grn_geo_cursor_callback#)(grn_ctxcxx . . $ grn_ctx# *ctx,
2130 grn_postingcxx . . $ grn_posting# *posting,
2131 double distance,
2132 void *user_data);
2133
2134 static void
2135 grn_geo_cursor_eachcxx . . $ grn_geo_cursor_each(70723fab98c199c1).(grn_ctxcxx . . $ grn_ctx# *ctx,
2136 grn_objcxx . . $ grn_obj# *geo_cursor,
2137 grn_geo_cursor_callbackcxx . . $ grn_geo_cursor_callback# callback,
2138 void *user_data)
2139 {
2140 grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *cursor;
2141 grn_objcxx . . $ grn_obj# *pat;
2142 grn_table_cursorcxx . . $ grn_table_cursor# *pat_cursor;
2143 grn_iicxx . . $ grn_ii# *ii;
2144 grn_ii_cursorcxx . . $ grn_ii_cursor# *ii_cursor;
2145 grn_postingcxx . . $ grn_posting# *posting = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
2146 grn_geo_pointcxx . . $ grn_geo_point# *current, *top_left, *bottom_right;
2147 grn_idcxx . . $ grn_id# index_id;
2148
2149 cursor = (grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *)geo_cursor;
2150 if (cursor->restcxx . . $ $anonymous_type_7c56213e446f27c4_5#rest. == 0) {
2151 return;
2152 }
2153
2154 pat = cursor->patcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat.;
2155 pat_cursor = cursor->pat_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat_cursor.;
2156 ii = (grn_iicxx . . $ grn_ii# *)(cursor->indexcxx . . $ $anonymous_type_7c56213e446f27c4_5#index.);
2157 ii_cursor = cursor->ii_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#ii_cursor.;
2158 current = &(cursor->currentcxx . . $ $anonymous_type_7c56213e446f27c4_5#current.);
2159 top_left = &(cursor->top_leftcxx . . $ $anonymous_type_7c56213e446f27c4_5#top_left.);
2160 bottom_right = &(cursor->bottom_rightcxx . . $ $anonymous_type_7c56213e446f27c4_5#bottom_right.);
2161
2162 while (truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!) {
2163 if (!pat_cursor) {
2164 grn_geo_cursor_entrycxx . . $ grn_geo_cursor_entry# entry;
2165 grn_geo_pointcxx . . $ grn_geo_point# entry_base;
2166 if (!grn_geo_cursor_entry_nextcxx . . $ grn_geo_cursor_entry_next(986e405ba0aaa297).(ctx, cursor, &entry)) {
2167 cursor->restcxx . . $ $anonymous_type_7c56213e446f27c4_5#rest. = 0;
2168 return;
2169 }
2170 grn_ntogcxx . . $ `lib/grn.h:669:9`!((uint8_t *)(&entry_base), entry.key, sizeof(grn_geo_point));
2171 if (!(cursor->pat_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat_cursor. = pat_cursor = grn_table_cursor_opencxx . . $ grn_table_cursor_open(a4cddc3087c69e91).(
2172 ctx,
2173 pat,
2174 &entry_base,
2175 (unsigned int)(entry.target_bitcxx . . $ $anonymous_type_7c56213e446f27c4_3#target_bit. + 1),
2176 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
2177 0,
2178 0,
2179 -1,
2180 GRN_CURSOR_PREFIXcxx . . $ `include/groonga/table.h:281:9`! | GRN_CURSOR_SIZE_BY_BITcxx . . $ `include/groonga/table.h:282:9`!))) {
2181 cursor->restcxx . . $ $anonymous_type_7c56213e446f27c4_5#rest. = 0;
2182 return;
2183 }
2184 #ifdef GEO_DEBUG
2185 inspect_mesh(ctx, &entry_base, entry.target_bit, 0);
2186 #endif
2187 }
2188
2189 while (ii_cursor || (index_id = grn_table_cursor_nextcxx . . $ grn_table_cursor_next(8dd58acc9865e889).(ctx, pat_cursor))) {
2190 if (!ii_cursor) {
2191 grn_table_get_keycxx . . $ grn_table_get_key(2c24f49dad267d35).(ctx, pat, index_id, current, sizeof(grn_geo_pointcxx . . $ grn_geo_point#));
2192 if (grn_geo_in_rectangle_rawcxx . . $ grn_geo_in_rectangle_raw(673da8d2ce007d30).(ctx, current, top_left, bottom_right)) {
2193 inspect_tidcxx . . $ `lib/geo.c:277:11`!(ctx, index_id, current, 0);
2194 if (!(cursor->ii_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#ii_cursor. = ii_cursor =
2195 grn_ii_cursor_opencxx . . $ grn_ii_cursor_open(5e1f33d5cbef52bd).(ctx,
2196 ii,
2197 index_id,
2198 GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!,
2199 GRN_ID_MAXcxx . . $ `include/groonga/groonga.h:56:9`!,
2200 (int)(ii->n_elementscxx . . $ _grn_ii#n_elements.),
2201 0))) {
2202 continue;
2203 }
2204 } else {
2205 continue;
2206 }
2207 }
2208
2209 while ((posting = grn_ii_cursor_nextcxx . . $ grn_ii_cursor_next(2ca859fa2305fa5c).(ctx, ii_cursor))) {
2210 if (cursor->offsetcxx . . $ $anonymous_type_7c56213e446f27c4_5#offset. == 0) {
2211 double distance = 0.0;
2212 if (cursor->need_distancecxx . . $ $anonymous_type_7c56213e446f27c4_5#need_distance.) {
2213 distance = grn_geo_distance_rectangle_rawcxx . . $ grn_geo_distance_rectangle_raw(efce70e58f1fe0a0).(ctx,
2214 &(cursor->centercxx . . $ $anonymous_type_7c56213e446f27c4_5#center.),
2215 &(cursor->currentcxx . . $ $anonymous_type_7c56213e446f27c4_5#current.));
2216 }
2217 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! keep_each = callback(ctx, posting, distance, user_data);
2218 if (cursor->restcxx . . $ $anonymous_type_7c56213e446f27c4_5#rest. > 0) {
2219 if (--(cursor->restcxx . . $ $anonymous_type_7c56213e446f27c4_5#rest.) == 0) {
2220 keep_each = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2221 }
2222 }
2223 if (!keep_each) {
2224 return;
2225 }
2226 } else {
2227 cursor->offsetcxx . . $ $anonymous_type_7c56213e446f27c4_5#offset.--;
2228 }
2229 }
2230 grn_ii_cursor_closecxx . . $ grn_ii_cursor_close(9f30b86a43abe2c6).(ctx, ii_cursor);
2231 cursor->ii_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#ii_cursor. = ii_cursor = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
2232 }
2233 grn_table_cursor_closecxx . . $ grn_table_cursor_close(4865d068a46d0f83).(ctx, pat_cursor);
2234 cursor->pat_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat_cursor. = pat_cursor = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
2235 }
2236 }
2237
2238 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
2239 grn_geo_cursor_next_callbackcxx . . $ grn_geo_cursor_next_callback(943715117427cffa).(grn_ctxcxx . . $ grn_ctx# *ctx,
2240 grn_postingcxx . . $ grn_posting# *posting,
2241 double distance,
2242 void *user_data)
2243 {
2244 grn_postingcxx . . $ grn_posting# **return_posting = user_data;
2245 *return_posting = posting;
2246 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2247 }
2248
2249 grn_postingcxx . . $ grn_posting# *
2250 grn_geo_cursor_nextcxx . . $ grn_geo_cursor_next(2f2e60582ae32319).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *geo_cursor)
2251 {
2252 grn_postingcxx . . $ grn_posting# *posting = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
2253 grn_geo_cursor_eachcxx . . $ grn_geo_cursor_each(70723fab98c199c1).(ctx, geo_cursor, grn_geo_cursor_next_callbackcxx . . $ grn_geo_cursor_next_callback(943715117427cffa)., &posting);
2254 return posting;
2255 }
2256
2257 grn_rccxx . . $ grn_rc#
2258 grn_geo_cursor_closecxx . . $ grn_geo_cursor_close(4865d068a46d0f83).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *geo_cursor)
2259 {
2260 grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *cursor;
2261
2262 if (!geo_cursor) {
2263 return GRN_INVALID_ARGUMENTcxx . . $ GRN_INVALID_ARGUMENT.;
2264 }
2265
2266 cursor = (grn_geo_cursor_in_rectanglecxx . . $ grn_geo_cursor_in_rectangle# *)geo_cursor;
2267 if (cursor->patcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat.) {
2268 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, cursor->patcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat.);
2269 }
2270 if (cursor->indexcxx . . $ $anonymous_type_7c56213e446f27c4_5#index.) {
2271 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, cursor->indexcxx . . $ $anonymous_type_7c56213e446f27c4_5#index.);
2272 }
2273 if (cursor->pat_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat_cursor.) {
2274 grn_table_cursor_closecxx . . $ grn_table_cursor_close(4865d068a46d0f83).(ctx, cursor->pat_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#pat_cursor.);
2275 }
2276 if (cursor->ii_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#ii_cursor.) {
2277 grn_ii_cursor_closecxx . . $ grn_ii_cursor_close(9f30b86a43abe2c6).(ctx, cursor->ii_cursorcxx . . $ $anonymous_type_7c56213e446f27c4_5#ii_cursor.);
2278 }
2279 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(cursor);
2280
2281 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
2282 }
2283
2284 typedef structcxx . . $ $anonymous_type_a6dd5fd738c9bb15_5# {
2285 grn_selector_datacxx . . $ grn_selector_data# *selector_datacxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#selector_data.;
2286 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! use_distancecxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#use_distance.;
2287 grn_hashcxx . . $ grn_hash# *rescxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#res.;
2288 grn_operatorcxx . . $ grn_operator# opcxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#op.;
2289 } grn_geo_select_in_rectangle_datacxx . . $ grn_geo_select_in_rectangle_data#;
2290
2291 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
2292 grn_geo_select_in_rectangle_callbackcxx . . $ grn_geo_select_in_rectangle_callback(943715117427cffa).(grn_ctxcxx . . $ grn_ctx# *ctx,
2293 grn_postingcxx . . $ grn_posting# *posting,
2294 double distance,
2295 void *user_data)
2296 {
2297 grn_geo_select_in_rectangle_datacxx . . $ grn_geo_select_in_rectangle_data# *data = user_data;
2298 grn_posting_internalcxx . . $ grn_posting_internal# add_posting = *((grn_posting_internalcxx . . $ grn_posting_internal# *)posting);
2299 if (data->use_distancecxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#use_distance.) {
2300 add_posting.weight_floatcxx . . $ $anonymous_type_fe7b80c5b60468ac_0#weight_float. =
2301 (float)((add_posting.weight_floatcxx . . $ $anonymous_type_fe7b80c5b60468ac_0#weight_float. + 1.0) * distance);
2302 } else {
2303 add_posting.weight_floatcxx . . $ $anonymous_type_fe7b80c5b60468ac_0#weight_float. += 1.0f;
2304 }
2305 grn_ii_posting_add_floatcxx . . $ grn_ii_posting_add_float(62be95d159451db1).(ctx,
2306 (grn_postingcxx . . $ grn_posting# *)(&add_posting),
2307 data->rescxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#res.,
2308 data->opcxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#op.);
2309 return ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.;
2310 }
2311
2312 grn_rccxx . . $ grn_rc#
2313 grn_geo_select_in_rectanglecxx . . $ grn_geo_select_in_rectangle(e0babf7a429da9d6).(grn_ctxcxx . . $ grn_ctx# *ctx,
2314 grn_objcxx . . $ grn_obj# *index,
2315 grn_objcxx . . $ grn_obj# *top_left_point,
2316 grn_objcxx . . $ grn_obj# *bottom_right_point,
2317 grn_objcxx . . $ grn_obj# *res,
2318 grn_operatorcxx . . $ grn_operator# op)
2319 {
2320 grn_objcxx . . $ grn_obj# *cursor;
2321
2322 grn_geo_select_in_rectangle_datacxx . . $ grn_geo_select_in_rectangle_data# data;
2323 data.selector_datacxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#selector_data. = grn_selector_data_getcxx . . $ grn_selector_data_get(e834f84f98eef4a5).(ctx);
2324 data.use_distancecxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#use_distance. =
2325 (data.selector_datacxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#selector_data. &&
2326 grn_selector_data_have_score_columncxx . . $ grn_selector_data_have_score_column(87993b14c3eb9c5f).(ctx, data.selector_datacxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#selector_data.));
2327 data.rescxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#res. = (grn_hashcxx . . $ grn_hash# *)res;
2328 data.opcxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#op. = op;
2329 cursor = grn_geo_cursor_open_in_rectanglecxx . . $ grn_geo_cursor_open_in_rectangle(97e994abda2a4247).(ctx,
2330 index,
2331 top_left_point,
2332 bottom_right_point,
2333 0,
2334 -1);
2335 if (cursor) {
2336 grn_geo_cursor_in_rectangle_set_need_distancecxx . . $ grn_geo_cursor_in_rectangle_set_need_distance(23cfc0d55e38b6dc).(ctx,
2337 cursor,
2338 data.use_distancecxx . . $ $anonymous_type_a6dd5fd738c9bb15_5#use_distance.);
2339 grn_geo_cursor_eachcxx . . $ grn_geo_cursor_each(70723fab98c199c1).(ctx,
2340 cursor,
2341 grn_geo_select_in_rectangle_callbackcxx . . $ grn_geo_select_in_rectangle_callback(943715117427cffa).,
2342 &data);
2343 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, cursor);
2344 grn_ii_resolve_sel_andcxx . . $ grn_ii_resolve_sel_and(8582dd5db79648f2).(ctx, (grn_hashcxx . . $ grn_hash# *)res, op);
2345 }
2346
2347 return ctx->rccxx . . $ _grn_ctx#rc.;
2348 }
2349
2350 static grn_rccxx . . $ grn_rc#
2351 geo_point_getcxx . . $ geo_point_get(c2a953968d52cf93).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *pat, int flags, grn_geo_pointcxx . . $ grn_geo_point# *geo_point)
2352 {
2353 grn_rccxx . . $ grn_rc# rc = GRN_SUCCESScxx . . $ GRN_SUCCESS.;
2354 grn_idcxx . . $ grn_id# id;
2355 grn_table_cursorcxx . . $ grn_table_cursor# *cursor = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
2356
2357 cursor = grn_table_cursor_opencxx . . $ grn_table_cursor_open(a4cddc3087c69e91).(ctx,
2358 pat,
2359 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
2360 0,
2361 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!,
2362 0,
2363 0,
2364 1,
2365 GRN_CURSOR_BY_KEYcxx . . $ `include/groonga/table.h:279:9`! | flags);
2366 if (!cursor) {
2367 rc = ctx->rccxx . . $ _grn_ctx#rc.;
2368 goto exit;
2369 }
2370
2371 id = grn_table_cursor_nextcxx . . $ grn_table_cursor_next(8dd58acc9865e889).(ctx, cursor);
2372 if (id == GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!) {
2373 rc = GRN_END_OF_DATAcxx . . $ GRN_END_OF_DATA.;
2374 } else {
2375 void *key;
2376 int key_size;
2377 key_size = grn_table_cursor_get_keycxx . . $ grn_table_cursor_get_key(7d620ebe94cee13a).(ctx, cursor, &key);
2378 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(geo_point, key, (size_t)key_size);
2379 }
2380
2381 exit:
2382 if (cursor) {
2383 grn_table_cursor_closecxx . . $ grn_table_cursor_close(4865d068a46d0f83).(ctx, cursor);
2384 }
2385 return rc;
2386 }
2387
2388 uint32_tcxx . . $ uint32_t#
2389 grn_geo_estimate_size_in_rectanglecxx . . $ grn_geo_estimate_size_in_rectangle(e84a6715c47f7dd8).(grn_ctxcxx . . $ grn_ctx# *ctx,
2390 grn_objcxx . . $ grn_obj# *index,
2391 grn_objcxx . . $ grn_obj# *top_left_point,
2392 grn_objcxx . . $ grn_obj# *bottom_right_point)
2393 {
2394 uint32_tcxx . . $ uint32_t# n = 0;
2395 unsigned int total_records;
2396 grn_rccxx . . $ grn_rc# rc;
2397 in_rectangle_datacxx . . $ in_rectangle_data# data;
2398
2399 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&(data.top_left_point_buffer));
2400 GRN_VOID_INITcxx . . $ `include/groonga/groonga.h:2749:9`!(&(data.bottom_right_point_buffer));
2401 if (in_rectangle_data_preparecxx . . $ in_rectangle_data_prepare(a3c4f2a05ab419c2).(ctx,
2402 index,
2403 top_left_point,
2404 bottom_right_point,
2405 "grn_geo_estimate_in_rectangle()",
2406 &data)) {
2407 goto exit;
2408 }
2409
2410 total_records = grn_table_sizecxx . . $ grn_table_size(8dd58acc9865e889).(ctx, data.patcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#pat.);
2411 if (total_records > 0) {
2412 grn_geo_pointcxx . . $ grn_geo_point# min, max;
2413 int select_latitude_distance, select_longitude_distance;
2414 int total_latitude_distance, total_longitude_distance;
2415 double select_ratio;
2416 double estimated_n_records;
2417 in_rectangle_area_datacxx . . $ in_rectangle_area_data# area_data;
2418
2419 rc = geo_point_getcxx . . $ geo_point_get(c2a953968d52cf93).(ctx, data.patcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#pat., GRN_CURSOR_ASCENDINGcxx . . $ `include/groonga/table.h:273:9`!, &min);
2420 if (!rc) {
2421 rc = geo_point_getcxx . . $ geo_point_get(c2a953968d52cf93).(ctx, data.patcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#pat., GRN_CURSOR_DESCENDINGcxx . . $ `include/groonga/table.h:274:9`!, &max);
2422 }
2423 if (rc) {
2424 if (rc == GRN_END_OF_DATAcxx . . $ GRN_END_OF_DATA.) {
2425 n = total_records;
2426 rc = GRN_SUCCESScxx . . $ GRN_SUCCESS.;
2427 }
2428 goto exit;
2429 }
2430
2431 in_rectangle_area_data_computecxx . . $ in_rectangle_area_data_compute(ede52f6bc8216).(ctx,
2432 data.top_leftcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left.,
2433 data.bottom_rightcxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right.,
2434 &area_data);
2435 select_latitude_distance =
2436 abscxx . . $ abs(7864480464b09eea).(area_data.maxcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#max..latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. - area_data.mincxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#min..latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.);
2437 select_longitude_distance =
2438 abscxx . . $ abs(7864480464b09eea).(area_data.maxcxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#max..longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. - area_data.mincxx . . $ $anonymous_type_a6dd5fd738c9bb15_3#min..longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.);
2439 total_latitude_distance = abscxx . . $ abs(7864480464b09eea).(max.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. - min.latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.);
2440 total_longitude_distance = abscxx . . $ abs(7864480464b09eea).(max.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. - min.longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.);
2441
2442 select_ratio = 1.0;
2443 if (select_latitude_distance < total_latitude_distance) {
2444 select_ratio *=
2445 ((double)select_latitude_distance / (double)total_latitude_distance);
2446 }
2447 if (select_longitude_distance < total_longitude_distance) {
2448 select_ratio *=
2449 ((double)select_longitude_distance / (double)total_longitude_distance);
2450 }
2451 estimated_n_records = ceil(total_records * select_ratio);
2452 n = (uint32_tcxx . . $ uint32_t#)estimated_n_records;
2453 }
2454
2455 exit:
2456 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, &(data.top_left_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#top_left_point_buffer.));
2457 grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, &(data.bottom_right_point_buffercxx . . $ $anonymous_type_a6dd5fd738c9bb15_2#bottom_right_point_buffer.));
2458 return n;
2459 }
2460
2461 int
2462 grn_geo_estimate_in_rectanglecxx . . $ grn_geo_estimate_in_rectangle(41a6f2b01778f011).(grn_ctxcxx . . $ grn_ctx# *ctx,
2463 grn_objcxx . . $ grn_obj# *index,
2464 grn_objcxx . . $ grn_obj# *top_left_point,
2465 grn_objcxx . . $ grn_obj# *bottom_right_point)
2466 {
2467 uint32_tcxx . . $ uint32_t# size;
2468
2469 size = grn_geo_estimate_size_in_rectanglecxx . . $ grn_geo_estimate_size_in_rectangle(e84a6715c47f7dd8).(ctx,
2470 index,
2471 top_left_point,
2472 bottom_right_point);
2473 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
2474 return -1;
2475 }
2476
2477 return (int)size;
2478 }
2479
2480 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
2481 grn_geo_in_circlecxx . . $ grn_geo_in_circle(e6c95e462de3c07).(grn_ctxcxx . . $ grn_ctx# *ctx,
2482 grn_objcxx . . $ grn_obj# *point,
2483 grn_objcxx . . $ grn_obj# *center,
2484 grn_objcxx . . $ grn_obj# *radius_or_point,
2485 grn_geo_approximate_typecxx . . $ grn_geo_approximate_type# approximate_type)
2486 {
2487 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! r = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2488 grn_objcxx . . $ grn_obj# center_, radius_or_point_;
2489 grn_idcxx . . $ grn_id# domain = point->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.;
2490 if (domain == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. || domain == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
2491 grn_geo_distance_raw_funccxx . . $ grn_geo_distance_raw_func# distance_raw_func;
2492 double d;
2493 if (center->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. != domain) {
2494 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&center_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain);
2495 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, center, &center_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
2496 goto exit;
2497 }
2498 center = &center_;
2499 }
2500
2501 distance_raw_func =
2502 grn_geo_resolve_distance_raw_funccxx . . $ grn_geo_resolve_distance_raw_func(8b468ae8ff6c91db).(ctx, approximate_type, domain);
2503 if (!distance_raw_func) {
2504 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
2505 "unknown approximate type: <%d>",
2506 approximate_type);
2507 goto exit;
2508 }
2509 d = distance_raw_func(ctx,
2510 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point),
2511 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(center));
2512 switch (radius_or_point->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.) {
2513 case GRN_DB_INT32cxx . . $ GRN_DB_INT32.:
2514 r = d <= GRN_INT32_VALUEcxx . . $ `include/groonga/groonga.h:3102:9`!(radius_or_point);
2515 break;
2516 case GRN_DB_UINT32cxx . . $ GRN_DB_UINT32.:
2517 r = d <= GRN_UINT32_VALUEcxx . . $ `include/groonga/groonga.h:3103:9`!(radius_or_point);
2518 break;
2519 case GRN_DB_INT64cxx . . $ GRN_DB_INT64.:
2520 r = d <= GRN_INT64_VALUEcxx . . $ `include/groonga/groonga.h:3104:9`!(radius_or_point);
2521 break;
2522 case GRN_DB_UINT64cxx . . $ GRN_DB_UINT64.:
2523 r = d <= GRN_UINT64_VALUEcxx . . $ `include/groonga/groonga.h:3105:9`!(radius_or_point);
2524 break;
2525 case GRN_DB_FLOAT32cxx . . $ GRN_DB_FLOAT32.:
2526 r = d <= GRN_FLOAT32_VALUEcxx . . $ `include/groonga/groonga.h:3107:9`!(radius_or_point);
2527 break;
2528 case GRN_DB_FLOATcxx . . $ GRN_DB_FLOAT.:
2529 r = d <= GRN_FLOAT_VALUEcxx . . $ `include/groonga/groonga.h:3108:9`!(radius_or_point);
2530 break;
2531 case GRN_DB_SHORT_TEXTcxx . . $ GRN_DB_SHORT_TEXT.:
2532 case GRN_DB_TEXTcxx . . $ GRN_DB_TEXT.:
2533 case GRN_DB_LONG_TEXTcxx . . $ GRN_DB_LONG_TEXT.:
2534 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&radius_or_point_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain);
2535 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, radius_or_point, &radius_or_point_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
2536 goto exit;
2537 }
2538 radius_or_point = &radius_or_point_;
2539 /* fallthru */
2540 case GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT.:
2541 case GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.:
2542 if (domain != radius_or_point->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.) { /* todo */
2543 goto exit;
2544 }
2545 r = d <= distance_raw_func(ctx,
2546 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(radius_or_point),
2547 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(center));
2548 break;
2549 default:
2550 goto exit;
2551 }
2552 } else {
2553 /* todo */
2554 }
2555 exit:
2556 return r;
2557 }
2558
2559 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
2560 grn_geo_in_rectangle_rawcxx . . $ grn_geo_in_rectangle_raw(673da8d2ce007d30).(grn_ctxcxx . . $ grn_ctx# *ctx,
2561 grn_geo_pointcxx . . $ grn_geo_point# *point,
2562 grn_geo_pointcxx . . $ grn_geo_point# *top_left,
2563 grn_geo_pointcxx . . $ grn_geo_point# *bottom_right)
2564 {
2565 if (point->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > top_left->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.) {
2566 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2567 }
2568 if (point->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < bottom_right->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude.) {
2569 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2570 }
2571
2572 if (GRN_GEO_LONGITUDE_IS_WRAPPEDcxx . . $ `lib/geo.c:46:9`!(top_left, bottom_right)) {
2573 if (point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) {
2574 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2575 }
2576 if (point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) {
2577 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2578 }
2579 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2580 } else {
2581 if (point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. < top_left->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) {
2582 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2583 }
2584 if (point->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. > bottom_right->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.) {
2585 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2586 }
2587 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2588 }
2589 }
2590
2591 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
2592 grn_geo_in_rectanglecxx . . $ grn_geo_in_rectangle(67353b157293bb80).(grn_ctxcxx . . $ grn_ctx# *ctx,
2593 grn_objcxx . . $ grn_obj# *point,
2594 grn_objcxx . . $ grn_obj# *top_left,
2595 grn_objcxx . . $ grn_obj# *bottom_right)
2596 {
2597 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! r = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2598 grn_objcxx . . $ grn_obj# top_left_, bottom_right_;
2599 grn_idcxx . . $ grn_id# domain = point->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.;
2600 if (domain == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. || domain == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
2601 if (top_left->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. != domain) {
2602 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&top_left_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain);
2603 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, top_left, &top_left_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
2604 goto exit;
2605 }
2606 top_left = &top_left_;
2607 }
2608 if (bottom_right->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. != domain) {
2609 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&bottom_right_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain);
2610 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, bottom_right, &bottom_right_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
2611 goto exit;
2612 }
2613 bottom_right = &bottom_right_;
2614 }
2615 r = grn_geo_in_rectangle_rawcxx . . $ grn_geo_in_rectangle_raw(673da8d2ce007d30).(ctx,
2616 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point),
2617 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(top_left),
2618 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(bottom_right));
2619 } else {
2620 /* todo */
2621 }
2622 exit:
2623 return r;
2624 }
2625
2626 typedef enumcxx . . $ $anonymous_type_a6dd5fd738c9bb15_6# {
2627 LONGITUDE_SHORTcxx . . $ LONGITUDE_SHORT.,
2628 LONGITUDE_LONGcxx . . $ LONGITUDE_LONG.,
2629 } distance_typecxx . . $ distance_type#;
2630
2631 typedef enumcxx . . $ $anonymous_type_a6dd5fd738c9bb15_7# {
2632 QUADRANT_1STcxx . . $ QUADRANT_1ST.,
2633 QUADRANT_2NDcxx . . $ QUADRANT_2ND.,
2634 QUADRANT_3RDcxx . . $ QUADRANT_3RD.,
2635 QUADRANT_4THcxx . . $ QUADRANT_4TH.,
2636 QUADRANT_1ST_TO_2NDcxx . . $ QUADRANT_1ST_TO_2ND.,
2637 QUADRANT_1ST_TO_3RDcxx . . $ QUADRANT_1ST_TO_3RD.,
2638 QUADRANT_1ST_TO_4THcxx . . $ QUADRANT_1ST_TO_4TH.,
2639 QUADRANT_2ND_TO_1STcxx . . $ QUADRANT_2ND_TO_1ST.,
2640 QUADRANT_2ND_TO_3RDcxx . . $ QUADRANT_2ND_TO_3RD.,
2641 QUADRANT_2ND_TO_4THcxx . . $ QUADRANT_2ND_TO_4TH.,
2642 QUADRANT_3RD_TO_1STcxx . . $ QUADRANT_3RD_TO_1ST.,
2643 QUADRANT_3RD_TO_2NDcxx . . $ QUADRANT_3RD_TO_2ND.,
2644 QUADRANT_3RD_TO_4THcxx . . $ QUADRANT_3RD_TO_4TH.,
2645 QUADRANT_4TH_TO_1STcxx . . $ QUADRANT_4TH_TO_1ST.,
2646 QUADRANT_4TH_TO_2NDcxx . . $ QUADRANT_4TH_TO_2ND.,
2647 QUADRANT_4TH_TO_3RDcxx . . $ QUADRANT_4TH_TO_3RD.,
2648 } quadrant_typecxx . . $ quadrant_type#;
2649
2650 static distance_typecxx . . $ distance_type#
2651 geo_longitude_distance_typecxx . . $ geo_longitude_distance_type(94c420abdaca1ea1).(int start_longitude, int end_longitude)
2652 {
2653 int diff_longitude;
2654 int east_to_west;
2655 int west_to_east;
2656 if (start_longitude >= 0) {
2657 diff_longitude = abscxx . . $ abs(7864480464b09eea).(start_longitude - end_longitude);
2658 } else {
2659 diff_longitude = abscxx . . $ abs(7864480464b09eea).(end_longitude - start_longitude);
2660 }
2661 east_to_west = start_longitude > 0 && end_longitude < 0;
2662 west_to_east = start_longitude < 0 && end_longitude > 0;
2663 if (start_longitude != end_longitude && (east_to_west || west_to_east) &&
2664 diff_longitude > 180 * GRN_GEO_RESOLUTIONcxx . . $ `include/groonga/groonga.h:2954:9`!) {
2665 return LONGITUDE_LONGcxx . . $ LONGITUDE_LONG.;
2666 } else {
2667 return LONGITUDE_SHORTcxx . . $ LONGITUDE_SHORT.;
2668 }
2669 }
2670
2671 static inline quadrant_typecxx . . $ quadrant_type#
2672 geo_quadrant_typecxx . . $ geo_quadrant_type(1023dfb645aa6dfb).(grn_geo_pointcxx . . $ grn_geo_point# *point1, grn_geo_pointcxx . . $ grn_geo_point# *point2)
2673 {
2674 #define QUADRANT_1ST_WITH_AXIScxx . . $ `lib/geo.c:2674:9`!(point) \
2675 (point->longitude >= 0) && (point->latitude >= 0)
2676 #define QUADRANT_2ND_WITH_AXIScxx . . $ `lib/geo.c:2676:9`!(point) \
2677 (point->longitude <= 0) && (point->latitude >= 0)
2678 #define QUADRANT_3RD_WITH_AXIScxx . . $ `lib/geo.c:2678:9`!(point) \
2679 (point->longitude <= 0) && (point->latitude <= 0)
2680 #define QUADRANT_4TH_WITH_AXIScxx . . $ `lib/geo.c:2680:9`!(point) \
2681 (point->longitude >= 0) && (point->latitude <= 0)
2682
2683 if (QUADRANT_1ST_WITH_AXIScxx . . $ `lib/geo.c:2674:9`!(point1) && QUADRANT_1ST_WITH_AXIScxx . . $ `lib/geo.c:2674:9`!(point2)) {
2684 return QUADRANT_1STcxx . . $ QUADRANT_1ST.;
2685 } else if (QUADRANT_2ND_WITH_AXIScxx . . $ `lib/geo.c:2676:9`!(point1) && QUADRANT_2ND_WITH_AXIScxx . . $ `lib/geo.c:2676:9`!(point2)) {
2686 return QUADRANT_2NDcxx . . $ QUADRANT_2ND.;
2687 } else if (QUADRANT_3RD_WITH_AXIScxx . . $ `lib/geo.c:2678:9`!(point1) && QUADRANT_3RD_WITH_AXIScxx . . $ `lib/geo.c:2678:9`!(point2)) {
2688 return QUADRANT_3RDcxx . . $ QUADRANT_3RD.;
2689 } else if (QUADRANT_4TH_WITH_AXIScxx . . $ `lib/geo.c:2680:9`!(point1) && QUADRANT_4TH_WITH_AXIScxx . . $ `lib/geo.c:2680:9`!(point2)) {
2690 return QUADRANT_4THcxx . . $ QUADRANT_4TH.;
2691 } else {
2692 if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. > 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. < 0 &&
2693 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. >= 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. >= 0) {
2694 return QUADRANT_1ST_TO_2NDcxx . . $ QUADRANT_1ST_TO_2ND.;
2695 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. < 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. > 0 &&
2696 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. >= 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. >= 0) {
2697 return QUADRANT_2ND_TO_1STcxx . . $ QUADRANT_2ND_TO_1ST.;
2698 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. < 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. > 0 &&
2699 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. <= 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. <= 0) {
2700 return QUADRANT_3RD_TO_4THcxx . . $ QUADRANT_3RD_TO_4TH.;
2701 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. > 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. < 0 &&
2702 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. <= 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. <= 0) {
2703 return QUADRANT_4TH_TO_3RDcxx . . $ QUADRANT_4TH_TO_3RD.;
2704 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= 0 &&
2705 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < 0) {
2706 return QUADRANT_1ST_TO_4THcxx . . $ QUADRANT_1ST_TO_4TH.;
2707 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= 0 &&
2708 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > 0) {
2709 return QUADRANT_4TH_TO_1STcxx . . $ QUADRANT_4TH_TO_1ST.;
2710 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= 0 &&
2711 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < 0) {
2712 return QUADRANT_2ND_TO_3RDcxx . . $ QUADRANT_2ND_TO_3RD.;
2713 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= 0 &&
2714 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > 0) {
2715 return QUADRANT_3RD_TO_2NDcxx . . $ QUADRANT_3RD_TO_2ND.;
2716 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= 0 &&
2717 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < 0) {
2718 return QUADRANT_1ST_TO_3RDcxx . . $ QUADRANT_1ST_TO_3RD.;
2719 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= 0 &&
2720 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > 0) {
2721 return QUADRANT_3RD_TO_1STcxx . . $ QUADRANT_3RD_TO_1ST.;
2722 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= 0 &&
2723 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < 0) {
2724 return QUADRANT_2ND_TO_4THcxx . . $ QUADRANT_2ND_TO_4TH.;
2725 } else if (point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. >= 0 && point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude. <= 0 &&
2726 point1->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. < 0 && point2->latitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#latitude. > 0) {
2727 return QUADRANT_4TH_TO_2NDcxx . . $ QUADRANT_4TH_TO_2ND.;
2728 } else {
2729 /* FIXME */
2730 return QUADRANT_1STcxx . . $ QUADRANT_1ST.;
2731 }
2732 }
2733 #undef QUADRANT_1ST_WITH_AXIScxx . . $ `lib/geo.c:2674:9`!
2734 #undef QUADRANT_2ND_WITH_AXIScxx . . $ `lib/geo.c:2676:9`!
2735 #undef QUADRANT_3RD_WITH_AXIScxx . . $ `lib/geo.c:2678:9`!
2736 #undef QUADRANT_4TH_WITH_AXIScxx . . $ `lib/geo.c:2680:9`!
2737 }
2738
2739 static inline double
2740 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(double start_longitude,
2741 double start_latitude,
2742 double end_longitude,
2743 double end_latitude)
2744 {
2745 double diff_longitude;
2746 double x, y;
2747
2748 diff_longitude = end_longitude - start_longitude;
2749 x = diff_longitude * cos((start_latitude + end_latitude) * 0.5);
2750 y = end_latitude - start_latitude;
2751 return sqrt((x * x) + (y * y));
2752 }
2753
2754 static inline double
2755 geo_distance_rectangle_short_dist_typecxx . . $ geo_distance_rectangle_short_dist_type(bf9db5636e64e736).(
2756 quadrant_typecxx . . $ quadrant_type# quad_type, double lng1, double lat1, double lng2, double lat2)
2757 {
2758 double distance;
2759 double longitude_delta, latitude_delta;
2760
2761 if (quad_type == QUADRANT_1ST_TO_4THcxx . . $ QUADRANT_1ST_TO_4TH. || quad_type == QUADRANT_4TH_TO_1STcxx . . $ QUADRANT_4TH_TO_1ST. ||
2762 quad_type == QUADRANT_2ND_TO_3RDcxx . . $ QUADRANT_2ND_TO_3RD. || quad_type == QUADRANT_3RD_TO_2NDcxx . . $ QUADRANT_3RD_TO_2ND.) {
2763 longitude_delta = lng2 - lng1;
2764 if (longitude_delta > 0 || longitude_delta < 0) {
2765 if (lat2 > lat1) {
2766 distance = geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1, lat1, lng2, lat2) *
2767 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2768 } else {
2769 distance = geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng2, lat2, lng1, lat1) *
2770 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2771 }
2772 } else {
2773 latitude_delta = fabs(lat1) + fabs(lat2);
2774 distance = sqrt(latitude_delta * latitude_delta) * GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2775 }
2776 } else if (quad_type == QUADRANT_1ST_TO_3RDcxx . . $ QUADRANT_1ST_TO_3RD. ||
2777 quad_type == QUADRANT_2ND_TO_4THcxx . . $ QUADRANT_2ND_TO_4TH.) {
2778 distance = geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1, lat1, lng2, lat2) *
2779 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2780 } else if (quad_type == QUADRANT_3RD_TO_1STcxx . . $ QUADRANT_3RD_TO_1ST. ||
2781 quad_type == QUADRANT_4TH_TO_2NDcxx . . $ QUADRANT_4TH_TO_2ND.) {
2782 distance = geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng2, lat2, lng1, lat1) *
2783 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2784 } else if (quad_type == QUADRANT_1ST_TO_2NDcxx . . $ QUADRANT_1ST_TO_2ND. ||
2785 quad_type == QUADRANT_2ND_TO_1STcxx . . $ QUADRANT_2ND_TO_1ST. ||
2786 quad_type == QUADRANT_3RD_TO_4THcxx . . $ QUADRANT_3RD_TO_4TH. ||
2787 quad_type == QUADRANT_4TH_TO_3RDcxx . . $ QUADRANT_4TH_TO_3RD.) {
2788 if (lat2 > lat1) {
2789 distance = geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1, lat1, lng2, lat2) *
2790 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2791 } else if (lat2 < lat1) {
2792 distance = geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng2, lat2, lng1, lat1) *
2793 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2794 } else {
2795 longitude_delta = lng2 - lng1;
2796 distance = longitude_delta * cos(lat1);
2797 distance = sqrt(distance * distance) * GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2798 }
2799 } else {
2800 distance = geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1, lat1, lng2, lat2) *
2801 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2802 }
2803 return distance;
2804 }
2805
2806 static inline double
2807 geo_distance_rectangle_long_dist_typecxx . . $ geo_distance_rectangle_long_dist_type(bf9db5636e64e736).(
2808 quadrant_typecxx . . $ quadrant_type# quad_type, double lng1, double lat1, double lng2, double lat2)
2809 {
2810 #define M_2PIcxx . . $ `lib/geo.c:2810:9`! 6.28318530717958647692
2811
2812 double distance;
2813
2814 if (quad_type == QUADRANT_1ST_TO_2NDcxx . . $ QUADRANT_1ST_TO_2ND. || quad_type == QUADRANT_4TH_TO_3RDcxx . . $ QUADRANT_4TH_TO_3RD.) {
2815 if (lat1 > lat2) {
2816 distance =
2817 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng2 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat2, lng1, lat1) *
2818 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2819 } else {
2820 distance =
2821 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1, lat1, lng2 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat2) *
2822 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2823 }
2824 } else if (quad_type == QUADRANT_2ND_TO_1STcxx . . $ QUADRANT_2ND_TO_1ST. ||
2825 quad_type == QUADRANT_3RD_TO_4THcxx . . $ QUADRANT_3RD_TO_4TH.) {
2826 if (lat1 > lat2) {
2827 distance =
2828 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng2, lat2, lng1 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat1) *
2829 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2830 } else {
2831 distance =
2832 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat1, lng2, lat2) *
2833 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2834 }
2835 } else if (quad_type == QUADRANT_1ST_TO_3RDcxx . . $ QUADRANT_1ST_TO_3RD.) {
2836 distance =
2837 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng2 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat2, lng1, lat1) *
2838 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2839 } else if (quad_type == QUADRANT_3RD_TO_1STcxx . . $ QUADRANT_3RD_TO_1ST.) {
2840 distance =
2841 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat1, lng2, lat2) *
2842 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2843 } else if (quad_type == QUADRANT_2ND_TO_4THcxx . . $ QUADRANT_2ND_TO_4TH.) {
2844 distance =
2845 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng2, lat2, lng1 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat1) *
2846 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2847 } else if (quad_type == QUADRANT_4TH_TO_2NDcxx . . $ QUADRANT_4TH_TO_2ND.) {
2848 distance =
2849 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1, lat1, lng2 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat2) *
2850 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2851 } else {
2852 if (lng1 > lng2) {
2853 distance =
2854 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1, lat1, lng2 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat2) *
2855 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2856 } else {
2857 distance =
2858 geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng2, lat2, lng1 + M_2PIcxx . . $ `lib/geo.c:2810:9`!, lat1) *
2859 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2860 }
2861 }
2862 return distance;
2863 #undef M_2PIcxx . . $ `lib/geo.c:2810:9`!
2864 }
2865
2866 double
2867 grn_geo_distance_rectangle_rawcxx . . $ grn_geo_distance_rectangle_raw(efce70e58f1fe0a0).(grn_ctxcxx . . $ grn_ctx# *ctx,
2868 grn_geo_pointcxx . . $ grn_geo_point# *point1,
2869 grn_geo_pointcxx . . $ grn_geo_point# *point2)
2870 {
2871
2872 double lng1, lat1, lng2, lat2, distance;
2873 distance_typecxx . . $ distance_type# dist_type;
2874 quadrant_typecxx . . $ quadrant_type# quad_type;
2875
2876 lat1 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point1->latitude);
2877 lng1 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point1->longitude);
2878 lat2 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point2->latitude);
2879 lng2 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point2->longitude);
2880 quad_type = geo_quadrant_typecxx . . $ geo_quadrant_type(1023dfb645aa6dfb).(point1, point2);
2881 if (quad_type <= QUADRANT_4THcxx . . $ QUADRANT_4TH.) {
2882 distance = geo_distance_rectangle_square_rootcxx . . $ geo_distance_rectangle_square_root(6ba6c9f826937c6e).(lng1, lat1, lng2, lat2) *
2883 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2884 } else {
2885 dist_type =
2886 geo_longitude_distance_typecxx . . $ geo_longitude_distance_type(94c420abdaca1ea1).(point1->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude., point2->longitudecxx . . $ $anonymous_type_2a7e33a0c5c5f400_0#longitude.);
2887 if (dist_type == LONGITUDE_SHORTcxx . . $ LONGITUDE_SHORT.) {
2888 distance = geo_distance_rectangle_short_dist_typecxx . . $ geo_distance_rectangle_short_dist_type(bf9db5636e64e736).(quad_type,
2889 lng1,
2890 lat1,
2891 lng2,
2892 lat2);
2893 } else {
2894 distance = geo_distance_rectangle_long_dist_typecxx . . $ geo_distance_rectangle_long_dist_type(bf9db5636e64e736).(quad_type,
2895 lng1,
2896 lat1,
2897 lng2,
2898 lat2);
2899 }
2900 }
2901 return distance;
2902 }
2903
2904 double
2905 grn_geo_distance_sphere_rawcxx . . $ grn_geo_distance_sphere_raw(efce70e58f1fe0a0).(grn_ctxcxx . . $ grn_ctx# *ctx,
2906 grn_geo_pointcxx . . $ grn_geo_point# *point1,
2907 grn_geo_pointcxx . . $ grn_geo_point# *point2)
2908 {
2909 double lng1, lat1, lng2, lat2, x, y;
2910
2911 lat1 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point1->latitude);
2912 lng1 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point1->longitude);
2913 lat2 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point2->latitude);
2914 lng2 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point2->longitude);
2915 x = sin(fabs(lng2 - lng1) * 0.5);
2916 y = sin(fabs(lat2 - lat1) * 0.5);
2917 return asin(sqrt((y * y) + cos(lat1) * cos(lat2) * x * x)) * 2 *
2918 GRN_GEO_RADIUScxx . . $ `lib/grn_geo.h:30:9`!;
2919 }
2920
2921 double
2922 grn_geo_distance_ellipsoid_rawcxx . . $ grn_geo_distance_ellipsoid_raw(93f279ea6bc01a4e).(grn_ctxcxx . . $ grn_ctx# *ctx,
2923 grn_geo_pointcxx . . $ grn_geo_point# *point1,
2924 grn_geo_pointcxx . . $ grn_geo_point# *point2,
2925 int c1,
2926 int c2,
2927 double c3)
2928 {
2929 double lng1, lat1, lng2, lat2, p, q, r, m, n, x, y;
2930
2931 lat1 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point1->latitude);
2932 lng1 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point1->longitude);
2933 lat2 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point2->latitude);
2934 lng2 = GRN_GEO_MSEC2RADIANcxx . . $ `include/groonga/groonga.h:2958:9`!(point2->longitude);
2935 p = (lat1 + lat2) * 0.5;
2936 q = (1 - c3 * sin(p) * sin(p));
2937 r = sqrt(q);
2938 m = c1 / (q * r);
2939 n = c2 / r;
2940 x = n * cos(p) * fabs(lng1 - lng2);
2941 y = m * fabs(lat1 - lat2);
2942 return sqrt((x * x) + (y * y));
2943 }
2944
2945 double
2946 grn_geo_distance_ellipsoid_raw_tokyocxx . . $ grn_geo_distance_ellipsoid_raw_tokyo(efce70e58f1fe0a0).(grn_ctxcxx . . $ grn_ctx# *ctx,
2947 grn_geo_pointcxx . . $ grn_geo_point# *point1,
2948 grn_geo_pointcxx . . $ grn_geo_point# *point2)
2949 {
2950 return grn_geo_distance_ellipsoid_rawcxx . . $ grn_geo_distance_ellipsoid_raw(93f279ea6bc01a4e).(ctx,
2951 point1,
2952 point2,
2953 GRN_GEO_BES_C1cxx . . $ `lib/grn_geo.h:31:9`!,
2954 GRN_GEO_BES_C2cxx . . $ `lib/grn_geo.h:32:9`!,
2955 GRN_GEO_BES_C3cxx . . $ `lib/grn_geo.h:33:9`!);
2956 }
2957
2958 double
2959 grn_geo_distance_ellipsoid_raw_wgs84cxx . . $ grn_geo_distance_ellipsoid_raw_wgs84(efce70e58f1fe0a0).(grn_ctxcxx . . $ grn_ctx# *ctx,
2960 grn_geo_pointcxx . . $ grn_geo_point# *point1,
2961 grn_geo_pointcxx . . $ grn_geo_point# *point2)
2962 {
2963 return grn_geo_distance_ellipsoid_rawcxx . . $ grn_geo_distance_ellipsoid_raw(93f279ea6bc01a4e).(ctx,
2964 point1,
2965 point2,
2966 GRN_GEO_GRS_C1cxx . . $ `lib/grn_geo.h:34:9`!,
2967 GRN_GEO_GRS_C2cxx . . $ `lib/grn_geo.h:35:9`!,
2968 GRN_GEO_GRS_C3cxx . . $ `lib/grn_geo.h:36:9`!);
2969 }
2970
2971 double
2972 grn_geo_distancecxx . . $ grn_geo_distance(c8fc4aa50dd36c79).(grn_ctxcxx . . $ grn_ctx# *ctx,
2973 grn_objcxx . . $ grn_obj# *point1,
2974 grn_objcxx . . $ grn_obj# *point2,
2975 grn_geo_approximate_typecxx . . $ grn_geo_approximate_type# type)
2976 {
2977 double d = 0.0;
2978
2979 switch (type) {
2980 case GRN_GEO_APPROXIMATE_RECTANGLEcxx . . $ GRN_GEO_APPROXIMATE_RECTANGLE.:
2981 d = grn_geo_distance_rectanglecxx . . $ grn_geo_distance_rectangle(58fe0e666eafa6a2).(ctx, point1, point2);
2982 break;
2983 case GRN_GEO_APPROXIMATE_SPHEREcxx . . $ GRN_GEO_APPROXIMATE_SPHERE.:
2984 d = grn_geo_distance_spherecxx . . $ grn_geo_distance_sphere(58fe0e666eafa6a2).(ctx, point1, point2);
2985 break;
2986 case GRN_GEO_APPROXIMATE_ELLIPSOIDcxx . . $ GRN_GEO_APPROXIMATE_ELLIPSOID.:
2987 d = grn_geo_distance_ellipsoidcxx . . $ grn_geo_distance_ellipsoid(58fe0e666eafa6a2).(ctx, point1, point2);
2988 break;
2989 default:
2990 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "unknown approximate type: <%d>", type);
2991 break;
2992 }
2993 return d;
2994 }
2995
2996 grn_rccxx . . $ grn_rc#
2997 grn_geo_distance_sortercxx . . $ grn_geo_distance_sorter(7034fb15f72963af).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_sorter_datacxx . . $ grn_sorter_data# *data)
2998 {
2999 const char *tag = "geo_distance():";
3000
3001 size_t n_args;
3002 grn_objcxx . . $ grn_obj# **args = grn_sorter_data_get_argscxx . . $ grn_sorter_data_get_args(6e0ec7429a6da1fd).(ctx, data, &n_args);
3003 if (!(n_args == 2)) {
3004 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
3005 "%s wrong number of arguments (%u for 2)",
3006 tag,
3007 (uint32_t)n_args);
3008 return ctx->rccxx . . $ _grn_ctx#rc.;
3009 }
3010
3011 grn_objcxx . . $ grn_obj# *table = grn_sorter_data_get_tablecxx . . $ grn_sorter_data_get_table(7614de0143e67c9c).(ctx, data);
3012 size_t offset = grn_sorter_data_get_offsetcxx . . $ grn_sorter_data_get_offset(e2e7e6d68a2b0473).(ctx, data);
3013 size_t limit = grn_sorter_data_get_limitcxx . . $ grn_sorter_data_get_limit(e2e7e6d68a2b0473).(ctx, data);
3014 grn_objcxx . . $ grn_obj# *result = grn_sorter_data_get_resultcxx . . $ grn_sorter_data_get_result(7614de0143e67c9c).(ctx, data);
3015
3016 grn_objcxx . . $ grn_obj# *column = args[0];
3017 grn_objcxx . . $ grn_obj# *point = args[1];
3018
3019 grn_idcxx . . $ grn_id# column_range = grn_obj_get_rangecxx . . $ grn_obj_get_range(8dd58acc9865e889).(ctx, column);
3020 if (!(column_range == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. ||
3021 column_range == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.)) {
3022 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
3023 "%s 1st argument's type must be TokyoGeoPoint or WGS84GeoPoint: %s(%u)",
3024 tag,
3025 grn_type_id_to_string_builtin(ctx, column_range),
3026 column_range);
3027 return ctx->rccxx . . $ _grn_ctx#rc.;
3028 }
3029
3030 grn_objcxx . . $ grn_obj# casted_point;
3031 GRN_VALUE_FIX_SIZE_INITcxx . . $ `include/groonga/groonga.h:2738:9`!(&casted_point, 0, column_range);
3032 grn_rccxx . . $ grn_rc# rc = grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, point, &casted_point, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
3033 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
3034 grn_objcxx . . $ grn_obj# inspected;
3035 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
3036 grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, point);
3037 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
3038 "%s 2nd argument must's %s: <%.*s>",
3039 tag,
3040 grn_type_id_to_string_builtin(ctx, column_range),
3041 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
3042 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
3043 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
3044 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &casted_point);
3045 return ctx->rccxx . . $ _grn_ctx#rc.;
3046 }
3047
3048 grn_geo_table_sortcxx . . $ grn_geo_table_sort(2f9441c09e3051fc).(ctx, table, offset, limit, result, column, &casted_point);
3049 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &casted_point);
3050 return ctx->rccxx . . $ _grn_ctx#rc.;
3051 }
3052
3053 double
3054 grn_geo_distance_rectanglecxx . . $ grn_geo_distance_rectangle(58fe0e666eafa6a2).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *point1, grn_objcxx . . $ grn_obj# *point2)
3055 {
3056 double d = 0;
3057 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! point1_initialized = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
3058 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! point2_initialized = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
3059 grn_objcxx . . $ grn_obj# point1_, point2_;
3060 grn_idcxx . . $ grn_id# domain1 = point1->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.;
3061 grn_idcxx . . $ grn_id# domain2 = point2->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.;
3062 if (domain1 == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. || domain1 == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
3063 if (domain1 != domain2) {
3064 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&point2_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain1);
3065 point2_initialized = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
3066 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, point2, &point2_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
3067 goto exit;
3068 }
3069 point2 = &point2_;
3070 }
3071 } else if (domain2 == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. ||
3072 domain2 == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
3073 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&point1_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain2);
3074 point1_initialized = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
3075 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, point1, &point1_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
3076 goto exit;
3077 }
3078 point1 = &point1_;
3079 } else if ((GRN_DB_SHORT_TEXTcxx . . $ GRN_DB_SHORT_TEXT. <= domain1 && domain1 <= GRN_DB_LONG_TEXTcxx . . $ GRN_DB_LONG_TEXT.) &&
3080 (GRN_DB_SHORT_TEXTcxx . . $ GRN_DB_SHORT_TEXT. <= domain2 && domain2 <= GRN_DB_LONG_TEXTcxx . . $ GRN_DB_LONG_TEXT.)) {
3081 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&point1_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, GRN_DB_WGS84_GEO_POINT);
3082 point1_initialized = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
3083 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, point1, &point1_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
3084 goto exit;
3085 }
3086 point1 = &point1_;
3087
3088 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&point2_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, GRN_DB_WGS84_GEO_POINT);
3089 point2_initialized = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
3090 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, point2, &point2_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
3091 goto exit;
3092 }
3093 point2 = &point2_;
3094 } else {
3095 goto exit;
3096 }
3097 d = grn_geo_distance_rectangle_rawcxx . . $ grn_geo_distance_rectangle_raw(efce70e58f1fe0a0).(ctx,
3098 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point1),
3099 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point2));
3100 exit:
3101 if (point1_initialized) {
3102 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &point1_);
3103 }
3104 if (point2_initialized) {
3105 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &point2_);
3106 }
3107 return d;
3108 }
3109
3110 double
3111 grn_geo_distance_spherecxx . . $ grn_geo_distance_sphere(58fe0e666eafa6a2).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *point1, grn_objcxx . . $ grn_obj# *point2)
3112 {
3113 double d = 0;
3114 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! point2_initialized = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
3115 grn_objcxx . . $ grn_obj# point2_;
3116 grn_idcxx . . $ grn_id# domain = point1->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.;
3117 if (domain == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. || domain == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
3118 if (point2->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. != domain) {
3119 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&point2_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain);
3120 point2_initialized = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
3121 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, point2, &point2_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
3122 goto exit;
3123 }
3124 point2 = &point2_;
3125 }
3126 d = grn_geo_distance_sphere_rawcxx . . $ grn_geo_distance_sphere_raw(efce70e58f1fe0a0).(ctx,
3127 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point1),
3128 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point2));
3129 } else {
3130 /* todo */
3131 }
3132 exit:
3133 if (point2_initialized) {
3134 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &point2_);
3135 }
3136 return d;
3137 }
3138
3139 double
3140 grn_geo_distance_ellipsoidcxx . . $ grn_geo_distance_ellipsoid(58fe0e666eafa6a2).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *point1, grn_objcxx . . $ grn_obj# *point2)
3141 {
3142 double d = 0;
3143 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! point2_initialized = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
3144 grn_objcxx . . $ grn_obj# point2_;
3145 grn_idcxx . . $ grn_id# domain = point1->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain.;
3146 if (domain == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT. || domain == GRN_DB_WGS84_GEO_POINTcxx . . $ GRN_DB_WGS84_GEO_POINT.) {
3147 if (point2->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. != domain) {
3148 GRN_OBJ_INITcxx . . $ `include/groonga/groonga.h:947:9`!(&point2_, GRN_BULKcxx . . $ `include/groonga/groonga.h:868:9`!, 0, domain);
3149 point2_initialized = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
3150 if (grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, point2, &point2_, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
3151 goto exit;
3152 }
3153 point2 = &point2_;
3154 }
3155 if (domain == GRN_DB_TOKYO_GEO_POINTcxx . . $ GRN_DB_TOKYO_GEO_POINT.) {
3156 d = grn_geo_distance_ellipsoid_raw_tokyocxx . . $ grn_geo_distance_ellipsoid_raw_tokyo(efce70e58f1fe0a0).(ctx,
3157 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point1),
3158 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point2));
3159 } else {
3160 d = grn_geo_distance_ellipsoid_raw_wgs84cxx . . $ grn_geo_distance_ellipsoid_raw_wgs84(efce70e58f1fe0a0).(ctx,
3161 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point1),
3162 GRN_GEO_POINT_VALUE_RAWcxx . . $ `include/groonga/groonga.h:3112:9`!(point2));
3163 }
3164 } else {
3165 /* todo */
3166 }
3167 exit:
3168 if (point2_initialized) {
3169 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &point2_);
3170 }
3171 return d;
3172 }