@sentryware/s2-node 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (471) hide show
  1. package/.circleci/config.yml +45 -0
  2. package/.dockerignore +1 -0
  3. package/.gitmodules +3 -0
  4. package/CHANGELOG.md +33 -0
  5. package/LICENSE +201 -0
  6. package/README.md +147 -0
  7. package/binding.gyp +170 -0
  8. package/docker/Dockerfile.node20.test +8 -0
  9. package/docker/Dockerfile.node22.test +8 -0
  10. package/docker/Dockerfile.node24.test +8 -0
  11. package/index.d.ts +117 -0
  12. package/index.js +6 -0
  13. package/jest.config.js +184 -0
  14. package/package.json +43 -0
  15. package/publish-linux.sh +18 -0
  16. package/publish-osx.sh +19 -0
  17. package/src/builder.cc +84 -0
  18. package/src/builder.h +29 -0
  19. package/src/cell.cc +71 -0
  20. package/src/cell.h +26 -0
  21. package/src/cell_id.cc +210 -0
  22. package/src/cell_id.h +44 -0
  23. package/src/cell_union.cc +237 -0
  24. package/src/cell_union.h +34 -0
  25. package/src/earth.cc +185 -0
  26. package/src/earth.h +33 -0
  27. package/src/latlng.cc +132 -0
  28. package/src/latlng.h +28 -0
  29. package/src/loop.cc +51 -0
  30. package/src/loop.h +21 -0
  31. package/src/point.cc +69 -0
  32. package/src/point.h +23 -0
  33. package/src/polygon.cc +36 -0
  34. package/src/polygon.h +20 -0
  35. package/src/polyline.cc +186 -0
  36. package/src/polyline.h +34 -0
  37. package/src/region_coverer.cc +450 -0
  38. package/src/region_coverer.h +56 -0
  39. package/src/s2.cc +27 -0
  40. package/test/Cell.test.js +37 -0
  41. package/test/CellId.test.js +135 -0
  42. package/test/CellUnion.test.js +150 -0
  43. package/test/Earth.test.js +62 -0
  44. package/test/LatLng.test.js +45 -0
  45. package/test/Point.test.js +14 -0
  46. package/test/Polyline.test.js +78 -0
  47. package/test/RegionCoverer.test.js +301 -0
  48. package/test.sh +16 -0
  49. package/third_party/s2geometry/.travis.yml +163 -0
  50. package/third_party/s2geometry/AUTHORS +13 -0
  51. package/third_party/s2geometry/CONTRIBUTING.md +65 -0
  52. package/third_party/s2geometry/CONTRIBUTORS +30 -0
  53. package/third_party/s2geometry/LICENSE +202 -0
  54. package/third_party/s2geometry/NOTICE +5 -0
  55. package/third_party/s2geometry/README.md +127 -0
  56. package/third_party/s2geometry/doc/examples/point_index.cc +44 -0
  57. package/third_party/s2geometry/doc/examples/term_index.cc +99 -0
  58. package/third_party/s2geometry/doc/examples/term_index.py +101 -0
  59. package/third_party/s2geometry/src/python/coder.i +125 -0
  60. package/third_party/s2geometry/src/python/pywraps2_test.py +786 -0
  61. package/third_party/s2geometry/src/python/s2.i +37 -0
  62. package/third_party/s2geometry/src/python/s2_common.i +756 -0
  63. package/third_party/s2geometry/src/s2/_fp_contract_off.h +60 -0
  64. package/third_party/s2geometry/src/s2/base/casts.h +318 -0
  65. package/third_party/s2geometry/src/s2/base/commandlineflags.h +67 -0
  66. package/third_party/s2geometry/src/s2/base/integral_types.h +31 -0
  67. package/third_party/s2geometry/src/s2/base/log_severity.h +40 -0
  68. package/third_party/s2geometry/src/s2/base/logging.h +173 -0
  69. package/third_party/s2geometry/src/s2/base/mutex.h +61 -0
  70. package/third_party/s2geometry/src/s2/base/port.h +999 -0
  71. package/third_party/s2geometry/src/s2/base/spinlock.h +60 -0
  72. package/third_party/s2geometry/src/s2/base/stringprintf.cc +107 -0
  73. package/third_party/s2geometry/src/s2/base/stringprintf.h +53 -0
  74. package/third_party/s2geometry/src/s2/base/strtoint.cc +65 -0
  75. package/third_party/s2geometry/src/s2/base/strtoint.h +106 -0
  76. package/third_party/s2geometry/src/s2/base/timer.h +50 -0
  77. package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector.cc +164 -0
  78. package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector.h +110 -0
  79. package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector_test.cc +232 -0
  80. package/third_party/s2geometry/src/s2/encoded_s2point_vector.cc +838 -0
  81. package/third_party/s2geometry/src/s2/encoded_s2point_vector.h +140 -0
  82. package/third_party/s2geometry/src/s2/encoded_s2point_vector_test.cc +344 -0
  83. package/third_party/s2geometry/src/s2/encoded_s2shape_index.cc +181 -0
  84. package/third_party/s2geometry/src/s2/encoded_s2shape_index.h +276 -0
  85. package/third_party/s2geometry/src/s2/encoded_s2shape_index_test.cc +244 -0
  86. package/third_party/s2geometry/src/s2/encoded_string_vector.cc +66 -0
  87. package/third_party/s2geometry/src/s2/encoded_string_vector.h +164 -0
  88. package/third_party/s2geometry/src/s2/encoded_string_vector_test.cc +69 -0
  89. package/third_party/s2geometry/src/s2/encoded_uint_vector.h +299 -0
  90. package/third_party/s2geometry/src/s2/encoded_uint_vector_test.cc +124 -0
  91. package/third_party/s2geometry/src/s2/id_set_lexicon.cc +81 -0
  92. package/third_party/s2geometry/src/s2/id_set_lexicon.h +199 -0
  93. package/third_party/s2geometry/src/s2/id_set_lexicon_test.cc +70 -0
  94. package/third_party/s2geometry/src/s2/mutable_s2shape_index.cc +1585 -0
  95. package/third_party/s2geometry/src/s2/mutable_s2shape_index.h +600 -0
  96. package/third_party/s2geometry/src/s2/mutable_s2shape_index_test.cc +589 -0
  97. package/third_party/s2geometry/src/s2/r1interval.h +220 -0
  98. package/third_party/s2geometry/src/s2/r1interval_test.cc +185 -0
  99. package/third_party/s2geometry/src/s2/r2.h +26 -0
  100. package/third_party/s2geometry/src/s2/r2rect.cc +93 -0
  101. package/third_party/s2geometry/src/s2/r2rect.h +234 -0
  102. package/third_party/s2geometry/src/s2/r2rect_test.cc +228 -0
  103. package/third_party/s2geometry/src/s2/s1angle.cc +54 -0
  104. package/third_party/s2geometry/src/s2/s1angle.h +336 -0
  105. package/third_party/s2geometry/src/s2/s1angle_test.cc +185 -0
  106. package/third_party/s2geometry/src/s2/s1chord_angle.cc +159 -0
  107. package/third_party/s2geometry/src/s2/s1chord_angle.h +369 -0
  108. package/third_party/s2geometry/src/s2/s1chord_angle_test.cc +207 -0
  109. package/third_party/s2geometry/src/s2/s1interval.cc +296 -0
  110. package/third_party/s2geometry/src/s2/s1interval.h +266 -0
  111. package/third_party/s2geometry/src/s2/s1interval_test.cc +469 -0
  112. package/third_party/s2geometry/src/s2/s2boolean_operation.cc +2391 -0
  113. package/third_party/s2geometry/src/s2/s2boolean_operation.h +501 -0
  114. package/third_party/s2geometry/src/s2/s2boolean_operation_test.cc +1400 -0
  115. package/third_party/s2geometry/src/s2/s2builder.cc +1828 -0
  116. package/third_party/s2geometry/src/s2/s2builder.h +1057 -0
  117. package/third_party/s2geometry/src/s2/s2builder_graph.cc +1084 -0
  118. package/third_party/s2geometry/src/s2/s2builder_graph.h +799 -0
  119. package/third_party/s2geometry/src/s2/s2builder_graph_test.cc +462 -0
  120. package/third_party/s2geometry/src/s2/s2builder_layer.h +50 -0
  121. package/third_party/s2geometry/src/s2/s2builder_test.cc +1329 -0
  122. package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer.cc +313 -0
  123. package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer.h +221 -0
  124. package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer_test.cc +261 -0
  125. package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies.cc +392 -0
  126. package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies.h +86 -0
  127. package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies_test.cc +182 -0
  128. package/third_party/s2geometry/src/s2/s2builderutil_graph_shape.h +57 -0
  129. package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer.cc +212 -0
  130. package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer.h +218 -0
  131. package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer_test.cc +367 -0
  132. package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer.cc +74 -0
  133. package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer.h +122 -0
  134. package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer_test.cc +167 -0
  135. package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer.cc +191 -0
  136. package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer.h +211 -0
  137. package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer_test.cc +312 -0
  138. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer.cc +105 -0
  139. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer.h +174 -0
  140. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer_test.cc +220 -0
  141. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer.cc +98 -0
  142. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer.h +292 -0
  143. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer_test.cc +233 -0
  144. package/third_party/s2geometry/src/s2/s2builderutil_snap_functions.cc +354 -0
  145. package/third_party/s2geometry/src/s2/s2builderutil_snap_functions.h +239 -0
  146. package/third_party/s2geometry/src/s2/s2builderutil_snap_functions_test.cc +716 -0
  147. package/third_party/s2geometry/src/s2/s2builderutil_testing.cc +37 -0
  148. package/third_party/s2geometry/src/s2/s2builderutil_testing.h +100 -0
  149. package/third_party/s2geometry/src/s2/s2builderutil_testing_test.cc +85 -0
  150. package/third_party/s2geometry/src/s2/s2cap.cc +347 -0
  151. package/third_party/s2geometry/src/s2/s2cap.h +286 -0
  152. package/third_party/s2geometry/src/s2/s2cap_test.cc +379 -0
  153. package/third_party/s2geometry/src/s2/s2cell.cc +552 -0
  154. package/third_party/s2geometry/src/s2/s2cell.h +249 -0
  155. package/third_party/s2geometry/src/s2/s2cell_id.cc +619 -0
  156. package/third_party/s2geometry/src/s2/s2cell_id.h +705 -0
  157. package/third_party/s2geometry/src/s2/s2cell_id_test.cc +633 -0
  158. package/third_party/s2geometry/src/s2/s2cell_index.cc +149 -0
  159. package/third_party/s2geometry/src/s2/s2cell_index.h +660 -0
  160. package/third_party/s2geometry/src/s2/s2cell_index_test.cc +411 -0
  161. package/third_party/s2geometry/src/s2/s2cell_test.cc +687 -0
  162. package/third_party/s2geometry/src/s2/s2cell_union.cc +515 -0
  163. package/third_party/s2geometry/src/s2/s2cell_union.h +399 -0
  164. package/third_party/s2geometry/src/s2/s2cell_union_test.cc +598 -0
  165. package/third_party/s2geometry/src/s2/s2centroids.cc +84 -0
  166. package/third_party/s2geometry/src/s2/s2centroids.h +87 -0
  167. package/third_party/s2geometry/src/s2/s2centroids_test.cc +82 -0
  168. package/third_party/s2geometry/src/s2/s2closest_cell_query.cc +123 -0
  169. package/third_party/s2geometry/src/s2/s2closest_cell_query.h +385 -0
  170. package/third_party/s2geometry/src/s2/s2closest_cell_query_base.h +841 -0
  171. package/third_party/s2geometry/src/s2/s2closest_cell_query_base_test.cc +63 -0
  172. package/third_party/s2geometry/src/s2/s2closest_cell_query_test.cc +412 -0
  173. package/third_party/s2geometry/src/s2/s2closest_edge_query.cc +106 -0
  174. package/third_party/s2geometry/src/s2/s2closest_edge_query.h +421 -0
  175. package/third_party/s2geometry/src/s2/s2closest_edge_query_base.h +946 -0
  176. package/third_party/s2geometry/src/s2/s2closest_edge_query_base_test.cc +59 -0
  177. package/third_party/s2geometry/src/s2/s2closest_edge_query_test.cc +505 -0
  178. package/third_party/s2geometry/src/s2/s2closest_edge_query_testing.h +91 -0
  179. package/third_party/s2geometry/src/s2/s2closest_point_query.cc +66 -0
  180. package/third_party/s2geometry/src/s2/s2closest_point_query.h +465 -0
  181. package/third_party/s2geometry/src/s2/s2closest_point_query_base.h +767 -0
  182. package/third_party/s2geometry/src/s2/s2closest_point_query_base_test.cc +63 -0
  183. package/third_party/s2geometry/src/s2/s2closest_point_query_test.cc +312 -0
  184. package/third_party/s2geometry/src/s2/s2contains_point_query.h +328 -0
  185. package/third_party/s2geometry/src/s2/s2contains_point_query_test.cc +159 -0
  186. package/third_party/s2geometry/src/s2/s2contains_vertex_query.cc +39 -0
  187. package/third_party/s2geometry/src/s2/s2contains_vertex_query.h +66 -0
  188. package/third_party/s2geometry/src/s2/s2contains_vertex_query_test.cc +67 -0
  189. package/third_party/s2geometry/src/s2/s2convex_hull_query.cc +198 -0
  190. package/third_party/s2geometry/src/s2/s2convex_hull_query.h +110 -0
  191. package/third_party/s2geometry/src/s2/s2convex_hull_query_test.cc +208 -0
  192. package/third_party/s2geometry/src/s2/s2coords.cc +146 -0
  193. package/third_party/s2geometry/src/s2/s2coords.h +459 -0
  194. package/third_party/s2geometry/src/s2/s2coords_internal.h +71 -0
  195. package/third_party/s2geometry/src/s2/s2coords_test.cc +218 -0
  196. package/third_party/s2geometry/src/s2/s2crossing_edge_query.cc +380 -0
  197. package/third_party/s2geometry/src/s2/s2crossing_edge_query.h +220 -0
  198. package/third_party/s2geometry/src/s2/s2crossing_edge_query_test.cc +382 -0
  199. package/third_party/s2geometry/src/s2/s2debug.cc +23 -0
  200. package/third_party/s2geometry/src/s2/s2debug.h +69 -0
  201. package/third_party/s2geometry/src/s2/s2distance_target.h +165 -0
  202. package/third_party/s2geometry/src/s2/s2earth.cc +52 -0
  203. package/third_party/s2geometry/src/s2/s2earth.h +268 -0
  204. package/third_party/s2geometry/src/s2/s2earth_test.cc +146 -0
  205. package/third_party/s2geometry/src/s2/s2edge_clipping.cc +462 -0
  206. package/third_party/s2geometry/src/s2/s2edge_clipping.h +183 -0
  207. package/third_party/s2geometry/src/s2/s2edge_clipping_test.cc +335 -0
  208. package/third_party/s2geometry/src/s2/s2edge_crosser.cc +85 -0
  209. package/third_party/s2geometry/src/s2/s2edge_crosser.h +343 -0
  210. package/third_party/s2geometry/src/s2/s2edge_crosser_test.cc +264 -0
  211. package/third_party/s2geometry/src/s2/s2edge_crossings.cc +515 -0
  212. package/third_party/s2geometry/src/s2/s2edge_crossings.h +138 -0
  213. package/third_party/s2geometry/src/s2/s2edge_crossings_internal.h +59 -0
  214. package/third_party/s2geometry/src/s2/s2edge_crossings_test.cc +246 -0
  215. package/third_party/s2geometry/src/s2/s2edge_distances.cc +419 -0
  216. package/third_party/s2geometry/src/s2/s2edge_distances.h +192 -0
  217. package/third_party/s2geometry/src/s2/s2edge_distances_test.cc +539 -0
  218. package/third_party/s2geometry/src/s2/s2edge_tessellator.cc +276 -0
  219. package/third_party/s2geometry/src/s2/s2edge_tessellator.h +101 -0
  220. package/third_party/s2geometry/src/s2/s2edge_tessellator_test.cc +492 -0
  221. package/third_party/s2geometry/src/s2/s2edge_vector_shape.h +85 -0
  222. package/third_party/s2geometry/src/s2/s2edge_vector_shape_test.cc +66 -0
  223. package/third_party/s2geometry/src/s2/s2error.cc +29 -0
  224. package/third_party/s2geometry/src/s2/s2error.h +147 -0
  225. package/third_party/s2geometry/src/s2/s2error_test.cc +31 -0
  226. package/third_party/s2geometry/src/s2/s2furthest_edge_query.cc +117 -0
  227. package/third_party/s2geometry/src/s2/s2furthest_edge_query.h +439 -0
  228. package/third_party/s2geometry/src/s2/s2furthest_edge_query_test.cc +487 -0
  229. package/third_party/s2geometry/src/s2/s2latlng.cc +90 -0
  230. package/third_party/s2geometry/src/s2/s2latlng.h +234 -0
  231. package/third_party/s2geometry/src/s2/s2latlng_rect.cc +727 -0
  232. package/third_party/s2geometry/src/s2/s2latlng_rect.h +434 -0
  233. package/third_party/s2geometry/src/s2/s2latlng_rect_bounder.cc +344 -0
  234. package/third_party/s2geometry/src/s2/s2latlng_rect_bounder.h +89 -0
  235. package/third_party/s2geometry/src/s2/s2latlng_rect_bounder_test.cc +306 -0
  236. package/third_party/s2geometry/src/s2/s2latlng_rect_test.cc +1030 -0
  237. package/third_party/s2geometry/src/s2/s2latlng_test.cc +165 -0
  238. package/third_party/s2geometry/src/s2/s2lax_loop_shape.cc +104 -0
  239. package/third_party/s2geometry/src/s2/s2lax_loop_shape.h +153 -0
  240. package/third_party/s2geometry/src/s2/s2lax_loop_shape_test.cc +101 -0
  241. package/third_party/s2geometry/src/s2/s2lax_polygon_shape.cc +348 -0
  242. package/third_party/s2geometry/src/s2/s2lax_polygon_shape.h +183 -0
  243. package/third_party/s2geometry/src/s2/s2lax_polygon_shape_test.cc +234 -0
  244. package/third_party/s2geometry/src/s2/s2lax_polyline_shape.cc +118 -0
  245. package/third_party/s2geometry/src/s2/s2lax_polyline_shape.h +124 -0
  246. package/third_party/s2geometry/src/s2/s2lax_polyline_shape_test.cc +62 -0
  247. package/third_party/s2geometry/src/s2/s2loop.cc +1509 -0
  248. package/third_party/s2geometry/src/s2/s2loop.h +711 -0
  249. package/third_party/s2geometry/src/s2/s2loop_measures.cc +313 -0
  250. package/third_party/s2geometry/src/s2/s2loop_measures.h +280 -0
  251. package/third_party/s2geometry/src/s2/s2loop_measures_test.cc +367 -0
  252. package/third_party/s2geometry/src/s2/s2loop_test.cc +1371 -0
  253. package/third_party/s2geometry/src/s2/s2max_distance_targets.cc +265 -0
  254. package/third_party/s2geometry/src/s2/s2max_distance_targets.h +241 -0
  255. package/third_party/s2geometry/src/s2/s2max_distance_targets_test.cc +367 -0
  256. package/third_party/s2geometry/src/s2/s2measures.cc +128 -0
  257. package/third_party/s2geometry/src/s2/s2measures.h +78 -0
  258. package/third_party/s2geometry/src/s2/s2measures_test.cc +135 -0
  259. package/third_party/s2geometry/src/s2/s2metrics.cc +122 -0
  260. package/third_party/s2geometry/src/s2/s2metrics.h +199 -0
  261. package/third_party/s2geometry/src/s2/s2metrics_test.cc +127 -0
  262. package/third_party/s2geometry/src/s2/s2min_distance_targets.cc +295 -0
  263. package/third_party/s2geometry/src/s2/s2min_distance_targets.h +273 -0
  264. package/third_party/s2geometry/src/s2/s2min_distance_targets_test.cc +239 -0
  265. package/third_party/s2geometry/src/s2/s2padded_cell.cc +162 -0
  266. package/third_party/s2geometry/src/s2/s2padded_cell.h +108 -0
  267. package/third_party/s2geometry/src/s2/s2padded_cell_test.cc +138 -0
  268. package/third_party/s2geometry/src/s2/s2point.h +38 -0
  269. package/third_party/s2geometry/src/s2/s2point_compression.cc +388 -0
  270. package/third_party/s2geometry/src/s2/s2point_compression.h +78 -0
  271. package/third_party/s2geometry/src/s2/s2point_compression_test.cc +305 -0
  272. package/third_party/s2geometry/src/s2/s2point_index.h +345 -0
  273. package/third_party/s2geometry/src/s2/s2point_index_test.cc +147 -0
  274. package/third_party/s2geometry/src/s2/s2point_region.cc +72 -0
  275. package/third_party/s2geometry/src/s2/s2point_region.h +76 -0
  276. package/third_party/s2geometry/src/s2/s2point_region_test.cc +100 -0
  277. package/third_party/s2geometry/src/s2/s2point_span.h +57 -0
  278. package/third_party/s2geometry/src/s2/s2point_test.cc +47 -0
  279. package/third_party/s2geometry/src/s2/s2point_vector_shape.h +127 -0
  280. package/third_party/s2geometry/src/s2/s2point_vector_shape_test.cc +59 -0
  281. package/third_party/s2geometry/src/s2/s2pointutil.cc +131 -0
  282. package/third_party/s2geometry/src/s2/s2pointutil.h +138 -0
  283. package/third_party/s2geometry/src/s2/s2pointutil_test.cc +157 -0
  284. package/third_party/s2geometry/src/s2/s2polygon.cc +1569 -0
  285. package/third_party/s2geometry/src/s2/s2polygon.h +934 -0
  286. package/third_party/s2geometry/src/s2/s2polygon_test.cc +3025 -0
  287. package/third_party/s2geometry/src/s2/s2polyline.cc +645 -0
  288. package/third_party/s2geometry/src/s2/s2polyline.h +379 -0
  289. package/third_party/s2geometry/src/s2/s2polyline_alignment.cc +414 -0
  290. package/third_party/s2geometry/src/s2/s2polyline_alignment.h +245 -0
  291. package/third_party/s2geometry/src/s2/s2polyline_alignment_internal.h +158 -0
  292. package/third_party/s2geometry/src/s2/s2polyline_alignment_test.cc +610 -0
  293. package/third_party/s2geometry/src/s2/s2polyline_measures.cc +42 -0
  294. package/third_party/s2geometry/src/s2/s2polyline_measures.h +53 -0
  295. package/third_party/s2geometry/src/s2/s2polyline_measures_test.cc +57 -0
  296. package/third_party/s2geometry/src/s2/s2polyline_simplifier.cc +187 -0
  297. package/third_party/s2geometry/src/s2/s2polyline_simplifier.h +109 -0
  298. package/third_party/s2geometry/src/s2/s2polyline_simplifier_test.cc +165 -0
  299. package/third_party/s2geometry/src/s2/s2polyline_test.cc +554 -0
  300. package/third_party/s2geometry/src/s2/s2predicates.cc +1486 -0
  301. package/third_party/s2geometry/src/s2/s2predicates.h +282 -0
  302. package/third_party/s2geometry/src/s2/s2predicates_internal.h +135 -0
  303. package/third_party/s2geometry/src/s2/s2predicates_test.cc +1427 -0
  304. package/third_party/s2geometry/src/s2/s2projections.cc +109 -0
  305. package/third_party/s2geometry/src/s2/s2projections.h +161 -0
  306. package/third_party/s2geometry/src/s2/s2projections_test.cc +78 -0
  307. package/third_party/s2geometry/src/s2/s2r2rect.cc +88 -0
  308. package/third_party/s2geometry/src/s2/s2r2rect.h +292 -0
  309. package/third_party/s2geometry/src/s2/s2r2rect_test.cc +312 -0
  310. package/third_party/s2geometry/src/s2/s2region.cc +26 -0
  311. package/third_party/s2geometry/src/s2/s2region.h +142 -0
  312. package/third_party/s2geometry/src/s2/s2region_coverer.cc +514 -0
  313. package/third_party/s2geometry/src/s2/s2region_coverer.h +356 -0
  314. package/third_party/s2geometry/src/s2/s2region_coverer_test.cc +509 -0
  315. package/third_party/s2geometry/src/s2/s2region_intersection.cc +84 -0
  316. package/third_party/s2geometry/src/s2/s2region_intersection.h +79 -0
  317. package/third_party/s2geometry/src/s2/s2region_term_indexer.cc +270 -0
  318. package/third_party/s2geometry/src/s2/s2region_term_indexer.h +299 -0
  319. package/third_party/s2geometry/src/s2/s2region_term_indexer_test.cc +209 -0
  320. package/third_party/s2geometry/src/s2/s2region_test.cc +370 -0
  321. package/third_party/s2geometry/src/s2/s2region_union.cc +90 -0
  322. package/third_party/s2geometry/src/s2/s2region_union.h +83 -0
  323. package/third_party/s2geometry/src/s2/s2region_union_test.cc +89 -0
  324. package/third_party/s2geometry/src/s2/s2shape.h +283 -0
  325. package/third_party/s2geometry/src/s2/s2shape_index.cc +321 -0
  326. package/third_party/s2geometry/src/s2/s2shape_index.h +781 -0
  327. package/third_party/s2geometry/src/s2/s2shape_index_buffered_region.cc +113 -0
  328. package/third_party/s2geometry/src/s2/s2shape_index_buffered_region.h +135 -0
  329. package/third_party/s2geometry/src/s2/s2shape_index_buffered_region_test.cc +162 -0
  330. package/third_party/s2geometry/src/s2/s2shape_index_measures.cc +92 -0
  331. package/third_party/s2geometry/src/s2/s2shape_index_measures.h +100 -0
  332. package/third_party/s2geometry/src/s2/s2shape_index_measures_test.cc +136 -0
  333. package/third_party/s2geometry/src/s2/s2shape_index_region.h +350 -0
  334. package/third_party/s2geometry/src/s2/s2shape_index_region_test.cc +161 -0
  335. package/third_party/s2geometry/src/s2/s2shape_index_test.cc +24 -0
  336. package/third_party/s2geometry/src/s2/s2shape_measures.cc +138 -0
  337. package/third_party/s2geometry/src/s2/s2shape_measures.h +95 -0
  338. package/third_party/s2geometry/src/s2/s2shape_measures_test.cc +139 -0
  339. package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries.cc +120 -0
  340. package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries.h +66 -0
  341. package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries_test.cc +170 -0
  342. package/third_party/s2geometry/src/s2/s2shapeutil_coding.cc +253 -0
  343. package/third_party/s2geometry/src/s2/s2shapeutil_coding.h +283 -0
  344. package/third_party/s2geometry/src/s2/s2shapeutil_coding_test.cc +54 -0
  345. package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force.cc +40 -0
  346. package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force.h +41 -0
  347. package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force_test.cc +55 -0
  348. package/third_party/s2geometry/src/s2/s2shapeutil_count_edges.h +57 -0
  349. package/third_party/s2geometry/src/s2/s2shapeutil_count_edges_test.cc +43 -0
  350. package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator.cc +45 -0
  351. package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator.h +72 -0
  352. package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator_test.cc +116 -0
  353. package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point.cc +107 -0
  354. package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point.h +48 -0
  355. package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point_test.cc +104 -0
  356. package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator.cc +58 -0
  357. package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator.h +65 -0
  358. package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator_test.cc +61 -0
  359. package/third_party/s2geometry/src/s2/s2shapeutil_shape_edge.h +58 -0
  360. package/third_party/s2geometry/src/s2/s2shapeutil_shape_edge_id.h +97 -0
  361. package/third_party/s2geometry/src/s2/s2shapeutil_testing.cc +104 -0
  362. package/third_party/s2geometry/src/s2/s2shapeutil_testing.h +36 -0
  363. package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs.cc +440 -0
  364. package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs.h +72 -0
  365. package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs_test.cc +184 -0
  366. package/third_party/s2geometry/src/s2/s2testing.cc +464 -0
  367. package/third_party/s2geometry/src/s2/s2testing.h +385 -0
  368. package/third_party/s2geometry/src/s2/s2testing_test.cc +166 -0
  369. package/third_party/s2geometry/src/s2/s2text_format.cc +506 -0
  370. package/third_party/s2geometry/src/s2/s2text_format.h +289 -0
  371. package/third_party/s2geometry/src/s2/s2text_format_test.cc +417 -0
  372. package/third_party/s2geometry/src/s2/s2wedge_relations.cc +80 -0
  373. package/third_party/s2geometry/src/s2/s2wedge_relations.h +64 -0
  374. package/third_party/s2geometry/src/s2/s2wedge_relations_test.cc +89 -0
  375. package/third_party/s2geometry/src/s2/sequence_lexicon.h +296 -0
  376. package/third_party/s2geometry/src/s2/sequence_lexicon_test.cc +113 -0
  377. package/third_party/s2geometry/src/s2/strings/ostringstream.cc +35 -0
  378. package/third_party/s2geometry/src/s2/strings/ostringstream.h +105 -0
  379. package/third_party/s2geometry/src/s2/strings/serialize.cc +46 -0
  380. package/third_party/s2geometry/src/s2/strings/serialize.h +40 -0
  381. package/third_party/s2geometry/src/s2/third_party/absl/algorithm/algorithm.h +187 -0
  382. package/third_party/s2geometry/src/s2/third_party/absl/base/attributes.h +666 -0
  383. package/third_party/s2geometry/src/s2/third_party/absl/base/casts.h +189 -0
  384. package/third_party/s2geometry/src/s2/third_party/absl/base/config.h +462 -0
  385. package/third_party/s2geometry/src/s2/third_party/absl/base/dynamic_annotations.cc +129 -0
  386. package/third_party/s2geometry/src/s2/third_party/absl/base/dynamic_annotations.h +394 -0
  387. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/atomic_hook.h +168 -0
  388. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/identity.h +33 -0
  389. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/inline_variable.h +117 -0
  390. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/invoke.h +188 -0
  391. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/raw_logging.cc +254 -0
  392. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/raw_logging.h +205 -0
  393. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/throw_delegate.cc +106 -0
  394. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/throw_delegate.h +71 -0
  395. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/unaligned_access.h +322 -0
  396. package/third_party/s2geometry/src/s2/third_party/absl/base/log_severity.h +77 -0
  397. package/third_party/s2geometry/src/s2/third_party/absl/base/macros.h +236 -0
  398. package/third_party/s2geometry/src/s2/third_party/absl/base/optimization.h +177 -0
  399. package/third_party/s2geometry/src/s2/third_party/absl/base/policy_checks.h +124 -0
  400. package/third_party/s2geometry/src/s2/third_party/absl/base/port.h +97 -0
  401. package/third_party/s2geometry/src/s2/third_party/absl/base/thread_annotations.h +277 -0
  402. package/third_party/s2geometry/src/s2/third_party/absl/container/fixed_array.h +523 -0
  403. package/third_party/s2geometry/src/s2/third_party/absl/container/inlined_vector.h +1453 -0
  404. package/third_party/s2geometry/src/s2/third_party/absl/container/internal/compressed_tuple.h +191 -0
  405. package/third_party/s2geometry/src/s2/third_party/absl/container/internal/container_memory.h +424 -0
  406. package/third_party/s2geometry/src/s2/third_party/absl/container/internal/layout.h +739 -0
  407. package/third_party/s2geometry/src/s2/third_party/absl/memory/memory.h +755 -0
  408. package/third_party/s2geometry/src/s2/third_party/absl/meta/type_traits.h +436 -0
  409. package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128.cc +232 -0
  410. package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128.h +656 -0
  411. package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128_have_intrinsic.inc +3 -0
  412. package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128_no_intrinsic.inc +3 -0
  413. package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii.cc +198 -0
  414. package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii.h +239 -0
  415. package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii_ctype.h +66 -0
  416. package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/bits.h +53 -0
  417. package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/memutil.cc +110 -0
  418. package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/memutil.h +146 -0
  419. package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/resize_uninitialized.h +72 -0
  420. package/third_party/s2geometry/src/s2/third_party/absl/strings/match.cc +38 -0
  421. package/third_party/s2geometry/src/s2/third_party/absl/strings/match.h +89 -0
  422. package/third_party/s2geometry/src/s2/third_party/absl/strings/numbers.cc +909 -0
  423. package/third_party/s2geometry/src/s2/third_party/absl/strings/numbers.h +187 -0
  424. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_cat.cc +240 -0
  425. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_cat.h +398 -0
  426. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_join.h +22 -0
  427. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_split.cc +47 -0
  428. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_split.h +43 -0
  429. package/third_party/s2geometry/src/s2/third_party/absl/strings/string_view.cc +245 -0
  430. package/third_party/s2geometry/src/s2/third_party/absl/strings/string_view.h +602 -0
  431. package/third_party/s2geometry/src/s2/third_party/absl/strings/strip.cc +42 -0
  432. package/third_party/s2geometry/src/s2/third_party/absl/strings/strip.h +130 -0
  433. package/third_party/s2geometry/src/s2/third_party/absl/types/span.h +793 -0
  434. package/third_party/s2geometry/src/s2/third_party/absl/utility/utility.h +299 -0
  435. package/third_party/s2geometry/src/s2/util/bits/bit-interleave.cc +274 -0
  436. package/third_party/s2geometry/src/s2/util/bits/bit-interleave.h +53 -0
  437. package/third_party/s2geometry/src/s2/util/bits/bits.cc +155 -0
  438. package/third_party/s2geometry/src/s2/util/bits/bits.h +745 -0
  439. package/third_party/s2geometry/src/s2/util/coding/coder.cc +83 -0
  440. package/third_party/s2geometry/src/s2/util/coding/coder.h +553 -0
  441. package/third_party/s2geometry/src/s2/util/coding/nth-derivative.h +134 -0
  442. package/third_party/s2geometry/src/s2/util/coding/transforms.h +62 -0
  443. package/third_party/s2geometry/src/s2/util/coding/varint.cc +289 -0
  444. package/third_party/s2geometry/src/s2/util/coding/varint.h +476 -0
  445. package/third_party/s2geometry/src/s2/util/endian/endian.h +859 -0
  446. package/third_party/s2geometry/src/s2/util/gtl/btree.h +2471 -0
  447. package/third_party/s2geometry/src/s2/util/gtl/btree_container.h +411 -0
  448. package/third_party/s2geometry/src/s2/util/gtl/btree_map.h +79 -0
  449. package/third_party/s2geometry/src/s2/util/gtl/btree_set.h +73 -0
  450. package/third_party/s2geometry/src/s2/util/gtl/compact_array.h +653 -0
  451. package/third_party/s2geometry/src/s2/util/gtl/container_logging.h +291 -0
  452. package/third_party/s2geometry/src/s2/util/gtl/dense_hash_set.h +358 -0
  453. package/third_party/s2geometry/src/s2/util/gtl/densehashtable.h +1493 -0
  454. package/third_party/s2geometry/src/s2/util/gtl/hashtable_common.h +253 -0
  455. package/third_party/s2geometry/src/s2/util/gtl/layout.h +28 -0
  456. package/third_party/s2geometry/src/s2/util/gtl/legacy_random_shuffle.h +77 -0
  457. package/third_party/s2geometry/src/s2/util/hash/mix.h +76 -0
  458. package/third_party/s2geometry/src/s2/util/math/exactfloat/exactfloat.cc +832 -0
  459. package/third_party/s2geometry/src/s2/util/math/exactfloat/exactfloat.h +646 -0
  460. package/third_party/s2geometry/src/s2/util/math/mathutil.cc +75 -0
  461. package/third_party/s2geometry/src/s2/util/math/mathutil.h +189 -0
  462. package/third_party/s2geometry/src/s2/util/math/matrix3x3.h +574 -0
  463. package/third_party/s2geometry/src/s2/util/math/vector.h +569 -0
  464. package/third_party/s2geometry/src/s2/util/math/vector3_hash.h +54 -0
  465. package/third_party/s2geometry/src/s2/util/units/length-units.cc +21 -0
  466. package/third_party/s2geometry/src/s2/util/units/length-units.h +135 -0
  467. package/third_party/s2geometry/src/s2/util/units/physical-units.h +313 -0
  468. package/third_party/s2geometry/src/s2/value_lexicon.h +234 -0
  469. package/third_party/s2geometry/src/s2/value_lexicon_test.cc +121 -0
  470. package/third_party/s2geometry/third_party/cmake/FindGFlags.cmake +48 -0
  471. package/third_party/s2geometry/third_party/cmake/FindGlog.cmake +48 -0
