@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,1057 @@
1
+ // Copyright 2016 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
+ // This class is a replacement for S2PolygonBuilder. Once all clients have
19
+ // been updated to use this class, S2PolygonBuilder will be removed.
20
+
21
+ #ifndef S2_S2BUILDER_H_
22
+ #define S2_S2BUILDER_H_
23
+
24
+ #include <memory>
25
+ #include <utility>
26
+ #include <vector>
27
+ #include "s2/base/integral_types.h"
28
+ #include "s2/third_party/absl/base/macros.h"
29
+ #include "s2/_fp_contract_off.h"
30
+ #include "s2/id_set_lexicon.h"
31
+ #include "s2/mutable_s2shape_index.h"
32
+ #include "s2/s1angle.h"
33
+ #include "s2/s1chord_angle.h"
34
+ #include "s2/s2cell_id.h"
35
+ #include "s2/s2error.h"
36
+ #include "s2/s2point_index.h"
37
+ #include "s2/s2shape_index.h"
38
+ #include "s2/util/gtl/compact_array.h"
39
+
40
+ class S2Loop;
41
+ class S2Polygon;
42
+ class S2Polyline;
43
+
44
+ // S2Builder is a tool for assembling polygonal geometry from edges. Here are
45
+ // some of the things it is designed for:
46
+ //
47
+ // 1. Building polygons, polylines, and polygon meshes from unsorted
48
+ // collections of edges.
49
+ //
50
+ // 2. Snapping geometry to discrete representations (such as S2CellId centers
51
+ // or E7 lat/lng coordinates) while preserving the input topology and with
52
+ // guaranteed error bounds.
53
+ //
54
+ // 3. Simplifying geometry (e.g. for indexing, display, or storage).
55
+ //
56
+ // 4. Importing geometry from other formats, including repairing geometry
57
+ // that has errors.
58
+ //
59
+ // 5. As a tool for implementing more complex operations such as polygon
60
+ // intersections and unions.
61
+ //
62
+ // The implementation is based on the framework of "snap rounding". Unlike
63
+ // most snap rounding implementations, S2Builder defines edges as geodesics on
64
+ // the sphere (straight lines) and uses the topology of the sphere (i.e.,
65
+ // there are no "seams" at the poles or 180th meridian). The algorithm is
66
+ // designed to be 100% robust for arbitrary input geometry. It offers the
67
+ // following properties:
68
+ //
69
+ // - Guaranteed bounds on how far input vertices and edges can move during
70
+ // the snapping process (i.e., at most the given "snap_radius").
71
+ //
72
+ // - Guaranteed minimum separation between edges and vertices other than
73
+ // their endpoints (similar to the goals of Iterated Snap Rounding). In
74
+ // other words, edges that do not intersect in the output are guaranteed
75
+ // to have a minimum separation between them.
76
+ //
77
+ // - Idempotency (similar to the goals of Stable Snap Rounding), i.e. if the
78
+ // input already meets the output criteria then it will not be modified.
79
+ //
80
+ // - Preservation of the input topology (up to the creation of
81
+ // degeneracies). This means that there exists a continuous deformation
82
+ // from the input to the output such that no vertex crosses an edge. In
83
+ // other words, self-intersections won't be created, loops won't change
84
+ // orientation, etc.
85
+ //
86
+ // - The ability to snap to arbitrary discrete point sets (such as S2CellId
87
+ // centers, E7 lat/lng points on the sphere, or simply a subset of the
88
+ // input vertices), rather than being limited to an integer grid.
89
+ //
90
+ // Here are some of its other features:
91
+ //
92
+ // - It can handle both directed and undirected edges. Undirected edges can
93
+ // be useful for importing data from other formats, e.g. where loops have
94
+ // unspecified orientations.
95
+ //
96
+ // - It can eliminate self-intersections by finding all edge pairs that cross
97
+ // and adding a new vertex at each intersection point.
98
+ //
99
+ // - It can simplify polygons to within a specified tolerance. For example,
100
+ // if two vertices are close enough they will be merged, and if an edge
101
+ // passes nearby a vertex then it will be rerouted through that vertex.
102
+ // Optionally, it can also detect nearly straight chains of short edges and
103
+ // replace them with a single long edge, while maintaining the same
104
+ // accuracy, separation, and topology guarantees ("simplify_edge_chains").
105
+ //
106
+ // - It supports many different output types through the concept of "layers"
107
+ // (polylines, polygons, polygon meshes, etc). You can build multiple
108
+ // layers at once in order to ensure that snapping does not create
109
+ // intersections between different objects (for example, you can simplify a
110
+ // set of contour lines without the risk of having them cross each other).
111
+ //
112
+ // - It supports edge labels, which allow you to attach arbitrary information
113
+ // to edges and have it preserved during the snapping process. (This can
114
+ // also be achieved using layers, at a coarser level of granularity.)
115
+ //
116
+ // Caveats:
117
+ //
118
+ // - Because S2Builder only works with edges, it cannot distinguish between
119
+ // the empty and full polygons. If your application can generate both the
120
+ // empty and full polygons, you must implement logic outside of this class.
121
+ //
122
+ // Example showing how to snap a polygon to E7 coordinates:
123
+ //
124
+ // using s2builderutil::IntLatLngSnapFunction;
125
+ // S2Builder builder(S2Builder::Options(IntLatLngSnapFunction(7)));
126
+ // S2Polygon output;
127
+ // builder.StartLayer(absl::make_unique<s2builderutil::S2PolygonLayer>(&output));
128
+ // builder.AddPolygon(input);
129
+ // S2Error error;
130
+ // if (!builder.Build(&error)) {
131
+ // S2_LOG(ERROR) << error;
132
+ // ...
133
+ // }
134
+ class S2Builder {
135
+ public:
136
+ // Indicates whether the input edges are undirected. Typically this is
137
+ // specified for each output layer (e.g., s2builderutil::S2PolygonLayer).
138
+ //
139
+ // Directed edges are preferred, since otherwise the output is ambiguous.
140
+ // For example, output polygons may be the *inverse* of the intended result
141
+ // (e.g., a polygon intended to represent the world's oceans may instead
142
+ // represent the world's land masses). Directed edges are also somewhat
143
+ // more efficient.
144
+ //
145
+ // However even with undirected edges, most S2Builder layer types try to
146
+ // preserve the input edge direction whenever possible. Generally, edges
147
+ // are reversed only when it would yield a simpler output. For example,
148
+ // S2PolygonLayer assumes that polygons created from undirected edges should
149
+ // cover at most half of the sphere. Similarly, S2PolylineVectorLayer
150
+ // assembles edges into as few polylines as possible, even if this means
151
+ // reversing some of the "undirected" input edges.
152
+ //
153
+ // For shapes with interiors, directed edges should be oriented so that the
154
+ // interior is to the left of all edges. This means that for a polygon with
155
+ // holes, the outer loops ("shells") should be directed counter-clockwise
156
+ // while the inner loops ("holes") should be directed clockwise. Note that
157
+ // S2Builder::AddPolygon() follows this convention automatically.
158
+ enum class EdgeType { DIRECTED, UNDIRECTED };
159
+
160
+ // A SnapFunction restricts the locations of the output vertices. For
161
+ // example, there are predefined snap functions that require vertices to be
162
+ // located at S2CellId centers or at E5/E6/E7 coordinates. The SnapFunction
163
+ // can also specify a minimum spacing between vertices (the "snap radius").
164
+ //
165
+ // A SnapFunction defines the following methods:
166
+ //
167
+ // 1. The SnapPoint() method, which snaps a point P to a nearby point (the
168
+ // "candidate snap site"). Any point may be returned, including P
169
+ // itself (this is the "identity snap function").
170
+ //
171
+ // 2. "snap_radius", the maximum distance that vertices can move when
172
+ // snapped. The snap_radius must be at least as large as the maximum
173
+ // distance between P and SnapPoint(P) for any point P.
174
+ //
175
+ // 3. "max_edge_deviation", the maximum distance that edges can move when
176
+ // snapped. It is slightly larger than "snap_radius" because when a
177
+ // geodesic edge is snapped, the center of the edge moves further than
178
+ // its endpoints. This value is computed automatically by S2Builder.
179
+ //
180
+ // 4. "min_vertex_separation", the guaranteed minimum distance between
181
+ // vertices in the output. This is generally a fraction of
182
+ // "snap_radius" where the fraction depends on the snap function.
183
+ //
184
+ // 5. A "min_edge_vertex_separation", the guaranteed minimum distance
185
+ // between edges and non-incident vertices in the output. This is
186
+ // generally a fraction of "snap_radius" where the fraction depends on
187
+ // the snap function.
188
+ //
189
+ // It is important to note that SnapPoint() does not define the actual
190
+ // mapping from input vertices to output vertices, since the points it
191
+ // returns (the candidate snap sites) are further filtered to ensure that
192
+ // they are separated by at least the snap radius. For example, if you
193
+ // specify E7 coordinates (2cm resolution) and a snap radius of 10m, then a
194
+ // subset of points returned by SnapPoint will be chosen (the "snap sites"),
195
+ // and each input vertex will be mapped to the closest site. Therefore you
196
+ // cannot assume that P is necessarily snapped to SnapPoint(P).
197
+ //
198
+ // S2Builder makes the following guarantees:
199
+ //
200
+ // 1. Every vertex is at a location returned by SnapPoint().
201
+ //
202
+ // 2. Vertices are within "snap_radius" of the corresponding input vertex.
203
+ //
204
+ // 3. Edges are within "max_edge_deviation" of the corresponding input edge
205
+ // (a distance slightly larger than "snap_radius").
206
+ //
207
+ // 4. Vertices are separated by at least "min_vertex_separation"
208
+ // (a fraction of "snap_radius" that depends on the snap function).
209
+ //
210
+ // 5. Edges and non-incident vertices are separated by at least
211
+ // "min_edge_vertex_separation" (a fraction of "snap_radius").
212
+ //
213
+ // 6. Vertex and edge locations do not change unless one of the conditions
214
+ // above is not already met (idempotency / stability).
215
+ //
216
+ // 7. The topology of the input geometry is preserved (up to the creation
217
+ // of degeneracies). This means that there exists a continuous
218
+ // deformation from the input to the output such that no vertex
219
+ // crosses an edge.
220
+ class SnapFunction {
221
+ public:
222
+ virtual ~SnapFunction() {}
223
+
224
+ // The maximum distance that vertices can move when snapped.
225
+ //
226
+ // If the snap radius is zero, then vertices are snapped together only if
227
+ // they are identical. Edges will not be snapped to any vertices other
228
+ // than their endpoints, even if there are vertices whose distance to the
229
+ // edge is zero, unless split_crossing_edges() is true.
230
+ //
231
+ // REQUIRES: snap_radius() <= kMaxSnapRadius
232
+ virtual S1Angle snap_radius() const = 0;
233
+
234
+ // The maximum supported snap radius (equivalent to about 7800km).
235
+ static S1Angle kMaxSnapRadius();
236
+
237
+ // The maximum distance that the center of an edge can move when snapped.
238
+ // This is slightly larger than "snap_radius" because when a geodesic edge
239
+ // is snapped, the center of the edge moves further than its endpoints.
240
+ S1Angle max_edge_deviation() const;
241
+
242
+ // The guaranteed minimum distance between vertices in the output.
243
+ // This is generally some fraction of "snap_radius".
244
+ virtual S1Angle min_vertex_separation() const = 0;
245
+
246
+ // The guaranteed minimum spacing between edges and non-incident vertices
247
+ // in the output. This is generally some fraction of "snap_radius".
248
+ virtual S1Angle min_edge_vertex_separation() const = 0;
249
+
250
+ // Returns a candidate snap site for the given point. The final vertex
251
+ // locations are a subset of the snap sites returned by this function
252
+ // (spaced at least "min_vertex_separation" apart).
253
+ //
254
+ // The only requirement is that SnapPoint(x) must return a point whose
255
+ // distance from "x" is no greater than "snap_radius".
256
+ virtual S2Point SnapPoint(const S2Point& point) const = 0;
257
+
258
+ // Returns a deep copy of this SnapFunction.
259
+ virtual std::unique_ptr<SnapFunction> Clone() const = 0;
260
+ };
261
+
262
+ class Options {
263
+ public:
264
+ Options();
265
+
266
+ // Convenience constructor that calls set_snap_function().
267
+ explicit Options(const SnapFunction& snap_function);
268
+
269
+ // Sets the desired snap function. The snap function is copied
270
+ // internally, so you can safely pass a temporary object.
271
+ //
272
+ // Note that if your input data includes vertices that were created using
273
+ // S2::GetIntersection(), then you should use a "snap_radius" of
274
+ // at least S2::kIntersectionSnapRadius, e.g. by calling
275
+ //
276
+ // options.set_snap_function(s2builderutil::IdentitySnapFunction(
277
+ // S2::kIntersectionSnapRadius));
278
+ //
279
+ // DEFAULT: s2builderutil::IdentitySnapFunction(S1Angle::Zero())
280
+ // [This does no snapping and preserves all input vertices exactly.]
281
+ const SnapFunction& snap_function() const;
282
+ void set_snap_function(const SnapFunction& snap_function);
283
+
284
+ // If true, then detect all pairs of crossing edges and eliminate them by
285
+ // adding a new vertex at their intersection point.
286
+ //
287
+ // When this option is true, the effective snap_radius() for edges is
288
+ // increased by S2::kIntersectionError to take into account the
289
+ // additional error when computing intersection points. In other words,
290
+ // edges may move by up to snap_radius() + S2::kIntersectionError.
291
+ //
292
+ // Undirected edges should always be used when the output is a polygon,
293
+ // since splitting a directed loop at a self-intersection converts it into
294
+ // two loops that don't define a consistent interior according to the
295
+ // "interior is on the left" rule. (On the other hand, it is fine to use
296
+ // directed edges when defining a polygon *mesh* because in that case the
297
+ // input consists of sibling edge pairs.)
298
+ //
299
+ // Self-intersections can also arise when importing data from a 2D
300
+ // projection. You can minimize this problem by subdividing the input
301
+ // edges so that the S2 edges (which are geodesics) stay close to the
302
+ // original projected edges (which are curves on the sphere). This can
303
+ // be done using s2builderutil::EdgeSplitter(), for example.
304
+ //
305
+ // DEFAULT: false
306
+ bool split_crossing_edges() const;
307
+ void set_split_crossing_edges(bool split_crossing_edges);
308
+
309
+ // If true, then simplify the output geometry by replacing nearly straight
310
+ // chains of short edges with a single long edge.
311
+ //
312
+ // The combined effect of snapping and simplifying will not change the
313
+ // input by more than the guaranteed tolerances (see the list documented
314
+ // with the SnapFunction class). For example, simplified edges are
315
+ // guaranteed to pass within snap_radius() of the *original* positions of
316
+ // all vertices that were removed from that edge. This is a much tighter
317
+ // guarantee than can be achieved by snapping and simplifying separately.
318
+ //
319
+ // However, note that this option does not guarantee idempotency. In
320
+ // other words, simplifying geometry that has already been simplified once
321
+ // may simplify it further. (This is unavoidable, since tolerances are
322
+ // measured with respect to the original geometry, which is no longer
323
+ // available when the geometry is simplified a second time.)
324
+ //
325
+ // When the output consists of multiple layers, simplification is
326
+ // guaranteed to be consistent: for example, edge chains are simplified in
327
+ // the same way across layers, and simplification preserves topological
328
+ // relationships between layers (e.g., no crossing edges will be created).
329
+ // Note that edge chains in different layers do not need to be identical
330
+ // (or even have the same number of vertices, etc) in order to be
331
+ // simplified together. All that is required is that they are close
332
+ // enough together so that the same simplified edge can meet all of their
333
+ // individual snapping guarantees.
334
+ //
335
+ // Note that edge chains are approximated as parametric curves rather than
336
+ // point sets. This means that if an edge chain backtracks on itself (for
337
+ // example, ABCDEFEDCDEFGH) then such backtracking will be preserved to
338
+ // within snap_radius() (for example, if the preceding point were all in a
339
+ // straight line then the edge chain would be simplified to ACFCFH, noting
340
+ // that C and F have degree > 2 and therefore can't be simplified away).
341
+ //
342
+ // Simplified edges are assigned all labels associated with the edges of
343
+ // the simplified chain.
344
+ //
345
+ // For this option to have any effect, a SnapFunction with a non-zero
346
+ // snap_radius() must be specified. Also note that vertices specified
347
+ // using ForceVertex are never simplified away.
348
+ //
349
+ // DEFAULT: false
350
+ bool simplify_edge_chains() const;
351
+ void set_simplify_edge_chains(bool simplify_edge_chains);
352
+
353
+ // If true, then snapping occurs only when the input geometry does not
354
+ // already meet the S2Builder output guarantees (see the SnapFunction
355
+ // class description for details). This means that if all input vertices
356
+ // are at snapped locations, all vertex pairs are separated by at least
357
+ // min_vertex_separation(), and all edge-vertex pairs are separated by at
358
+ // least min_edge_vertex_separation(), then no snapping is done.
359
+ //
360
+ // If false, then all vertex pairs and edge-vertex pairs closer than
361
+ // "snap_radius" will be considered for snapping. This can be useful, for
362
+ // example, if you know that your geometry contains errors and you want to
363
+ // make sure that features closer together than "snap_radius" are merged.
364
+ //
365
+ // This option is automatically turned off by simplify_edge_chains(),
366
+ // since simplifying edge chains is never guaranteed to be idempotent.
367
+ //
368
+ // DEFAULT: true
369
+ bool idempotent() const;
370
+ void set_idempotent(bool idempotent);
371
+
372
+ // Options may be assigned and copied.
373
+ Options(const Options& options);
374
+ Options& operator=(const Options& options);
375
+
376
+ private:
377
+ std::unique_ptr<SnapFunction> snap_function_;
378
+ bool split_crossing_edges_ = false;
379
+ bool simplify_edge_chains_ = false;
380
+ bool idempotent_ = true;
381
+ };
382
+
383
+ // The following classes are only needed by Layer implementations.
384
+ class GraphOptions;
385
+ class Graph;
386
+
387
+ // For output layers that represent polygons, there is an ambiguity inherent
388
+ // in spherical geometry that does not exist in planar geometry. Namely, if
389
+ // a polygon has no edges, does it represent the empty polygon (containing
390
+ // no points) or the full polygon (containing all points)? This ambiguity
391
+ // also occurs for polygons that consist only of degeneracies, e.g. a
392
+ // degenerate loop with only two edges could be either a degenerate shell in
393
+ // the empty polygon or a degenerate hole in the full polygon.
394
+ //
395
+ // To resolve this ambiguity, an IsFullPolygonPredicate may be specified for
396
+ // each output layer (see AddIsFullPolygonPredicate below). If the output
397
+ // after snapping consists only of degenerate edges and/or sibling pairs
398
+ // (including the case where there are no edges at all), then the layer
399
+ // implementation calls the given predicate to determine whether the polygon
400
+ // is empty or full except for those degeneracies. The predicate is given
401
+ // an S2Builder::Graph containing the output edges, but note that in general
402
+ // the predicate must also have knowledge of the input geometry in order to
403
+ // determine the correct result.
404
+ //
405
+ // This predicate is only needed by layers that are assembled into polygons.
406
+ // It is not used by other layer types.
407
+ using IsFullPolygonPredicate =
408
+ std::function<bool (const Graph& g, S2Error* error)>;
409
+
410
+ // Default constructor; requires Init() to be called.
411
+ S2Builder();
412
+
413
+ // Convenience constructor that calls Init(). Note that to use the default
414
+ // options, C++ syntax requires an extra layer of parentheses:
415
+ //
416
+ // S2Builder builder{S2Builder::Options()};
417
+ explicit S2Builder(const Options& options);
418
+
419
+ // Initializes an S2Builder with the given options.
420
+ void Init(const Options& options);
421
+ const Options& options() const { return options_; }
422
+
423
+ // Starts a new output layer. This method must be called before adding any
424
+ // edges to the S2Builder. You may call this method multiple times to build
425
+ // multiple geometric objects that are snapped to the same set of sites.
426
+ //
427
+ // For example, if you have a set of contour lines, then you could put each
428
+ // contour line in a separate layer. This keeps the contour lines separate
429
+ // from each other, while also ensuring that no crossing edges are created
430
+ // when they are snapped and/or simplified. (This is not true if the
431
+ // contour lines are snapped or simplified independently.)
432
+ //
433
+ // Similarly, if you have a set of polygons that share common boundaries
434
+ // (e.g., countries), you can snap and/or simplify them at the same time by
435
+ // putting them in different layers, while ensuring that their boundaries
436
+ // remain consistent (i.e., no crossing edges or T-vertices are introduced).
437
+ //
438
+ // Ownership of the layer is transferred to the S2Builder. Example usage:
439
+ //
440
+ // S2Polyline line1, line2;
441
+ // builder.StartLayer(make_unique<s2builderutil::S2PolylineLayer>(&line1)));
442
+ // ... Add edges using builder.AddEdge(), etc ...
443
+ // builder.StartLayer(make_unique<s2builderutil::S2PolylineLayer>(&line2)));
444
+ // ... Add edges using builder.AddEdge(), etc ...
445
+ // S2Error error;
446
+ // S2_CHECK(builder.Build(&error)) << error; // Builds "line1" & "line2"
447
+ class Layer;
448
+ void StartLayer(std::unique_ptr<Layer> layer);
449
+
450
+ // Adds a degenerate edge (representing a point) to the current layer.
451
+ void AddPoint(const S2Point& v);
452
+
453
+ // Adds the given edge to the current layer.
454
+ void AddEdge(const S2Point& v0, const S2Point& v1);
455
+
456
+ // Adds the edges in the given polyline. (Note that if the polyline
457
+ // consists of 0 or 1 vertices, this method does nothing.)
458
+ void AddPolyline(const S2Polyline& polyline);
459
+
460
+ // Adds the edges in the given loop. If the sign() of the loop is negative
461
+ // (i.e. this loop represents a hole within a polygon), the edge directions
462
+ // are automatically reversed to ensure that the polygon interior is always
463
+ // to the left of every edge.
464
+ void AddLoop(const S2Loop& loop);
465
+
466
+ // Adds the loops in the given polygon. Loops representing holes have their
467
+ // edge directions automatically reversed as described for AddLoop(). Note
468
+ // that this method does not distinguish between the empty and full polygons,
469
+ // i.e. adding a full polygon has the same effect as adding an empty one.
470
+ void AddPolygon(const S2Polygon& polygon);
471
+
472
+ // Adds the edges of the given shape to the current layer.
473
+ void AddShape(const S2Shape& shape);
474
+
475
+ // For layers that are assembled into polygons, this method specifies a
476
+ // predicate that is called when the output consists entirely of degenerate
477
+ // edges and/or sibling pairs. The predicate is given an S2Builder::Graph
478
+ // containing the output edges (if any) and is responsible for deciding
479
+ // whether this graph represents the empty polygon (possibly with degenerate
480
+ // shells) or the full polygon (possibly with degenerate holes). Note that
481
+ // this cannot be determined from the output edges alone; it also requires
482
+ // knowledge of the input geometry. (Also see IsFullPolygonPredicate above.)
483
+ //
484
+ // This method should be called at most once per layer; additional calls
485
+ // simply overwrite the previous value for the current layer.
486
+ //
487
+ // The default predicate simply returns false (i.e., degenerate polygons are
488
+ // assumed to be empty). Arguably it would better to return an error in
489
+ // this case, but the fact is that relatively few clients need to be able to
490
+ // construct full polygons, and it is unreasonable to expect all such
491
+ // clients to supply an appropriate predicate.
492
+ //
493
+ // The reason for having a predicate rather than a boolean value is that the
494
+ // predicate is responsible for determining whether the output polygon is
495
+ // empty or full. In general the input geometry is not degenerate, but
496
+ // rather collapses into a degenerate configuration due to snapping and/or
497
+ // simplification.
498
+ //
499
+ // TODO(ericv): Provide standard predicates to handle common cases,
500
+ // e.g. valid input geometry that becomes degenerate due to snapping.
501
+ void AddIsFullPolygonPredicate(IsFullPolygonPredicate predicate);
502
+
503
+ // A predicate that returns an error indicating that no polygon predicate
504
+ // has been specified.
505
+ static bool IsFullPolygonUnspecified(const S2Builder::Graph& g,
506
+ S2Error* error);
507
+
508
+ // Returns a predicate that returns a constant value (true or false);
509
+ static IsFullPolygonPredicate IsFullPolygon(bool is_full);
510
+
511
+ // Forces a vertex to be located at the given position. This can be used to
512
+ // prevent certain input vertices from moving. However if you are trying to
513
+ // preserve part of the input boundary, be aware that this option does not
514
+ // prevent edges from being split by new vertices.
515
+ //
516
+ // Forced vertices are never snapped; if this is desired then you need to
517
+ // call options().snap_function().SnapPoint() explicitly. Forced vertices
518
+ // are also never simplified away (if simplify_edge_chains() is used).
519
+ //
520
+ // Caveat: Since this method can place vertices arbitrarily close together,
521
+ // S2Builder makes no minimum separation guaranteees with forced vertices.
522
+ void ForceVertex(const S2Point& vertex);
523
+
524
+ // Every edge can have a set of non-negative integer labels attached to it.
525
+ // When used with an appropriate layer type, you can then retrieve the
526
+ // labels associated with each output edge. This can be useful when merging
527
+ // or combining data from several sources. (Note that in many cases it is
528
+ // easier to use separate output layers rather than labels.)
529
+ //
530
+ // Labels are 32-bit non-negative integers. To support other label types,
531
+ // you can use ValueLexicon to store the set of unique labels seen so far:
532
+ //
533
+ // ValueLexicon<MyLabel> my_label_lexicon;
534
+ // builder.set_label(my_label_lexicon.Add(label));
535
+ //
536
+ // The current set of labels is represented as a stack. This makes it easy
537
+ // to add and remove labels hierarchically (e.g., polygon 5, loop 2). Use
538
+ // set_label() and clear_labels() if you need at most one label per edge.
539
+ //
540
+ using Label = int32;
541
+
542
+ // Clear the stack of labels.
543
+ void clear_labels();
544
+
545
+ // Add a label to the stack.
546
+ // REQUIRES: label >= 0.
547
+ void push_label(Label label);
548
+
549
+ // Remove a label from the stack.
550
+ void pop_label();
551
+
552
+ // Convenience function that clears the stack and adds a single label.
553
+ // REQUIRES: label >= 0.
554
+ void set_label(Label label);
555
+
556
+ // Performs the requested edge splitting, snapping, simplification, etc, and
557
+ // then assembles the resulting edges into the requested output layers.
558
+ //
559
+ // Returns true if all edges were assembled; otherwise sets "error"
560
+ // appropriately. Depending on the error, some or all output layers may
561
+ // have been created. Automatically resets the S2Builder state so that it
562
+ // can be reused.
563
+ //
564
+ // REQUIRES: error != nullptr.
565
+ bool Build(S2Error* error);
566
+
567
+ // Clears all input data and resets the builder state. Any options
568
+ // specified are preserved.
569
+ void Reset();
570
+
571
+ private:
572
+ ////////////////////// Input Types /////////////////////////
573
+ // All types associated with the S2Builder inputs are prefixed with "Input".
574
+
575
+ // Identifies an input vertex.
576
+ using InputVertexId = int32;
577
+
578
+ // Defines an input edge.
579
+ using InputEdge = std::pair<InputVertexId, InputVertexId>;
580
+
581
+ // Identifies an input edge.
582
+ using InputEdgeId = int32;
583
+
584
+ // Identifies the set of input edge ids that were snapped to a given edge.
585
+ using InputEdgeIdSetId = int32;
586
+
587
+ // Sort key for prioritizing input vertices. (Note that keys are *not*
588
+ // compared using std::less; see SortInputVertices for details.)
589
+ using InputVertexKey = std::pair<S2CellId, InputVertexId>;
590
+
591
+ ////////////////////// Output Types /////////////////////////
592
+ // These types define the output vertices and edges.
593
+
594
+ // Identifies a snapped vertex ("snap site"). If there is only one layer,
595
+ // than SiteId is the same as Graph::VertexId, but if there are many layers
596
+ // then each Graph may contain only a subset of the sites. Also see
597
+ // GraphOptions::allow_vertex_filtering().
598
+ using SiteId = int32;
599
+
600
+ // Defines an output edge.
601
+ using Edge = std::pair<SiteId, SiteId>;
602
+
603
+ // Identifies an output edge.
604
+ using EdgeId = int32;
605
+
606
+ // Identifies an output edge in a particular layer.
607
+ using LayerEdgeId = std::pair<int, EdgeId>;
608
+
609
+ class EdgeChainSimplifier;
610
+
611
+ InputVertexId AddVertex(const S2Point& v);
612
+ void ChooseSites();
613
+ void CopyInputEdges();
614
+ std::vector<InputVertexKey> SortInputVertices();
615
+ void AddEdgeCrossings(const MutableS2ShapeIndex& input_edge_index);
616
+ void AddForcedSites(S2PointIndex<SiteId>* site_index);
617
+ bool is_forced(SiteId v) const;
618
+ void ChooseInitialSites(S2PointIndex<SiteId>* site_index);
619
+ S2Point SnapSite(const S2Point& point) const;
620
+ void CollectSiteEdges(const S2PointIndex<SiteId>& site_index);
621
+ void SortSitesByDistance(const S2Point& x,
622
+ gtl::compact_array<SiteId>* sites) const;
623
+ void AddExtraSites(const MutableS2ShapeIndex& input_edge_index);
624
+ void MaybeAddExtraSites(InputEdgeId edge_id,
625
+ InputEdgeId max_edge_id,
626
+ const std::vector<SiteId>& chain,
627
+ const MutableS2ShapeIndex& input_edge_index,
628
+ std::vector<InputEdgeId>* snap_queue);
629
+ void AddExtraSite(const S2Point& new_site,
630
+ InputEdgeId max_edge_id,
631
+ const MutableS2ShapeIndex& input_edge_index,
632
+ std::vector<InputEdgeId>* snap_queue);
633
+ S2Point GetSeparationSite(const S2Point& site_to_avoid,
634
+ const S2Point& v0, const S2Point& v1,
635
+ InputEdgeId input_edge_id) const;
636
+ S2Point GetCoverageEndpoint(const S2Point& p, const S2Point& x,
637
+ const S2Point& y, const S2Point& n) const;
638
+ void SnapEdge(InputEdgeId e, std::vector<SiteId>* chain) const;
639
+
640
+ void BuildLayers();
641
+ void BuildLayerEdges(
642
+ std::vector<std::vector<Edge>>* layer_edges,
643
+ std::vector<std::vector<InputEdgeIdSetId>>* layer_input_edge_ids,
644
+ IdSetLexicon* input_edge_id_set_lexicon);
645
+ void AddSnappedEdges(
646
+ InputEdgeId begin, InputEdgeId end, const GraphOptions& options,
647
+ std::vector<Edge>* edges, std::vector<InputEdgeIdSetId>* input_edge_ids,
648
+ IdSetLexicon* input_edge_id_set_lexicon,
649
+ std::vector<gtl::compact_array<InputVertexId>>* site_vertices) const;
650
+ void MaybeAddInputVertex(
651
+ InputVertexId v, SiteId id,
652
+ std::vector<gtl::compact_array<InputVertexId>>* site_vertices) const;
653
+ void AddSnappedEdge(SiteId src, SiteId dst, InputEdgeIdSetId id,
654
+ EdgeType edge_type, std::vector<Edge>* edges,
655
+ std::vector<InputEdgeIdSetId>* input_edge_ids) const;
656
+ void SimplifyEdgeChains(
657
+ const std::vector<gtl::compact_array<InputVertexId>>& site_vertices,
658
+ std::vector<std::vector<Edge>>* layer_edges,
659
+ std::vector<std::vector<InputEdgeIdSetId>>* layer_input_edge_ids,
660
+ IdSetLexicon* input_edge_id_set_lexicon) const;
661
+ void MergeLayerEdges(
662
+ const std::vector<std::vector<Edge>>& layer_edges,
663
+ const std::vector<std::vector<InputEdgeIdSetId>>& layer_input_edge_ids,
664
+ std::vector<Edge>* edges,
665
+ std::vector<InputEdgeIdSetId>* input_edge_ids,
666
+ std::vector<int>* edge_layers) const;
667
+ static bool StableLessThan(const Edge& a, const Edge& b,
668
+ const LayerEdgeId& ai, const LayerEdgeId& bi);
669
+
670
+ //////////// Parameters /////////////
671
+
672
+ // S2Builder options.
673
+ Options options_;
674
+
675
+ // The maximum distance (inclusive) that a vertex can move when snapped,
676
+ // equal to S1ChordAngle(options_.snap_function().snap_radius()).
677
+ S1ChordAngle site_snap_radius_ca_;
678
+
679
+ // The maximum distance (inclusive) that an edge can move when snapping to a
680
+ // snap site. It can be slightly larger than the site snap radius when
681
+ // edges are being split at crossings.
682
+ S1ChordAngle edge_snap_radius_ca_;
683
+
684
+ S1Angle max_edge_deviation_;
685
+ S1ChordAngle edge_site_query_radius_ca_;
686
+ S1ChordAngle min_edge_length_to_split_ca_;
687
+
688
+ S1Angle min_site_separation_;
689
+ S1ChordAngle min_site_separation_ca_;
690
+ S1ChordAngle min_edge_site_separation_ca_;
691
+ S1ChordAngle min_edge_site_separation_ca_limit_;
692
+
693
+ S1ChordAngle max_adjacent_site_separation_ca_;
694
+
695
+ // The squared sine of the edge snap radius. This is equivalent to the snap
696
+ // radius (squared) for distances measured through the interior of the
697
+ // sphere to the plane containing an edge. This value is used only when
698
+ // interpolating new points along edges (see GetSeparationSite).
699
+ double edge_snap_radius_sin2_;
700
+
701
+ // A copy of the argument to Build().
702
+ S2Error* error_;
703
+
704
+ // True if snapping was requested. This is true if either snap_radius() is
705
+ // positive, or split_crossing_edges() is true (which implicitly requests
706
+ // snapping to ensure that both crossing edges are snapped to the
707
+ // intersection point).
708
+ bool snapping_requested_;
709
+
710
+ // Initially false, and set to true when it is discovered that at least one
711
+ // input vertex or edge does not meet the output guarantees (e.g., that
712
+ // vertices are separated by at least snap_function.min_vertex_separation).
713
+ bool snapping_needed_;
714
+
715
+ //////////// Input Data /////////////
716
+
717
+ // A flag indicating whether label_set_ has been modified since the last
718
+ // time label_set_id_ was computed.
719
+ bool label_set_modified_;
720
+
721
+ std::vector<S2Point> input_vertices_;
722
+ std::vector<InputEdge> input_edges_;
723
+
724
+ std::vector<std::unique_ptr<Layer>> layers_;
725
+ std::vector<GraphOptions> layer_options_;
726
+ std::vector<InputEdgeId> layer_begins_;
727
+ std::vector<IsFullPolygonPredicate> layer_is_full_polygon_predicates_;
728
+
729
+ // Each input edge has "label set id" (an int32) representing the set of
730
+ // labels attached to that edge. This vector is populated only if at least
731
+ // one label is used.
732
+ using LabelSetId = int32;
733
+ std::vector<LabelSetId> label_set_ids_;
734
+ IdSetLexicon label_set_lexicon_;
735
+
736
+ // The current set of labels (represented as a stack).
737
+ std::vector<Label> label_set_;
738
+
739
+ // The LabelSetId corresponding to the current label set, computed on demand
740
+ // (by adding it to label_set_lexicon()).
741
+ LabelSetId label_set_id_;
742
+
743
+ ////////////// Data for Snapping and Simplifying //////////////
744
+
745
+ // The number of sites specified using ForceVertex(). These sites are
746
+ // always at the beginning of the sites_ vector.
747
+ SiteId num_forced_sites_;
748
+
749
+ // The set of snapped vertex locations ("sites").
750
+ std::vector<S2Point> sites_;
751
+
752
+ // A map from each input edge to the set of sites "nearby" that edge,
753
+ // defined as the set of sites that are candidates for snapping and/or
754
+ // avoidance. Note that compact_array will inline up to two sites, which
755
+ // usually takes care of the vast majority of edges. Sites are kept sorted
756
+ // by increasing distance from the origin of the input edge.
757
+ //
758
+ // Once snapping is finished, this field is discarded unless edge chain
759
+ // simplification was requested, in which case instead the sites are
760
+ // filtered by removing the ones that each edge was snapped to, leaving only
761
+ // the "sites to avoid" (needed for simplification).
762
+ std::vector<gtl::compact_array<SiteId>> edge_sites_;
763
+
764
+ S2Builder(const S2Builder&) = delete;
765
+ S2Builder& operator=(const S2Builder&) = delete;
766
+ };
767
+
768
+ // This class is only needed by S2Builder::Layer implementations. A layer is
769
+ // responsible for assembling an S2Builder::Graph of snapped edges into the
770
+ // desired output format (e.g., an S2Polygon). The GraphOptions class allows
771
+ // each Layer type to specify requirements on its input graph: for example, if
772
+ // DegenerateEdges::DISCARD is specified, then S2Builder will ensure that all
773
+ // degenerate edges are removed before passing the graph to the S2Layer::Build
774
+ // method.
775
+ class S2Builder::GraphOptions {
776
+ public:
777
+ using EdgeType = S2Builder::EdgeType;
778
+ enum class DegenerateEdges;
779
+ enum class DuplicateEdges;
780
+ enum class SiblingPairs;
781
+
782
+ // All S2Builder::Layer subtypes should specify GraphOptions explicitly
783
+ // using this constructor, rather than relying on default values.
784
+ GraphOptions(EdgeType edge_type, DegenerateEdges degenerate_edges,
785
+ DuplicateEdges duplicate_edges, SiblingPairs sibling_pairs)
786
+ : edge_type_(edge_type), degenerate_edges_(degenerate_edges),
787
+ duplicate_edges_(duplicate_edges), sibling_pairs_(sibling_pairs),
788
+ allow_vertex_filtering_(true) {
789
+ }
790
+
791
+ // The default options specify that all edges should be kept, since this
792
+ // produces the least surprising output and makes it easier to diagnose the
793
+ // problem when an option is left unspecified.
794
+ GraphOptions() : edge_type_(EdgeType::DIRECTED),
795
+ degenerate_edges_(DegenerateEdges::KEEP),
796
+ duplicate_edges_(DuplicateEdges::KEEP),
797
+ sibling_pairs_(SiblingPairs::KEEP),
798
+ allow_vertex_filtering_(true) {
799
+ }
800
+
801
+ // Specifies whether the S2Builder input edges should be treated as
802
+ // undirected. If true, then all input edges are duplicated into pairs
803
+ // consisting of an edge and a sibling (reverse) edge. The layer
804
+ // implementation is responsible for ensuring that exactly one edge from
805
+ // each pair is used in the output, i.e. *only half* of the graph edges will
806
+ // be used. (Note that some values of the sibling_pairs() option
807
+ // automatically take care of this issue by removing half of the edges and
808
+ // changing edge_type() to DIRECTED.)
809
+ //
810
+ // DEFAULT: EdgeType::DIRECTED
811
+ EdgeType edge_type() const;
812
+ void set_edge_type(EdgeType edge_type);
813
+
814
+ // Controls how degenerate edges (i.e., an edge from a vertex to itself) are
815
+ // handled. Such edges may be present in the input, or they may be created
816
+ // when both endpoints of an edge are snapped to the same output vertex.
817
+ // The options available are:
818
+ //
819
+ // DISCARD: Discards all degenerate edges. This is useful for layers that
820
+ // do not support degeneracies, such as S2PolygonLayer.
821
+ //
822
+ // DISCARD_EXCESS: Discards all degenerate edges that are connected to
823
+ // non-degenerate edges. (Any remaining duplicate edges can
824
+ // be merged using DuplicateEdges::MERGE.) This is useful
825
+ // for simplifying polygons while ensuring that loops that
826
+ // collapse to a single point do not disappear.
827
+ //
828
+ // KEEP: Keeps all degenerate edges. Be aware that this may create many
829
+ // redundant edges when simplifying geometry (e.g., a polyline of the
830
+ // form AABBBBBCCCCCCDDDD). DegenerateEdges::KEEP is mainly useful
831
+ // for algorithms that require an output edge for every input edge.
832
+ //
833
+ // DEFAULT: DegenerateEdges::KEEP
834
+ enum class DegenerateEdges { DISCARD, DISCARD_EXCESS, KEEP };
835
+ DegenerateEdges degenerate_edges() const;
836
+ void set_degenerate_edges(DegenerateEdges degenerate_edges);
837
+
838
+ // Controls how duplicate edges (i.e., edges that are present multiple
839
+ // times) are handled. Such edges may be present in the input, or they can
840
+ // be created when vertices are snapped together. When several edges are
841
+ // merged, the result is a single edge labelled with all of the original
842
+ // input edge ids.
843
+ //
844
+ // DEFAULT: DuplicateEdges::KEEP
845
+ enum class DuplicateEdges { MERGE, KEEP };
846
+ DuplicateEdges duplicate_edges() const;
847
+ void set_duplicate_edges(DuplicateEdges duplicate_edges);
848
+
849
+ // Controls how sibling edge pairs (i.e., pairs consisting of an edge and
850
+ // its reverse edge) are handled. Layer types that define an interior
851
+ // (e.g., polygons) normally discard such edge pairs since they do not
852
+ // affect the result (i.e., they define a "loop" with no interior). The
853
+ // various options include:
854
+ //
855
+ // DISCARD: Discards all sibling edge pairs.
856
+ //
857
+ // DISCARD_EXCESS: Like DISCARD, except that a single sibling pair is kept
858
+ // if the result would otherwise be empty. This is useful
859
+ // for polygons with degeneracies (S2LaxPolygonShape), and
860
+ // for simplifying polylines while ensuring that they are
861
+ // not split into multiple disconnected pieces.
862
+ //
863
+ // KEEP: Keeps sibling pairs. This can be used to create polylines that
864
+ // double back on themselves, or degenerate loops (with a layer type
865
+ // such as S2LaxPolygonShape).
866
+ //
867
+ // REQUIRE: Requires that all edges have a sibling (and returns an error
868
+ // otherwise). This is useful with layer types that create a
869
+ // collection of adjacent polygons (a polygon mesh).
870
+ //
871
+ // CREATE: Ensures that all edges have a sibling edge by creating them if
872
+ // necessary. This is useful with polygon meshes where the input
873
+ // polygons do not cover the entire sphere. Such edges always
874
+ // have an empty set of labels.
875
+ //
876
+ // If edge_type() is EdgeType::UNDIRECTED, a sibling edge pair is considered
877
+ // to consist of four edges (two duplicate edges and their siblings), since
878
+ // only two of these four edges will be used in the final output.
879
+ //
880
+ // Furthermore, since the options REQUIRE and CREATE guarantee that all
881
+ // edges will have siblings, S2Builder implements these options for
882
+ // undirected edges by discarding half of the edges in each direction and
883
+ // changing the edge_type() to EdgeType::DIRECTED. For example, two
884
+ // undirected input edges between vertices A and B would first be converted
885
+ // into two directed edges in each direction, and then one edge of each pair
886
+ // would be discarded leaving only one edge in each direction.
887
+ //
888
+ // Degenerate edges are considered not to have siblings. If such edges are
889
+ // present, they are passed through unchanged by SiblingPairs::DISCARD. For
890
+ // SiblingPairs::REQUIRE or SiblingPairs::CREATE with undirected edges, the
891
+ // number of copies of each degenerate edge is reduced by a factor of two.
892
+ //
893
+ // Any of the options that discard edges (DISCARD, DISCARD_EXCESS, and
894
+ // REQUIRE/CREATE in the case of undirected edges) have the side effect that
895
+ // when duplicate edges are present, all of the corresponding edge labels
896
+ // are merged together and assigned to the remaining edges. (This avoids
897
+ // the problem of having to decide which edges are discarded.) Note that
898
+ // this merging takes place even when all copies of an edge are kept, and
899
+ // that even labels attached to duplicate degenerate edges are merged. For
900
+ // example, consider the graph {AB1, AB2, BA3, CD4, CD5} (where XYn denotes
901
+ // an edge from X to Y with label "n"). With SiblingPairs::DISCARD, we need
902
+ // to discard one of the copies of AB. But which one? Rather than choosing
903
+ // arbitrarily, instead we merge the labels of all duplicate edges (even
904
+ // ones where no sibling pairs were discarded), yielding {AB12, CD45, CD45}
905
+ // (assuming that duplicate edges are being kept).
906
+ //
907
+ // DEFAULT: SiblingPairs::KEEP
908
+ enum class SiblingPairs { DISCARD, DISCARD_EXCESS, KEEP, REQUIRE, CREATE };
909
+ SiblingPairs sibling_pairs() const;
910
+ void set_sibling_pairs(SiblingPairs sibling_pairs);
911
+
912
+ // This is a specialized option that is only needed by clients want to work
913
+ // with the graphs for multiple layers at the same time (e.g., in order to
914
+ // check whether the same edge is present in two different graphs). [Note
915
+ // that if you need to do this, usually it is easier just to build a single
916
+ // graph with suitable edge labels.]
917
+ //
918
+ // When there are a large number of layers, then by default S2Builder builds
919
+ // a minimal subgraph for each layer containing only the vertices needed by
920
+ // the edges in that layer. This ensures that layer types that iterate over
921
+ // the vertices run in time proportional to the size of that layer rather
922
+ // than the size of all layers combined. (For example, if there are a
923
+ // million layers with one edge each, then each layer would be passed a
924
+ // graph with 2 vertices rather than 2 million vertices.)
925
+ //
926
+ // If this option is set to false, this optimization is disabled. Instead
927
+ // the graph passed to this layer will contain the full set of vertices.
928
+ // (This is not recommended when the number of layers could be large.)
929
+ //
930
+ // DEFAULT: true
931
+ bool allow_vertex_filtering() const;
932
+ void set_allow_vertex_filtering(bool allow_vertex_filtering);
933
+
934
+ private:
935
+ EdgeType edge_type_;
936
+ DegenerateEdges degenerate_edges_;
937
+ DuplicateEdges duplicate_edges_;
938
+ SiblingPairs sibling_pairs_;
939
+ bool allow_vertex_filtering_;
940
+ };
941
+
942
+ bool operator==(const S2Builder::GraphOptions& x,
943
+ const S2Builder::GraphOptions& y);
944
+
945
+
946
+ ////////////////// Implementation details follow ////////////////////
947
+
948
+
949
+ // The maximum snap radius is just large enough to support snapping to
950
+ // S2CellId level 0. It is equivalent to 7800km on the Earth's surface.
951
+ inline S1Angle S2Builder::SnapFunction::kMaxSnapRadius() {
952
+ // This value can't be larger than 85.7 degrees without changing the code
953
+ // related to min_edge_length_to_split_ca_, and increasing it to 90 degrees
954
+ // or more would most likely require significant changes to the algorithm.
955
+ return S1Angle::Degrees(70);
956
+ }
957
+
958
+ inline const S2Builder::SnapFunction& S2Builder::Options::snap_function()
959
+ const {
960
+ return *snap_function_;
961
+ }
962
+
963
+ inline void S2Builder::Options::set_snap_function(
964
+ const SnapFunction& snap_function) {
965
+ snap_function_ = snap_function.Clone();
966
+ }
967
+
968
+ inline bool S2Builder::Options::split_crossing_edges() const {
969
+ return split_crossing_edges_;
970
+ }
971
+
972
+ inline void S2Builder::Options::set_split_crossing_edges(
973
+ bool split_crossing_edges) {
974
+ split_crossing_edges_ = split_crossing_edges;
975
+ }
976
+
977
+ inline bool S2Builder::Options::simplify_edge_chains() const {
978
+ return simplify_edge_chains_;
979
+ }
980
+
981
+ inline void S2Builder::Options::set_simplify_edge_chains(
982
+ bool simplify_edge_chains) {
983
+ simplify_edge_chains_ = simplify_edge_chains;
984
+
985
+ // Simplification requires a non-zero snap radius, and while it might be
986
+ // possible to do some simplifying without snapping, it is much simpler to
987
+ // always snap (even if the input geometry already meets the other output
988
+ // requirements). We need to compute edge_sites_ in order to avoid
989
+ // approaching non-incident vertices too closely, for example.
990
+ set_idempotent(false);
991
+ }
992
+
993
+ inline bool S2Builder::Options::idempotent() const {
994
+ return idempotent_;
995
+ }
996
+
997
+ inline void S2Builder::Options::set_idempotent(bool idempotent) {
998
+ idempotent_ = idempotent;
999
+ }
1000
+
1001
+ inline S2Builder::GraphOptions::EdgeType
1002
+ S2Builder::GraphOptions::edge_type() const {
1003
+ return edge_type_;
1004
+ }
1005
+
1006
+ inline void S2Builder::GraphOptions::set_edge_type(EdgeType edge_type) {
1007
+ edge_type_ = edge_type;
1008
+ }
1009
+
1010
+ inline S2Builder::GraphOptions::DegenerateEdges
1011
+ S2Builder::GraphOptions::degenerate_edges() const {
1012
+ return degenerate_edges_;
1013
+ }
1014
+
1015
+ inline void S2Builder::GraphOptions::set_degenerate_edges(
1016
+ DegenerateEdges degenerate_edges) {
1017
+ degenerate_edges_ = degenerate_edges;
1018
+ }
1019
+
1020
+ inline S2Builder::GraphOptions::DuplicateEdges
1021
+ S2Builder::GraphOptions::duplicate_edges() const {
1022
+ return duplicate_edges_;
1023
+ }
1024
+
1025
+ inline void S2Builder::GraphOptions::set_duplicate_edges(
1026
+ DuplicateEdges duplicate_edges) {
1027
+ duplicate_edges_ = duplicate_edges;
1028
+ }
1029
+
1030
+ inline S2Builder::GraphOptions::SiblingPairs
1031
+ S2Builder::GraphOptions::sibling_pairs() const {
1032
+ return sibling_pairs_;
1033
+ }
1034
+
1035
+ inline void S2Builder::GraphOptions::set_sibling_pairs(
1036
+ SiblingPairs sibling_pairs) {
1037
+ sibling_pairs_ = sibling_pairs;
1038
+ }
1039
+
1040
+ inline bool S2Builder::GraphOptions::allow_vertex_filtering() const {
1041
+ return allow_vertex_filtering_;
1042
+ }
1043
+
1044
+ inline void S2Builder::GraphOptions::set_allow_vertex_filtering(
1045
+ bool allow_vertex_filtering) {
1046
+ allow_vertex_filtering_ = allow_vertex_filtering;
1047
+ }
1048
+
1049
+ inline bool S2Builder::is_forced(SiteId v) const {
1050
+ return v < num_forced_sites_;
1051
+ }
1052
+
1053
+ inline void S2Builder::AddPoint(const S2Point& v) {
1054
+ AddEdge(v, v);
1055
+ }
1056
+
1057
+ #endif // S2_S2BUILDER_H_