@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.
- package/.circleci/config.yml +45 -0
- package/.dockerignore +1 -0
- package/.gitmodules +3 -0
- package/CHANGELOG.md +33 -0
- package/LICENSE +201 -0
- package/README.md +147 -0
- package/binding.gyp +170 -0
- package/docker/Dockerfile.node20.test +8 -0
- package/docker/Dockerfile.node22.test +8 -0
- package/docker/Dockerfile.node24.test +8 -0
- package/index.d.ts +117 -0
- package/index.js +6 -0
- package/jest.config.js +184 -0
- package/package.json +43 -0
- package/publish-linux.sh +18 -0
- package/publish-osx.sh +19 -0
- package/src/builder.cc +84 -0
- package/src/builder.h +29 -0
- package/src/cell.cc +71 -0
- package/src/cell.h +26 -0
- package/src/cell_id.cc +210 -0
- package/src/cell_id.h +44 -0
- package/src/cell_union.cc +237 -0
- package/src/cell_union.h +34 -0
- package/src/earth.cc +185 -0
- package/src/earth.h +33 -0
- package/src/latlng.cc +132 -0
- package/src/latlng.h +28 -0
- package/src/loop.cc +51 -0
- package/src/loop.h +21 -0
- package/src/point.cc +69 -0
- package/src/point.h +23 -0
- package/src/polygon.cc +36 -0
- package/src/polygon.h +20 -0
- package/src/polyline.cc +186 -0
- package/src/polyline.h +34 -0
- package/src/region_coverer.cc +450 -0
- package/src/region_coverer.h +56 -0
- package/src/s2.cc +27 -0
- package/test/Cell.test.js +37 -0
- package/test/CellId.test.js +135 -0
- package/test/CellUnion.test.js +150 -0
- package/test/Earth.test.js +62 -0
- package/test/LatLng.test.js +45 -0
- package/test/Point.test.js +14 -0
- package/test/Polyline.test.js +78 -0
- package/test/RegionCoverer.test.js +301 -0
- package/test.sh +16 -0
- package/third_party/s2geometry/.travis.yml +163 -0
- package/third_party/s2geometry/AUTHORS +13 -0
- package/third_party/s2geometry/CONTRIBUTING.md +65 -0
- package/third_party/s2geometry/CONTRIBUTORS +30 -0
- package/third_party/s2geometry/LICENSE +202 -0
- package/third_party/s2geometry/NOTICE +5 -0
- package/third_party/s2geometry/README.md +127 -0
- package/third_party/s2geometry/doc/examples/point_index.cc +44 -0
- package/third_party/s2geometry/doc/examples/term_index.cc +99 -0
- package/third_party/s2geometry/doc/examples/term_index.py +101 -0
- package/third_party/s2geometry/src/python/coder.i +125 -0
- package/third_party/s2geometry/src/python/pywraps2_test.py +786 -0
- package/third_party/s2geometry/src/python/s2.i +37 -0
- package/third_party/s2geometry/src/python/s2_common.i +756 -0
- package/third_party/s2geometry/src/s2/_fp_contract_off.h +60 -0
- package/third_party/s2geometry/src/s2/base/casts.h +318 -0
- package/third_party/s2geometry/src/s2/base/commandlineflags.h +67 -0
- package/third_party/s2geometry/src/s2/base/integral_types.h +31 -0
- package/third_party/s2geometry/src/s2/base/log_severity.h +40 -0
- package/third_party/s2geometry/src/s2/base/logging.h +173 -0
- package/third_party/s2geometry/src/s2/base/mutex.h +61 -0
- package/third_party/s2geometry/src/s2/base/port.h +999 -0
- package/third_party/s2geometry/src/s2/base/spinlock.h +60 -0
- package/third_party/s2geometry/src/s2/base/stringprintf.cc +107 -0
- package/third_party/s2geometry/src/s2/base/stringprintf.h +53 -0
- package/third_party/s2geometry/src/s2/base/strtoint.cc +65 -0
- package/third_party/s2geometry/src/s2/base/strtoint.h +106 -0
- package/third_party/s2geometry/src/s2/base/timer.h +50 -0
- package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector.cc +164 -0
- package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector.h +110 -0
- package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector_test.cc +232 -0
- package/third_party/s2geometry/src/s2/encoded_s2point_vector.cc +838 -0
- package/third_party/s2geometry/src/s2/encoded_s2point_vector.h +140 -0
- package/third_party/s2geometry/src/s2/encoded_s2point_vector_test.cc +344 -0
- package/third_party/s2geometry/src/s2/encoded_s2shape_index.cc +181 -0
- package/third_party/s2geometry/src/s2/encoded_s2shape_index.h +276 -0
- package/third_party/s2geometry/src/s2/encoded_s2shape_index_test.cc +244 -0
- package/third_party/s2geometry/src/s2/encoded_string_vector.cc +66 -0
- package/third_party/s2geometry/src/s2/encoded_string_vector.h +164 -0
- package/third_party/s2geometry/src/s2/encoded_string_vector_test.cc +69 -0
- package/third_party/s2geometry/src/s2/encoded_uint_vector.h +299 -0
- package/third_party/s2geometry/src/s2/encoded_uint_vector_test.cc +124 -0
- package/third_party/s2geometry/src/s2/id_set_lexicon.cc +81 -0
- package/third_party/s2geometry/src/s2/id_set_lexicon.h +199 -0
- package/third_party/s2geometry/src/s2/id_set_lexicon_test.cc +70 -0
- package/third_party/s2geometry/src/s2/mutable_s2shape_index.cc +1585 -0
- package/third_party/s2geometry/src/s2/mutable_s2shape_index.h +600 -0
- package/third_party/s2geometry/src/s2/mutable_s2shape_index_test.cc +589 -0
- package/third_party/s2geometry/src/s2/r1interval.h +220 -0
- package/third_party/s2geometry/src/s2/r1interval_test.cc +185 -0
- package/third_party/s2geometry/src/s2/r2.h +26 -0
- package/third_party/s2geometry/src/s2/r2rect.cc +93 -0
- package/third_party/s2geometry/src/s2/r2rect.h +234 -0
- package/third_party/s2geometry/src/s2/r2rect_test.cc +228 -0
- package/third_party/s2geometry/src/s2/s1angle.cc +54 -0
- package/third_party/s2geometry/src/s2/s1angle.h +336 -0
- package/third_party/s2geometry/src/s2/s1angle_test.cc +185 -0
- package/third_party/s2geometry/src/s2/s1chord_angle.cc +159 -0
- package/third_party/s2geometry/src/s2/s1chord_angle.h +369 -0
- package/third_party/s2geometry/src/s2/s1chord_angle_test.cc +207 -0
- package/third_party/s2geometry/src/s2/s1interval.cc +296 -0
- package/third_party/s2geometry/src/s2/s1interval.h +266 -0
- package/third_party/s2geometry/src/s2/s1interval_test.cc +469 -0
- package/third_party/s2geometry/src/s2/s2boolean_operation.cc +2391 -0
- package/third_party/s2geometry/src/s2/s2boolean_operation.h +501 -0
- package/third_party/s2geometry/src/s2/s2boolean_operation_test.cc +1400 -0
- package/third_party/s2geometry/src/s2/s2builder.cc +1828 -0
- package/third_party/s2geometry/src/s2/s2builder.h +1057 -0
- package/third_party/s2geometry/src/s2/s2builder_graph.cc +1084 -0
- package/third_party/s2geometry/src/s2/s2builder_graph.h +799 -0
- package/third_party/s2geometry/src/s2/s2builder_graph_test.cc +462 -0
- package/third_party/s2geometry/src/s2/s2builder_layer.h +50 -0
- package/third_party/s2geometry/src/s2/s2builder_test.cc +1329 -0
- package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer.cc +313 -0
- package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer.h +221 -0
- package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer_test.cc +261 -0
- package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies.cc +392 -0
- package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies.h +86 -0
- package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies_test.cc +182 -0
- package/third_party/s2geometry/src/s2/s2builderutil_graph_shape.h +57 -0
- package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer.cc +212 -0
- package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer.h +218 -0
- package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer_test.cc +367 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer.cc +74 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer.h +122 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer_test.cc +167 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer.cc +191 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer.h +211 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer_test.cc +312 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer.cc +105 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer.h +174 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer_test.cc +220 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer.cc +98 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer.h +292 -0
- package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer_test.cc +233 -0
- package/third_party/s2geometry/src/s2/s2builderutil_snap_functions.cc +354 -0
- package/third_party/s2geometry/src/s2/s2builderutil_snap_functions.h +239 -0
- package/third_party/s2geometry/src/s2/s2builderutil_snap_functions_test.cc +716 -0
- package/third_party/s2geometry/src/s2/s2builderutil_testing.cc +37 -0
- package/third_party/s2geometry/src/s2/s2builderutil_testing.h +100 -0
- package/third_party/s2geometry/src/s2/s2builderutil_testing_test.cc +85 -0
- package/third_party/s2geometry/src/s2/s2cap.cc +347 -0
- package/third_party/s2geometry/src/s2/s2cap.h +286 -0
- package/third_party/s2geometry/src/s2/s2cap_test.cc +379 -0
- package/third_party/s2geometry/src/s2/s2cell.cc +552 -0
- package/third_party/s2geometry/src/s2/s2cell.h +249 -0
- package/third_party/s2geometry/src/s2/s2cell_id.cc +619 -0
- package/third_party/s2geometry/src/s2/s2cell_id.h +705 -0
- package/third_party/s2geometry/src/s2/s2cell_id_test.cc +633 -0
- package/third_party/s2geometry/src/s2/s2cell_index.cc +149 -0
- package/third_party/s2geometry/src/s2/s2cell_index.h +660 -0
- package/third_party/s2geometry/src/s2/s2cell_index_test.cc +411 -0
- package/third_party/s2geometry/src/s2/s2cell_test.cc +687 -0
- package/third_party/s2geometry/src/s2/s2cell_union.cc +515 -0
- package/third_party/s2geometry/src/s2/s2cell_union.h +399 -0
- package/third_party/s2geometry/src/s2/s2cell_union_test.cc +598 -0
- package/third_party/s2geometry/src/s2/s2centroids.cc +84 -0
- package/third_party/s2geometry/src/s2/s2centroids.h +87 -0
- package/third_party/s2geometry/src/s2/s2centroids_test.cc +82 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query.cc +123 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query.h +385 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query_base.h +841 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query_base_test.cc +63 -0
- package/third_party/s2geometry/src/s2/s2closest_cell_query_test.cc +412 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query.cc +106 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query.h +421 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query_base.h +946 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query_base_test.cc +59 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query_test.cc +505 -0
- package/third_party/s2geometry/src/s2/s2closest_edge_query_testing.h +91 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query.cc +66 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query.h +465 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query_base.h +767 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query_base_test.cc +63 -0
- package/third_party/s2geometry/src/s2/s2closest_point_query_test.cc +312 -0
- package/third_party/s2geometry/src/s2/s2contains_point_query.h +328 -0
- package/third_party/s2geometry/src/s2/s2contains_point_query_test.cc +159 -0
- package/third_party/s2geometry/src/s2/s2contains_vertex_query.cc +39 -0
- package/third_party/s2geometry/src/s2/s2contains_vertex_query.h +66 -0
- package/third_party/s2geometry/src/s2/s2contains_vertex_query_test.cc +67 -0
- package/third_party/s2geometry/src/s2/s2convex_hull_query.cc +198 -0
- package/third_party/s2geometry/src/s2/s2convex_hull_query.h +110 -0
- package/third_party/s2geometry/src/s2/s2convex_hull_query_test.cc +208 -0
- package/third_party/s2geometry/src/s2/s2coords.cc +146 -0
- package/third_party/s2geometry/src/s2/s2coords.h +459 -0
- package/third_party/s2geometry/src/s2/s2coords_internal.h +71 -0
- package/third_party/s2geometry/src/s2/s2coords_test.cc +218 -0
- package/third_party/s2geometry/src/s2/s2crossing_edge_query.cc +380 -0
- package/third_party/s2geometry/src/s2/s2crossing_edge_query.h +220 -0
- package/third_party/s2geometry/src/s2/s2crossing_edge_query_test.cc +382 -0
- package/third_party/s2geometry/src/s2/s2debug.cc +23 -0
- package/third_party/s2geometry/src/s2/s2debug.h +69 -0
- package/third_party/s2geometry/src/s2/s2distance_target.h +165 -0
- package/third_party/s2geometry/src/s2/s2earth.cc +52 -0
- package/third_party/s2geometry/src/s2/s2earth.h +268 -0
- package/third_party/s2geometry/src/s2/s2earth_test.cc +146 -0
- package/third_party/s2geometry/src/s2/s2edge_clipping.cc +462 -0
- package/third_party/s2geometry/src/s2/s2edge_clipping.h +183 -0
- package/third_party/s2geometry/src/s2/s2edge_clipping_test.cc +335 -0
- package/third_party/s2geometry/src/s2/s2edge_crosser.cc +85 -0
- package/third_party/s2geometry/src/s2/s2edge_crosser.h +343 -0
- package/third_party/s2geometry/src/s2/s2edge_crosser_test.cc +264 -0
- package/third_party/s2geometry/src/s2/s2edge_crossings.cc +515 -0
- package/third_party/s2geometry/src/s2/s2edge_crossings.h +138 -0
- package/third_party/s2geometry/src/s2/s2edge_crossings_internal.h +59 -0
- package/third_party/s2geometry/src/s2/s2edge_crossings_test.cc +246 -0
- package/third_party/s2geometry/src/s2/s2edge_distances.cc +419 -0
- package/third_party/s2geometry/src/s2/s2edge_distances.h +192 -0
- package/third_party/s2geometry/src/s2/s2edge_distances_test.cc +539 -0
- package/third_party/s2geometry/src/s2/s2edge_tessellator.cc +276 -0
- package/third_party/s2geometry/src/s2/s2edge_tessellator.h +101 -0
- package/third_party/s2geometry/src/s2/s2edge_tessellator_test.cc +492 -0
- package/third_party/s2geometry/src/s2/s2edge_vector_shape.h +85 -0
- package/third_party/s2geometry/src/s2/s2edge_vector_shape_test.cc +66 -0
- package/third_party/s2geometry/src/s2/s2error.cc +29 -0
- package/third_party/s2geometry/src/s2/s2error.h +147 -0
- package/third_party/s2geometry/src/s2/s2error_test.cc +31 -0
- package/third_party/s2geometry/src/s2/s2furthest_edge_query.cc +117 -0
- package/third_party/s2geometry/src/s2/s2furthest_edge_query.h +439 -0
- package/third_party/s2geometry/src/s2/s2furthest_edge_query_test.cc +487 -0
- package/third_party/s2geometry/src/s2/s2latlng.cc +90 -0
- package/third_party/s2geometry/src/s2/s2latlng.h +234 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect.cc +727 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect.h +434 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect_bounder.cc +344 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect_bounder.h +89 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect_bounder_test.cc +306 -0
- package/third_party/s2geometry/src/s2/s2latlng_rect_test.cc +1030 -0
- package/third_party/s2geometry/src/s2/s2latlng_test.cc +165 -0
- package/third_party/s2geometry/src/s2/s2lax_loop_shape.cc +104 -0
- package/third_party/s2geometry/src/s2/s2lax_loop_shape.h +153 -0
- package/third_party/s2geometry/src/s2/s2lax_loop_shape_test.cc +101 -0
- package/third_party/s2geometry/src/s2/s2lax_polygon_shape.cc +348 -0
- package/third_party/s2geometry/src/s2/s2lax_polygon_shape.h +183 -0
- package/third_party/s2geometry/src/s2/s2lax_polygon_shape_test.cc +234 -0
- package/third_party/s2geometry/src/s2/s2lax_polyline_shape.cc +118 -0
- package/third_party/s2geometry/src/s2/s2lax_polyline_shape.h +124 -0
- package/third_party/s2geometry/src/s2/s2lax_polyline_shape_test.cc +62 -0
- package/third_party/s2geometry/src/s2/s2loop.cc +1509 -0
- package/third_party/s2geometry/src/s2/s2loop.h +711 -0
- package/third_party/s2geometry/src/s2/s2loop_measures.cc +313 -0
- package/third_party/s2geometry/src/s2/s2loop_measures.h +280 -0
- package/third_party/s2geometry/src/s2/s2loop_measures_test.cc +367 -0
- package/third_party/s2geometry/src/s2/s2loop_test.cc +1371 -0
- package/third_party/s2geometry/src/s2/s2max_distance_targets.cc +265 -0
- package/third_party/s2geometry/src/s2/s2max_distance_targets.h +241 -0
- package/third_party/s2geometry/src/s2/s2max_distance_targets_test.cc +367 -0
- package/third_party/s2geometry/src/s2/s2measures.cc +128 -0
- package/third_party/s2geometry/src/s2/s2measures.h +78 -0
- package/third_party/s2geometry/src/s2/s2measures_test.cc +135 -0
- package/third_party/s2geometry/src/s2/s2metrics.cc +122 -0
- package/third_party/s2geometry/src/s2/s2metrics.h +199 -0
- package/third_party/s2geometry/src/s2/s2metrics_test.cc +127 -0
- package/third_party/s2geometry/src/s2/s2min_distance_targets.cc +295 -0
- package/third_party/s2geometry/src/s2/s2min_distance_targets.h +273 -0
- package/third_party/s2geometry/src/s2/s2min_distance_targets_test.cc +239 -0
- package/third_party/s2geometry/src/s2/s2padded_cell.cc +162 -0
- package/third_party/s2geometry/src/s2/s2padded_cell.h +108 -0
- package/third_party/s2geometry/src/s2/s2padded_cell_test.cc +138 -0
- package/third_party/s2geometry/src/s2/s2point.h +38 -0
- package/third_party/s2geometry/src/s2/s2point_compression.cc +388 -0
- package/third_party/s2geometry/src/s2/s2point_compression.h +78 -0
- package/third_party/s2geometry/src/s2/s2point_compression_test.cc +305 -0
- package/third_party/s2geometry/src/s2/s2point_index.h +345 -0
- package/third_party/s2geometry/src/s2/s2point_index_test.cc +147 -0
- package/third_party/s2geometry/src/s2/s2point_region.cc +72 -0
- package/third_party/s2geometry/src/s2/s2point_region.h +76 -0
- package/third_party/s2geometry/src/s2/s2point_region_test.cc +100 -0
- package/third_party/s2geometry/src/s2/s2point_span.h +57 -0
- package/third_party/s2geometry/src/s2/s2point_test.cc +47 -0
- package/third_party/s2geometry/src/s2/s2point_vector_shape.h +127 -0
- package/third_party/s2geometry/src/s2/s2point_vector_shape_test.cc +59 -0
- package/third_party/s2geometry/src/s2/s2pointutil.cc +131 -0
- package/third_party/s2geometry/src/s2/s2pointutil.h +138 -0
- package/third_party/s2geometry/src/s2/s2pointutil_test.cc +157 -0
- package/third_party/s2geometry/src/s2/s2polygon.cc +1569 -0
- package/third_party/s2geometry/src/s2/s2polygon.h +934 -0
- package/third_party/s2geometry/src/s2/s2polygon_test.cc +3025 -0
- package/third_party/s2geometry/src/s2/s2polyline.cc +645 -0
- package/third_party/s2geometry/src/s2/s2polyline.h +379 -0
- package/third_party/s2geometry/src/s2/s2polyline_alignment.cc +414 -0
- package/third_party/s2geometry/src/s2/s2polyline_alignment.h +245 -0
- package/third_party/s2geometry/src/s2/s2polyline_alignment_internal.h +158 -0
- package/third_party/s2geometry/src/s2/s2polyline_alignment_test.cc +610 -0
- package/third_party/s2geometry/src/s2/s2polyline_measures.cc +42 -0
- package/third_party/s2geometry/src/s2/s2polyline_measures.h +53 -0
- package/third_party/s2geometry/src/s2/s2polyline_measures_test.cc +57 -0
- package/third_party/s2geometry/src/s2/s2polyline_simplifier.cc +187 -0
- package/third_party/s2geometry/src/s2/s2polyline_simplifier.h +109 -0
- package/third_party/s2geometry/src/s2/s2polyline_simplifier_test.cc +165 -0
- package/third_party/s2geometry/src/s2/s2polyline_test.cc +554 -0
- package/third_party/s2geometry/src/s2/s2predicates.cc +1486 -0
- package/third_party/s2geometry/src/s2/s2predicates.h +282 -0
- package/third_party/s2geometry/src/s2/s2predicates_internal.h +135 -0
- package/third_party/s2geometry/src/s2/s2predicates_test.cc +1427 -0
- package/third_party/s2geometry/src/s2/s2projections.cc +109 -0
- package/third_party/s2geometry/src/s2/s2projections.h +161 -0
- package/third_party/s2geometry/src/s2/s2projections_test.cc +78 -0
- package/third_party/s2geometry/src/s2/s2r2rect.cc +88 -0
- package/third_party/s2geometry/src/s2/s2r2rect.h +292 -0
- package/third_party/s2geometry/src/s2/s2r2rect_test.cc +312 -0
- package/third_party/s2geometry/src/s2/s2region.cc +26 -0
- package/third_party/s2geometry/src/s2/s2region.h +142 -0
- package/third_party/s2geometry/src/s2/s2region_coverer.cc +514 -0
- package/third_party/s2geometry/src/s2/s2region_coverer.h +356 -0
- package/third_party/s2geometry/src/s2/s2region_coverer_test.cc +509 -0
- package/third_party/s2geometry/src/s2/s2region_intersection.cc +84 -0
- package/third_party/s2geometry/src/s2/s2region_intersection.h +79 -0
- package/third_party/s2geometry/src/s2/s2region_term_indexer.cc +270 -0
- package/third_party/s2geometry/src/s2/s2region_term_indexer.h +299 -0
- package/third_party/s2geometry/src/s2/s2region_term_indexer_test.cc +209 -0
- package/third_party/s2geometry/src/s2/s2region_test.cc +370 -0
- package/third_party/s2geometry/src/s2/s2region_union.cc +90 -0
- package/third_party/s2geometry/src/s2/s2region_union.h +83 -0
- package/third_party/s2geometry/src/s2/s2region_union_test.cc +89 -0
- package/third_party/s2geometry/src/s2/s2shape.h +283 -0
- package/third_party/s2geometry/src/s2/s2shape_index.cc +321 -0
- package/third_party/s2geometry/src/s2/s2shape_index.h +781 -0
- package/third_party/s2geometry/src/s2/s2shape_index_buffered_region.cc +113 -0
- package/third_party/s2geometry/src/s2/s2shape_index_buffered_region.h +135 -0
- package/third_party/s2geometry/src/s2/s2shape_index_buffered_region_test.cc +162 -0
- package/third_party/s2geometry/src/s2/s2shape_index_measures.cc +92 -0
- package/third_party/s2geometry/src/s2/s2shape_index_measures.h +100 -0
- package/third_party/s2geometry/src/s2/s2shape_index_measures_test.cc +136 -0
- package/third_party/s2geometry/src/s2/s2shape_index_region.h +350 -0
- package/third_party/s2geometry/src/s2/s2shape_index_region_test.cc +161 -0
- package/third_party/s2geometry/src/s2/s2shape_index_test.cc +24 -0
- package/third_party/s2geometry/src/s2/s2shape_measures.cc +138 -0
- package/third_party/s2geometry/src/s2/s2shape_measures.h +95 -0
- package/third_party/s2geometry/src/s2/s2shape_measures_test.cc +139 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries.cc +120 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries.h +66 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries_test.cc +170 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_coding.cc +253 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_coding.h +283 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_coding_test.cc +54 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force.cc +40 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force.h +41 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force_test.cc +55 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_count_edges.h +57 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_count_edges_test.cc +43 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator.cc +45 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator.h +72 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator_test.cc +116 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point.cc +107 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point.h +48 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point_test.cc +104 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator.cc +58 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator.h +65 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator_test.cc +61 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_shape_edge.h +58 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_shape_edge_id.h +97 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_testing.cc +104 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_testing.h +36 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs.cc +440 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs.h +72 -0
- package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs_test.cc +184 -0
- package/third_party/s2geometry/src/s2/s2testing.cc +464 -0
- package/third_party/s2geometry/src/s2/s2testing.h +385 -0
- package/third_party/s2geometry/src/s2/s2testing_test.cc +166 -0
- package/third_party/s2geometry/src/s2/s2text_format.cc +506 -0
- package/third_party/s2geometry/src/s2/s2text_format.h +289 -0
- package/third_party/s2geometry/src/s2/s2text_format_test.cc +417 -0
- package/third_party/s2geometry/src/s2/s2wedge_relations.cc +80 -0
- package/third_party/s2geometry/src/s2/s2wedge_relations.h +64 -0
- package/third_party/s2geometry/src/s2/s2wedge_relations_test.cc +89 -0
- package/third_party/s2geometry/src/s2/sequence_lexicon.h +296 -0
- package/third_party/s2geometry/src/s2/sequence_lexicon_test.cc +113 -0
- package/third_party/s2geometry/src/s2/strings/ostringstream.cc +35 -0
- package/third_party/s2geometry/src/s2/strings/ostringstream.h +105 -0
- package/third_party/s2geometry/src/s2/strings/serialize.cc +46 -0
- package/third_party/s2geometry/src/s2/strings/serialize.h +40 -0
- package/third_party/s2geometry/src/s2/third_party/absl/algorithm/algorithm.h +187 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/attributes.h +666 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/casts.h +189 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/config.h +462 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/dynamic_annotations.cc +129 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/dynamic_annotations.h +394 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/atomic_hook.h +168 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/identity.h +33 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/inline_variable.h +117 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/invoke.h +188 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/raw_logging.cc +254 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/raw_logging.h +205 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/throw_delegate.cc +106 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/throw_delegate.h +71 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/internal/unaligned_access.h +322 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/log_severity.h +77 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/macros.h +236 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/optimization.h +177 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/policy_checks.h +124 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/port.h +97 -0
- package/third_party/s2geometry/src/s2/third_party/absl/base/thread_annotations.h +277 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/fixed_array.h +523 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/inlined_vector.h +1453 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/internal/compressed_tuple.h +191 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/internal/container_memory.h +424 -0
- package/third_party/s2geometry/src/s2/third_party/absl/container/internal/layout.h +739 -0
- package/third_party/s2geometry/src/s2/third_party/absl/memory/memory.h +755 -0
- package/third_party/s2geometry/src/s2/third_party/absl/meta/type_traits.h +436 -0
- package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128.cc +232 -0
- package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128.h +656 -0
- package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128_have_intrinsic.inc +3 -0
- package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128_no_intrinsic.inc +3 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii.cc +198 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii.h +239 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii_ctype.h +66 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/bits.h +53 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/memutil.cc +110 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/memutil.h +146 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/resize_uninitialized.h +72 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/match.cc +38 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/match.h +89 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/numbers.cc +909 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/numbers.h +187 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_cat.cc +240 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_cat.h +398 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_join.h +22 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_split.cc +47 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/str_split.h +43 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/string_view.cc +245 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/string_view.h +602 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/strip.cc +42 -0
- package/third_party/s2geometry/src/s2/third_party/absl/strings/strip.h +130 -0
- package/third_party/s2geometry/src/s2/third_party/absl/types/span.h +793 -0
- package/third_party/s2geometry/src/s2/third_party/absl/utility/utility.h +299 -0
- package/third_party/s2geometry/src/s2/util/bits/bit-interleave.cc +274 -0
- package/third_party/s2geometry/src/s2/util/bits/bit-interleave.h +53 -0
- package/third_party/s2geometry/src/s2/util/bits/bits.cc +155 -0
- package/third_party/s2geometry/src/s2/util/bits/bits.h +745 -0
- package/third_party/s2geometry/src/s2/util/coding/coder.cc +83 -0
- package/third_party/s2geometry/src/s2/util/coding/coder.h +553 -0
- package/third_party/s2geometry/src/s2/util/coding/nth-derivative.h +134 -0
- package/third_party/s2geometry/src/s2/util/coding/transforms.h +62 -0
- package/third_party/s2geometry/src/s2/util/coding/varint.cc +289 -0
- package/third_party/s2geometry/src/s2/util/coding/varint.h +476 -0
- package/third_party/s2geometry/src/s2/util/endian/endian.h +859 -0
- package/third_party/s2geometry/src/s2/util/gtl/btree.h +2471 -0
- package/third_party/s2geometry/src/s2/util/gtl/btree_container.h +411 -0
- package/third_party/s2geometry/src/s2/util/gtl/btree_map.h +79 -0
- package/third_party/s2geometry/src/s2/util/gtl/btree_set.h +73 -0
- package/third_party/s2geometry/src/s2/util/gtl/compact_array.h +653 -0
- package/third_party/s2geometry/src/s2/util/gtl/container_logging.h +291 -0
- package/third_party/s2geometry/src/s2/util/gtl/dense_hash_set.h +358 -0
- package/third_party/s2geometry/src/s2/util/gtl/densehashtable.h +1493 -0
- package/third_party/s2geometry/src/s2/util/gtl/hashtable_common.h +253 -0
- package/third_party/s2geometry/src/s2/util/gtl/layout.h +28 -0
- package/third_party/s2geometry/src/s2/util/gtl/legacy_random_shuffle.h +77 -0
- package/third_party/s2geometry/src/s2/util/hash/mix.h +76 -0
- package/third_party/s2geometry/src/s2/util/math/exactfloat/exactfloat.cc +832 -0
- package/third_party/s2geometry/src/s2/util/math/exactfloat/exactfloat.h +646 -0
- package/third_party/s2geometry/src/s2/util/math/mathutil.cc +75 -0
- package/third_party/s2geometry/src/s2/util/math/mathutil.h +189 -0
- package/third_party/s2geometry/src/s2/util/math/matrix3x3.h +574 -0
- package/third_party/s2geometry/src/s2/util/math/vector.h +569 -0
- package/third_party/s2geometry/src/s2/util/math/vector3_hash.h +54 -0
- package/third_party/s2geometry/src/s2/util/units/length-units.cc +21 -0
- package/third_party/s2geometry/src/s2/util/units/length-units.h +135 -0
- package/third_party/s2geometry/src/s2/util/units/physical-units.h +313 -0
- package/third_party/s2geometry/src/s2/value_lexicon.h +234 -0
- package/third_party/s2geometry/src/s2/value_lexicon_test.cc +121 -0
- package/third_party/s2geometry/third_party/cmake/FindGFlags.cmake +48 -0
- 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_
|