@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,209 @@
|
|
|
1
|
+
// Copyright 2017 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
|
+
#include "s2/s2region_term_indexer.h"
|
|
19
|
+
|
|
20
|
+
#include <cstdio>
|
|
21
|
+
#include <memory>
|
|
22
|
+
#include <set>
|
|
23
|
+
#include <string>
|
|
24
|
+
#include <unordered_map>
|
|
25
|
+
#include <vector>
|
|
26
|
+
|
|
27
|
+
#include "s2/base/commandlineflags.h"
|
|
28
|
+
#include "s2/base/logging.h"
|
|
29
|
+
#include <gtest/gtest.h>
|
|
30
|
+
|
|
31
|
+
#include "s2/s2cap.h"
|
|
32
|
+
#include "s2/s2cell.h"
|
|
33
|
+
#include "s2/s2cell_id.h"
|
|
34
|
+
#include "s2/s2cell_union.h"
|
|
35
|
+
#include "s2/s2testing.h"
|
|
36
|
+
|
|
37
|
+
using std::vector;
|
|
38
|
+
|
|
39
|
+
S2_DEFINE_int32(iters, 400, "number of iterations for testing");
|
|
40
|
+
|
|
41
|
+
namespace {
|
|
42
|
+
|
|
43
|
+
enum QueryType { POINT, CAP };
|
|
44
|
+
|
|
45
|
+
void TestRandomCaps(const S2RegionTermIndexer::Options& options,
|
|
46
|
+
QueryType query_type) {
|
|
47
|
+
// This function creates an index consisting either of points (if
|
|
48
|
+
// options.index_contains_points_only() is true) or S2Caps of random size.
|
|
49
|
+
// It then executes queries consisting of points (if query_type == POINT)
|
|
50
|
+
// or S2Caps of random size (if query_type == CAP).
|
|
51
|
+
S2RegionTermIndexer indexer(options);
|
|
52
|
+
S2RegionCoverer coverer(options);
|
|
53
|
+
vector<S2Cap> caps;
|
|
54
|
+
vector<S2CellUnion> coverings;
|
|
55
|
+
std::unordered_map<string, vector<int>> index;
|
|
56
|
+
int index_terms = 0, query_terms = 0;
|
|
57
|
+
for (int i = 0; i < FLAGS_iters; ++i) {
|
|
58
|
+
// Choose the region to be indexed: either a single point or a cap
|
|
59
|
+
// of random size (up to a full sphere).
|
|
60
|
+
S2Cap cap;
|
|
61
|
+
vector<string> terms;
|
|
62
|
+
if (options.index_contains_points_only()) {
|
|
63
|
+
cap = S2Cap::FromPoint(S2Testing::RandomPoint());
|
|
64
|
+
terms = indexer.GetIndexTerms(cap.center(), "");
|
|
65
|
+
} else {
|
|
66
|
+
cap = S2Testing::GetRandomCap(
|
|
67
|
+
0.3 * S2Cell::AverageArea(options.max_level()),
|
|
68
|
+
4.0 * S2Cell::AverageArea(options.min_level()));
|
|
69
|
+
terms = indexer.GetIndexTerms(cap, "");
|
|
70
|
+
}
|
|
71
|
+
caps.push_back(cap);
|
|
72
|
+
coverings.push_back(coverer.GetCovering(cap));
|
|
73
|
+
for (const string& term : terms) {
|
|
74
|
+
index[term].push_back(i);
|
|
75
|
+
}
|
|
76
|
+
index_terms += terms.size();
|
|
77
|
+
}
|
|
78
|
+
for (int i = 0; i < FLAGS_iters; ++i) {
|
|
79
|
+
// Choose the region to be queried: either a random point or a cap of
|
|
80
|
+
// random size.
|
|
81
|
+
S2Cap cap;
|
|
82
|
+
vector<string> terms;
|
|
83
|
+
if (query_type == QueryType::CAP) {
|
|
84
|
+
cap = S2Cap::FromPoint(S2Testing::RandomPoint());
|
|
85
|
+
terms = indexer.GetQueryTerms(cap.center(), "");
|
|
86
|
+
} else {
|
|
87
|
+
cap = S2Testing::GetRandomCap(
|
|
88
|
+
0.3 * S2Cell::AverageArea(options.max_level()),
|
|
89
|
+
4.0 * S2Cell::AverageArea(options.min_level()));
|
|
90
|
+
terms = indexer.GetQueryTerms(cap, "");
|
|
91
|
+
}
|
|
92
|
+
// Compute the expected results of the S2Cell query by brute force.
|
|
93
|
+
S2CellUnion covering = coverer.GetCovering(cap);
|
|
94
|
+
std::set<int> expected, actual;
|
|
95
|
+
for (int j = 0; j < caps.size(); ++j) {
|
|
96
|
+
if (covering.Intersects(coverings[j])) {
|
|
97
|
+
expected.insert(j);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (const string& term : terms) {
|
|
101
|
+
actual.insert(index[term].begin(), index[term].end());
|
|
102
|
+
}
|
|
103
|
+
EXPECT_EQ(expected, actual);
|
|
104
|
+
query_terms += terms.size();
|
|
105
|
+
}
|
|
106
|
+
printf("Index terms/doc: %.2f, Query terms/doc: %.2f\n",
|
|
107
|
+
static_cast<double>(index_terms) / FLAGS_iters,
|
|
108
|
+
static_cast<double>(query_terms) / FLAGS_iters);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// We run one test case for each combination of space vs. time optimization,
|
|
112
|
+
// and indexing regions vs. only points.
|
|
113
|
+
|
|
114
|
+
TEST(S2RegionTermIndexer, IndexRegionsQueryRegionsOptimizeTime) {
|
|
115
|
+
S2RegionTermIndexer::Options options;
|
|
116
|
+
options.set_optimize_for_space(false); // Optimize for time.
|
|
117
|
+
options.set_min_level(0); // Use face cells.
|
|
118
|
+
options.set_max_level(16);
|
|
119
|
+
options.set_max_cells(20);
|
|
120
|
+
TestRandomCaps(options, QueryType::CAP);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
TEST(S2RegionTermIndexer, IndexRegionsQueryPointsOptimizeTime) {
|
|
124
|
+
S2RegionTermIndexer::Options options;
|
|
125
|
+
options.set_optimize_for_space(false); // Optimize for time.
|
|
126
|
+
options.set_min_level(0); // Use face cells.
|
|
127
|
+
options.set_max_level(16);
|
|
128
|
+
options.set_max_cells(20);
|
|
129
|
+
TestRandomCaps(options, QueryType::POINT);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
TEST(S2RegionTermIndexer, IndexRegionsQueryRegionsOptimizeTimeWithLevelMod) {
|
|
133
|
+
S2RegionTermIndexer::Options options;
|
|
134
|
+
options.set_optimize_for_space(false); // Optimize for time.
|
|
135
|
+
options.set_min_level(6); // Constrain min/max levels.
|
|
136
|
+
options.set_max_level(12);
|
|
137
|
+
options.set_level_mod(3);
|
|
138
|
+
TestRandomCaps(options, QueryType::CAP);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
TEST(S2RegionTermIndexer, IndexRegionsQueryRegionsOptimizeSpace) {
|
|
142
|
+
S2RegionTermIndexer::Options options;
|
|
143
|
+
options.set_optimize_for_space(true); // Optimize for space.
|
|
144
|
+
options.set_min_level(4);
|
|
145
|
+
options.set_max_level(S2CellId::kMaxLevel); // Use leaf cells.
|
|
146
|
+
options.set_max_cells(8);
|
|
147
|
+
TestRandomCaps(options, QueryType::CAP);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
TEST(S2RegionTermIndexer, IndexPointsQueryRegionsOptimizeTime) {
|
|
151
|
+
S2RegionTermIndexer::Options options;
|
|
152
|
+
options.set_optimize_for_space(false); // Optimize for time.
|
|
153
|
+
options.set_min_level(0); // Use face cells.
|
|
154
|
+
options.set_max_level(S2CellId::kMaxLevel);
|
|
155
|
+
options.set_level_mod(2);
|
|
156
|
+
options.set_max_cells(20);
|
|
157
|
+
options.set_index_contains_points_only(true);
|
|
158
|
+
TestRandomCaps(options, QueryType::CAP);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
TEST(S2RegionTermIndexer, IndexPointsQueryRegionsOptimizeSpace) {
|
|
162
|
+
S2RegionTermIndexer::Options options;
|
|
163
|
+
options.set_optimize_for_space(true); // Optimize for space.
|
|
164
|
+
options.set_index_contains_points_only(true);
|
|
165
|
+
// Use default parameter values.
|
|
166
|
+
TestRandomCaps(options, QueryType::CAP);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
TEST(S2RegionTermIndexer, MaxLevelSetLoosely) {
|
|
170
|
+
// Test that correct terms are generated even when (max_level - min_level)
|
|
171
|
+
// is not a multiple of level_mod.
|
|
172
|
+
S2RegionTermIndexer::Options options;
|
|
173
|
+
options.set_min_level(1);
|
|
174
|
+
options.set_level_mod(2);
|
|
175
|
+
options.set_max_level(19);
|
|
176
|
+
S2RegionTermIndexer indexer1(options);
|
|
177
|
+
options.set_max_level(20);
|
|
178
|
+
S2RegionTermIndexer indexer2(options);
|
|
179
|
+
|
|
180
|
+
S2Point point = S2Testing::RandomPoint();
|
|
181
|
+
EXPECT_EQ(indexer1.GetIndexTerms(point, ""),
|
|
182
|
+
indexer2.GetIndexTerms(point, ""));
|
|
183
|
+
EXPECT_EQ(indexer1.GetQueryTerms(point, ""),
|
|
184
|
+
indexer2.GetQueryTerms(point, ""));
|
|
185
|
+
|
|
186
|
+
S2Cap cap = S2Testing::GetRandomCap(0.0, 1.0); // Area range.
|
|
187
|
+
EXPECT_EQ(indexer1.GetIndexTerms(cap, ""),
|
|
188
|
+
indexer2.GetIndexTerms(cap, ""));
|
|
189
|
+
EXPECT_EQ(indexer1.GetQueryTerms(cap, ""),
|
|
190
|
+
indexer2.GetQueryTerms(cap, ""));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
TEST(S2RegionTermIndexer, MoveConstructor) {
|
|
194
|
+
S2RegionTermIndexer x;
|
|
195
|
+
x.mutable_options()->set_max_cells(12345);
|
|
196
|
+
S2RegionTermIndexer y = std::move(x);
|
|
197
|
+
EXPECT_EQ(12345, y.options().max_cells());
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
TEST(S2RegionTermIndexer, MoveAssignmentOperator) {
|
|
201
|
+
S2RegionTermIndexer x;
|
|
202
|
+
x.mutable_options()->set_max_cells(12345);
|
|
203
|
+
S2RegionTermIndexer y;
|
|
204
|
+
y.mutable_options()->set_max_cells(0);
|
|
205
|
+
y = std::move(x);
|
|
206
|
+
EXPECT_EQ(12345, y.options().max_cells());
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
} // namespace
|
|
@@ -0,0 +1,370 @@
|
|
|
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
|
+
|
|
17
|
+
#include "s2/s2region.h"
|
|
18
|
+
|
|
19
|
+
#include <gtest/gtest.h>
|
|
20
|
+
#include "s2/third_party/absl/container/fixed_array.h"
|
|
21
|
+
#include "s2/third_party/absl/memory/memory.h"
|
|
22
|
+
#include "s2/s2cap.h"
|
|
23
|
+
#include "s2/s2cell.h"
|
|
24
|
+
#include "s2/s2cell_id.h"
|
|
25
|
+
#include "s2/s2cell_union.h"
|
|
26
|
+
#include "s2/s2latlng.h"
|
|
27
|
+
#include "s2/s2latlng_rect.h"
|
|
28
|
+
#include "s2/s2loop.h"
|
|
29
|
+
#include "s2/s2point_compression.h"
|
|
30
|
+
#include "s2/s2point_region.h"
|
|
31
|
+
#include "s2/s2pointutil.h"
|
|
32
|
+
#include "s2/s2polygon.h"
|
|
33
|
+
#include "s2/s2polyline.h"
|
|
34
|
+
#include "s2/s2r2rect.h"
|
|
35
|
+
#include "s2/s2region_intersection.h"
|
|
36
|
+
#include "s2/s2region_union.h"
|
|
37
|
+
#include "s2/s2testing.h"
|
|
38
|
+
#include "s2/s2text_format.h"
|
|
39
|
+
|
|
40
|
+
using std::unique_ptr;
|
|
41
|
+
using std::vector;
|
|
42
|
+
|
|
43
|
+
namespace {
|
|
44
|
+
|
|
45
|
+
////////////// These values are in version 1 encoding format. ////////////////
|
|
46
|
+
|
|
47
|
+
// S2Cap.
|
|
48
|
+
const char kEncodedCapEmpty[] =
|
|
49
|
+
"000000000000F03F00000000000000000000000000000000000000000000F0BF";
|
|
50
|
+
const char kEncodedCapFull[] =
|
|
51
|
+
"000000000000F03F000000000000000000000000000000000000000000001040";
|
|
52
|
+
// S2Cap from S2Point(3, 2, 1).Normalize()
|
|
53
|
+
const char kEncodedCapFromPoint[] =
|
|
54
|
+
"3F36105836A8E93F2A2460E5CE1AE13F2A2460E5CE1AD13F0000000000000000";
|
|
55
|
+
// S2Cap from S2Point(0, 0, 1) with height 5
|
|
56
|
+
const char kEncodedCapFromCenterHeight[] =
|
|
57
|
+
"00000000000000000000000000000000000000000000F03F0000000000001040";
|
|
58
|
+
|
|
59
|
+
// S2CellId.
|
|
60
|
+
// S2CellId from Face 0.
|
|
61
|
+
const char kEncodedCellIDFace0[] = "0000000000000010";
|
|
62
|
+
// S2CellId from Face 5.
|
|
63
|
+
const char kEncodedCellIDFace5[] = "00000000000000B0";
|
|
64
|
+
// S2CellId from Face 0 in the last S2Cell at kMaxLevel.
|
|
65
|
+
const char kEncodedCellIDFace0MaxLevel[] = "0100000000000020";
|
|
66
|
+
// S2CellId from Face 5 in the last S2Cell at kMaxLevel.
|
|
67
|
+
const char kEncodedCellIDFace5MaxLevel[] = "01000000000000C0";
|
|
68
|
+
// S2CellId FromFacePosLevel(3, 0x12345678, S2CellId::kMaxLevel - 4)
|
|
69
|
+
const char kEncodedCellIDFacePosLevel[] = "0057341200000060";
|
|
70
|
+
// S2CellId from the 0 value.
|
|
71
|
+
const char kEncodedCellIDInvalid[] = "0000000000000000";
|
|
72
|
+
|
|
73
|
+
// S2Cell.
|
|
74
|
+
// S2Cell from S2Point(1, 2, 3)
|
|
75
|
+
const char kEncodedCellFromPoint[] = "F51392E0F35DCC43";
|
|
76
|
+
// S2Cell from LatLng(39.0, -120.0) - The Lake Tahoe border corner of CA/NV.
|
|
77
|
+
const char kEncodedCellFromLatLng[] = "6308962A95849980";
|
|
78
|
+
// S2Cell from FacePosLevel(3, 0x12345678, S2CellId::kMaxLevel - 4)
|
|
79
|
+
const char kEncodedCellFromFacePosLevel[] = "0057341200000060";
|
|
80
|
+
// S2Cell from Face 0.
|
|
81
|
+
const char kEncodedCellFace0[] = "0000000000000010";
|
|
82
|
+
|
|
83
|
+
// S2CellUnion.
|
|
84
|
+
// An uninitialized empty S2CellUnion.
|
|
85
|
+
const char kEncodedCellUnionEmpty[] = "010000000000000000";
|
|
86
|
+
// S2CellUnion from an S2CellId from Face 1.
|
|
87
|
+
const char kEncodedCellUnionFace1[] = "0101000000000000000000000000000030";
|
|
88
|
+
// S2CellUnion from the cells {0x33, 0x8e3748fab, 0x91230abcdef83427};
|
|
89
|
+
const char kEncodedCellUnionFromCells[] =
|
|
90
|
+
"0103000000000000003300000000000000AB8F74E3080000002734F8DEBC0A2391";
|
|
91
|
+
|
|
92
|
+
// S2LatLngRect
|
|
93
|
+
const char kEncodedRectEmpty[] =
|
|
94
|
+
"01000000000000F03F0000000000000000182D4454FB210940182D4454FB2109C0";
|
|
95
|
+
const char kEncodedRectFull[] =
|
|
96
|
+
"01182D4454FB21F9BF182D4454FB21F93F182D4454FB2109C0182D4454FB210940";
|
|
97
|
+
// S2LatLngRect from Center=(80,170), Size=(40,60)
|
|
98
|
+
const char kEncodedRectCentersize[] =
|
|
99
|
+
"0165732D3852C1F03F182D4454FB21F93FF75B8A41358C03408744E74A185706C0";
|
|
100
|
+
|
|
101
|
+
// S2Loop
|
|
102
|
+
const char kEncodedLoopEmpty[] =
|
|
103
|
+
"010100000000000000000000000000000000000000000000000000F03F0000000000010000"
|
|
104
|
+
"00000000F03F0000000000000000182D4454FB210940182D4454FB2109C0";
|
|
105
|
+
const char kEncodedLoopFull[] =
|
|
106
|
+
"010100000000000000000000000000000000000000000000000000F0BF010000000001182D"
|
|
107
|
+
"4454FB21F9BF182D4454FB21F93F182D4454FB2109C0182D4454FB210940";
|
|
108
|
+
// S2Loop from the unit test value kCross1;
|
|
109
|
+
const char kEncodedLoopCross[] =
|
|
110
|
+
"0108000000D44A8442C3F9EF3F7EDA2AB341DC913F27DCF7C958DEA1BFB4825F3C81FDEF3F"
|
|
111
|
+
"27DCF7C958DE913F1EDD892B0BDF91BFB4825F3C81FDEF3F27DCF7C958DE913F1EDD892B0B"
|
|
112
|
+
"DF913FD44A8442C3F9EF3F7EDA2AB341DC913F27DCF7C958DEA13FD44A8442C3F9EF3F7EDA"
|
|
113
|
+
"2AB341DC91BF27DCF7C958DEA13FB4825F3C81FDEF3F27DCF7C958DE91BF1EDD892B0BDF91"
|
|
114
|
+
"3FB4825F3C81FDEF3F27DCF7C958DE91BF1EDD892B0BDF91BFD44A8442C3F9EF3F7EDA2AB3"
|
|
115
|
+
"41DC91BF27DCF7C958DEA1BF0000000000013EFC10E8F8DFA1BF3EFC10E8F8DFA13F389D52"
|
|
116
|
+
"A246DF91BF389D52A246DF913F";
|
|
117
|
+
// S2Loop encoded using EncodeCompressed from snapped points.
|
|
118
|
+
// vector<S2Point> snapped_loop_a_vertices = {
|
|
119
|
+
// S2CellId(s2textformat::MakePoint("0:178")).ToPoint(),
|
|
120
|
+
// S2CellId(s2textformat::MakePoint("-1:180")).ToPoint(),
|
|
121
|
+
// S2CellId(s2textformat::MakePoint("0:-179")).ToPoint(),
|
|
122
|
+
// S2CellId(s2textformat::MakePoint("1:-180")).ToPoint()};
|
|
123
|
+
// snapped_loop = make_unique<S2Loop>(snapped_loop_a_vertices));
|
|
124
|
+
// absl::FixedArray<S2XYZFaceSiTi> points(loop.num_vertices());
|
|
125
|
+
// loop.GetXYZFaceSiTiVertices(points.data());
|
|
126
|
+
// loop.EncodeCompressed(encoder, points.data(), level);
|
|
127
|
+
//
|
|
128
|
+
const char kEncodedLoopCompressed[] =
|
|
129
|
+
"041B02222082A222A806A0C7A991DE86D905D7C3A691F2DEE40383908880A095880500000"
|
|
130
|
+
"3";
|
|
131
|
+
|
|
132
|
+
// S2PointRegion
|
|
133
|
+
// The difference between an S2PointRegion and an S2Point being encoded is the
|
|
134
|
+
// presence of the encoding version number as the first 8 bits. (i.e. when
|
|
135
|
+
// S2Loop and others encode a stream of S2Points, they are writing triples of
|
|
136
|
+
// doubles instead of encoding the points with the version byte.)
|
|
137
|
+
// S2PointRegion(S2::Origin())
|
|
138
|
+
const char kEncodedPointOrigin[] =
|
|
139
|
+
"013BED86AA997A84BF88EC8B48C53C653FACD2721A90FFEF3F";
|
|
140
|
+
// S2PointRegion(S2Point(12.34, 56.78, 9.1011).Normalize())
|
|
141
|
+
const char kEncodedPointTesting[] =
|
|
142
|
+
"0109AD578332DBCA3FBC9FDB9BB4E4EE3FE67E7C2CA7CEC33F";
|
|
143
|
+
|
|
144
|
+
// S2Polygon
|
|
145
|
+
// S2Polygon from s2textformat::MakePolygon("").
|
|
146
|
+
// This is encoded in compressed format v4.
|
|
147
|
+
const char kEncodedPolygonEmpty[] = "041E00";
|
|
148
|
+
// S2Polygon from s2textformat::MakePolygon("full").
|
|
149
|
+
// This is encoded in compressed format v4.
|
|
150
|
+
const char kEncodedPolygonFull[] = "040001010B000100";
|
|
151
|
+
// S2Polygon from the unit test value kCross1. Encoded in lossless format.
|
|
152
|
+
const char kEncodedPolygon1Loops[] =
|
|
153
|
+
"010100010000000108000000D44A8442C3F9EF3F7EDA2AB341DC913F27DCF7C958DEA1BFB4"
|
|
154
|
+
"825F3C81FDEF3F27DCF7C958DE913F1EDD892B0BDF91BFB4825F3C81FDEF3F27DCF7C958DE"
|
|
155
|
+
"913F1EDD892B0BDF913FD44A8442C3F9EF3F7EDA2AB341DC913F27DCF7C958DEA13FD44A84"
|
|
156
|
+
"42C3F9EF3F7EDA2AB341DC91BF27DCF7C958DEA13FB4825F3C81FDEF3F27DCF7C958DE91BF"
|
|
157
|
+
"1EDD892B0BDF913FB4825F3C81FDEF3F27DCF7C958DE91BF1EDD892B0BDF91BFD44A8442C3"
|
|
158
|
+
"F9EF3F7EDA2AB341DC91BF27DCF7C958DEA1BF0000000000013EFC10E8F8DFA1BF3EFC10E8"
|
|
159
|
+
"F8DFA13F389D52A246DF91BF389D52A246DF913F013EFC10E8F8DFA1BF3EFC10E8F8DFA13F"
|
|
160
|
+
"389D52A246DF91BF389D52A246DF913F";
|
|
161
|
+
// S2Polygon from the unit test value kCross1+kCrossHole.
|
|
162
|
+
// This is encoded in lossless format.
|
|
163
|
+
const char kEncodedPolygon2Loops[] =
|
|
164
|
+
"010101020000000108000000D44A8442C3F9EF3F7EDA2AB341DC913F27DCF7C958DEA1BFB4"
|
|
165
|
+
"825F3C81FDEF3F27DCF7C958DE913F1EDD892B0BDF91BFB4825F3C81FDEF3F27DCF7C958DE"
|
|
166
|
+
"913F1EDD892B0BDF913FD44A8442C3F9EF3F7EDA2AB341DC913F27DCF7C958DEA13FD44A84"
|
|
167
|
+
"42C3F9EF3F7EDA2AB341DC91BF27DCF7C958DEA13FB4825F3C81FDEF3F27DCF7C958DE91BF"
|
|
168
|
+
"1EDD892B0BDF913FB4825F3C81FDEF3F27DCF7C958DE91BF1EDD892B0BDF91BFD44A8442C3"
|
|
169
|
+
"F9EF3F7EDA2AB341DC91BF27DCF7C958DEA1BF0000000000013EFC10E8F8DFA1BF3EFC10E8"
|
|
170
|
+
"F8DFA13F389D52A246DF91BF389D52A246DF913F0104000000C5D7FA4B60FFEF3F1EDD892B"
|
|
171
|
+
"0BDF813F214C95C437DF81BFC5D7FA4B60FFEF3F1EDD892B0BDF813F214C95C437DF813FC5"
|
|
172
|
+
"D7FA4B60FFEF3F1EDD892B0BDF81BF214C95C437DF813FC5D7FA4B60FFEF3F1EDD892B0BDF"
|
|
173
|
+
"81BF214C95C437DF81BF000100000001900C5E3B73DF81BF900C5E3B73DF813F399D52A246"
|
|
174
|
+
"DF81BF399D52A246DF813F013EFC10E8F8DFA1BF3EFC10E8F8DFA13F389D52A246DF91BF38"
|
|
175
|
+
"9D52A246DF913F";
|
|
176
|
+
// TODO(user): Generate S2Polygons that use compressed encoding format for
|
|
177
|
+
// testing.
|
|
178
|
+
|
|
179
|
+
// S2Polyline
|
|
180
|
+
// An S2Polyline from an empty vector.
|
|
181
|
+
const char kEncodedPolylineEmpty[] = "0100000000";
|
|
182
|
+
// An S2Polyline from 3 S2LatLngs {(0, 0),(0, 90),(0,180)};
|
|
183
|
+
const char kEncodedPolylineSemiEquator[] =
|
|
184
|
+
"0103000000000000000000F03F00000000000000000000000000000000075C143326A6913C"
|
|
185
|
+
"000000000000F03F0000000000000000000000000000F0BF075C143326A6A13C0000000000"
|
|
186
|
+
"000000";
|
|
187
|
+
// An S2Polyline from MakePolyline("0:0, 0:10, 10:20, 20:30");
|
|
188
|
+
const char kEncodedPolyline3Segments[] =
|
|
189
|
+
"0104000000000000000000F03F00000000000000000000000000000000171C818C8B83EF3F"
|
|
190
|
+
"89730B7E1A3AC63F000000000000000061B46C3A039DED3FE2DC829F868ED53F89730B7E1A"
|
|
191
|
+
"3AC63F1B995E6FA10AEA3F1B2D5242F611DE3FF50B8A74A8E3D53F";
|
|
192
|
+
|
|
193
|
+
// Encode/Decode not yet implemented for these types.
|
|
194
|
+
// S2R2Rect
|
|
195
|
+
// S2RegionIntersection
|
|
196
|
+
// S2RegionUnion
|
|
197
|
+
|
|
198
|
+
//////////////////////////////////////////////////////////////
|
|
199
|
+
|
|
200
|
+
// HexEncodeStr returns the data in str in hex encoded form.
|
|
201
|
+
const string HexEncodeStr(const string& str) {
|
|
202
|
+
static const char* const lut = "0123456789ABCDEF";
|
|
203
|
+
|
|
204
|
+
string result;
|
|
205
|
+
result.reserve(2 * str.size());
|
|
206
|
+
for (size_t i = 0; i < str.length(); ++i) {
|
|
207
|
+
const unsigned char c = str[i];
|
|
208
|
+
result.push_back(lut[c >> 4]);
|
|
209
|
+
result.push_back(lut[c & 15]);
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
class S2RegionEncodeDecodeTest : public testing::Test {
|
|
215
|
+
protected:
|
|
216
|
+
// TestEncodeDecode tests that the input encodes to match the expected
|
|
217
|
+
// golden data, and then returns the decode of the data into dst.
|
|
218
|
+
template <class Region>
|
|
219
|
+
void TestEncodeDecode(const string& golden, const Region& src, Region* dst) {
|
|
220
|
+
Encoder encoder;
|
|
221
|
+
src.Encode(&encoder);
|
|
222
|
+
|
|
223
|
+
EXPECT_EQ(golden, HexEncodeStr(string(encoder.base(), encoder.length())));
|
|
224
|
+
|
|
225
|
+
Decoder decoder(encoder.base(), encoder.length());
|
|
226
|
+
dst->Decode(&decoder);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
TEST_F(S2RegionEncodeDecodeTest, S2Cap) {
|
|
231
|
+
S2Cap cap;
|
|
232
|
+
S2Cap cap_empty = S2Cap::Empty();
|
|
233
|
+
S2Cap cap_full = S2Cap::Full();
|
|
234
|
+
S2Cap cap_from_point = S2Cap::FromPoint(S2Point(3, 2, 1).Normalize());
|
|
235
|
+
S2Cap cap_from_center_height =
|
|
236
|
+
S2Cap::FromCenterHeight(S2Point(0, 0, 1).Normalize(), 5);
|
|
237
|
+
|
|
238
|
+
TestEncodeDecode(kEncodedCapEmpty, cap_empty, &cap);
|
|
239
|
+
EXPECT_TRUE(cap_empty.ApproxEquals(cap));
|
|
240
|
+
TestEncodeDecode(kEncodedCapFull, cap_full, &cap);
|
|
241
|
+
EXPECT_TRUE(cap_full.ApproxEquals(cap));
|
|
242
|
+
TestEncodeDecode(kEncodedCapFromPoint, cap_from_point, &cap);
|
|
243
|
+
EXPECT_TRUE(cap_from_point.ApproxEquals(cap));
|
|
244
|
+
TestEncodeDecode(kEncodedCapFromCenterHeight, cap_from_center_height, &cap);
|
|
245
|
+
EXPECT_TRUE(cap_from_center_height.ApproxEquals(cap));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
TEST_F(S2RegionEncodeDecodeTest, S2Cell) {
|
|
249
|
+
S2Cell cell;
|
|
250
|
+
S2Cell cell_from_point(S2Point(1, 2, 3));
|
|
251
|
+
S2Cell cell_from_latlng(S2LatLng::FromDegrees(39.0, -120.0));
|
|
252
|
+
S2Cell cell_from_face_pos_lvl(
|
|
253
|
+
S2Cell::FromFacePosLevel(3, 0x12345678, S2CellId::kMaxLevel - 4));
|
|
254
|
+
S2Cell cell_from_from_face(S2Cell::FromFace(0));
|
|
255
|
+
|
|
256
|
+
TestEncodeDecode(kEncodedCellFromPoint, cell_from_point, &cell);
|
|
257
|
+
EXPECT_EQ(cell_from_point, cell);
|
|
258
|
+
TestEncodeDecode(kEncodedCellFromLatLng, cell_from_latlng, &cell);
|
|
259
|
+
EXPECT_EQ(cell_from_latlng, cell);
|
|
260
|
+
TestEncodeDecode(kEncodedCellFromFacePosLevel, cell_from_face_pos_lvl, &cell);
|
|
261
|
+
EXPECT_EQ(cell_from_face_pos_lvl, cell);
|
|
262
|
+
TestEncodeDecode(kEncodedCellFace0, cell_from_from_face, &cell);
|
|
263
|
+
EXPECT_EQ(cell_from_from_face, cell);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
TEST_F(S2RegionEncodeDecodeTest, S2CellUnion) {
|
|
267
|
+
S2CellUnion cu;
|
|
268
|
+
const S2CellUnion cu_empty;
|
|
269
|
+
const S2CellUnion cu_face1({S2CellId::FromFace(1)});
|
|
270
|
+
// Cell ids taken from S2CellUnion EncodeDecode test.
|
|
271
|
+
const S2CellUnion cu_latlngs =
|
|
272
|
+
S2CellUnion::FromNormalized({S2CellId(0x33),
|
|
273
|
+
S2CellId(0x8e3748fab),
|
|
274
|
+
S2CellId(0x91230abcdef83427)});
|
|
275
|
+
|
|
276
|
+
TestEncodeDecode(kEncodedCellUnionEmpty, cu_empty, &cu);
|
|
277
|
+
EXPECT_EQ(cu_empty, cu);
|
|
278
|
+
TestEncodeDecode(kEncodedCellUnionFace1, cu_face1, &cu);
|
|
279
|
+
EXPECT_EQ(cu_face1, cu);
|
|
280
|
+
TestEncodeDecode(kEncodedCellUnionFromCells, cu_latlngs, &cu);
|
|
281
|
+
EXPECT_EQ(cu_latlngs, cu);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
TEST_F(S2RegionEncodeDecodeTest, S2LatLngRect) {
|
|
285
|
+
S2LatLngRect rect;
|
|
286
|
+
S2LatLngRect rect_empty = S2LatLngRect::Empty();
|
|
287
|
+
S2LatLngRect rect_full = S2LatLngRect::Full();
|
|
288
|
+
S2LatLngRect rect_from_center_size = S2LatLngRect::FromCenterSize(
|
|
289
|
+
S2LatLng::FromDegrees(80, 170), S2LatLng::FromDegrees(40, 60));
|
|
290
|
+
|
|
291
|
+
TestEncodeDecode(kEncodedRectEmpty, rect_empty, &rect);
|
|
292
|
+
EXPECT_TRUE(rect_empty.ApproxEquals(rect));
|
|
293
|
+
TestEncodeDecode(kEncodedRectFull, rect_full, &rect);
|
|
294
|
+
EXPECT_TRUE(rect_full.ApproxEquals(rect));
|
|
295
|
+
TestEncodeDecode(kEncodedRectCentersize, rect_from_center_size, &rect);
|
|
296
|
+
EXPECT_TRUE(rect_from_center_size.ApproxEquals(rect));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
TEST_F(S2RegionEncodeDecodeTest, S2Loop) {
|
|
300
|
+
const string kCross1 = "-2:1, -1:1, 1:1, 2:1, 2:-1, 1:-1, -1:-1, -2:-1";
|
|
301
|
+
const string kCrossCenterHole = "-0.5:0.5, 0.5:0.5, 0.5:-0.5, -0.5:-0.5;";
|
|
302
|
+
|
|
303
|
+
S2Loop loop;
|
|
304
|
+
S2Loop loop_empty(S2Loop::kEmpty());
|
|
305
|
+
S2Loop loop_full(S2Loop::kFull());
|
|
306
|
+
unique_ptr<S2Loop> loop_cross = s2textformat::MakeLoop(kCross1);
|
|
307
|
+
|
|
308
|
+
TestEncodeDecode(kEncodedLoopEmpty, loop_empty, &loop);
|
|
309
|
+
EXPECT_TRUE(loop_empty.Equals(&loop));
|
|
310
|
+
TestEncodeDecode(kEncodedLoopFull, loop_full, &loop);
|
|
311
|
+
EXPECT_TRUE(loop_full.Equals(&loop));
|
|
312
|
+
TestEncodeDecode(kEncodedLoopCross, *loop_cross, &loop);
|
|
313
|
+
EXPECT_TRUE(loop_cross->Equals(&loop));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
TEST_F(S2RegionEncodeDecodeTest, S2PointRegion) {
|
|
318
|
+
S2PointRegion point(S2::Origin());
|
|
319
|
+
S2PointRegion point_origin(S2::Origin());
|
|
320
|
+
S2PointRegion point_testing(S2Point(12.34, 56.78, 9.1011).Normalize());
|
|
321
|
+
|
|
322
|
+
TestEncodeDecode(kEncodedPointOrigin, point_origin, &point);
|
|
323
|
+
TestEncodeDecode(kEncodedPointTesting, point_testing, &point);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
TEST_F(S2RegionEncodeDecodeTest, S2Polygon) {
|
|
327
|
+
const string kCross1 = "-2:1, -1:1, 1:1, 2:1, 2:-1, 1:-1, -1:-1, -2:-1";
|
|
328
|
+
const string kCrossCenterHole = "-0.5:0.5, 0.5:0.5, 0.5:-0.5, -0.5:-0.5;";
|
|
329
|
+
|
|
330
|
+
S2Polygon polygon;
|
|
331
|
+
unique_ptr<S2Polygon> polygon_empty = s2textformat::MakePolygon("");
|
|
332
|
+
unique_ptr<S2Polygon> polygon_full =
|
|
333
|
+
s2textformat::MakeVerbatimPolygon("full");
|
|
334
|
+
unique_ptr<S2Polygon> polygon_cross = s2textformat::MakePolygon(kCross1);
|
|
335
|
+
unique_ptr<S2Polygon> polygon_cross_hole =
|
|
336
|
+
s2textformat::MakePolygon(kCross1 + ";" + kCrossCenterHole);
|
|
337
|
+
|
|
338
|
+
TestEncodeDecode(kEncodedPolygonEmpty, *polygon_empty, &polygon);
|
|
339
|
+
EXPECT_TRUE(polygon_empty->Equals(&polygon));
|
|
340
|
+
TestEncodeDecode(kEncodedPolygonFull, *polygon_full, &polygon);
|
|
341
|
+
EXPECT_TRUE(polygon_full->Equals(&polygon));
|
|
342
|
+
TestEncodeDecode(kEncodedPolygon1Loops, *polygon_cross, &polygon);
|
|
343
|
+
EXPECT_TRUE(polygon_cross->Equals(&polygon));
|
|
344
|
+
TestEncodeDecode(kEncodedPolygon2Loops, *polygon_cross_hole, &polygon);
|
|
345
|
+
EXPECT_TRUE(polygon_cross_hole->Equals(&polygon));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
TEST_F(S2RegionEncodeDecodeTest, S2Polyline) {
|
|
349
|
+
S2Polyline polyline;
|
|
350
|
+
vector<S2Point> vertices;
|
|
351
|
+
S2Polyline polyline_empty(vertices);
|
|
352
|
+
vector<S2LatLng> latlngs = {S2LatLng::FromDegrees(0, 0),
|
|
353
|
+
S2LatLng::FromDegrees(0, 90),
|
|
354
|
+
S2LatLng::FromDegrees(0, 180)};
|
|
355
|
+
S2Polyline polyline_semi(latlngs);
|
|
356
|
+
unique_ptr<S2Polyline> polyline_3segments =
|
|
357
|
+
s2textformat::MakePolyline("0:0, 0:10, 10:20, 20:30");
|
|
358
|
+
|
|
359
|
+
TestEncodeDecode(kEncodedPolylineEmpty, polyline_empty, &polyline);
|
|
360
|
+
EXPECT_TRUE(polyline_empty.Equals(&polyline));
|
|
361
|
+
TestEncodeDecode(kEncodedPolylineSemiEquator, polyline_semi, &polyline);
|
|
362
|
+
EXPECT_TRUE(polyline_semi.Equals(&polyline));
|
|
363
|
+
TestEncodeDecode(kEncodedPolyline3Segments, *polyline_3segments, &polyline);
|
|
364
|
+
EXPECT_TRUE(polyline_3segments->Equals(&polyline));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// TODO(user): When the remaining types implement Encode/Decode, add their
|
|
368
|
+
// test cases here. i.e. S2R2Rect, S2RegionIntersection, S2RegionUnion, etc.
|
|
369
|
+
|
|
370
|
+
} // namespace
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright 2005 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
|
+
#include "s2/s2region_union.h"
|
|
19
|
+
|
|
20
|
+
#include "s2/s2cap.h"
|
|
21
|
+
#include "s2/s2latlng_rect.h"
|
|
22
|
+
|
|
23
|
+
using std::vector;
|
|
24
|
+
|
|
25
|
+
S2RegionUnion::S2RegionUnion(vector<std::unique_ptr<S2Region>> regions) {
|
|
26
|
+
Init(std::move(regions));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void S2RegionUnion::Init(vector<std::unique_ptr<S2Region>> regions) {
|
|
30
|
+
S2_DCHECK(regions_.empty());
|
|
31
|
+
regions_ = std::move(regions);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
S2RegionUnion::S2RegionUnion(const S2RegionUnion& src)
|
|
35
|
+
: regions_(src.num_regions()) {
|
|
36
|
+
for (int i = 0; i < num_regions(); ++i) {
|
|
37
|
+
regions_[i].reset(src.region(i)->Clone());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
vector<std::unique_ptr<S2Region>> S2RegionUnion::Release() {
|
|
42
|
+
vector<std::unique_ptr<S2Region>> result;
|
|
43
|
+
result.swap(regions_);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
void S2RegionUnion::Add(std::unique_ptr<S2Region> region) {
|
|
48
|
+
regions_.push_back(std::move(region));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
S2RegionUnion* S2RegionUnion::Clone() const {
|
|
52
|
+
return new S2RegionUnion(*this);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
S2Cap S2RegionUnion::GetCapBound() const {
|
|
56
|
+
// TODO(ericv): This could be optimized to return a tighter bound,
|
|
57
|
+
// but doesn't seem worth it unless profiling shows otherwise.
|
|
58
|
+
return GetRectBound().GetCapBound();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
S2LatLngRect S2RegionUnion::GetRectBound() const {
|
|
62
|
+
S2LatLngRect result = S2LatLngRect::Empty();
|
|
63
|
+
for (int i = 0; i < num_regions(); ++i) {
|
|
64
|
+
result = result.Union(region(i)->GetRectBound());
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
bool S2RegionUnion::Contains(const S2Cell& cell) const {
|
|
70
|
+
// Note that this method is allowed to return false even if the cell
|
|
71
|
+
// is contained by the region.
|
|
72
|
+
for (int i = 0; i < num_regions(); ++i) {
|
|
73
|
+
if (region(i)->Contains(cell)) return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
bool S2RegionUnion::Contains(const S2Point& p) const {
|
|
79
|
+
for (int i = 0; i < num_regions(); ++i) {
|
|
80
|
+
if (region(i)->Contains(p)) return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
bool S2RegionUnion::MayIntersect(const S2Cell& cell) const {
|
|
86
|
+
for (int i = 0; i < num_regions(); ++i) {
|
|
87
|
+
if (region(i)->MayIntersect(cell)) return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|