@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,786 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2006 Google Inc. All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS-IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
import unittest
|
|
18
|
+
from collections import defaultdict
|
|
19
|
+
|
|
20
|
+
import pywraps2 as s2
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class PyWrapS2TestCase(unittest.TestCase):
|
|
24
|
+
|
|
25
|
+
def testContainsIsWrappedCorrectly(self):
|
|
26
|
+
london = s2.S2LatLngRect(s2.S2LatLng.FromDegrees(51.3368602, 0.4931979),
|
|
27
|
+
s2.S2LatLng.FromDegrees(51.7323965, 0.1495211))
|
|
28
|
+
e14lj = s2.S2LatLngRect(s2.S2LatLng.FromDegrees(51.5213527, -0.0476026),
|
|
29
|
+
s2.S2LatLng.FromDegrees(51.5213527, -0.0476026))
|
|
30
|
+
self.assertTrue(london.Contains(e14lj))
|
|
31
|
+
|
|
32
|
+
def testS2CellIdEqualsIsWrappedCorrectly(self):
|
|
33
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
34
|
+
cell = s2.S2CellId(london)
|
|
35
|
+
same_cell = s2.S2CellId(london)
|
|
36
|
+
self.assertEqual(cell, same_cell)
|
|
37
|
+
|
|
38
|
+
def testS2CellIdComparsionIsWrappedCorrectly(self):
|
|
39
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
40
|
+
cell = s2.S2CellId(london)
|
|
41
|
+
self.assertLess(cell, cell.next())
|
|
42
|
+
self.assertGreater(cell.next(), cell)
|
|
43
|
+
|
|
44
|
+
def testS2CellIdFromToTokenIsWrappedCorrectly(self):
|
|
45
|
+
cell = s2.S2CellId.FromToken("487604c489f841c3")
|
|
46
|
+
self.assertEqual(cell.ToToken(), "487604c489f841c3")
|
|
47
|
+
self.assertEqual(cell.id(), 0x487604c489f841c3)
|
|
48
|
+
|
|
49
|
+
cell = s2.S2CellId.FromToken("487")
|
|
50
|
+
self.assertEqual(cell.ToToken(), "487")
|
|
51
|
+
self.assertEqual(cell.id(), 0x4870000000000000)
|
|
52
|
+
|
|
53
|
+
cell = s2.S2CellId.FromToken("this is invalid")
|
|
54
|
+
self.assertEqual(cell.ToToken(), "X")
|
|
55
|
+
self.assertEqual(cell.id(), 0)
|
|
56
|
+
|
|
57
|
+
def testS2CellIdGetEdgeNeighborsIsWrappedCorrectly(self):
|
|
58
|
+
cell = s2.S2CellId(0x466d319000000000)
|
|
59
|
+
expected_neighbors = [s2.S2CellId(0x466d31b000000000),
|
|
60
|
+
s2.S2CellId(0x466d317000000000),
|
|
61
|
+
s2.S2CellId(0x466d323000000000),
|
|
62
|
+
s2.S2CellId(0x466d31f000000000)]
|
|
63
|
+
neighbors = cell.GetEdgeNeighbors()
|
|
64
|
+
self.assertEqual(neighbors, expected_neighbors)
|
|
65
|
+
|
|
66
|
+
def testS2CellIdGetAllNeighborsIsWrappedCorrectly(self):
|
|
67
|
+
cell = s2.S2CellId(0x6aa7590000000000)
|
|
68
|
+
expected_neighbors = (s2.S2CellId(0x2ab3530000000000),
|
|
69
|
+
s2.S2CellId(0x2ab34b0000000000),
|
|
70
|
+
s2.S2CellId(0x2ab34d0000000000),
|
|
71
|
+
s2.S2CellId(0x6aa75b0000000000),
|
|
72
|
+
s2.S2CellId(0x6aa7570000000000),
|
|
73
|
+
s2.S2CellId(0x6aa75f0000000000),
|
|
74
|
+
s2.S2CellId(0x6aa7510000000000),
|
|
75
|
+
s2.S2CellId(0x6aa75d0000000000))
|
|
76
|
+
neighbors = cell.GetAllNeighbors(cell.level())
|
|
77
|
+
self.assertEqual(neighbors, expected_neighbors)
|
|
78
|
+
|
|
79
|
+
def testS2CellIdIntersectsIsTrueForOverlap(self):
|
|
80
|
+
cell1 = s2.S2CellId(0x89c259c000000000)
|
|
81
|
+
cell2 = s2.S2CellId(0x89c2590000000000)
|
|
82
|
+
self.assertTrue(cell1.intersects(cell2))
|
|
83
|
+
|
|
84
|
+
def testS2CellIdIntersectsIsFalseForNonOverlap(self):
|
|
85
|
+
cell1 = s2.S2CellId(0x89c259c000000000)
|
|
86
|
+
cell2 = s2.S2CellId(0x89e83d0000000000)
|
|
87
|
+
self.assertFalse(cell1.intersects(cell2))
|
|
88
|
+
|
|
89
|
+
def testS2HashingIsWrappedCorrectly(self):
|
|
90
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
91
|
+
cell = s2.S2CellId(london)
|
|
92
|
+
same_cell = s2.S2CellId(london)
|
|
93
|
+
self.assertEqual(hash(cell), hash(same_cell))
|
|
94
|
+
|
|
95
|
+
def testCovererIsWrappedCorrectly(self):
|
|
96
|
+
london = s2.S2LatLngRect(s2.S2LatLng.FromDegrees(51.3368602, 0.4931979),
|
|
97
|
+
s2.S2LatLng.FromDegrees(51.7323965, 0.1495211))
|
|
98
|
+
e14lj = s2.S2LatLngRect(s2.S2LatLng.FromDegrees(51.5213527, -0.0476026),
|
|
99
|
+
s2.S2LatLng.FromDegrees(51.5213527, -0.0476026))
|
|
100
|
+
coverer = s2.S2RegionCoverer()
|
|
101
|
+
coverer.set_max_cells(6)
|
|
102
|
+
self.assertEqual(6, coverer.max_cells())
|
|
103
|
+
covering = coverer.GetCovering(e14lj)
|
|
104
|
+
self.assertLessEqual(len(covering), 6)
|
|
105
|
+
for cellid in covering:
|
|
106
|
+
self.assertTrue(london.Contains(s2.S2Cell(cellid)))
|
|
107
|
+
interior = coverer.GetInteriorCovering(e14lj)
|
|
108
|
+
for cellid in interior:
|
|
109
|
+
self.assertTrue(london.Contains(s2.S2Cell(cellid)))
|
|
110
|
+
|
|
111
|
+
def testS2CellUnionIsWrappedCorrectly(self):
|
|
112
|
+
cell_union = s2.S2CellUnion()
|
|
113
|
+
cell_union.Init([0x466d319000000000, 0x466d31b000000000])
|
|
114
|
+
self.assertEqual(cell_union.num_cells(), 2)
|
|
115
|
+
trondheim = s2.S2LatLng.FromDegrees(63.431052, 10.395083)
|
|
116
|
+
self.assertTrue(cell_union.Contains(s2.S2CellId(trondheim)))
|
|
117
|
+
|
|
118
|
+
# Init() calls Normalized, so cell_ids() are normalized.
|
|
119
|
+
cell_union2 = s2.S2CellUnion.FromNormalized(cell_union.cell_ids())
|
|
120
|
+
# There is no S2CellUnion::Equals, and cell_ids is a non-iterable
|
|
121
|
+
# SWIG object, so just perform the same checks again.
|
|
122
|
+
self.assertEqual(cell_union2.num_cells(), 2)
|
|
123
|
+
self.assertTrue(cell_union2.Contains(s2.S2CellId(trondheim)))
|
|
124
|
+
|
|
125
|
+
def testS2PolygonIsWrappedCorrectly(self):
|
|
126
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
127
|
+
polygon = s2.S2Polygon(s2.S2Cell(s2.S2CellId(london)))
|
|
128
|
+
self.assertEqual(polygon.num_loops(), 1)
|
|
129
|
+
point = london.ToPoint()
|
|
130
|
+
self.assertTrue(polygon.Contains(point))
|
|
131
|
+
|
|
132
|
+
def testS2LoopIsWrappedCorrectly(self):
|
|
133
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
134
|
+
polygon = s2.S2Polygon(s2.S2Cell(s2.S2CellId(london)))
|
|
135
|
+
loop = polygon.loop(0)
|
|
136
|
+
self.assertTrue(loop.IsValid())
|
|
137
|
+
self.assertEqual(0, loop.depth())
|
|
138
|
+
self.assertFalse(loop.is_hole())
|
|
139
|
+
self.assertEqual(4, loop.num_vertices())
|
|
140
|
+
self.assertTrue(loop.IsNormalized())
|
|
141
|
+
point = london.ToPoint()
|
|
142
|
+
self.assertTrue(loop.Contains(point))
|
|
143
|
+
|
|
144
|
+
def testS2LoopUsesValueEquality(self):
|
|
145
|
+
self.assertEqual(s2.S2Loop(), s2.S2Loop())
|
|
146
|
+
|
|
147
|
+
def testS2PolygonCopiesLoopInConstructorBecauseItTakesOwnership(self):
|
|
148
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
149
|
+
loop = s2.S2Loop(s2.S2Cell(s2.S2CellId(london)))
|
|
150
|
+
s2.S2Polygon(loop)
|
|
151
|
+
|
|
152
|
+
def testS2PolygonInitNestedIsWrappedCorrectly(self):
|
|
153
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
154
|
+
small_loop = s2.S2Loop(s2.S2Cell(s2.S2CellId(london)))
|
|
155
|
+
big_loop = s2.S2Loop(s2.S2Cell(s2.S2CellId(london).parent(1)))
|
|
156
|
+
polygon = s2.S2Polygon()
|
|
157
|
+
polygon.InitNested([big_loop, small_loop])
|
|
158
|
+
|
|
159
|
+
def testS2PolygonInitNestedWithIncorrectTypeIsWrappedCorrectly(self):
|
|
160
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
161
|
+
loop = s2.S2Loop(s2.S2Cell(s2.S2CellId(london)))
|
|
162
|
+
polygon = s2.S2Polygon()
|
|
163
|
+
with self.assertRaises(TypeError):
|
|
164
|
+
polygon.InitNested([loop, s2.S2CellId()])
|
|
165
|
+
|
|
166
|
+
def testS2PolygonGetAreaIsWrappedCorrectly(self):
|
|
167
|
+
# Cell at level 10 containing central London.
|
|
168
|
+
|
|
169
|
+
london_level_10 = s2.S2CellId(
|
|
170
|
+
s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)).parent(10)
|
|
171
|
+
polygon = s2.S2Polygon(s2.S2Cell(london_level_10))
|
|
172
|
+
# Because S2Cell.ExactArea() isn't swigged, compare S2Polygon.GetArea() with
|
|
173
|
+
# S2CellUnion.ExactArea().
|
|
174
|
+
cell_union = s2.S2CellUnion()
|
|
175
|
+
cell_union.Init([london_level_10.id()])
|
|
176
|
+
self.assertAlmostEqual(cell_union.ExactArea(), polygon.GetArea(), places=10)
|
|
177
|
+
|
|
178
|
+
def testS2PolygonGetOverlapFractions(self):
|
|
179
|
+
# Matches S2Polygon, OverlapFractions test from cs/s2polygon_test.cc
|
|
180
|
+
a = s2.S2Polygon()
|
|
181
|
+
b = s2.S2Polygon()
|
|
182
|
+
r1, r2 = s2.S2Polygon.GetOverlapFractions(a, b)
|
|
183
|
+
self.assertAlmostEqual(1.0, r1)
|
|
184
|
+
self.assertAlmostEqual(1.0, r2)
|
|
185
|
+
|
|
186
|
+
def verts2loop(vs):
|
|
187
|
+
loop = s2.S2Loop()
|
|
188
|
+
loop.Init([s2.S2LatLng.FromDegrees(*v).ToPoint() for v in vs])
|
|
189
|
+
return loop
|
|
190
|
+
|
|
191
|
+
loop1verts = [(-10, 10), (0, 10), (0, -10), (-10, -10), (-10, 0)]
|
|
192
|
+
b = s2.S2Polygon(verts2loop(loop1verts))
|
|
193
|
+
r1, r2 = s2.S2Polygon.GetOverlapFractions(a, b)
|
|
194
|
+
self.assertAlmostEqual(1.0, r1)
|
|
195
|
+
self.assertAlmostEqual(0.0, r2)
|
|
196
|
+
|
|
197
|
+
loop2verts = [(-10, 0), (10, 0), (10, -10), (-10, -10)]
|
|
198
|
+
a = s2.S2Polygon(verts2loop(loop2verts))
|
|
199
|
+
r1, r2 = s2.S2Polygon.GetOverlapFractions(a, b)
|
|
200
|
+
self.assertAlmostEqual(0.5, r1)
|
|
201
|
+
self.assertAlmostEqual(0.5, r2)
|
|
202
|
+
|
|
203
|
+
def testGetS2LatLngVertexIsWrappedCorrectly(self):
|
|
204
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
205
|
+
polygon = s2.S2Polygon(s2.S2Cell(s2.S2CellId(london)))
|
|
206
|
+
loop = polygon.loop(0)
|
|
207
|
+
first_vertex = loop.GetS2LatLngVertex(0)
|
|
208
|
+
self.assertIsInstance(first_vertex, s2.S2LatLng)
|
|
209
|
+
self.assertEqual("51.500152,-0.126235", first_vertex.ToStringInDegrees())
|
|
210
|
+
second_vertex = loop.GetS2LatLngVertex(1)
|
|
211
|
+
self.assertIsInstance(second_vertex, s2.S2LatLng)
|
|
212
|
+
self.assertEqual("51.500153,-0.126235", second_vertex.ToStringInDegrees())
|
|
213
|
+
|
|
214
|
+
def testS2PolylineInitFromS2LatLngs(self):
|
|
215
|
+
e7_10deg = 0x5f5e100
|
|
216
|
+
list_ll = []
|
|
217
|
+
for lat, lng in [(0, 0), (0, e7_10deg), (e7_10deg, e7_10deg)]:
|
|
218
|
+
list_ll.append(s2.S2LatLng.FromE7(lat, lng))
|
|
219
|
+
line = s2.S2Polyline()
|
|
220
|
+
line.InitFromS2LatLngs(list_ll)
|
|
221
|
+
self.assertAlmostEqual(20.0, line.GetLength().degrees())
|
|
222
|
+
|
|
223
|
+
def testS2PolylineInitFromS2Points(self):
|
|
224
|
+
e7_10deg = 0x5f5e100
|
|
225
|
+
list_points = []
|
|
226
|
+
for lat, lng in [(0, 0), (0, e7_10deg), (e7_10deg, e7_10deg)]:
|
|
227
|
+
list_points.append(s2.S2LatLng.FromE7(lat, lng).ToPoint())
|
|
228
|
+
line = s2.S2Polyline()
|
|
229
|
+
line.InitFromS2Points(list_points)
|
|
230
|
+
self.assertAlmostEqual(20.0, line.GetLength().degrees())
|
|
231
|
+
|
|
232
|
+
def testS2PolylineUsesValueEquality(self):
|
|
233
|
+
self.assertEqual(s2.S2Polyline(), s2.S2Polyline())
|
|
234
|
+
|
|
235
|
+
def testS2PointsCanBeNormalized(self):
|
|
236
|
+
line = s2.S2Polyline()
|
|
237
|
+
line.InitFromS2LatLngs([s2.S2LatLng.FromDegrees(37.794484, -122.394871),
|
|
238
|
+
s2.S2LatLng.FromDegrees(37.762699, -122.435158)])
|
|
239
|
+
self.assertNotAlmostEqual(line.GetCentroid().Norm(), 1.0)
|
|
240
|
+
self.assertAlmostEqual(line.GetCentroid().Normalize().Norm(), 1.0)
|
|
241
|
+
|
|
242
|
+
def testS1AngleComparsionIsWrappedCorrectly(self):
|
|
243
|
+
ten_degrees = s2.S1Angle.Degrees(10)
|
|
244
|
+
one_hundred_degrees = s2.S1Angle.Degrees(100)
|
|
245
|
+
self.assertLess(ten_degrees, one_hundred_degrees)
|
|
246
|
+
self.assertGreater(one_hundred_degrees, ten_degrees)
|
|
247
|
+
|
|
248
|
+
def testS2PolygonIntersectsWithPolyline(self):
|
|
249
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
250
|
+
polygon = s2.S2Polygon(s2.S2Cell(s2.S2CellId(london).parent(15)))
|
|
251
|
+
line = s2.S2Polyline()
|
|
252
|
+
line.InitFromS2LatLngs([s2.S2LatLng.FromDegrees(51.5, -0.128),
|
|
253
|
+
s2.S2LatLng.FromDegrees(51.5, -0.125)])
|
|
254
|
+
intersections = polygon.IntersectWithPolyline(line)
|
|
255
|
+
self.assertEqual(1, len(intersections))
|
|
256
|
+
|
|
257
|
+
def testS2PolygonUsesValueEquality(self):
|
|
258
|
+
self.assertEqual(s2.S2Polygon(), s2.S2Polygon())
|
|
259
|
+
|
|
260
|
+
def testCrossingSign(self):
|
|
261
|
+
a = s2.S2LatLng.FromDegrees(-1, 0).ToPoint()
|
|
262
|
+
b = s2.S2LatLng.FromDegrees(1, 0).ToPoint()
|
|
263
|
+
c = s2.S2LatLng.FromDegrees(0, -1).ToPoint()
|
|
264
|
+
d = s2.S2LatLng.FromDegrees(0, 1).ToPoint()
|
|
265
|
+
# SWIG flattens namespaces, so this is just s2.CrossingSign,
|
|
266
|
+
# not s2.S2.CrossingSign.
|
|
267
|
+
self.assertEqual(1, s2.CrossingSign(a, b, c, d))
|
|
268
|
+
|
|
269
|
+
def testGetIntersection(self):
|
|
270
|
+
a = s2.S2LatLng.FromDegrees(-1, 0).ToPoint()
|
|
271
|
+
b = s2.S2LatLng.FromDegrees(1, 0).ToPoint()
|
|
272
|
+
c = s2.S2LatLng.FromDegrees(0, -1).ToPoint()
|
|
273
|
+
d = s2.S2LatLng.FromDegrees(0, 1).ToPoint()
|
|
274
|
+
# SWIG namespace flattening as above.
|
|
275
|
+
intersection = s2.GetIntersection(a, b, c, d)
|
|
276
|
+
self.assertEqual(
|
|
277
|
+
"0.000000,0.000000", s2.S2LatLng(intersection).ToStringInDegrees())
|
|
278
|
+
|
|
279
|
+
def testS2CellDistance(self):
|
|
280
|
+
# Level-0 cell (i.e. face) centered at (0, 0)
|
|
281
|
+
cell = s2.S2Cell(s2.S2CellId(0x1000000000000000))
|
|
282
|
+
|
|
283
|
+
p1 = s2.S2LatLng.FromDegrees(0, 0).ToPoint()
|
|
284
|
+
self.assertTrue(cell.Contains(p1))
|
|
285
|
+
d1 = cell.GetDistance(p1).ToAngle().degrees()
|
|
286
|
+
# Inside, so distance is 0, but boundary distance is not.
|
|
287
|
+
self.assertEqual(0.0, d1)
|
|
288
|
+
bd1 = cell.GetBoundaryDistance(p1).ToAngle().degrees()
|
|
289
|
+
self.assertEqual(45.0, bd1)
|
|
290
|
+
|
|
291
|
+
p2 = s2.S2LatLng.FromDegrees(0, 90).ToPoint()
|
|
292
|
+
self.assertFalse(cell.Contains(p2))
|
|
293
|
+
d2 = cell.GetDistance(p2).ToAngle().degrees()
|
|
294
|
+
self.assertAlmostEqual(45.0, d2)
|
|
295
|
+
bd2 = cell.GetBoundaryDistance(p2).ToAngle().degrees()
|
|
296
|
+
# Outside, so distance and boundary distance are the same.
|
|
297
|
+
self.assertAlmostEqual(45.0, bd2)
|
|
298
|
+
|
|
299
|
+
def testS2Rotate(self):
|
|
300
|
+
mtv_a = s2.S2LatLng.FromDegrees(37.4402777, -121.9638888).ToPoint()
|
|
301
|
+
mtv_b = s2.S2LatLng.FromDegrees(37.3613888, -121.9283333).ToPoint()
|
|
302
|
+
angle = s2.S1Angle.Radians(0.039678)
|
|
303
|
+
point = s2.Rotate(mtv_a, mtv_b, angle)
|
|
304
|
+
self.assertEqual("37.439095,-121.967802",
|
|
305
|
+
s2.S2LatLng(point).ToStringInDegrees())
|
|
306
|
+
|
|
307
|
+
def testS2TurnAngle(self):
|
|
308
|
+
mtv_a = s2.S2LatLng.FromDegrees(37.4402777, -121.9638888).ToPoint()
|
|
309
|
+
mtv_b = s2.S2LatLng.FromDegrees(37.3613888, -121.9283333).ToPoint()
|
|
310
|
+
mtv_c = s2.S2LatLng.FromDegrees(37.3447222, -122.0308333).ToPoint()
|
|
311
|
+
angle = s2.TurnAngle(mtv_a, mtv_b, mtv_c)
|
|
312
|
+
self.assertAlmostEqual(-1.7132025, angle)
|
|
313
|
+
|
|
314
|
+
def testEncodeDecode(self):
|
|
315
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
316
|
+
polygon = s2.S2Polygon(s2.S2Cell(s2.S2CellId(london).parent(15)))
|
|
317
|
+
self.assertEqual(polygon.num_loops(), 1)
|
|
318
|
+
|
|
319
|
+
encoder = s2.Encoder()
|
|
320
|
+
polygon.Encode(encoder)
|
|
321
|
+
|
|
322
|
+
encoded = encoder.buffer()
|
|
323
|
+
decoder = s2.Decoder(encoded)
|
|
324
|
+
decoded_polygon = s2.S2Polygon()
|
|
325
|
+
self.assertTrue(decoded_polygon.Decode(decoder))
|
|
326
|
+
|
|
327
|
+
self.assertEqual(decoded_polygon.num_loops(), 1)
|
|
328
|
+
self.assertTrue(decoded_polygon.Equals(polygon))
|
|
329
|
+
|
|
330
|
+
def testS2CapRegion(self):
|
|
331
|
+
center = s2.S2LatLng.FromDegrees(2.0, 3.0).ToPoint()
|
|
332
|
+
cap = s2.S2Cap(center, s2.S1Angle.Degrees(1.0))
|
|
333
|
+
|
|
334
|
+
inside = s2.S2LatLng.FromDegrees(2.1, 2.9).ToPoint()
|
|
335
|
+
outside = s2.S2LatLng.FromDegrees(0.0, 0.0).ToPoint()
|
|
336
|
+
self.assertTrue(cap.Contains(inside))
|
|
337
|
+
self.assertFalse(cap.Contains(outside))
|
|
338
|
+
self.assertTrue(cap.Contains(s2.S2Cell(inside)))
|
|
339
|
+
self.assertFalse(cap.Contains(s2.S2Cell(outside)))
|
|
340
|
+
self.assertTrue(cap.MayIntersect(s2.S2Cell(inside)))
|
|
341
|
+
self.assertFalse(cap.MayIntersect(s2.S2Cell(outside)))
|
|
342
|
+
|
|
343
|
+
self.assertTrue(cap.ApproxEquals(cap.GetCapBound()))
|
|
344
|
+
|
|
345
|
+
rect_bound = cap.GetRectBound()
|
|
346
|
+
self.assertTrue(rect_bound.Contains(inside))
|
|
347
|
+
self.assertFalse(rect_bound.Contains(outside))
|
|
348
|
+
|
|
349
|
+
def testS2LatLngRectRegion(self):
|
|
350
|
+
rect = s2.S2LatLngRect(s2.S2LatLng.FromDegrees(1.0, 2.0),
|
|
351
|
+
s2.S2LatLng.FromDegrees(3.0, 4.0))
|
|
352
|
+
|
|
353
|
+
inside = s2.S2LatLng.FromDegrees(2.0, 3.0).ToPoint()
|
|
354
|
+
outside = s2.S2LatLng.FromDegrees(0.0, 0.0).ToPoint()
|
|
355
|
+
|
|
356
|
+
self.assertTrue(rect.Contains(inside))
|
|
357
|
+
self.assertFalse(rect.Contains(outside))
|
|
358
|
+
self.assertTrue(rect.Contains(s2.S2Cell(inside)))
|
|
359
|
+
self.assertFalse(rect.Contains(s2.S2Cell(outside)))
|
|
360
|
+
self.assertTrue(rect.MayIntersect(s2.S2Cell(inside)))
|
|
361
|
+
self.assertFalse(rect.MayIntersect(s2.S2Cell(outside)))
|
|
362
|
+
|
|
363
|
+
cap_bound = rect.GetCapBound()
|
|
364
|
+
self.assertTrue(cap_bound.Contains(inside))
|
|
365
|
+
self.assertFalse(cap_bound.Contains(outside))
|
|
366
|
+
|
|
367
|
+
self.assertTrue(rect.ApproxEquals(rect.GetRectBound()))
|
|
368
|
+
|
|
369
|
+
def testS2CellRegion(self):
|
|
370
|
+
cell = s2.S2Cell(s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0)).parent(8))
|
|
371
|
+
|
|
372
|
+
inside = s2.S2LatLng.FromDegrees(3.0, 4.0).ToPoint()
|
|
373
|
+
outside = s2.S2LatLng.FromDegrees(30.0, 40.0).ToPoint()
|
|
374
|
+
|
|
375
|
+
self.assertTrue(cell.Contains(inside))
|
|
376
|
+
self.assertFalse(cell.Contains(outside))
|
|
377
|
+
self.assertTrue(cell.Contains(s2.S2Cell(inside)))
|
|
378
|
+
self.assertFalse(cell.Contains(s2.S2Cell(outside)))
|
|
379
|
+
self.assertTrue(cell.MayIntersect(s2.S2Cell(inside)))
|
|
380
|
+
self.assertFalse(cell.MayIntersect(s2.S2Cell(outside)))
|
|
381
|
+
|
|
382
|
+
cap_bound = cell.GetCapBound()
|
|
383
|
+
self.assertTrue(cap_bound.Contains(inside))
|
|
384
|
+
self.assertFalse(cap_bound.Contains(outside))
|
|
385
|
+
|
|
386
|
+
rect_bound = cell.GetRectBound()
|
|
387
|
+
self.assertTrue(rect_bound.Contains(inside))
|
|
388
|
+
self.assertFalse(rect_bound.Contains(outside))
|
|
389
|
+
|
|
390
|
+
def testS2CellUnionRegion(self):
|
|
391
|
+
cell_id = s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0)).parent(8)
|
|
392
|
+
cell_union = s2.S2CellUnion()
|
|
393
|
+
cell_union.Init([cell_id.id()])
|
|
394
|
+
|
|
395
|
+
inside = s2.S2LatLng.FromDegrees(3.0, 4.0).ToPoint()
|
|
396
|
+
outside = s2.S2LatLng.FromDegrees(30.0, 40.0).ToPoint()
|
|
397
|
+
|
|
398
|
+
self.assertTrue(cell_union.Contains(inside))
|
|
399
|
+
self.assertFalse(cell_union.Contains(outside))
|
|
400
|
+
self.assertTrue(cell_union.Contains(s2.S2Cell(inside)))
|
|
401
|
+
self.assertFalse(cell_union.Contains(s2.S2Cell(outside)))
|
|
402
|
+
self.assertTrue(cell_union.MayIntersect(s2.S2Cell(inside)))
|
|
403
|
+
self.assertFalse(cell_union.MayIntersect(s2.S2Cell(outside)))
|
|
404
|
+
|
|
405
|
+
cap_bound = cell_union.GetCapBound()
|
|
406
|
+
self.assertTrue(cap_bound.Contains(inside))
|
|
407
|
+
self.assertFalse(cap_bound.Contains(outside))
|
|
408
|
+
|
|
409
|
+
rect_bound = cell_union.GetRectBound()
|
|
410
|
+
self.assertTrue(rect_bound.Contains(inside))
|
|
411
|
+
self.assertFalse(rect_bound.Contains(outside))
|
|
412
|
+
|
|
413
|
+
def testS2CellUnionEmpty(self):
|
|
414
|
+
empty_cell_union = s2.S2CellUnion()
|
|
415
|
+
self.assertTrue(empty_cell_union.empty())
|
|
416
|
+
|
|
417
|
+
cell_id = s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0)).parent(8)
|
|
418
|
+
cell_union = s2.S2CellUnion()
|
|
419
|
+
cell_union.Init([cell_id.id()])
|
|
420
|
+
self.assertFalse(cell_union.empty())
|
|
421
|
+
|
|
422
|
+
def testS2CellUnionIntersectionWithS2CellUnion(self):
|
|
423
|
+
cell_id = s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0))
|
|
424
|
+
cell_union = s2.S2CellUnion()
|
|
425
|
+
cell_union.Init([cell_id.id()])
|
|
426
|
+
|
|
427
|
+
# No intersection.
|
|
428
|
+
outside_cell_id = s2.S2CellId(s2.S2LatLng.FromDegrees(5.0, 6.0))
|
|
429
|
+
outside_cell_union = s2.S2CellUnion()
|
|
430
|
+
outside_cell_union.Init([outside_cell_id.id()])
|
|
431
|
+
empty_intersection = cell_union.Intersection(outside_cell_union)
|
|
432
|
+
self.assertTrue(empty_intersection.empty())
|
|
433
|
+
|
|
434
|
+
# Complete overlap.
|
|
435
|
+
self_intersection = cell_union.Intersection(cell_union)
|
|
436
|
+
self.assertTrue(self_intersection.Contains(cell_union))
|
|
437
|
+
self.assertTrue(cell_union.Contains(self_intersection))
|
|
438
|
+
|
|
439
|
+
# Some intersection.
|
|
440
|
+
joint_cell_union = s2.S2CellUnion()
|
|
441
|
+
joint_cell_union.Init([cell_id.id(), outside_cell_id.id()])
|
|
442
|
+
outside_intersection = joint_cell_union.Intersection(outside_cell_union)
|
|
443
|
+
self.assertTrue(outside_intersection.Contains(outside_cell_id))
|
|
444
|
+
self.assertFalse(outside_intersection.Contains(cell_id))
|
|
445
|
+
|
|
446
|
+
def testS2CellUnionIntersectionWithS2CellId(self):
|
|
447
|
+
cell_id = s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0))
|
|
448
|
+
cell_union = s2.S2CellUnion()
|
|
449
|
+
cell_union.Init([cell_id.id()])
|
|
450
|
+
|
|
451
|
+
# No intersection.
|
|
452
|
+
outside_cell_id = s2.S2CellId(s2.S2LatLng.FromDegrees(4.0, 5.0))
|
|
453
|
+
empty_intersection = cell_union.Intersection(outside_cell_id)
|
|
454
|
+
self.assertTrue(empty_intersection.empty())
|
|
455
|
+
|
|
456
|
+
# Complete overlap.
|
|
457
|
+
intersection = cell_union.Intersection(cell_id)
|
|
458
|
+
self.assertTrue(intersection.Contains(cell_id))
|
|
459
|
+
|
|
460
|
+
# Some intersection.
|
|
461
|
+
joint_cell_union = s2.S2CellUnion()
|
|
462
|
+
joint_cell_union.Init([cell_id.id(), outside_cell_id.id()])
|
|
463
|
+
outside_intersection = joint_cell_union.Intersection(outside_cell_id)
|
|
464
|
+
self.assertTrue(outside_intersection.Contains(outside_cell_id))
|
|
465
|
+
self.assertFalse(outside_intersection.Contains(cell_id))
|
|
466
|
+
|
|
467
|
+
def testS2CellUnionIsNormalized(self):
|
|
468
|
+
empty_cell_union = s2.S2CellUnion()
|
|
469
|
+
self.assertTrue(empty_cell_union.IsNormalized())
|
|
470
|
+
|
|
471
|
+
london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
|
|
472
|
+
london_cell_id = s2.S2CellId(london)
|
|
473
|
+
normalized_union = s2.S2CellUnion()
|
|
474
|
+
normalized_union.Init([london_cell_id.id()])
|
|
475
|
+
self.assertTrue(normalized_union.IsNormalized())
|
|
476
|
+
|
|
477
|
+
def testS2CellUnionNormalizeS2CellUnion(self):
|
|
478
|
+
empty_cell_union = s2.S2CellUnion()
|
|
479
|
+
empty_cell_union.NormalizeS2CellUnion()
|
|
480
|
+
self.assertTrue(empty_cell_union.IsNormalized())
|
|
481
|
+
|
|
482
|
+
cell_id = s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0)).parent(8)
|
|
483
|
+
cell_union = s2.S2CellUnion()
|
|
484
|
+
cell_union.Init([cell_id.id()])
|
|
485
|
+
cell_union.NormalizeS2CellUnion()
|
|
486
|
+
self.assertTrue(cell_union.IsNormalized())
|
|
487
|
+
|
|
488
|
+
def testS2LoopRegion(self):
|
|
489
|
+
cell = s2.S2Cell(s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0)).parent(8))
|
|
490
|
+
loop = s2.S2Loop(cell)
|
|
491
|
+
|
|
492
|
+
inside = s2.S2LatLng.FromDegrees(3.0, 4.0).ToPoint()
|
|
493
|
+
outside = s2.S2LatLng.FromDegrees(30.0, 40.0).ToPoint()
|
|
494
|
+
|
|
495
|
+
self.assertTrue(loop.Contains(inside))
|
|
496
|
+
self.assertFalse(loop.Contains(outside))
|
|
497
|
+
self.assertTrue(loop.Contains(s2.S2Cell(inside)))
|
|
498
|
+
self.assertFalse(loop.Contains(s2.S2Cell(outside)))
|
|
499
|
+
self.assertTrue(loop.MayIntersect(s2.S2Cell(inside)))
|
|
500
|
+
self.assertFalse(loop.MayIntersect(s2.S2Cell(outside)))
|
|
501
|
+
|
|
502
|
+
cap_bound = loop.GetCapBound()
|
|
503
|
+
self.assertTrue(cap_bound.Contains(inside))
|
|
504
|
+
self.assertFalse(cap_bound.Contains(outside))
|
|
505
|
+
|
|
506
|
+
rect_bound = loop.GetRectBound()
|
|
507
|
+
self.assertTrue(rect_bound.Contains(inside))
|
|
508
|
+
self.assertFalse(rect_bound.Contains(outside))
|
|
509
|
+
|
|
510
|
+
def testS2PolygonRegion(self):
|
|
511
|
+
cell = s2.S2Cell(s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0)).parent(8))
|
|
512
|
+
polygon = s2.S2Polygon(cell)
|
|
513
|
+
|
|
514
|
+
inside = s2.S2LatLng.FromDegrees(3.0, 4.0).ToPoint()
|
|
515
|
+
outside = s2.S2LatLng.FromDegrees(30.0, 40.0).ToPoint()
|
|
516
|
+
|
|
517
|
+
self.assertTrue(polygon.Contains(inside))
|
|
518
|
+
self.assertFalse(polygon.Contains(outside))
|
|
519
|
+
self.assertTrue(polygon.Contains(s2.S2Cell(inside)))
|
|
520
|
+
self.assertFalse(polygon.Contains(s2.S2Cell(outside)))
|
|
521
|
+
self.assertTrue(polygon.MayIntersect(s2.S2Cell(inside)))
|
|
522
|
+
self.assertFalse(polygon.MayIntersect(s2.S2Cell(outside)))
|
|
523
|
+
|
|
524
|
+
cap_bound = polygon.GetCapBound()
|
|
525
|
+
self.assertTrue(cap_bound.Contains(inside))
|
|
526
|
+
self.assertFalse(cap_bound.Contains(outside))
|
|
527
|
+
|
|
528
|
+
rect_bound = polygon.GetRectBound()
|
|
529
|
+
self.assertTrue(rect_bound.Contains(inside))
|
|
530
|
+
self.assertFalse(rect_bound.Contains(outside))
|
|
531
|
+
|
|
532
|
+
def testS2PolylineRegion(self):
|
|
533
|
+
polyline = s2.S2Polyline()
|
|
534
|
+
polyline.InitFromS2LatLngs([s2.S2LatLng.FromDegrees(0.0, 0.0),
|
|
535
|
+
s2.S2LatLng.FromDegrees(1.0, 1.0)])
|
|
536
|
+
|
|
537
|
+
# Contains(S2Point) always return false.
|
|
538
|
+
self.assertFalse(
|
|
539
|
+
polyline.Contains(s2.S2LatLng.FromDegrees(0.0, 0.0).ToPoint()))
|
|
540
|
+
self.assertFalse(
|
|
541
|
+
polyline.Contains(s2.S2Cell(s2.S2LatLng.FromDegrees(0.0, 0.0))))
|
|
542
|
+
|
|
543
|
+
self.assertTrue(
|
|
544
|
+
polyline.MayIntersect(s2.S2Cell(s2.S2LatLng.FromDegrees(0.0, 0.0))))
|
|
545
|
+
self.assertFalse(
|
|
546
|
+
polyline.MayIntersect(s2.S2Cell(s2.S2LatLng.FromDegrees(3.0, 4.0))))
|
|
547
|
+
|
|
548
|
+
cap_bound = polyline.GetCapBound()
|
|
549
|
+
self.assertTrue(
|
|
550
|
+
cap_bound.Contains(s2.S2LatLng.FromDegrees(0.0, 0.0).ToPoint()))
|
|
551
|
+
self.assertFalse(
|
|
552
|
+
cap_bound.Contains(s2.S2LatLng.FromDegrees(2.0, 2.0).ToPoint()))
|
|
553
|
+
|
|
554
|
+
rect_bound = polyline.GetRectBound()
|
|
555
|
+
self.assertTrue(
|
|
556
|
+
rect_bound.Contains(s2.S2LatLng.FromDegrees(0.0, 0.0).ToPoint()))
|
|
557
|
+
self.assertFalse(
|
|
558
|
+
rect_bound.Contains(s2.S2LatLng.FromDegrees(2.0, 2.0).ToPoint()))
|
|
559
|
+
|
|
560
|
+
def testS2CellIdCenterSiTi(self):
|
|
561
|
+
cell = s2.S2CellId.FromFacePosLevel(3, 0x12345678, s2.S2CellId.kMaxLevel)
|
|
562
|
+
|
|
563
|
+
# Check that the (si, ti) coordinates of the center end in a
|
|
564
|
+
# 1 followed by (30 - level) 0s.
|
|
565
|
+
|
|
566
|
+
# Leaf level, 30.
|
|
567
|
+
face, si, ti = cell.GetCenterSiTi()
|
|
568
|
+
self.assertEqual(3, face)
|
|
569
|
+
self.assertEqual(1 << 0, si & 1)
|
|
570
|
+
self.assertEqual(1 << 0, ti & 1)
|
|
571
|
+
|
|
572
|
+
# Level 29.
|
|
573
|
+
face, si, ti = cell.parent(s2.S2CellId.kMaxLevel - 1).GetCenterSiTi()
|
|
574
|
+
self.assertEqual(3, face)
|
|
575
|
+
self.assertEqual(1 << 1, si & 3)
|
|
576
|
+
self.assertEqual(1 << 1, ti & 3)
|
|
577
|
+
|
|
578
|
+
# Level 28.
|
|
579
|
+
face, si, ti = cell.parent(s2.S2CellId.kMaxLevel - 2).GetCenterSiTi()
|
|
580
|
+
self.assertEqual(3, face)
|
|
581
|
+
self.assertEqual(1 << 2, si & 7)
|
|
582
|
+
self.assertEqual(1 << 2, ti & 7)
|
|
583
|
+
|
|
584
|
+
# Level 20.
|
|
585
|
+
face, si, ti = cell.parent(s2.S2CellId.kMaxLevel - 10).GetCenterSiTi()
|
|
586
|
+
self.assertEqual(3, face)
|
|
587
|
+
self.assertEqual(1 << 10, si & ((1 << 11) - 1))
|
|
588
|
+
self.assertEqual(1 << 10, ti & ((1 << 11) - 1))
|
|
589
|
+
|
|
590
|
+
# Level 10.
|
|
591
|
+
face, si, ti = cell.parent(s2.S2CellId.kMaxLevel - 20).GetCenterSiTi()
|
|
592
|
+
self.assertEqual(3, face)
|
|
593
|
+
self.assertEqual(1 << 20, si & ((1 << 21) - 1))
|
|
594
|
+
self.assertEqual(1 << 20, ti & ((1 << 21) - 1))
|
|
595
|
+
|
|
596
|
+
# Level 0.
|
|
597
|
+
face, si, ti = cell.parent(0).GetCenterSiTi()
|
|
598
|
+
self.assertEqual(3, face)
|
|
599
|
+
self.assertEqual(1 << 30, si & ((1 << 31) - 1))
|
|
600
|
+
self.assertEqual(1 << 30, ti & ((1 << 31) - 1))
|
|
601
|
+
|
|
602
|
+
def testS2CellIdToFromFaceIJ(self):
|
|
603
|
+
cell = s2.S2CellId.FromFaceIJ(3, 1234, 5678)
|
|
604
|
+
face, i, j, _ = cell.ToFaceIJOrientation()
|
|
605
|
+
self.assertEqual(3, face)
|
|
606
|
+
self.assertEqual(1234, i)
|
|
607
|
+
self.assertEqual(5678, j)
|
|
608
|
+
|
|
609
|
+
def testS2EarthMetricRadians(self):
|
|
610
|
+
radius_rad = s2.S2Earth.KmToRadians(12.34)
|
|
611
|
+
self.assertAlmostEqual(radius_rad, 0.0019368985451286374)
|
|
612
|
+
angle = s2.S1Angle.Radians(radius_rad)
|
|
613
|
+
radius_m = s2.S2Earth.RadiansToMeters(angle.radians())
|
|
614
|
+
self.assertEqual(radius_m, 12340.0)
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
class RegionTermIndexerTest(unittest.TestCase):
|
|
618
|
+
def _randomCaps(self, query_type, **indexer_options):
|
|
619
|
+
# This function creates an index consisting either of points (if
|
|
620
|
+
# options.index_contains_points_only() is true) or S2Caps of random size.
|
|
621
|
+
# It then executes queries consisting of points (if query_type == POINT)
|
|
622
|
+
# or S2Caps of random size (if query_type == CAP).
|
|
623
|
+
#
|
|
624
|
+
# indexer_options are set on both the indexer & coverer (if relevant)
|
|
625
|
+
# eg. _randomCaps('cap', min_level=0) calls indexer.set_min_level(0)
|
|
626
|
+
ITERATIONS = 400
|
|
627
|
+
|
|
628
|
+
indexer = s2.S2RegionTermIndexer()
|
|
629
|
+
coverer = s2.S2RegionCoverer()
|
|
630
|
+
|
|
631
|
+
# set indexer options
|
|
632
|
+
for opt_key, opt_value in indexer_options.items():
|
|
633
|
+
setter = "set_%s" % opt_key
|
|
634
|
+
getattr(indexer, setter)(opt_value)
|
|
635
|
+
if hasattr(coverer, setter):
|
|
636
|
+
getattr(coverer, setter)(opt_value)
|
|
637
|
+
|
|
638
|
+
caps = []
|
|
639
|
+
coverings = []
|
|
640
|
+
index = defaultdict(set)
|
|
641
|
+
|
|
642
|
+
index_terms = 0
|
|
643
|
+
query_terms = 0
|
|
644
|
+
for i in range(ITERATIONS):
|
|
645
|
+
# Choose the region to be indexed: either a single point or a cap
|
|
646
|
+
# of random size (up to a full sphere).
|
|
647
|
+
terms = []
|
|
648
|
+
if indexer.index_contains_points_only():
|
|
649
|
+
cap = s2.S2Cap.FromPoint(s2.S2Testing.RandomPoint())
|
|
650
|
+
terms = indexer.GetIndexTerms(cap.center(), "")
|
|
651
|
+
else:
|
|
652
|
+
cap = s2.S2Testing.GetRandomCap(
|
|
653
|
+
0.3 * s2.S2Cell.AverageArea(indexer.max_level()),
|
|
654
|
+
4.0 * s2.S2Cell.AverageArea(indexer.min_level())
|
|
655
|
+
)
|
|
656
|
+
terms = indexer.GetIndexTerms(cap, "")
|
|
657
|
+
|
|
658
|
+
caps.append(cap)
|
|
659
|
+
coverings.append(s2.S2CellUnion(coverer.GetCovering(cap)))
|
|
660
|
+
for term in terms:
|
|
661
|
+
index[term].add(i)
|
|
662
|
+
|
|
663
|
+
index_terms += len(terms)
|
|
664
|
+
|
|
665
|
+
for i in range(ITERATIONS):
|
|
666
|
+
# Choose the region to be queried: either a random point or a cap of
|
|
667
|
+
# random size.
|
|
668
|
+
terms = []
|
|
669
|
+
|
|
670
|
+
if query_type == 'cap':
|
|
671
|
+
cap = s2.S2Cap.FromPoint(s2.S2Testing.RandomPoint())
|
|
672
|
+
terms = indexer.GetQueryTerms(cap.center(), "")
|
|
673
|
+
else:
|
|
674
|
+
cap = s2.S2Testing.GetRandomCap(
|
|
675
|
+
0.3 * s2.S2Cell.AverageArea(indexer.max_level()),
|
|
676
|
+
4.0 * s2.S2Cell.AverageArea(indexer.min_level())
|
|
677
|
+
)
|
|
678
|
+
terms = indexer.GetQueryTerms(cap, "")
|
|
679
|
+
|
|
680
|
+
# Compute the expected results of the S2Cell query by brute force.
|
|
681
|
+
covering = s2.S2CellUnion(coverer.GetCovering(cap))
|
|
682
|
+
expected, actual = set(), set()
|
|
683
|
+
for j in range(len(caps)):
|
|
684
|
+
if covering.Intersects(coverings[j]):
|
|
685
|
+
expected.add(j)
|
|
686
|
+
|
|
687
|
+
for term in terms:
|
|
688
|
+
actual |= index[term]
|
|
689
|
+
|
|
690
|
+
self.assertEqual(expected, actual)
|
|
691
|
+
query_terms += len(terms)
|
|
692
|
+
|
|
693
|
+
print("Index terms/doc: %0.2f, Query terms/doc: %0.2f" % (
|
|
694
|
+
float(index_terms) / ITERATIONS,
|
|
695
|
+
float(query_terms) / ITERATIONS)
|
|
696
|
+
)
|
|
697
|
+
|
|
698
|
+
# We run one test case for each combination of space vs. time optimization,
|
|
699
|
+
# and indexing regions vs. only points.
|
|
700
|
+
|
|
701
|
+
def testIndexRegionsQueryRegionsOptimizeTime(self):
|
|
702
|
+
self._randomCaps("cap",
|
|
703
|
+
optimize_for_space=False,
|
|
704
|
+
min_level=0,
|
|
705
|
+
max_level=16,
|
|
706
|
+
max_cells=20,
|
|
707
|
+
)
|
|
708
|
+
|
|
709
|
+
def testIndexRegionsQueryPointsOptimizeTime(self):
|
|
710
|
+
self._randomCaps("point",
|
|
711
|
+
optimize_for_space=False,
|
|
712
|
+
min_level=0,
|
|
713
|
+
max_level=16,
|
|
714
|
+
max_cells=20,
|
|
715
|
+
)
|
|
716
|
+
|
|
717
|
+
def testIndexRegionsQueryRegionsOptimizeTimeWithLevelMod(self):
|
|
718
|
+
self._randomCaps("cap",
|
|
719
|
+
optimize_for_space=False,
|
|
720
|
+
min_level=6,
|
|
721
|
+
max_level=12,
|
|
722
|
+
level_mod=3,
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
def testIndexRegionsQueryRegionsOptimizeSpace(self):
|
|
726
|
+
self._randomCaps("cap",
|
|
727
|
+
optimize_for_space=True,
|
|
728
|
+
min_level=4,
|
|
729
|
+
max_level=s2.S2CellId.kMaxLevel,
|
|
730
|
+
max_cells=8,
|
|
731
|
+
)
|
|
732
|
+
|
|
733
|
+
def testIndexPointsQueryRegionsOptimizeTime(self):
|
|
734
|
+
self._randomCaps("cap",
|
|
735
|
+
optimize_for_space=False,
|
|
736
|
+
min_level=0,
|
|
737
|
+
max_level=s2.S2CellId.kMaxLevel,
|
|
738
|
+
level_mod=2,
|
|
739
|
+
max_cells=20,
|
|
740
|
+
index_contains_points_only=True,
|
|
741
|
+
)
|
|
742
|
+
|
|
743
|
+
def testIndexPointsQueryRegionsOptimizeSpace(self):
|
|
744
|
+
self._randomCaps("cap",
|
|
745
|
+
optimize_for_space=True,
|
|
746
|
+
index_contains_points_only=True,
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
def testMaxLevelSetLoosely(self):
|
|
750
|
+
# Test that correct terms are generated even when (max_level - min_level)
|
|
751
|
+
# is not a multiple of level_mod.
|
|
752
|
+
indexer1 = s2.S2RegionTermIndexer()
|
|
753
|
+
indexer1.set_min_level(1)
|
|
754
|
+
indexer1.set_level_mod(2)
|
|
755
|
+
indexer1.set_max_level(19)
|
|
756
|
+
|
|
757
|
+
indexer2 = s2.S2RegionTermIndexer()
|
|
758
|
+
indexer2.set_min_level(1)
|
|
759
|
+
indexer2.set_level_mod(2)
|
|
760
|
+
indexer2.set_max_level(19)
|
|
761
|
+
indexer2.set_max_level(20)
|
|
762
|
+
|
|
763
|
+
point = s2.S2Testing.RandomPoint()
|
|
764
|
+
|
|
765
|
+
self.assertEqual(
|
|
766
|
+
indexer1.GetIndexTerms(point, ""),
|
|
767
|
+
indexer2.GetIndexTerms(point, "")
|
|
768
|
+
)
|
|
769
|
+
self.assertEqual(
|
|
770
|
+
indexer1.GetQueryTerms(point, ""),
|
|
771
|
+
indexer2.GetQueryTerms(point, "")
|
|
772
|
+
)
|
|
773
|
+
|
|
774
|
+
cap = s2.S2Testing.GetRandomCap(0.0, 1.0)
|
|
775
|
+
self.assertEqual(
|
|
776
|
+
indexer1.GetIndexTerms(cap, ""),
|
|
777
|
+
indexer2.GetIndexTerms(cap, "")
|
|
778
|
+
)
|
|
779
|
+
self.assertEqual(
|
|
780
|
+
indexer1.GetQueryTerms(cap, ""),
|
|
781
|
+
indexer2.GetQueryTerms(cap, "")
|
|
782
|
+
)
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
if __name__ == "__main__":
|
|
786
|
+
unittest.main()
|