@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,419 @@
|
|
|
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/s2edge_distances.h"
|
|
19
|
+
|
|
20
|
+
#include <cfloat>
|
|
21
|
+
#include <cmath>
|
|
22
|
+
|
|
23
|
+
#include "s2/base/logging.h"
|
|
24
|
+
#include "s2/s1chord_angle.h"
|
|
25
|
+
#include "s2/s2edge_crossings.h"
|
|
26
|
+
#include "s2/s2pointutil.h"
|
|
27
|
+
#include "s2/s2predicates.h"
|
|
28
|
+
|
|
29
|
+
using std::max;
|
|
30
|
+
using std::min;
|
|
31
|
+
|
|
32
|
+
namespace S2 {
|
|
33
|
+
|
|
34
|
+
double GetDistanceFraction(const S2Point& x,
|
|
35
|
+
const S2Point& a0, const S2Point& a1) {
|
|
36
|
+
S2_DCHECK_NE(a0, a1);
|
|
37
|
+
double d0 = x.Angle(a0);
|
|
38
|
+
double d1 = x.Angle(a1);
|
|
39
|
+
return d0 / (d0 + d1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
S2Point InterpolateAtDistance(S1Angle ax_angle,
|
|
43
|
+
const S2Point& a, const S2Point& b) {
|
|
44
|
+
double ax = ax_angle.radians();
|
|
45
|
+
|
|
46
|
+
S2_DCHECK(S2::IsUnitLength(a));
|
|
47
|
+
S2_DCHECK(S2::IsUnitLength(b));
|
|
48
|
+
|
|
49
|
+
// Use RobustCrossProd() to compute the tangent vector at A towards B. The
|
|
50
|
+
// result is always perpendicular to A, even if A=B or A=-B, but it is not
|
|
51
|
+
// necessarily unit length. (We effectively normalize it below.)
|
|
52
|
+
Vector3_d normal = S2::RobustCrossProd(a, b);
|
|
53
|
+
Vector3_d tangent = normal.CrossProd(a);
|
|
54
|
+
S2_DCHECK(tangent != S2Point(0, 0, 0));
|
|
55
|
+
|
|
56
|
+
// Now compute the appropriate linear combination of A and "tangent". With
|
|
57
|
+
// infinite precision the result would always be unit length, but we
|
|
58
|
+
// normalize it anyway to ensure that the error is within acceptable bounds.
|
|
59
|
+
// (Otherwise errors can build up when the result of one interpolation is
|
|
60
|
+
// fed into another interpolation.)
|
|
61
|
+
return (cos(ax) * a + (sin(ax) / tangent.Norm()) * tangent).Normalize();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
S2Point Interpolate(double t, const S2Point& a, const S2Point& b) {
|
|
65
|
+
if (t == 0) return a;
|
|
66
|
+
if (t == 1) return b;
|
|
67
|
+
S1Angle ab(a, b);
|
|
68
|
+
return InterpolateAtDistance(t * ab, a, b);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// If the minimum distance from X to AB is attained at an interior point of AB
|
|
72
|
+
// (i.e., not an endpoint), and that distance is less than "min_dist" or
|
|
73
|
+
// "always_update" is true, then update "min_dist" and return true. Otherwise
|
|
74
|
+
// return false.
|
|
75
|
+
//
|
|
76
|
+
// The "Always" in the function name refers to the template argument, i.e.
|
|
77
|
+
// AlwaysUpdateMinInteriorDistance<true> always updates the given distance,
|
|
78
|
+
// while AlwaysUpdateMinInteriorDistance<false> does not. This optimization
|
|
79
|
+
// increases the speed of GetDistance() by about 10% without creating code
|
|
80
|
+
// duplication.
|
|
81
|
+
template <bool always_update>
|
|
82
|
+
inline bool AlwaysUpdateMinInteriorDistance(
|
|
83
|
+
const S2Point& x, const S2Point& a, const S2Point& b,
|
|
84
|
+
double xa2, double xb2, S1ChordAngle* min_dist) {
|
|
85
|
+
S2_DCHECK(S2::IsUnitLength(x) && S2::IsUnitLength(a) && S2::IsUnitLength(b));
|
|
86
|
+
S2_DCHECK_EQ(xa2, (x-a).Norm2());
|
|
87
|
+
S2_DCHECK_EQ(xb2, (x-b).Norm2());
|
|
88
|
+
|
|
89
|
+
// The closest point on AB could either be one of the two vertices (the
|
|
90
|
+
// "vertex case") or in the interior (the "interior case"). Let C = A x B.
|
|
91
|
+
// If X is in the spherical wedge extending from A to B around the axis
|
|
92
|
+
// through C, then we are in the interior case. Otherwise we are in the
|
|
93
|
+
// vertex case.
|
|
94
|
+
//
|
|
95
|
+
// Check whether we might be in the interior case. For this to be true, XAB
|
|
96
|
+
// and XBA must both be acute angles. Checking this condition exactly is
|
|
97
|
+
// expensive, so instead we consider the planar triangle ABX (which passes
|
|
98
|
+
// through the sphere's interior). The planar angles XAB and XBA are always
|
|
99
|
+
// less than the corresponding spherical angles, so if we are in the
|
|
100
|
+
// interior case then both of these angles must be acute.
|
|
101
|
+
//
|
|
102
|
+
// We check this by computing the squared edge lengths of the planar
|
|
103
|
+
// triangle ABX, and testing acuteness using the law of cosines:
|
|
104
|
+
//
|
|
105
|
+
// max(XA^2, XB^2) < min(XA^2, XB^2) + AB^2
|
|
106
|
+
//
|
|
107
|
+
if (max(xa2, xb2) >= min(xa2, xb2) + (a-b).Norm2()) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
// The minimum distance might be to a point on the edge interior. Let R
|
|
111
|
+
// be closest point to X that lies on the great circle through AB. Rather
|
|
112
|
+
// than computing the geodesic distance along the surface of the sphere,
|
|
113
|
+
// instead we compute the "chord length" through the sphere's interior.
|
|
114
|
+
// If the squared chord length exceeds min_dist.length2() then we can
|
|
115
|
+
// return "false" immediately.
|
|
116
|
+
//
|
|
117
|
+
// The squared chord length XR^2 can be expressed as XQ^2 + QR^2, where Q
|
|
118
|
+
// is the point X projected onto the plane through the great circle AB.
|
|
119
|
+
// The distance XQ^2 can be written as (X.C)^2 / |C|^2 where C = A x B.
|
|
120
|
+
// We ignore the QR^2 term and instead use XQ^2 as a lower bound, since it
|
|
121
|
+
// is faster and the corresponding distance on the Earth's surface is
|
|
122
|
+
// accurate to within 1% for distances up to about 1800km.
|
|
123
|
+
S2Point c = S2::RobustCrossProd(a, b);
|
|
124
|
+
double c2 = c.Norm2();
|
|
125
|
+
double x_dot_c = x.DotProd(c);
|
|
126
|
+
double x_dot_c2 = x_dot_c * x_dot_c;
|
|
127
|
+
if (!always_update && x_dot_c2 > c2 * min_dist->length2()) {
|
|
128
|
+
// The closest point on the great circle AB is too far away. We need to
|
|
129
|
+
// test this using ">" rather than ">=" because the actual minimum bound
|
|
130
|
+
// on the distance is (x_dot_c2 / c2), which can be rounded differently
|
|
131
|
+
// than the (more efficient) multiplicative test above.
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
// Otherwise we do the exact, more expensive test for the interior case.
|
|
135
|
+
// This test is very likely to succeed because of the conservative planar
|
|
136
|
+
// test we did initially.
|
|
137
|
+
S2Point cx = c.CrossProd(x);
|
|
138
|
+
if (a.DotProd(cx) >= 0 || b.DotProd(cx) <= 0) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
// Compute the squared chord length XR^2 = XQ^2 + QR^2 (see above).
|
|
142
|
+
// This calculation has good accuracy for all chord lengths since it
|
|
143
|
+
// is based on both the dot product and cross product (rather than
|
|
144
|
+
// deriving one from the other). However, note that the chord length
|
|
145
|
+
// representation itself loses accuracy as the angle approaches Pi.
|
|
146
|
+
double qr = 1 - sqrt(cx.Norm2() / c2);
|
|
147
|
+
double dist2 = (x_dot_c2 / c2) + (qr * qr);
|
|
148
|
+
if (!always_update && dist2 >= min_dist->length2()) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
*min_dist = S1ChordAngle::FromLength2(dist2);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// This function computes the distance from a point X to a line segment AB.
|
|
156
|
+
// If the distance is less than "min_dist" or "always_update" is true, it
|
|
157
|
+
// updates "min_dist" and returns true. Otherwise it returns false.
|
|
158
|
+
//
|
|
159
|
+
// The "Always" in the function name refers to the template argument, i.e.
|
|
160
|
+
// AlwaysUpdateMinDistance<true> always updates the given distance, while
|
|
161
|
+
// AlwaysUpdateMinDistance<false> does not. This optimization increases the
|
|
162
|
+
// speed of GetDistance() by about 10% without creating code duplication.
|
|
163
|
+
template <bool always_update>
|
|
164
|
+
inline bool AlwaysUpdateMinDistance(const S2Point& x,
|
|
165
|
+
const S2Point& a, const S2Point& b,
|
|
166
|
+
S1ChordAngle* min_dist) {
|
|
167
|
+
S2_DCHECK(S2::IsUnitLength(x) && S2::IsUnitLength(a) && S2::IsUnitLength(b));
|
|
168
|
+
|
|
169
|
+
double xa2 = (x-a).Norm2(), xb2 = (x-b).Norm2();
|
|
170
|
+
if (AlwaysUpdateMinInteriorDistance<always_update>(x, a, b, xa2, xb2,
|
|
171
|
+
min_dist)) {
|
|
172
|
+
return true; // Minimum distance is attained along the edge interior.
|
|
173
|
+
}
|
|
174
|
+
// Otherwise the minimum distance is to one of the endpoints.
|
|
175
|
+
double dist2 = min(xa2, xb2);
|
|
176
|
+
if (!always_update && dist2 >= min_dist->length2()) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
*min_dist = S1ChordAngle::FromLength2(dist2);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
S1Angle GetDistance(const S2Point& x, const S2Point& a, const S2Point& b) {
|
|
184
|
+
S1ChordAngle min_dist;
|
|
185
|
+
AlwaysUpdateMinDistance<true>(x, a, b, &min_dist);
|
|
186
|
+
return min_dist.ToAngle();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
bool UpdateMinDistance(const S2Point& x, const S2Point& a, const S2Point& b,
|
|
190
|
+
S1ChordAngle* min_dist) {
|
|
191
|
+
return AlwaysUpdateMinDistance<false>(x, a, b, min_dist);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
bool UpdateMaxDistance(const S2Point& x, const S2Point& a, const S2Point& b,
|
|
195
|
+
S1ChordAngle* max_dist) {
|
|
196
|
+
auto dist = max(S1ChordAngle(x, a), S1ChordAngle(x, b));
|
|
197
|
+
if (dist > S1ChordAngle::Right()) {
|
|
198
|
+
AlwaysUpdateMinDistance<true>(-x, a, b, &dist);
|
|
199
|
+
dist = S1ChordAngle::Straight() - dist;
|
|
200
|
+
}
|
|
201
|
+
if (*max_dist < dist) {
|
|
202
|
+
*max_dist = dist;
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
bool UpdateMinInteriorDistance(const S2Point& x,
|
|
211
|
+
const S2Point& a, const S2Point& b,
|
|
212
|
+
S1ChordAngle* min_dist) {
|
|
213
|
+
double xa2 = (x-a).Norm2(), xb2 = (x-b).Norm2();
|
|
214
|
+
return AlwaysUpdateMinInteriorDistance<false>(x, a, b, xa2, xb2, min_dist);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Returns the maximum error in the result of UpdateMinInteriorDistance,
|
|
218
|
+
// assuming that all input points are normalized to within the bounds
|
|
219
|
+
// guaranteed by S2Point::Normalize(). The error can be added or subtracted
|
|
220
|
+
// from an S1ChordAngle "x" using x.PlusError(error).
|
|
221
|
+
static double GetUpdateMinInteriorDistanceMaxError(S1ChordAngle dist) {
|
|
222
|
+
// If a point is more than 90 degrees from an edge, then the minimum
|
|
223
|
+
// distance is always to one of the endpoints, not to the edge interior.
|
|
224
|
+
if (dist >= S1ChordAngle::Right()) return 0.0;
|
|
225
|
+
|
|
226
|
+
// This bound includes all source of error, assuming that the input points
|
|
227
|
+
// are normalized to within the bounds guaranteed to S2Point::Normalize().
|
|
228
|
+
// "a" and "b" are components of chord length that are perpendicular and
|
|
229
|
+
// parallel to the plane containing the edge respectively.
|
|
230
|
+
double b = min(1.0, 0.5 * dist.length2());
|
|
231
|
+
double a = sqrt(b * (2 - b));
|
|
232
|
+
return ((2.5 + 2 * sqrt(3) + 8.5 * a) * a +
|
|
233
|
+
(2 + 2 * sqrt(3) / 3 + 6.5 * (1 - b)) * b +
|
|
234
|
+
(23 + 16 / sqrt(3)) * DBL_EPSILON) * DBL_EPSILON;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
double GetUpdateMinDistanceMaxError(S1ChordAngle dist) {
|
|
238
|
+
// There are two cases for the maximum error in UpdateMinDistance(),
|
|
239
|
+
// depending on whether the closest point is interior to the edge.
|
|
240
|
+
return max(GetUpdateMinInteriorDistanceMaxError(dist),
|
|
241
|
+
dist.GetS2PointConstructorMaxError());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
S2Point Project(const S2Point& x, const S2Point& a, const S2Point& b,
|
|
245
|
+
const Vector3_d& a_cross_b) {
|
|
246
|
+
S2_DCHECK(S2::IsUnitLength(a));
|
|
247
|
+
S2_DCHECK(S2::IsUnitLength(b));
|
|
248
|
+
S2_DCHECK(S2::IsUnitLength(x));
|
|
249
|
+
|
|
250
|
+
// Find the closest point to X along the great circle through AB.
|
|
251
|
+
S2Point p = x - (x.DotProd(a_cross_b) / a_cross_b.Norm2()) * a_cross_b;
|
|
252
|
+
|
|
253
|
+
// If this point is on the edge AB, then it's the closest point.
|
|
254
|
+
if (S2::SimpleCCW(a_cross_b, a, p) && S2::SimpleCCW(p, b, a_cross_b)) {
|
|
255
|
+
return p.Normalize();
|
|
256
|
+
}
|
|
257
|
+
// Otherwise, the closest point is either A or B.
|
|
258
|
+
return ((x - a).Norm2() <= (x - b).Norm2()) ? a : b;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
S2Point Project(const S2Point& x, const S2Point& a, const S2Point& b) {
|
|
262
|
+
return Project(x, a, b, S2::RobustCrossProd(a, b));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
bool UpdateEdgePairMinDistance(
|
|
266
|
+
const S2Point& a0, const S2Point& a1,
|
|
267
|
+
const S2Point& b0, const S2Point& b1,
|
|
268
|
+
S1ChordAngle* min_dist) {
|
|
269
|
+
if (*min_dist == S1ChordAngle::Zero()) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
if (S2::CrossingSign(a0, a1, b0, b1) > 0) {
|
|
273
|
+
*min_dist = S1ChordAngle::Zero();
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
// Otherwise, the minimum distance is achieved at an endpoint of at least
|
|
277
|
+
// one of the two edges. We use "|" rather than "||" below to ensure that
|
|
278
|
+
// all four possibilities are always checked.
|
|
279
|
+
//
|
|
280
|
+
// The calculation below computes each of the six vertex-vertex distances
|
|
281
|
+
// twice (this could be optimized).
|
|
282
|
+
return (UpdateMinDistance(a0, b0, b1, min_dist) |
|
|
283
|
+
UpdateMinDistance(a1, b0, b1, min_dist) |
|
|
284
|
+
UpdateMinDistance(b0, a0, a1, min_dist) |
|
|
285
|
+
UpdateMinDistance(b1, a0, a1, min_dist));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
bool UpdateEdgePairMaxDistance(
|
|
289
|
+
const S2Point& a0, const S2Point& a1,
|
|
290
|
+
const S2Point& b0, const S2Point& b1,
|
|
291
|
+
S1ChordAngle* max_dist) {
|
|
292
|
+
if (*max_dist == S1ChordAngle::Straight()) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
if (S2::CrossingSign(a0, a1, -b0, -b1) > 0) {
|
|
296
|
+
*max_dist = S1ChordAngle::Straight();
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
// Otherwise, the maximum distance is achieved at an endpoint of at least
|
|
300
|
+
// one of the two edges. We use "|" rather than "||" below to ensure that
|
|
301
|
+
// all four possibilities are always checked.
|
|
302
|
+
//
|
|
303
|
+
// The calculation below computes each of the six vertex-vertex distances
|
|
304
|
+
// twice (this could be optimized).
|
|
305
|
+
return (UpdateMaxDistance(a0, b0, b1, max_dist) |
|
|
306
|
+
UpdateMaxDistance(a1, b0, b1, max_dist) |
|
|
307
|
+
UpdateMaxDistance(b0, a0, a1, max_dist) |
|
|
308
|
+
UpdateMaxDistance(b1, a0, a1, max_dist));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
std::pair<S2Point, S2Point> GetEdgePairClosestPoints(
|
|
312
|
+
const S2Point& a0, const S2Point& a1,
|
|
313
|
+
const S2Point& b0, const S2Point& b1) {
|
|
314
|
+
if (S2::CrossingSign(a0, a1, b0, b1) > 0) {
|
|
315
|
+
S2Point x = S2::GetIntersection(a0, a1, b0, b1);
|
|
316
|
+
return std::make_pair(x, x);
|
|
317
|
+
}
|
|
318
|
+
// We save some work by first determining which vertex/edge pair achieves
|
|
319
|
+
// the minimum distance, and then computing the closest point on that edge.
|
|
320
|
+
S1ChordAngle min_dist;
|
|
321
|
+
AlwaysUpdateMinDistance<true>(a0, b0, b1, &min_dist);
|
|
322
|
+
enum { A0, A1, B0, B1 } closest_vertex = A0;
|
|
323
|
+
if (UpdateMinDistance(a1, b0, b1, &min_dist)) { closest_vertex = A1; }
|
|
324
|
+
if (UpdateMinDistance(b0, a0, a1, &min_dist)) { closest_vertex = B0; }
|
|
325
|
+
if (UpdateMinDistance(b1, a0, a1, &min_dist)) { closest_vertex = B1; }
|
|
326
|
+
switch (closest_vertex) {
|
|
327
|
+
case A0: return std::make_pair(a0, Project(a0, b0, b1));
|
|
328
|
+
case A1: return std::make_pair(a1, Project(a1, b0, b1));
|
|
329
|
+
case B0: return std::make_pair(Project(b0, a0, a1), b0);
|
|
330
|
+
case B1: return std::make_pair(Project(b1, a0, a1), b1);
|
|
331
|
+
default: S2_LOG(FATAL) << "Unreached (to suppress Android compiler warning)";
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
bool IsEdgeBNearEdgeA(const S2Point& a0, const S2Point& a1,
|
|
336
|
+
const S2Point& b0, const S2Point& b1,
|
|
337
|
+
S1Angle tolerance) {
|
|
338
|
+
S2_DCHECK_LT(tolerance.radians(), M_PI / 2);
|
|
339
|
+
S2_DCHECK_GT(tolerance.radians(), 0);
|
|
340
|
+
// The point on edge B=b0b1 furthest from edge A=a0a1 is either b0, b1, or
|
|
341
|
+
// some interior point on B. If it is an interior point on B, then it must be
|
|
342
|
+
// one of the two points where the great circle containing B (circ(B)) is
|
|
343
|
+
// furthest from the great circle containing A (circ(A)). At these points,
|
|
344
|
+
// the distance between circ(B) and circ(A) is the angle between the planes
|
|
345
|
+
// containing them.
|
|
346
|
+
|
|
347
|
+
Vector3_d a_ortho = S2::RobustCrossProd(a0, a1).Normalize();
|
|
348
|
+
const S2Point a_nearest_b0 = Project(b0, a0, a1, a_ortho);
|
|
349
|
+
const S2Point a_nearest_b1 = Project(b1, a0, a1, a_ortho);
|
|
350
|
+
// If a_nearest_b0 and a_nearest_b1 have opposite orientation from a0 and a1,
|
|
351
|
+
// we invert a_ortho so that it points in the same direction as a_nearest_b0 x
|
|
352
|
+
// a_nearest_b1. This helps us handle the case where A and B are oppositely
|
|
353
|
+
// oriented but otherwise might be near each other. We check orientation and
|
|
354
|
+
// invert rather than computing a_nearest_b0 x a_nearest_b1 because those two
|
|
355
|
+
// points might be equal, and have an unhelpful cross product.
|
|
356
|
+
if (s2pred::Sign(a_ortho, a_nearest_b0, a_nearest_b1) < 0) a_ortho *= -1;
|
|
357
|
+
|
|
358
|
+
// To check if all points on B are within tolerance of A, we first check to
|
|
359
|
+
// see if the endpoints of B are near A. If they are not, B is not near A.
|
|
360
|
+
const S1Angle b0_distance(b0, a_nearest_b0);
|
|
361
|
+
const S1Angle b1_distance(b1, a_nearest_b1);
|
|
362
|
+
if (b0_distance > tolerance || b1_distance > tolerance)
|
|
363
|
+
return false;
|
|
364
|
+
|
|
365
|
+
// If b0 and b1 are both within tolerance of A, we check to see if the angle
|
|
366
|
+
// between the planes containing B and A is greater than tolerance. If it is
|
|
367
|
+
// not, no point on B can be further than tolerance from A (recall that we
|
|
368
|
+
// already know that b0 and b1 are close to A, and S2Edges are all shorter
|
|
369
|
+
// than 180 degrees). The angle between the planes containing circ(A) and
|
|
370
|
+
// circ(B) is the angle between their normal vectors.
|
|
371
|
+
const Vector3_d b_ortho = S2::RobustCrossProd(b0, b1).Normalize();
|
|
372
|
+
const S1Angle planar_angle(a_ortho, b_ortho);
|
|
373
|
+
if (planar_angle <= tolerance)
|
|
374
|
+
return true;
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
// As planar_angle approaches M_PI, the projection of a_ortho onto the plane
|
|
378
|
+
// of B approaches the null vector, and normalizing it is numerically
|
|
379
|
+
// unstable. This makes it unreliable or impossible to identify pairs of
|
|
380
|
+
// points where circ(A) is furthest from circ(B). At this point in the
|
|
381
|
+
// algorithm, this can only occur for two reasons:
|
|
382
|
+
//
|
|
383
|
+
// 1.) b0 and b1 are closest to A at distinct endpoints of A, in which case
|
|
384
|
+
// the opposite orientation of a_ortho and b_ortho means that A and B are
|
|
385
|
+
// in opposite hemispheres and hence not close to each other.
|
|
386
|
+
//
|
|
387
|
+
// 2.) b0 and b1 are closest to A at the same endpoint of A, in which case
|
|
388
|
+
// the orientation of a_ortho was chosen arbitrarily to be that of a0
|
|
389
|
+
// cross a1. B must be shorter than 2*tolerance and all points in B are
|
|
390
|
+
// close to one endpoint of A, and hence to A.
|
|
391
|
+
//
|
|
392
|
+
// The logic applies when planar_angle is robustly greater than M_PI/2, but
|
|
393
|
+
// may be more computationally expensive than the logic beyond, so we choose a
|
|
394
|
+
// value close to M_PI.
|
|
395
|
+
if (planar_angle >= S1Angle::Radians(M_PI - 0.01)) {
|
|
396
|
+
return (S1Angle(b0, a0) < S1Angle(b0, a1)) ==
|
|
397
|
+
(S1Angle(b1, a0) < S1Angle(b1, a1));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Finally, if either of the two points on circ(B) where circ(B) is furthest
|
|
401
|
+
// from circ(A) lie on edge B, edge B is not near edge A.
|
|
402
|
+
//
|
|
403
|
+
// The normalized projection of a_ortho onto the plane of circ(B) is one of
|
|
404
|
+
// the two points along circ(B) where it is furthest from circ(A). The other
|
|
405
|
+
// is -1 times the normalized projection.
|
|
406
|
+
S2Point furthest = (a_ortho - a_ortho.DotProd(b_ortho) * b_ortho).Normalize();
|
|
407
|
+
S2_DCHECK(S2::IsUnitLength(furthest));
|
|
408
|
+
S2Point furthest_inv = -1 * furthest;
|
|
409
|
+
|
|
410
|
+
// A point p lies on B if you can proceed from b_ortho to b0 to p to b1 and
|
|
411
|
+
// back to b_ortho without ever turning right. We test this for furthest and
|
|
412
|
+
// furthest_inv, and return true if neither point lies on B.
|
|
413
|
+
return !((s2pred::Sign(b_ortho, b0, furthest) > 0 &&
|
|
414
|
+
s2pred::Sign(furthest, b1, b_ortho) > 0) ||
|
|
415
|
+
(s2pred::Sign(b_ortho, b0, furthest_inv) > 0 &&
|
|
416
|
+
s2pred::Sign(furthest_inv, b1, b_ortho) > 0));
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
} // namespace S2
|
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
// Defines a collection of functions for computing the distance to an edge,
|
|
19
|
+
// interpolating along an edge, projecting points onto edges, etc.
|
|
20
|
+
|
|
21
|
+
#ifndef S2_S2EDGE_DISTANCES_H_
|
|
22
|
+
#define S2_S2EDGE_DISTANCES_H_
|
|
23
|
+
|
|
24
|
+
#include <utility>
|
|
25
|
+
|
|
26
|
+
#include "s2/s1angle.h"
|
|
27
|
+
#include "s2/s1chord_angle.h"
|
|
28
|
+
#include "s2/s2point.h"
|
|
29
|
+
|
|
30
|
+
namespace S2 {
|
|
31
|
+
|
|
32
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
33
|
+
/////////////// (point, edge) functions ///////////////
|
|
34
|
+
|
|
35
|
+
// Returns the minimum distance from X to any point on the edge AB. All
|
|
36
|
+
// arguments should be unit length. The result is very accurate for small
|
|
37
|
+
// distances but may have some numerical error if the distance is large
|
|
38
|
+
// (approximately Pi/2 or greater). The case A == B is handled correctly.
|
|
39
|
+
//
|
|
40
|
+
// If you want to compare a distance against a fixed threshold, e.g.
|
|
41
|
+
// if (S2::GetDistance(x, a, b) < limit)
|
|
42
|
+
// then it is significantly faster to use UpdateMinDistance() below.
|
|
43
|
+
S1Angle GetDistance(const S2Point& x, const S2Point& a, const S2Point& b);
|
|
44
|
+
|
|
45
|
+
// Returns true if the distance from X to the edge AB is less than "limit".
|
|
46
|
+
// (Specify limit.Successor() for "less than or equal to".) This method is
|
|
47
|
+
// significantly faster than GetDistance(). If you want to compare against a
|
|
48
|
+
// fixed S1Angle, you should convert it to an S1ChordAngle once and save the
|
|
49
|
+
// value, since this step is relatively expensive.
|
|
50
|
+
//
|
|
51
|
+
// See s2pred::CompareEdgeDistance() for an exact version of this predicate.
|
|
52
|
+
bool IsDistanceLess(const S2Point& x, const S2Point& a, const S2Point& b,
|
|
53
|
+
S1ChordAngle limit);
|
|
54
|
+
|
|
55
|
+
// If the distance from X to the edge AB is less than "min_dist", this
|
|
56
|
+
// method updates "min_dist" and returns true. Otherwise it returns false.
|
|
57
|
+
// The case A == B is handled correctly.
|
|
58
|
+
//
|
|
59
|
+
// Use this method when you want to compute many distances and keep track of
|
|
60
|
+
// the minimum. It is significantly faster than using GetDistance(),
|
|
61
|
+
// because (1) using S1ChordAngle is much faster than S1Angle, and (2) it
|
|
62
|
+
// can save a lot of work by not actually computing the distance when it is
|
|
63
|
+
// obviously larger than the current minimum.
|
|
64
|
+
bool UpdateMinDistance(const S2Point& x, const S2Point& a, const S2Point& b,
|
|
65
|
+
S1ChordAngle* min_dist);
|
|
66
|
+
|
|
67
|
+
// If the maximum distance from X to the edge AB is greater than "max_dist",
|
|
68
|
+
// this method updates "max_dist" and returns true. Otherwise it returns false.
|
|
69
|
+
// The case A == B is handled correctly.
|
|
70
|
+
bool UpdateMaxDistance(const S2Point& x, const S2Point& a, const S2Point& b,
|
|
71
|
+
S1ChordAngle* max_dist);
|
|
72
|
+
|
|
73
|
+
// Returns the maximum error in the result of UpdateMinDistance (and
|
|
74
|
+
// associated functions such as UpdateMinInteriorDistance, IsDistanceLess,
|
|
75
|
+
// etc), assuming that all input points are normalized to within the bounds
|
|
76
|
+
// guaranteed by S2Point::Normalize(). The error can be added or subtracted
|
|
77
|
+
// from an S1ChordAngle "x" using x.PlusError(error).
|
|
78
|
+
//
|
|
79
|
+
// Note that accuracy goes down as the distance approaches 0 degrees or 180
|
|
80
|
+
// degrees (for different reasons). Near 0 degrees the error is acceptable
|
|
81
|
+
// for all practical purposes (about 1.2e-15 radians ~= 8 nanometers). For
|
|
82
|
+
// exactly antipodal points the maximum error is quite high (0.5 meters), but
|
|
83
|
+
// this error drops rapidly as the points move away from antipodality
|
|
84
|
+
// (approximately 1 millimeter for points that are 50 meters from antipodal,
|
|
85
|
+
// and 1 micrometer for points that are 50km from antipodal).
|
|
86
|
+
//
|
|
87
|
+
// TODO(ericv): Currently the error bound does not hold for edges whose
|
|
88
|
+
// endpoints are antipodal to within about 1e-15 radians (less than 1 micron).
|
|
89
|
+
// This could be fixed by extending S2::RobustCrossProd to use higher
|
|
90
|
+
// precision when necessary.
|
|
91
|
+
double GetUpdateMinDistanceMaxError(S1ChordAngle dist);
|
|
92
|
+
|
|
93
|
+
// Returns true if the minimum distance from X to the edge AB is attained at
|
|
94
|
+
// an interior point of AB (i.e., not an endpoint), and that distance is less
|
|
95
|
+
// than "limit". (Specify limit.Successor() for "less than or equal to".)
|
|
96
|
+
bool IsInteriorDistanceLess(const S2Point& x,
|
|
97
|
+
const S2Point& a, const S2Point& b,
|
|
98
|
+
S1ChordAngle limit);
|
|
99
|
+
|
|
100
|
+
// If the minimum distance from X to AB is attained at an interior point of AB
|
|
101
|
+
// (i.e., not an endpoint), and that distance is less than "min_dist", then
|
|
102
|
+
// this method updates "min_dist" and returns true. Otherwise returns false.
|
|
103
|
+
bool UpdateMinInteriorDistance(const S2Point& x,
|
|
104
|
+
const S2Point& a, const S2Point& b,
|
|
105
|
+
S1ChordAngle* min_dist);
|
|
106
|
+
|
|
107
|
+
// Returns the point along the edge AB that is closest to the point X.
|
|
108
|
+
// The fractional distance of this point along the edge AB can be obtained
|
|
109
|
+
// using GetDistanceFraction() above. Requires that all vectors have
|
|
110
|
+
// unit length.
|
|
111
|
+
S2Point Project(const S2Point& x, const S2Point& a, const S2Point& b);
|
|
112
|
+
|
|
113
|
+
// A slightly more efficient version of Project() where the cross product of
|
|
114
|
+
// the two endpoints has been precomputed. The cross product does not need to
|
|
115
|
+
// be normalized, but should be computed using S2::RobustCrossProd() for the
|
|
116
|
+
// most accurate results. Requires that x, a, and b have unit length.
|
|
117
|
+
S2Point Project(const S2Point& x, const S2Point& a, const S2Point& b,
|
|
118
|
+
const Vector3_d& a_cross_b);
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
122
|
+
/////////////// (point along edge) functions ///////////////
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
// Given a point X and an edge AB, returns the distance ratio AX / (AX + BX).
|
|
126
|
+
// If X happens to be on the line segment AB, this is the fraction "t" such
|
|
127
|
+
// that X == Interpolate(t, A, B). Requires that A and B are distinct.
|
|
128
|
+
double GetDistanceFraction(const S2Point& x,
|
|
129
|
+
const S2Point& a, const S2Point& b);
|
|
130
|
+
|
|
131
|
+
// Returns the point X along the line segment AB whose distance from A is the
|
|
132
|
+
// given fraction "t" of the distance AB. Does NOT require that "t" be
|
|
133
|
+
// between 0 and 1. Note that all distances are measured on the surface of
|
|
134
|
+
// the sphere, so this is more complicated than just computing (1-t)*a + t*b
|
|
135
|
+
// and normalizing the result.
|
|
136
|
+
S2Point Interpolate(double t, const S2Point& a, const S2Point& b);
|
|
137
|
+
|
|
138
|
+
// Like Interpolate(), except that the parameter "ax" represents the desired
|
|
139
|
+
// distance from A to the result X rather than a fraction between 0 and 1.
|
|
140
|
+
S2Point InterpolateAtDistance(S1Angle ax, const S2Point& a, const S2Point& b);
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
144
|
+
/////////////// (edge, edge) functions ///////////////
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
// Like UpdateMinDistance(), but computes the minimum distance between the
|
|
148
|
+
// given pair of edges. (If the two edges cross, the distance is zero.)
|
|
149
|
+
// The cases a0 == a1 and b0 == b1 are handled correctly.
|
|
150
|
+
bool UpdateEdgePairMinDistance(const S2Point& a0, const S2Point& a1,
|
|
151
|
+
const S2Point& b0, const S2Point& b1,
|
|
152
|
+
S1ChordAngle* min_dist);
|
|
153
|
+
|
|
154
|
+
// As above, but for maximum distances. If one edge crosses the antipodal
|
|
155
|
+
// reflection of the other, the distance is Pi.
|
|
156
|
+
bool UpdateEdgePairMaxDistance(const S2Point& a0, const S2Point& a1,
|
|
157
|
+
const S2Point& b0, const S2Point& b1,
|
|
158
|
+
S1ChordAngle* max_dist);
|
|
159
|
+
|
|
160
|
+
// Returns the pair of points (a, b) that achieves the minimum distance
|
|
161
|
+
// between edges a0a1 and b0b1, where "a" is a point on a0a1 and "b" is a
|
|
162
|
+
// point on b0b1. If the two edges intersect, "a" and "b" are both equal to
|
|
163
|
+
// the intersection point. Handles a0 == a1 and b0 == b1 correctly.
|
|
164
|
+
std::pair<S2Point, S2Point> GetEdgePairClosestPoints(
|
|
165
|
+
const S2Point& a0, const S2Point& a1,
|
|
166
|
+
const S2Point& b0, const S2Point& b1);
|
|
167
|
+
|
|
168
|
+
// Returns true if every point on edge B=b0b1 is no further than "tolerance"
|
|
169
|
+
// from some point on edge A=a0a1. Equivalently, returns true if the directed
|
|
170
|
+
// Hausdorff distance from B to A is no more than "tolerance".
|
|
171
|
+
// Requires that tolerance is less than 90 degrees.
|
|
172
|
+
bool IsEdgeBNearEdgeA(const S2Point& a0, const S2Point& a1,
|
|
173
|
+
const S2Point& b0, const S2Point& b1,
|
|
174
|
+
S1Angle tolerance);
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
////////////////// Implementation details follow ////////////////////
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
inline bool IsDistanceLess(const S2Point& x, const S2Point& a,
|
|
181
|
+
const S2Point& b, S1ChordAngle limit) {
|
|
182
|
+
return UpdateMinDistance(x, a, b, &limit);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
inline bool IsInteriorDistanceLess(const S2Point& x, const S2Point& a,
|
|
186
|
+
const S2Point& b, S1ChordAngle limit) {
|
|
187
|
+
return UpdateMinInteriorDistance(x, a, b, &limit);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
} // namespace S2
|
|
191
|
+
|
|
192
|
+
#endif // S2_S2EDGE_DISTANCES_H_
|