@@ -0,0 +1,781 @@
1
+ // Copyright 2012 Google Inc. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS-IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+
16
+ // Author: ericv@google.com (Eric Veach)
17
+ //
18
+ // S2ShapeIndex is an abstract base class for indexing polygonal geometry in
19
+ // memory. The main documentation is with the class definition below.
20
+ // (Some helper classes are defined first.)
21
+
22
+ #ifndef S2_S2SHAPE_INDEX_H_
23
+ #define S2_S2SHAPE_INDEX_H_
24
+
25
+ #include <array>
26
+ #include <atomic>
27
+ #include <cstddef>
28
+ #include <iterator>
29
+ #include <memory>
30
+ #include <utility>
31
+ #include <vector>
32
+
33
+ #include "s2/base/integral_types.h"
34
+ #include "s2/base/logging.h"
35
+ #include "s2/base/mutex.h"
36
+ #include "s2/base/spinlock.h"
37
+ #include "s2/_fp_contract_off.h"
38
+ #include "s2/s2cell_id.h"
39
+ #include "s2/s2pointutil.h"
40
+ #include "s2/s2shape.h"
41
+ #include "s2/third_party/absl/base/macros.h"
42
+ #include "s2/third_party/absl/base/thread_annotations.h"
43
+ #include "s2/third_party/absl/memory/memory.h"
44
+ #include "s2/util/gtl/compact_array.h"
45
+
46
+ class R1Interval;
47
+ class S2PaddedCell;
48
+
49
+ // S2ClippedShape represents the part of a shape that intersects an S2Cell.
50
+ // It consists of the set of edge ids that intersect that cell, and a boolean
51
+ // indicating whether the center of the cell is inside the shape (for shapes
52
+ // that have an interior).
53
+ //
54
+ // Note that the edges themselves are not clipped; we always use the original
55
+ // edges for intersection tests so that the results will be the same as the
56
+ // original shape.
57
+ class S2ClippedShape {
58
+ public:
59
+ // The shape id of the clipped shape.
60
+ int shape_id() const;
61
+
62
+ // Returns true if the center of the S2CellId is inside the shape. Returns
63
+ // false for shapes that do not have an interior.
64
+ bool contains_center() const;
65
+
66
+ // The number of edges that intersect the S2CellId.
67
+ int num_edges() const;
68
+
69
+ // Returns the edge id of the given edge in this clipped shape. Edges are
70
+ // sorted in increasing order of edge id.
71
+ //
72
+ // REQUIRES: 0 <= i < num_edges()
73
+ int edge(int i) const;
74
+
75
+ // Returns true if the clipped shape contains the given edge id.
76
+ bool ContainsEdge(int id) const;
77
+
78
+ private:
79
+ // This class may be copied by value, but note that it does *not* own its
80
+ // underlying data. (It is owned by the containing S2ShapeIndexCell.)
81
+
82
+ friend class MutableS2ShapeIndex;
83
+ friend class S2ShapeIndexCell;
84
+ friend class S2Stats;
85
+
86
+ // Internal methods are documented with their definition.
87
+ void Init(int32 shape_id, int32 num_edges);
88
+ void Destruct();
89
+ bool is_inline() const;
90
+ void set_contains_center(bool contains_center);
91
+ void set_edge(int i, int edge);
92
+
93
+ // All fields are packed into 16 bytes (assuming 64-bit pointers). Up to
94
+ // two edge ids are stored inline; this is an important optimization for
95
+ // clients that use S2Shapes consisting of a single edge.
96
+ int32 shape_id_;
97
+ uint32 contains_center_ : 1; // shape contains the cell center
98
+ uint32 num_edges_ : 31;
99
+
100
+ // If there are more than two edges, this field holds a pointer.
101
+ // Otherwise it holds an array of edge ids.
102
+ union {
103
+ int32* edges_; // Owned by the containing S2ShapeIndexCell.
104
+ std::array<int32, 2> inline_edges_;
105
+ };
106
+ };
107
+
108
+ // S2ShapeIndexCell stores the index contents for a particular S2CellId.
109
+ // It consists of a set of clipped shapes.
110
+ class S2ShapeIndexCell {
111
+ public:
112
+ S2ShapeIndexCell() {}
113
+ ~S2ShapeIndexCell();
114
+
115
+ // Returns the number of clipped shapes in this cell.
116
+ int num_clipped() const { return shapes_.size(); }
117
+
118
+ // Returns the clipped shape at the given index. Shapes are kept sorted in
119
+ // increasing order of shape id.
120
+ //
121
+ // REQUIRES: 0 <= i < num_clipped()
122
+ const S2ClippedShape& clipped(int i) const { return shapes_[i]; }
123
+
124
+ // Returns a pointer to the clipped shape corresponding to the given shape,
125
+ // or nullptr if the shape does not intersect this cell.
126
+ const S2ClippedShape* find_clipped(const S2Shape* shape) const;
127
+ const S2ClippedShape* find_clipped(int shape_id) const;
128
+
129
+ // Convenience method that returns the total number of edges in all clipped
130
+ // shapes.
131
+ int num_edges() const;
132
+
133
+ // Appends an encoded representation of the S2ShapeIndexCell to "encoder".
134
+ // "num_shape_ids" should be set to index.num_shape_ids(); this information
135
+ // allows the encoding to be more compact in some cases.
136
+ //
137
+ // REQUIRES: "encoder" uses the default constructor, so that its buffer
138
+ // can be enlarged as necessary by calling Ensure(int).
139
+ void Encode(int num_shape_ids, Encoder* encoder) const;
140
+
141
+ // Decodes an S2ShapeIndexCell, returning true on success.
142
+ // "num_shape_ids" should be set to index.num_shape_ids().
143
+ bool Decode(int num_shape_ids, Decoder* decoder);
144
+
145
+ private:
146
+ friend class MutableS2ShapeIndex;
147
+ friend class EncodedS2ShapeIndex;
148
+ friend class S2Stats;
149
+
150
+ // Internal methods are documented with their definitions.
151
+ S2ClippedShape* add_shapes(int n);
152
+ static void EncodeEdges(const S2ClippedShape& clipped, Encoder* encoder);
153
+ static bool DecodeEdges(int num_edges, S2ClippedShape* clipped,
154
+ Decoder* decoder);
155
+
156
+ using S2ClippedShapeSet = gtl::compact_array<S2ClippedShape>;
157
+ S2ClippedShapeSet shapes_;
158
+
159
+ S2ShapeIndexCell(const S2ShapeIndexCell&) = delete;
160
+ void operator=(const S2ShapeIndexCell&) = delete;
161
+ };
162
+
163
+ // S2ShapeIndex is an abstract base class for indexing polygonal geometry in
164
+ // memory. The objects in the index are known as "shapes", and may consist of
165
+ // points, polylines, and/or polygons, possibly overlapping. The index makes
166
+ // it very fast to answer queries such as finding nearby shapes, measuring
167
+ // distances, testing for intersection and containment, etc.
168
+ //
169
+ // Each object in the index implements the S2Shape interface. An S2Shape is a
170
+ // collection of edges that optionally defines an interior. The edges do not
171
+ // need to be connected, so for example an S2Shape can represent a polygon
172
+ // with multiple shells and/or holes, or a set of polylines, or a set of
173
+ // points. All geometry within a single S2Shape must have the same dimension,
174
+ // so for example if you want to create an S2ShapeIndex containing a polyline
175
+ // and 10 points, then you will need at least two different S2Shape objects.
176
+ //
177
+ // The most important type of S2ShapeIndex is MutableS2ShapeIndex, which
178
+ // allows you to build an index incrementally by adding or removing shapes.
179
+ // Soon there will also be an EncodedS2ShapeIndex type that makes it possible
180
+ // to keep the index data in encoded form. Code that only needs read-only
181
+ // ("const") access to an index should use the S2ShapeIndex base class as the
182
+ // parameter type, so that it will work with any S2ShapeIndex subtype. For
183
+ // example:
184
+ //
185
+ // void DoSomething(const S2ShapeIndex& index) {
186
+ // ... works with MutableS2ShapeIndex or EncodedS2ShapeIndex ...
187
+ // }
188
+ //
189
+ // There are a number of built-in classes that work with S2ShapeIndex objects.
190
+ // Generally these classes accept any collection of geometry that can be
191
+ // represented by an S2ShapeIndex, i.e. any combination of points, polylines,
192
+ // and polygons. Such classes include:
193
+ //
194
+ // - S2ContainsPointQuery: returns the shape(s) that contain a given point.
195
+ //
196
+ // - S2ClosestEdgeQuery: returns the closest edge(s) to a given point, edge,
197
+ // S2CellId, or S2ShapeIndex.
198
+ //
199
+ // - S2CrossingEdgeQuery: returns the edge(s) that cross a given edge.
200
+ //
201
+ // - S2BooleanOperation: computes boolean operations such as union,
202
+ // and boolean predicates such as containment.
203
+ //
204
+ // - S2ShapeIndexRegion: computes approximations for a collection of geometry.
205
+ //
206
+ // - S2ShapeIndexBufferedRegion: computes approximations that have been
207
+ // expanded by a given radius.
208
+ //
209
+ // Here is an example showing how to index a set of polygons and then
210
+ // determine which polygon(s) contain each of a set of query points:
211
+ //
212
+ // void TestContainment(const vector<S2Point>& points,
213
+ // const vector<S2Polygon*>& polygons) {
214
+ // MutableS2ShapeIndex index;
215
+ // for (auto polygon : polygons) {
216
+ // index.Add(absl::make_unique<S2Polygon::Shape>(polygon));
217
+ // }
218
+ // auto query = MakeS2ContainsPointQuery(&index);
219
+ // for (const auto& point : points) {
220
+ // for (S2Shape* shape : query.GetContainingShapes(point)) {
221
+ // S2Polygon* polygon = polygons[shape->id()];
222
+ // ... do something with (point, polygon) ...
223
+ // }
224
+ // }
225
+ // }
226
+ //
227
+ // This example uses S2Polygon::Shape, which is one example of an S2Shape
228
+ // object. S2Polyline and S2Loop also have nested Shape classes, and there are
229
+ // additional S2Shape types defined in *_shape.h.
230
+ //
231
+ // Internally, an S2ShapeIndex is essentially a map from S2CellIds to the set
232
+ // of shapes that intersect each S2CellId. It is adaptively refined to ensure
233
+ // that no cell contains more than a small number of edges.
234
+ //
235
+ // In addition to implementing a shared set of virtual methods, all
236
+ // S2ShapeIndex subtypes define an Iterator type with the same API. This
237
+ // makes it easy to convert code that uses a particular S2ShapeIndex subtype
238
+ // to instead use the abstract base class (or vice versa). You can also
239
+ // choose to avoid the overhead of virtual method calls by making the
240
+ // S2ShapeIndex type a template argument, like this:
241
+ //
242
+ // template <class IndexType>
243
+ // void DoSomething(const IndexType& index) {
244
+ // for (typename IndexType::Iterator it(&index, S2ShapeIndex::BEGIN);
245
+ // !it.done(); it.Next()) {
246
+ // ...
247
+ // }
248
+ // }
249
+ //
250
+ // Subtypes provided by the S2 library have the same thread-safety properties
251
+ // as std::vector. That is, const methods may be called concurrently from
252
+ // multiple threads, and non-const methods require exclusive access to the
253
+ // S2ShapeIndex.
254
+ class S2ShapeIndex {
255
+ protected:
256
+ class IteratorBase;
257
+
258
+ public:
259
+ virtual ~S2ShapeIndex() {}
260
+
261
+ // Returns the number of distinct shape ids in the index. This is the same
262
+ // as the number of shapes provided that no shapes have ever been removed.
263
+ // (Shape ids are never reused.)
264
+ virtual int num_shape_ids() const = 0;
265
+
266
+ // Returns a pointer to the shape with the given id, or nullptr if the shape
267
+ // has been removed from the index.
268
+ virtual S2Shape* shape(int id) const = 0;
269
+
270
+ // Allows iterating over the indexed shapes using range-based for loops:
271
+ //
272
+ // for (S2Shape* shape : index) { ... }
273
+ //
274
+ // CAVEAT: Returns nullptr for shapes that have been removed from the index.
275
+ class ShapeIterator
276
+ : public std::iterator<std::forward_iterator_tag, S2Shape*> {
277
+ public:
278
+ ShapeIterator() = default;
279
+ S2Shape* operator*() const;
280
+ ShapeIterator& operator++();
281
+ ShapeIterator operator++(int);
282
+
283
+ // REQUIRES: "it" and *this must reference the same S2ShapeIndex.
284
+ bool operator==(ShapeIterator it) const;
285
+
286
+ // REQUIRES: "it" and *this must reference the same S2ShapeIndex.
287
+ bool operator!=(ShapeIterator it) const;
288
+
289
+ private:
290
+ friend class S2ShapeIndex;
291
+ ShapeIterator(const S2ShapeIndex* index, int shape_id)
292
+ : index_(index), shape_id_(shape_id) {}
293
+
294
+ const S2ShapeIndex* index_ = nullptr;
295
+ int shape_id_ = 0;
296
+ };
297
+ ShapeIterator begin() const;
298
+ ShapeIterator end() const;
299
+
300
+ // Returns the number of bytes currently occupied by the index (including any
301
+ // unused space at the end of vectors, etc).
302
+ virtual size_t SpaceUsed() const = 0;
303
+
304
+ // Minimizes memory usage by requesting that any data structures that can be
305
+ // rebuilt should be discarded. This method invalidates all iterators.
306
+ //
307
+ // Like all non-const methods, this method is not thread-safe.
308
+ virtual void Minimize() = 0;
309
+
310
+ // The possible relationships between a "target" cell and the cells of the
311
+ // S2ShapeIndex. If the target is an index cell or is contained by an index
312
+ // cell, it is "INDEXED". If the target is subdivided into one or more
313
+ // index cells, it is "SUBDIVIDED". Otherwise it is "DISJOINT".
314
+ enum CellRelation {
315
+ INDEXED, // Target is contained by an index cell
316
+ SUBDIVIDED, // Target is subdivided into one or more index cells
317
+ DISJOINT // Target does not intersect any index cells
318
+ };
319
+
320
+ // When passed to an Iterator constructor, specifies whether the iterator
321
+ // should be positioned at the beginning of the index (BEGIN), the end of
322
+ // the index (END), or arbitrarily (UNPOSITIONED). By default iterators are
323
+ // unpositioned, since this avoids an extra seek in this situation where one
324
+ // of the seek methods (such as Locate) is immediately called.
325
+ enum InitialPosition { BEGIN, END, UNPOSITIONED };
326
+
327
+ // A random access iterator that provides low-level access to the cells of
328
+ // the index. Cells are sorted in increasing order of S2CellId.
329
+ class Iterator {
330
+ public:
331
+ // Default constructor; must be followed by a call to Init().
332
+ Iterator() : iter_(nullptr) {}
333
+
334
+ // Constructs an iterator positioned as specified. By default iterators
335
+ // are unpositioned, since this avoids an extra seek in this situation
336
+ // where one of the seek methods (such as Locate) is immediately called.
337
+ //
338
+ // If you want to position the iterator at the beginning, e.g. in order to
339
+ // loop through the entire index, do this instead:
340
+ //
341
+ // for (S2ShapeIndex::Iterator it(&index, S2ShapeIndex::BEGIN);
342
+ // !it.done(); it.Next()) { ... }
343
+ explicit Iterator(const S2ShapeIndex* index,
344
+ InitialPosition pos = UNPOSITIONED)
345
+ : iter_(index->NewIterator(pos)) {}
346
+
347
+ // Initializes an iterator for the given S2ShapeIndex. This method may
348
+ // also be called in order to restore an iterator to a valid state after
349
+ // the underlying index has been updated (although it is usually easier
350
+ // just to declare a new iterator whenever required, since iterator
351
+ // construction is cheap).
352
+ void Init(const S2ShapeIndex* index,
353
+ InitialPosition pos = UNPOSITIONED) {
354
+ iter_ = index->NewIterator(pos);
355
+ }
356
+
357
+ // Iterators are copyable and movable.
358
+ Iterator(const Iterator&);
359
+ Iterator& operator=(const Iterator&);
360
+ Iterator(Iterator&&);
361
+ Iterator& operator=(Iterator&&);
362
+
363
+ // Returns the S2CellId of the current index cell. If done() is true,
364
+ // returns a value larger than any valid S2CellId (S2CellId::Sentinel()).
365
+ S2CellId id() const { return iter_->id(); }
366
+
367
+ // Returns the center point of the cell.
368
+ // REQUIRES: !done()
369
+ S2Point center() const { return id().ToPoint(); }
370
+
371
+ // Returns a reference to the contents of the current index cell.
372
+ // REQUIRES: !done()
373
+ const S2ShapeIndexCell& cell() const { return iter_->cell(); }
374
+
375
+ // Returns true if the iterator is positioned past the last index cell.
376
+ bool done() const { return iter_->done(); }
377
+
378
+ // Positions the iterator at the first index cell (if any).
379
+ void Begin() { iter_->Begin(); }
380
+
381
+ // Positions the iterator past the last index cell.
382
+ void Finish() { iter_->Finish(); }
383
+
384
+ // Positions the iterator at the next index cell.
385
+ // REQUIRES: !done()
386
+ void Next() { iter_->Next(); }
387
+
388
+ // If the iterator is already positioned at the beginning, returns false.
389
+ // Otherwise positions the iterator at the previous entry and returns true.
390
+ bool Prev() { return iter_->Prev(); }
391
+
392
+ // Positions the iterator at the first cell with id() >= target, or at the
393
+ // end of the index if no such cell exists.
394
+ void Seek(S2CellId target) { iter_->Seek(target); }
395
+
396
+ // Positions the iterator at the cell containing "target". If no such cell
397
+ // exists, returns false and leaves the iterator positioned arbitrarily.
398
+ // The returned index cell is guaranteed to contain all edges that might
399
+ // intersect the line segment between "target" and the cell center.
400
+ bool Locate(const S2Point& target) {
401
+ return IteratorBase::LocateImpl(target, this);
402
+ }
403
+
404
+ // Let T be the target S2CellId. If T is contained by some index cell I
405
+ // (including equality), this method positions the iterator at I and
406
+ // returns INDEXED. Otherwise if T contains one or more (smaller) index
407
+ // cells, it positions the iterator at the first such cell I and returns
408
+ // SUBDIVIDED. Otherwise it returns DISJOINT and leaves the iterator
409
+ // positioned arbitrarily.
410
+ CellRelation Locate(S2CellId target) {
411
+ return IteratorBase::LocateImpl(target, this);
412
+ }
413
+
414
+ private:
415
+ // Although S2ShapeIndex::Iterator can be used to iterate over any
416
+ // index subtype, it is more efficient to use the subtype's iterator when
417
+ // the subtype is known at compile time. For example, MutableS2ShapeIndex
418
+ // should use a MutableS2ShapeIndex::Iterator.
419
+ //
420
+ // The following declarations prevent accidental use of
421
+ // S2ShapeIndex::Iterator when the actual subtype is known. (If you
422
+ // really want to do this, you can down_cast the index argument to
423
+ // S2ShapeIndex.)
424
+ template <class T>
425
+ explicit Iterator(const T* index, InitialPosition pos = UNPOSITIONED) {}
426
+
427
+ template <class T>
428
+ void Init(const T* index, InitialPosition pos = UNPOSITIONED) {}
429
+
430
+ std::unique_ptr<IteratorBase> iter_;
431
+ };
432
+
433
+ // ShapeFactory is an interface for decoding vectors of S2Shapes. It allows
434
+ // random access to the shapes in order to support lazy decoding. See
435
+ // s2shapeutil_coding.h for useful subtypes.
436
+ class ShapeFactory {
437
+ public:
438
+ virtual ~ShapeFactory() {}
439
+
440
+ // Returns the number of S2Shapes in the vector.
441
+ virtual int size() const = 0;
442
+
443
+ // Returns the S2Shape object corresponding to the given "shape_id".
444
+ // Returns nullptr if a shape cannot be decoded or a shape is missing
445
+ // (e.g., because MutableS2ShapeIndex::Release() was called).
446
+ virtual std::unique_ptr<S2Shape> operator[](int shape_id) const = 0;
447
+
448
+ // Returns a deep copy of this ShapeFactory.
449
+ virtual std::unique_ptr<ShapeFactory> Clone() const = 0;
450
+ };
451
+
452
+ protected:
453
+ // Each subtype of S2ShapeIndex should define an Iterator type derived
454
+ // from the following base class.
455
+ class IteratorBase {
456
+ public:
457
+ virtual ~IteratorBase() {}
458
+
459
+ IteratorBase(const IteratorBase&);
460
+ IteratorBase& operator=(const IteratorBase&);
461
+
462
+ // Returns the S2CellId of the current index cell. If done() is true,
463
+ // returns a value larger than any valid S2CellId (S2CellId::Sentinel()).
464
+ S2CellId id() const;
465
+
466
+ // Returns the center point of the cell.
467
+ // REQUIRES: !done()
468
+ S2Point center() const;
469
+
470
+ // Returns a reference to the contents of the current index cell.
471
+ // REQUIRES: !done()
472
+ const S2ShapeIndexCell& cell() const;
473
+
474
+ // Returns true if the iterator is positioned past the last index cell.
475
+ bool done() const;
476
+
477
+ // Positions the iterator at the first index cell (if any).
478
+ virtual void Begin() = 0;
479
+
480
+ // Positions the iterator past the last index cell.
481
+ virtual void Finish() = 0;
482
+
483
+ // Positions the iterator at the next index cell.
484
+ // REQUIRES: !done()
485
+ virtual void Next() = 0;
486
+
487
+ // If the iterator is already positioned at the beginning, returns false.
488
+ // Otherwise positions the iterator at the previous entry and returns true.
489
+ virtual bool Prev() = 0;
490
+
491
+ // Positions the iterator at the first cell with id() >= target, or at the
492
+ // end of the index if no such cell exists.
493
+ virtual void Seek(S2CellId target) = 0;
494
+
495
+ // Positions the iterator at the cell containing "target". If no such cell
496
+ // exists, returns false and leaves the iterator positioned arbitrarily.
497
+ // The returned index cell is guaranteed to contain all edges that might
498
+ // intersect the line segment between "target" and the cell center.
499
+ virtual bool Locate(const S2Point& target) = 0;
500
+
501
+ // Let T be the target S2CellId. If T is contained by some index cell I
502
+ // (including equality), this method positions the iterator at I and
503
+ // returns INDEXED. Otherwise if T contains one or more (smaller) index
504
+ // cells, it positions the iterator at the first such cell I and returns
505
+ // SUBDIVIDED. Otherwise it returns DISJOINT and leaves the iterator
506
+ // positioned arbitrarily.
507
+ virtual CellRelation Locate(S2CellId target) = 0;
508
+
509
+ protected:
510
+ IteratorBase() : id_(S2CellId::Sentinel()), cell_(nullptr) {}
511
+
512
+ // Sets the iterator state. "cell" typically points to the cell contents,
513
+ // but may also be given as "nullptr" in order to implement decoding on
514
+ // demand. In that situation, the first that the client attempts to
515
+ // access the cell contents, the GetCell() method is called and "cell_" is
516
+ // updated in a thread-safe way.
517
+ void set_state(S2CellId id, const S2ShapeIndexCell* cell);
518
+
519
+ // Sets the iterator state so that done() is true.
520
+ void set_finished();
521
+
522
+ // Returns the current contents of the "cell_" field, which may be nullptr
523
+ // if the cell contents have not been decoded yet.
524
+ const S2ShapeIndexCell* raw_cell() const;
525
+
526
+ // This method is called to decode the contents of the current cell, if
527
+ // set_state() was previously called with a nullptr "cell" argument. This
528
+ // allows decoding on demand for subtypes that keep the cell contents in
529
+ // an encoded state. It does not need to be implemented at all if
530
+ // set_state() is always called with (cell != nullptr).
531
+ //
532
+ // REQUIRES: This method is thread-safe.
533
+ // REQUIRES: Multiple calls to this method return the same value.
534
+ virtual const S2ShapeIndexCell* GetCell() const = 0;
535
+
536
+ // Returns an exact copy of this iterator.
537
+ virtual std::unique_ptr<IteratorBase> Clone() const = 0;
538
+
539
+ // Makes a copy of the given source iterator.
540
+ // REQUIRES: "other" has the same concrete type as "this".
541
+ virtual void Copy(const IteratorBase& other) = 0;
542
+
543
+ // The default implementation of Locate(S2Point). It is instantiated by
544
+ // each subtype in order to (1) minimize the number of virtual method
545
+ // calls (since subtypes are typically "final") and (2) ensure that the
546
+ // correct versions of non-virtual methods such as cell() are called.
547
+ template <class Iter>
548
+ static bool LocateImpl(const S2Point& target, Iter* it);
549
+
550
+ // The default implementation of Locate(S2CellId) (see comments above).
551
+ template <class Iter>
552
+ static CellRelation LocateImpl(S2CellId target, Iter* it);
553
+
554
+ private:
555
+ friend class Iterator;
556
+
557
+ // This method is "const" because it is used internally by "const" methods
558
+ // in order to implement decoding on demand.
559
+ void set_cell(const S2ShapeIndexCell* cell) const;
560
+
561
+ S2CellId id_;
562
+ mutable std::atomic<const S2ShapeIndexCell*> cell_;
563
+ };
564
+
565
+ // Returns a new iterator positioned as specified.
566
+ virtual std::unique_ptr<IteratorBase> NewIterator(InitialPosition pos)
567
+ const = 0;
568
+ };
569
+
570
+ ////////////////// Implementation details follow ////////////////////
571
+
572
+
573
+ inline int S2ClippedShape::shape_id() const {
574
+ return shape_id_;
575
+ }
576
+
577
+ inline bool S2ClippedShape::contains_center() const {
578
+ return contains_center_;
579
+ }
580
+
581
+ inline int S2ClippedShape::num_edges() const {
582
+ return num_edges_;
583
+ }
584
+
585
+ inline int S2ClippedShape::edge(int i) const {
586
+ return is_inline() ? inline_edges_[i] : edges_[i];
587
+ }
588
+
589
+ // Initialize an S2ClippedShape to hold the given number of edges.
590
+ inline void S2ClippedShape::Init(int32 shape_id, int32 num_edges) {
591
+ shape_id_ = shape_id;
592
+ num_edges_ = num_edges;
593
+ contains_center_ = false;
594
+ if (!is_inline()) {
595
+ edges_ = new int32[num_edges];
596
+ }
597
+ }
598
+
599
+ // Free any memory allocated by this S2ClippedShape. We don't do this in
600
+ // the destructor because S2ClippedShapes are copied by STL code, and we
601
+ // don't want to repeatedly copy and free the edge data. Instead the data
602
+ // is owned by the containing S2ShapeIndexCell.
603
+ inline void S2ClippedShape::Destruct() {
604
+ if (!is_inline()) delete[] edges_;
605
+ }
606
+
607
+ inline bool S2ClippedShape::is_inline() const {
608
+ return num_edges_ <= inline_edges_.size();
609
+ }
610
+
611
+ // Set "contains_center_" to indicate whether this clipped shape contains the
612
+ // center of the cell to which it belongs.
613
+ inline void S2ClippedShape::set_contains_center(bool contains_center) {
614
+ contains_center_ = contains_center;
615
+ }
616
+
617
+ // Set the i-th edge of this clipped shape to be the given edge of the
618
+ // original shape.
619
+ inline void S2ClippedShape::set_edge(int i, int edge) {
620
+ if (is_inline()) {
621
+ inline_edges_[i] = edge;
622
+ } else {
623
+ edges_[i] = edge;
624
+ }
625
+ }
626
+
627
+ inline const S2ClippedShape* S2ShapeIndexCell::find_clipped(
628
+ const S2Shape* shape) const {
629
+ return find_clipped(shape->id());
630
+ }
631
+
632
+ // Inline because an index cell frequently contains just one shape.
633
+ inline int S2ShapeIndexCell::num_edges() const {
634
+ int n = 0;
635
+ for (int i = 0; i < num_clipped(); ++i) n += clipped(i).num_edges();
636
+ return n;
637
+ }
638
+
639
+ inline S2Shape* S2ShapeIndex::ShapeIterator::operator*() const {
640
+ return index_->shape(shape_id_);
641
+ }
642
+
643
+ inline S2ShapeIndex::ShapeIterator& S2ShapeIndex::ShapeIterator::operator++() {
644
+ ++shape_id_;
645
+ return *this;
646
+ }
647
+
648
+ inline S2ShapeIndex::ShapeIterator S2ShapeIndex::ShapeIterator::operator++(
649
+ int) {
650
+ return ShapeIterator(index_, shape_id_++);
651
+ }
652
+
653
+ inline bool S2ShapeIndex::ShapeIterator::operator==(ShapeIterator it) const {
654
+ S2_DCHECK_EQ(index_, it.index_);
655
+ return shape_id_ == it.shape_id_;
656
+ }
657
+
658
+ inline bool S2ShapeIndex::ShapeIterator::operator!=(ShapeIterator it) const {
659
+ S2_DCHECK_EQ(index_, it.index_);
660
+ return shape_id_ != it.shape_id_;
661
+ }
662
+
663
+ inline S2ShapeIndex::ShapeIterator S2ShapeIndex::begin() const {
664
+ return ShapeIterator(this, 0);
665
+ }
666
+
667
+ inline S2ShapeIndex::ShapeIterator S2ShapeIndex::end() const {
668
+ return ShapeIterator(this, num_shape_ids());
669
+ }
670
+
671
+ inline S2ShapeIndex::IteratorBase::IteratorBase(const IteratorBase& other)
672
+ : id_(other.id_), cell_(other.raw_cell()) {
673
+ }
674
+
675
+ inline S2ShapeIndex::IteratorBase&
676
+ S2ShapeIndex::IteratorBase::operator=(const IteratorBase& other) {
677
+ id_ = other.id_;
678
+ set_cell(other.raw_cell());
679
+ return *this;
680
+ }
681
+
682
+ inline S2CellId S2ShapeIndex::IteratorBase::id() const {
683
+ return id_;
684
+ }
685
+
686
+ inline const S2ShapeIndexCell& S2ShapeIndex::IteratorBase::cell() const {
687
+ // Like other const methods, this method is thread-safe provided that it
688
+ // does not overlap with calls to non-const methods.
689
+ S2_DCHECK(!done());
690
+ auto cell = raw_cell();
691
+ if (cell == nullptr) {
692
+ cell = GetCell();
693
+ set_cell(cell);
694
+ }
695
+ return *cell;
696
+ }
697
+
698
+ inline bool S2ShapeIndex::IteratorBase::done() const {
699
+ return id_ == S2CellId::Sentinel();
700
+ }
701
+
702
+ inline S2Point S2ShapeIndex::IteratorBase::center() const {
703
+ S2_DCHECK(!done());
704
+ return id().ToPoint();
705
+ }
706
+
707
+ inline void S2ShapeIndex::IteratorBase::set_state(
708
+ S2CellId id, const S2ShapeIndexCell* cell) {
709
+ id_ = id;
710
+ set_cell(cell);
711
+ }
712
+
713
+ inline void S2ShapeIndex::IteratorBase::set_finished() {
714
+ id_ = S2CellId::Sentinel();
715
+ set_cell(nullptr);
716
+ }
717
+
718
+ inline const S2ShapeIndexCell* S2ShapeIndex::IteratorBase::raw_cell()
719
+ const {
720
+ return cell_.load(std::memory_order_relaxed);
721
+ }
722
+
723
+ inline void S2ShapeIndex::IteratorBase::set_cell(
724
+ const S2ShapeIndexCell* cell) const {
725
+ cell_.store(cell, std::memory_order_relaxed);
726
+ }
727
+
728
+ template <class Iter>
729
+ inline bool S2ShapeIndex::IteratorBase::LocateImpl(
730
+ const S2Point& target_point, Iter* it) {
731
+ // Let I = cell_map_->lower_bound(T), where T is the leaf cell containing
732
+ // "target_point". Then if T is contained by an index cell, then the
733
+ // containing cell is either I or I'. We test for containment by comparing
734
+ // the ranges of leaf cells spanned by T, I, and I'.
735
+
736
+ S2CellId target(target_point);
737
+ it->Seek(target);
738
+ if (!it->done() && it->id().range_min() <= target) return true;
739
+ if (it->Prev() && it->id().range_max() >= target) return true;
740
+ return false;
741
+ }
742
+
743
+ template <class Iter>
744
+ inline S2ShapeIndex::CellRelation
745
+ S2ShapeIndex::IteratorBase::LocateImpl(S2CellId target, Iter* it) {
746
+ // Let T be the target, let I = cell_map_->lower_bound(T.range_min()), and
747
+ // let I' be the predecessor of I. If T contains any index cells, then T
748
+ // contains I. Similarly, if T is contained by an index cell, then the
749
+ // containing cell is either I or I'. We test for containment by comparing
750
+ // the ranges of leaf cells spanned by T, I, and I'.
751
+
752
+ it->Seek(target.range_min());
753
+ if (!it->done()) {
754
+ if (it->id() >= target && it->id().range_min() <= target) return INDEXED;
755
+ if (it->id() <= target.range_max()) return SUBDIVIDED;
756
+ }
757
+ if (it->Prev() && it->id().range_max() >= target) return INDEXED;
758
+ return DISJOINT;
759
+ }
760
+
761
+ inline S2ShapeIndex::Iterator::Iterator(const Iterator& other)
762
+ : iter_(other.iter_->Clone()) {
763
+ }
764
+
765
+ inline S2ShapeIndex::Iterator& S2ShapeIndex::Iterator::operator=(
766
+ const Iterator& other) {
767
+ iter_->Copy(*other.iter_);
768
+ return *this;
769
+ }
770
+
771
+ inline S2ShapeIndex::Iterator::Iterator(Iterator&& other)
772
+ : iter_(std::move(other.iter_)) {
773
+ }
774
+
775
+ inline S2ShapeIndex::Iterator& S2ShapeIndex::Iterator::operator=(
776
+ Iterator&& other) {
777
+ iter_ = std::move(other.iter_);
778
+ return *this;
779
+ }
780
+
781
+ #endif // S2_S2SHAPE_INDEX_H_