@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,183 @@
|
|
|
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:
|
|
19
|
+
//
|
|
20
|
+
// (1) Robustly clipping geodesic edges to the faces of the S2 biunit cube
|
|
21
|
+
// (see s2coords.h), and
|
|
22
|
+
//
|
|
23
|
+
// (2) Robustly clipping 2D edges against 2D rectangles.
|
|
24
|
+
//
|
|
25
|
+
// These functions can be used to efficiently find the set of S2CellIds that
|
|
26
|
+
// are intersected by a geodesic edge (e.g., see S2CrossingEdgeQuery).
|
|
27
|
+
|
|
28
|
+
#ifndef S2_S2EDGE_CLIPPING_H_
|
|
29
|
+
#define S2_S2EDGE_CLIPPING_H_
|
|
30
|
+
|
|
31
|
+
#include <cmath>
|
|
32
|
+
|
|
33
|
+
#include "s2/base/logging.h"
|
|
34
|
+
#include "s2/third_party/absl/container/inlined_vector.h"
|
|
35
|
+
#include "s2/_fp_contract_off.h"
|
|
36
|
+
#include "s2/r2.h"
|
|
37
|
+
#include "s2/r2rect.h"
|
|
38
|
+
#include "s2/s2point.h"
|
|
39
|
+
|
|
40
|
+
namespace S2 {
|
|
41
|
+
|
|
42
|
+
// FaceSegment represents an edge AB clipped to an S2 cube face. It is
|
|
43
|
+
// represented by a face index and a pair of (u,v) coordinates.
|
|
44
|
+
struct FaceSegment {
|
|
45
|
+
int face;
|
|
46
|
+
R2Point a, b;
|
|
47
|
+
};
|
|
48
|
+
using FaceSegmentVector = absl::InlinedVector<FaceSegment, 6>;
|
|
49
|
+
|
|
50
|
+
// Subdivides the given edge AB at every point where it crosses the boundary
|
|
51
|
+
// between two S2 cube faces and returns the corresponding FaceSegments. The
|
|
52
|
+
// segments are returned in order from A toward B. The input points must be
|
|
53
|
+
// unit length.
|
|
54
|
+
//
|
|
55
|
+
// This method guarantees that the returned segments form a continuous path
|
|
56
|
+
// from A to B, and that all vertices are within kFaceClipErrorUVDist of the
|
|
57
|
+
// line AB. All vertices lie within the [-1,1]x[-1,1] cube face rectangles.
|
|
58
|
+
// The results are consistent with s2pred::Sign(), i.e. the edge is
|
|
59
|
+
// well-defined even its endpoints are antipodal. [TODO(ericv): Extend the
|
|
60
|
+
// implementation of S2::RobustCrossProd so that this statement is true.]
|
|
61
|
+
void GetFaceSegments(const S2Point& a, const S2Point& b,
|
|
62
|
+
FaceSegmentVector* segments);
|
|
63
|
+
|
|
64
|
+
// Given an edge AB and a face, returns the (u,v) coordinates for the portion
|
|
65
|
+
// of AB that intersects that face. This method guarantees that the clipped
|
|
66
|
+
// vertices lie within the [-1,1]x[-1,1] cube face rectangle and are within
|
|
67
|
+
// kFaceClipErrorUVDist of the line AB, but the results may differ from
|
|
68
|
+
// those produced by GetFaceSegments. Returns false if AB does not
|
|
69
|
+
// intersect the given face.
|
|
70
|
+
bool ClipToFace(const S2Point& a, const S2Point& b, int face,
|
|
71
|
+
R2Point* a_uv, R2Point* b_uv);
|
|
72
|
+
|
|
73
|
+
// Like ClipToFace, but rather than clipping to the square [-1,1]x[-1,1]
|
|
74
|
+
// in (u,v) space, this method clips to [-R,R]x[-R,R] where R=(1+padding).
|
|
75
|
+
bool ClipToPaddedFace(const S2Point& a, const S2Point& b, int face,
|
|
76
|
+
double padding, R2Point* a_uv, R2Point* b_uv);
|
|
77
|
+
|
|
78
|
+
// The maximum error in the vertices returned by GetFaceSegments and
|
|
79
|
+
// ClipToFace (compared to an exact calculation):
|
|
80
|
+
//
|
|
81
|
+
// - kFaceClipErrorRadians is the maximum angle between a returned vertex
|
|
82
|
+
// and the nearest point on the exact edge AB. It is equal to the
|
|
83
|
+
// maximum directional error in S2::RobustCrossProd, plus the error when
|
|
84
|
+
// projecting points onto a cube face.
|
|
85
|
+
//
|
|
86
|
+
// - kFaceClipErrorDist is the same angle expressed as a maximum distance
|
|
87
|
+
// in (u,v)-space. In other words, a returned vertex is at most this far
|
|
88
|
+
// from the exact edge AB projected into (u,v)-space.
|
|
89
|
+
|
|
90
|
+
// - kFaceClipErrorUVCoord is the same angle expressed as the maximum error
|
|
91
|
+
// in an individual u- or v-coordinate. In other words, for each
|
|
92
|
+
// returned vertex there is a point on the exact edge AB whose u- and
|
|
93
|
+
// v-coordinates differ from the vertex by at most this amount.
|
|
94
|
+
|
|
95
|
+
extern const double kFaceClipErrorRadians;
|
|
96
|
+
extern const double kFaceClipErrorUVDist;
|
|
97
|
+
extern const double kFaceClipErrorUVCoord;
|
|
98
|
+
|
|
99
|
+
// Returns true if the edge AB intersects the given (closed) rectangle to
|
|
100
|
+
// within the error bound below.
|
|
101
|
+
bool IntersectsRect(const R2Point& a, const R2Point& b, const R2Rect& rect);
|
|
102
|
+
|
|
103
|
+
// The maximum error in IntersectRect. If some point of AB is inside the
|
|
104
|
+
// rectangle by at least this distance, the result is guaranteed to be true;
|
|
105
|
+
// if all points of AB are outside the rectangle by at least this distance,
|
|
106
|
+
// the result is guaranteed to be false. This bound assumes that "rect" is
|
|
107
|
+
// a subset of the rectangle [-1,1]x[-1,1] or extends slightly outside it
|
|
108
|
+
// (e.g., by 1e-10 or less).
|
|
109
|
+
extern const double kIntersectsRectErrorUVDist;
|
|
110
|
+
|
|
111
|
+
// Given an edge AB, returns the portion of AB that is contained by the given
|
|
112
|
+
// rectangle "clip". Returns false if there is no intersection.
|
|
113
|
+
bool ClipEdge(const R2Point& a, const R2Point& b, const R2Rect& clip,
|
|
114
|
+
R2Point* a_clipped, R2Point* b_clipped);
|
|
115
|
+
|
|
116
|
+
// Given an edge AB and a rectangle "clip", returns the bounding rectangle of
|
|
117
|
+
// the portion of AB intersected by "clip". The resulting bound may be
|
|
118
|
+
// empty. This is a convenience function built on top of ClipEdgeBound.
|
|
119
|
+
R2Rect GetClippedEdgeBound(const R2Point& a, const R2Point& b,
|
|
120
|
+
const R2Rect& clip);
|
|
121
|
+
|
|
122
|
+
// This function can be used to clip an edge AB to sequence of rectangles
|
|
123
|
+
// efficiently. It represents the clipped edges by their bounding boxes
|
|
124
|
+
// rather than as a pair of endpoints. Specifically, let A'B' be some
|
|
125
|
+
// portion of an edge AB, and let "bound" be a tight bound of A'B'. This
|
|
126
|
+
// function updates "bound" (in place) to be a tight bound of A'B'
|
|
127
|
+
// intersected with a given rectangle "clip". If A'B' does not intersect
|
|
128
|
+
// "clip", returns false and does not necessarily update "bound".
|
|
129
|
+
//
|
|
130
|
+
// REQUIRES: "bound" is a tight bounding rectangle for some portion of AB.
|
|
131
|
+
// (This condition is automatically satisfied if you start with the bounding
|
|
132
|
+
// box of AB and clip to a sequence of rectangles, stopping when the method
|
|
133
|
+
// returns false.)
|
|
134
|
+
bool ClipEdgeBound(const R2Point& a, const R2Point& b,
|
|
135
|
+
const R2Rect& clip, R2Rect* bound);
|
|
136
|
+
|
|
137
|
+
// The maximum error in the vertices generated by ClipEdge and the bounds
|
|
138
|
+
// generated by ClipEdgeBound (compared to an exact calculation):
|
|
139
|
+
//
|
|
140
|
+
// - kEdgeClipErrorUVCoord is the maximum error in a u- or v-coordinate
|
|
141
|
+
// compared to the exact result, assuming that the points A and B are in
|
|
142
|
+
// the rectangle [-1,1]x[1,1] or slightly outside it (by 1e-10 or less).
|
|
143
|
+
//
|
|
144
|
+
// - kEdgeClipErrorUVDist is the maximum distance from a clipped point to
|
|
145
|
+
// the corresponding exact result. It is equal to the error in a single
|
|
146
|
+
// coordinate because at most one coordinate is subject to error.
|
|
147
|
+
|
|
148
|
+
extern const double kEdgeClipErrorUVCoord;
|
|
149
|
+
extern const double kEdgeClipErrorUVDist;
|
|
150
|
+
|
|
151
|
+
// Given a value x that is some linear combination of a and b, returns the
|
|
152
|
+
// value x1 that is the same linear combination of a1 and b1. This function
|
|
153
|
+
// makes the following guarantees:
|
|
154
|
+
// - If x == a, then x1 = a1 (exactly).
|
|
155
|
+
// - If x == b, then x1 = b1 (exactly).
|
|
156
|
+
// - If a <= x <= b, then a1 <= x1 <= b1 (even if a1 == b1).
|
|
157
|
+
// REQUIRES: a != b
|
|
158
|
+
double InterpolateDouble(double x, double a, double b, double a1, double b1);
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
////////////////// Implementation details follow ////////////////////
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
inline bool ClipToFace(const S2Point& a, const S2Point& b, int face,
|
|
165
|
+
R2Point* a_uv, R2Point* b_uv) {
|
|
166
|
+
return ClipToPaddedFace(a, b, face, 0.0, a_uv, b_uv);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
inline double InterpolateDouble(double x, double a, double b,
|
|
170
|
+
double a1, double b1) {
|
|
171
|
+
S2_DCHECK_NE(a, b);
|
|
172
|
+
// To get results that are accurate near both A and B, we interpolate
|
|
173
|
+
// starting from the closer of the two points.
|
|
174
|
+
if (std::fabs(a - x) <= std::fabs(b - x)) {
|
|
175
|
+
return a1 + (b1 - a1) * (x - a) / (b - a);
|
|
176
|
+
} else {
|
|
177
|
+
return b1 + (a1 - b1) * (x - b) / (a - b);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
} // namespace S2
|
|
182
|
+
|
|
183
|
+
#endif // S2_S2EDGE_CLIPPING_H_
|
|
@@ -0,0 +1,335 @@
|
|
|
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_clipping.h"
|
|
19
|
+
|
|
20
|
+
#include <algorithm>
|
|
21
|
+
#include <cfloat>
|
|
22
|
+
#include <cmath>
|
|
23
|
+
#include <string>
|
|
24
|
+
|
|
25
|
+
#include "s2/base/logging.h"
|
|
26
|
+
#include <gtest/gtest.h>
|
|
27
|
+
#include "s2/third_party/absl/strings/str_cat.h"
|
|
28
|
+
#include "s2/r1interval.h"
|
|
29
|
+
#include "s2/r2rect.h"
|
|
30
|
+
#include "s2/s1chord_angle.h"
|
|
31
|
+
#include "s2/s1interval.h"
|
|
32
|
+
#include "s2/s2coords.h"
|
|
33
|
+
#include "s2/s2pointutil.h"
|
|
34
|
+
#include "s2/s2testing.h"
|
|
35
|
+
|
|
36
|
+
using absl::StrCat;
|
|
37
|
+
using std::fabs;
|
|
38
|
+
using std::max;
|
|
39
|
+
|
|
40
|
+
void TestFaceClipping(const S2Point& a_raw, const S2Point& b_raw) {
|
|
41
|
+
S2Point a = a_raw.Normalize();
|
|
42
|
+
S2Point b = b_raw.Normalize();
|
|
43
|
+
// TODO(ericv): Remove the following line once S2::RobustCrossProd is
|
|
44
|
+
// extended to use simulation of simplicity.
|
|
45
|
+
if (a == -b) return;
|
|
46
|
+
|
|
47
|
+
// First we test GetFaceSegments.
|
|
48
|
+
S2::FaceSegmentVector segments;
|
|
49
|
+
S2::GetFaceSegments(a, b, &segments);
|
|
50
|
+
int n = segments.size();
|
|
51
|
+
EXPECT_GE(n, 1);
|
|
52
|
+
|
|
53
|
+
::testing::Message msg;
|
|
54
|
+
msg << "\nA=" << a_raw << "\nB=" << b_raw;
|
|
55
|
+
msg << "\nN=" << S2::RobustCrossProd(a, b) << "\nSegments:\n";
|
|
56
|
+
int i = 0;
|
|
57
|
+
for (const S2::FaceSegment& s : segments) {
|
|
58
|
+
msg << i++ << ": face=" << s.face << ", a=" << s.a << ", b=" << s.b << "\n";
|
|
59
|
+
}
|
|
60
|
+
SCOPED_TRACE(msg);
|
|
61
|
+
|
|
62
|
+
R2Rect biunit(R1Interval(-1, 1), R1Interval(-1, 1));
|
|
63
|
+
const double kErrorRadians = S2::kFaceClipErrorRadians;
|
|
64
|
+
|
|
65
|
+
// The first and last vertices should approximately equal A and B.
|
|
66
|
+
EXPECT_LE(a.Angle(S2::FaceUVtoXYZ(segments[0].face, segments[0].a)),
|
|
67
|
+
kErrorRadians);
|
|
68
|
+
EXPECT_LE(b.Angle(S2::FaceUVtoXYZ(segments[n-1].face, segments[n-1].b)),
|
|
69
|
+
kErrorRadians);
|
|
70
|
+
|
|
71
|
+
S2Point norm = S2::RobustCrossProd(a, b).Normalize();
|
|
72
|
+
S2Point a_tangent = norm.CrossProd(a);
|
|
73
|
+
S2Point b_tangent = b.CrossProd(norm);
|
|
74
|
+
for (int i = 0; i < n; ++i) {
|
|
75
|
+
// Vertices may not protrude outside the biunit square.
|
|
76
|
+
EXPECT_TRUE(biunit.Contains(segments[i].a));
|
|
77
|
+
EXPECT_TRUE(biunit.Contains(segments[i].b));
|
|
78
|
+
if (i == 0) continue;
|
|
79
|
+
|
|
80
|
+
// The two representations of each interior vertex (on adjacent faces)
|
|
81
|
+
// must correspond to exactly the same S2Point.
|
|
82
|
+
EXPECT_NE(segments[i-1].face, segments[i].face);
|
|
83
|
+
EXPECT_EQ(S2::FaceUVtoXYZ(segments[i-1].face, segments[i-1].b),
|
|
84
|
+
S2::FaceUVtoXYZ(segments[i].face, segments[i].a));
|
|
85
|
+
|
|
86
|
+
// Interior vertices should be in the plane containing A and B, and should
|
|
87
|
+
// be contained in the wedge of angles between A and B (i.e., the dot
|
|
88
|
+
// products with a_tangent and b_tangent should be non-negative).
|
|
89
|
+
S2Point p = S2::FaceUVtoXYZ(segments[i].face, segments[i].a).Normalize();
|
|
90
|
+
EXPECT_LE(fabs(p.DotProd(norm)), kErrorRadians);
|
|
91
|
+
EXPECT_GE(p.DotProd(a_tangent), -kErrorRadians);
|
|
92
|
+
EXPECT_GE(p.DotProd(b_tangent), -kErrorRadians);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Now we test ClipToPaddedFace (sometimes with a padding of zero). We do
|
|
96
|
+
// this by defining an (x,y) coordinate system for the plane containing AB,
|
|
97
|
+
// and converting points along the great circle AB to angles in the range
|
|
98
|
+
// [-Pi, Pi]. We then accumulate the angle intervals spanned by each
|
|
99
|
+
// clipped edge; the union over all 6 faces should approximately equal the
|
|
100
|
+
// interval covered by the original edge.
|
|
101
|
+
S2Testing::Random* rnd = &S2Testing::rnd;
|
|
102
|
+
double padding = rnd->OneIn(10) ? 0.0 : 1e-10 * pow(1e-5, rnd->RandDouble());
|
|
103
|
+
S2Point x_axis = a, y_axis = a_tangent;
|
|
104
|
+
S1Interval expected_angles(0, a.Angle(b));
|
|
105
|
+
S1Interval max_angles = expected_angles.Expanded(kErrorRadians);
|
|
106
|
+
S1Interval actual_angles;
|
|
107
|
+
for (int face = 0; face < 6; ++face) {
|
|
108
|
+
R2Point a_uv, b_uv;
|
|
109
|
+
if (S2::ClipToPaddedFace(a, b, face, padding, &a_uv, &b_uv)) {
|
|
110
|
+
S2Point a_clip = S2::FaceUVtoXYZ(face, a_uv).Normalize();
|
|
111
|
+
S2Point b_clip = S2::FaceUVtoXYZ(face, b_uv).Normalize();
|
|
112
|
+
EXPECT_LE(fabs(a_clip.DotProd(norm)), kErrorRadians);
|
|
113
|
+
EXPECT_LE(fabs(b_clip.DotProd(norm)), kErrorRadians);
|
|
114
|
+
if (a_clip.Angle(a) > kErrorRadians) {
|
|
115
|
+
EXPECT_DOUBLE_EQ(1 + padding, max(fabs(a_uv[0]), fabs(a_uv[1])));
|
|
116
|
+
}
|
|
117
|
+
if (b_clip.Angle(b) > kErrorRadians) {
|
|
118
|
+
EXPECT_DOUBLE_EQ(1 + padding, max(fabs(b_uv[0]), fabs(b_uv[1])));
|
|
119
|
+
}
|
|
120
|
+
double a_angle = atan2(a_clip.DotProd(y_axis), a_clip.DotProd(x_axis));
|
|
121
|
+
double b_angle = atan2(b_clip.DotProd(y_axis), b_clip.DotProd(x_axis));
|
|
122
|
+
// Rounding errors may cause b_angle to be slightly less than a_angle.
|
|
123
|
+
// We handle this by constructing the interval with FromPointPair(),
|
|
124
|
+
// which is okay since the interval length is much less than M_PI.
|
|
125
|
+
S1Interval face_angles = S1Interval::FromPointPair(a_angle, b_angle);
|
|
126
|
+
EXPECT_TRUE(max_angles.Contains(face_angles));
|
|
127
|
+
actual_angles = actual_angles.Union(face_angles);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
EXPECT_TRUE(actual_angles.Expanded(kErrorRadians).Contains(expected_angles));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
void TestFaceClippingEdgePair(const S2Point& a, const S2Point& b) {
|
|
134
|
+
TestFaceClipping(a, b);
|
|
135
|
+
TestFaceClipping(b, a);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// This function is designed to choose line segment endpoints that are difficult
|
|
139
|
+
// to handle correctly. Given two adjacent cube vertices P and Q, it returns
|
|
140
|
+
// either an edge midpoint, face midpoint, or corner vertex along the edge PQ
|
|
141
|
+
// and then perturbs it slightly. It also sometimes returns a random point from
|
|
142
|
+
// anywhere on the sphere.
|
|
143
|
+
S2Point PerturbedCornerOrMidpoint(const S2Point& p, const S2Point& q) {
|
|
144
|
+
S2Testing::Random* rnd = &S2Testing::rnd;
|
|
145
|
+
S2Point a = (rnd->Uniform(3) - 1) * p + (rnd->Uniform(3) - 1) * q;
|
|
146
|
+
if (rnd->OneIn(10)) {
|
|
147
|
+
// This perturbation often has no effect except on coordinates that are
|
|
148
|
+
// zero, in which case the perturbed value is so small that operations on
|
|
149
|
+
// it often result in underflow.
|
|
150
|
+
a += pow(1e-300, rnd->RandDouble()) * S2Testing::RandomPoint();
|
|
151
|
+
} else if (rnd->OneIn(2)) {
|
|
152
|
+
// For coordinates near 1 (say > 0.5), this perturbation yields values
|
|
153
|
+
// that are only a few representable values away from the initial value.
|
|
154
|
+
a += 4 * DBL_EPSILON * S2Testing::RandomPoint();
|
|
155
|
+
} else {
|
|
156
|
+
// A perturbation whose magnitude is in the range [1e-25, 1e-10].
|
|
157
|
+
a += 1e-10 * pow(1e-15, rnd->RandDouble()) * S2Testing::RandomPoint();
|
|
158
|
+
}
|
|
159
|
+
if (a.Norm2() < DBL_MIN) {
|
|
160
|
+
// If a.Norm2() is denormalized, Normalize() loses too much precision.
|
|
161
|
+
return PerturbedCornerOrMidpoint(p, q);
|
|
162
|
+
}
|
|
163
|
+
return a;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
TEST(S2EdgeUtil, FaceClipping) {
|
|
167
|
+
// Start with a few simple cases.
|
|
168
|
+
// An edge that is entirely contained within one cube face:
|
|
169
|
+
TestFaceClippingEdgePair(S2Point(1, -0.5, -0.5), S2Point(1, 0.5, 0.5));
|
|
170
|
+
// An edge that crosses one cube edge:
|
|
171
|
+
TestFaceClippingEdgePair(S2Point(1, 0, 0), S2Point(0, 1, 0));
|
|
172
|
+
// An edge that crosses two opposite edges of face 0:
|
|
173
|
+
TestFaceClippingEdgePair(S2Point(0.75, 0, -1), S2Point(0.75, 0, 1));
|
|
174
|
+
// An edge that crosses two adjacent edges of face 2:
|
|
175
|
+
TestFaceClippingEdgePair(S2Point(1, 0, 0.75), S2Point(0, 1, 0.75));
|
|
176
|
+
// An edge that crosses three cube edges (four faces):
|
|
177
|
+
TestFaceClippingEdgePair(S2Point(1, 0.9, 0.95), S2Point(-1, 0.95, 0.9));
|
|
178
|
+
|
|
179
|
+
// Comprehensively test edges that are difficult to handle, especially those
|
|
180
|
+
// that nearly follow one of the 12 cube edges.
|
|
181
|
+
S2Testing::Random* rnd = &S2Testing::rnd;
|
|
182
|
+
R2Rect biunit(R1Interval(-1, 1), R1Interval(-1, 1));
|
|
183
|
+
const int kIters = 1000; // Test passes with 1e6 iterations
|
|
184
|
+
for (int iter = 0; iter < kIters; ++iter) {
|
|
185
|
+
SCOPED_TRACE(StrCat("Iteration ", iter));
|
|
186
|
+
// Choose two adjacent cube corners P and Q.
|
|
187
|
+
int face = rnd->Uniform(6);
|
|
188
|
+
int i = rnd->Uniform(4);
|
|
189
|
+
int j = (i + 1) & 3;
|
|
190
|
+
S2Point p = S2::FaceUVtoXYZ(face, biunit.GetVertex(i));
|
|
191
|
+
S2Point q = S2::FaceUVtoXYZ(face, biunit.GetVertex(j));
|
|
192
|
+
|
|
193
|
+
// Now choose two points that are nearly on the edge PQ, preferring points
|
|
194
|
+
// that are near cube corners, face midpoints, or edge midpoints.
|
|
195
|
+
S2Point a = PerturbedCornerOrMidpoint(p, q);
|
|
196
|
+
S2Point b = PerturbedCornerOrMidpoint(p, q);
|
|
197
|
+
TestFaceClipping(a, b);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Choose a random point in the rectangle defined by points A and B, sometimes
|
|
202
|
+
// returning a point on the edge AB or the points A and B themselves.
|
|
203
|
+
R2Point ChooseRectPoint(const R2Point& a, const R2Point& b) {
|
|
204
|
+
S2Testing::Random* rnd = &S2Testing::rnd;
|
|
205
|
+
if (rnd->OneIn(5)) {
|
|
206
|
+
return rnd->OneIn(2) ? a : b;
|
|
207
|
+
} else if (rnd->OneIn(3)) {
|
|
208
|
+
return a + rnd->RandDouble() * (b - a);
|
|
209
|
+
} else {
|
|
210
|
+
// a[i] may be >, <, or == b[i], so we write it like this instead
|
|
211
|
+
// of using UniformDouble.
|
|
212
|
+
return R2Point(a[0] + rnd->RandDouble() * (b[0] - a[0]),
|
|
213
|
+
a[1] + rnd->RandDouble() * (b[1] - a[1]));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Given a point X on the line AB (which is checked), return the fraction "t"
|
|
218
|
+
// such that x = (1-t)*a + t*b. Return 0 if A = B.
|
|
219
|
+
double GetFraction(const R2Point& x, const R2Point& a, const R2Point& b) {
|
|
220
|
+
// A bound for the error in edge clipping plus the error in the calculation
|
|
221
|
+
// below (which is similar to IntersectsRect).
|
|
222
|
+
const double kError = (S2::kEdgeClipErrorUVDist +
|
|
223
|
+
S2::kIntersectsRectErrorUVDist);
|
|
224
|
+
if (a == b) return 0.0;
|
|
225
|
+
R2Point dir = (b - a).Normalize();
|
|
226
|
+
EXPECT_LE(fabs((x - a).DotProd(dir.Ortho())), kError);
|
|
227
|
+
return (x - a).DotProd(dir);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Given a point P representing a possibly clipped endpoint A of an edge AB,
|
|
231
|
+
// verify that "clip" contains P, and that if clipping occurred (i.e., P != A)
|
|
232
|
+
// then P is on the boundary of "clip".
|
|
233
|
+
void CheckPointOnBoundary(const R2Point& p, const R2Point& a,
|
|
234
|
+
const R2Rect& clip) {
|
|
235
|
+
EXPECT_TRUE(clip.Contains(p));
|
|
236
|
+
if (p != a) {
|
|
237
|
+
EXPECT_FALSE(clip.Contains(R2Point(nextafter(p[0], a[0]),
|
|
238
|
+
nextafter(p[1], a[1]))));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Given an edge AB and a rectangle "clip", verify that IntersectsRect(),
|
|
243
|
+
// ClipEdge(), and ClipEdgeBound() produce consistent results.
|
|
244
|
+
void TestClipEdge(const R2Point& a, const R2Point& b, const R2Rect& clip) {
|
|
245
|
+
// A bound for the error in edge clipping plus the error in the
|
|
246
|
+
// IntersectsRect calculation below.
|
|
247
|
+
const double kError = (S2::kEdgeClipErrorUVDist +
|
|
248
|
+
S2::kIntersectsRectErrorUVDist);
|
|
249
|
+
R2Point a_clipped, b_clipped;
|
|
250
|
+
if (!S2::ClipEdge(a, b, clip, &a_clipped, &b_clipped)) {
|
|
251
|
+
EXPECT_FALSE(S2::IntersectsRect(a, b, clip.Expanded(-kError)));
|
|
252
|
+
} else {
|
|
253
|
+
EXPECT_TRUE(S2::IntersectsRect(a, b, clip.Expanded(kError)));
|
|
254
|
+
// Check that the clipped points lie on the edge AB, and that the points
|
|
255
|
+
// have the expected order along the segment AB.
|
|
256
|
+
EXPECT_LE(GetFraction(a_clipped, a, b), GetFraction(b_clipped, a, b));
|
|
257
|
+
// Check that the clipped portion of AB is as large as possible.
|
|
258
|
+
CheckPointOnBoundary(a_clipped, a, clip);
|
|
259
|
+
CheckPointOnBoundary(b_clipped, b, clip);
|
|
260
|
+
}
|
|
261
|
+
// Choose a random initial bound to pass to ClipEdgeBound.
|
|
262
|
+
R2Rect initial_clip = R2Rect::FromPointPair(ChooseRectPoint(a, b),
|
|
263
|
+
ChooseRectPoint(a, b));
|
|
264
|
+
R2Rect bound = S2::GetClippedEdgeBound(a, b, initial_clip);
|
|
265
|
+
if (bound.is_empty()) return; // Precondition of ClipEdgeBound not met
|
|
266
|
+
R2Rect max_bound = bound.Intersection(clip);
|
|
267
|
+
if (!S2::ClipEdgeBound(a, b, clip, &bound)) {
|
|
268
|
+
EXPECT_FALSE(S2::IntersectsRect(a, b, max_bound.Expanded(-kError)));
|
|
269
|
+
} else {
|
|
270
|
+
EXPECT_TRUE(S2::IntersectsRect(a, b, max_bound.Expanded(kError)));
|
|
271
|
+
// Check that the bound is as large as possible.
|
|
272
|
+
int ai = (a[0] > b[0]), aj = (a[1] > b[1]);
|
|
273
|
+
CheckPointOnBoundary(bound.GetVertex(ai, aj), a, max_bound);
|
|
274
|
+
CheckPointOnBoundary(bound.GetVertex(1-ai, 1-aj), b, max_bound);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Given an interval "clip", randomly choose either a value in the interval, a
|
|
279
|
+
// value outside the interval, or one of the two interval endpoints, ensuring
|
|
280
|
+
// that all cases have reasonable probability for any interval "clip".
|
|
281
|
+
double ChooseEndpoint(const R1Interval& clip) {
|
|
282
|
+
S2Testing::Random* rnd = &S2Testing::rnd;
|
|
283
|
+
if (rnd->OneIn(5)) {
|
|
284
|
+
return rnd->OneIn(2) ? clip.lo() : clip.hi();
|
|
285
|
+
} else {
|
|
286
|
+
switch (rnd->Uniform(3)) {
|
|
287
|
+
case 0: return clip.lo() - rnd->RandDouble();
|
|
288
|
+
case 1: return clip.hi() + rnd->RandDouble();
|
|
289
|
+
default: return clip.lo() + rnd->RandDouble() * clip.GetLength();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Given a rectangle "clip", choose a point that may lie in the rectangle
|
|
295
|
+
// interior, along an extended edge, exactly at a vertex, or in one of the
|
|
296
|
+
// eight regions exterior to "clip" that are separated by its extended edges.
|
|
297
|
+
// Also sometimes return points that are exactly on one of the extended
|
|
298
|
+
// diagonals of "clip". All cases are reasonably likely to occur for any
|
|
299
|
+
// given rectangle "clip".
|
|
300
|
+
R2Point ChooseEndpoint(const R2Rect& clip) {
|
|
301
|
+
if (S2Testing::rnd.OneIn(10)) {
|
|
302
|
+
// Return a point on one of the two extended diagonals.
|
|
303
|
+
int diag = S2Testing::rnd.Uniform(2);
|
|
304
|
+
double t = S2Testing::rnd.UniformDouble(-1, 2);
|
|
305
|
+
return (1 - t) * clip.GetVertex(diag) + t * clip.GetVertex(diag + 2);
|
|
306
|
+
} else {
|
|
307
|
+
return R2Point(ChooseEndpoint(clip[0]), ChooseEndpoint(clip[1]));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Given a rectangle "clip", test the S2EdgeUtil edge clipping methods using
|
|
312
|
+
// many edges that are randomly constructed to trigger special cases.
|
|
313
|
+
void TestEdgeClipping(const R2Rect& clip) {
|
|
314
|
+
const int kIters = 1000; // Test passes with 1e6 iterations
|
|
315
|
+
for (int iter = 0; iter < kIters; ++iter) {
|
|
316
|
+
SCOPED_TRACE(StrCat("Iteration ", iter));
|
|
317
|
+
TestClipEdge(ChooseEndpoint(clip), ChooseEndpoint(clip), clip);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
TEST(S2EdgeUtil, EdgeClipping) {
|
|
322
|
+
S2Testing::Random* rnd = &S2Testing::rnd;
|
|
323
|
+
// Test clipping against random rectangles.
|
|
324
|
+
for (int i = 0; i < 5; ++i) {
|
|
325
|
+
TestEdgeClipping(R2Rect::FromPointPair(
|
|
326
|
+
R2Point(rnd->UniformDouble(-1, 1), rnd->UniformDouble(-1, 1)),
|
|
327
|
+
R2Point(rnd->UniformDouble(-1, 1), rnd->UniformDouble(-1, 1))));
|
|
328
|
+
}
|
|
329
|
+
// Also clip against one-dimensional, singleton, and empty rectangles.
|
|
330
|
+
TestEdgeClipping(R2Rect(R1Interval(-0.7, -0.7), R1Interval(0.3, 0.35)));
|
|
331
|
+
TestEdgeClipping(R2Rect(R1Interval(0.2, 0.5), R1Interval(0.3, 0.3)));
|
|
332
|
+
TestEdgeClipping(R2Rect(R1Interval(-0.7, 0.3), R1Interval(0, 0)));
|
|
333
|
+
TestEdgeClipping(R2Rect::FromPoint(R2Point(0.3, 0.8)));
|
|
334
|
+
TestEdgeClipping(R2Rect::Empty());
|
|
335
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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_crosser.h"
|
|
19
|
+
|
|
20
|
+
#include "s2/base/logging.h"
|
|
21
|
+
#include "s2/s2pointutil.h"
|
|
22
|
+
#include "s2/s2predicates.h"
|
|
23
|
+
|
|
24
|
+
int S2EdgeCrosser::CrossingSignInternal(const S2Point* d) {
|
|
25
|
+
// Compute the actual result, and then save the current vertex D as the next
|
|
26
|
+
// vertex C, and save the orientation of the next triangle ACB (which is
|
|
27
|
+
// opposite to the current triangle BDA).
|
|
28
|
+
int result = CrossingSignInternal2(*d);
|
|
29
|
+
c_ = d;
|
|
30
|
+
acb_ = -bda_;
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
inline int S2EdgeCrosser::CrossingSignInternal2(const S2Point& d) {
|
|
35
|
+
// At this point, a very common situation is that A,B,C,D are four points on
|
|
36
|
+
// a line such that AB does not overlap CD. (For example, this happens when
|
|
37
|
+
// a line or curve is sampled finely, or when geometry is constructed by
|
|
38
|
+
// computing the union of S2CellIds.) Most of the time, we can determine
|
|
39
|
+
// that AB and CD do not intersect by computing the two outward-facing
|
|
40
|
+
// tangents at A and B (parallel to AB) and testing whether AB and CD are on
|
|
41
|
+
// opposite sides of the plane perpendicular to one of these tangents. This
|
|
42
|
+
// is moderately expensive but still much cheaper than s2pred::ExpensiveSign.
|
|
43
|
+
if (!have_tangents_) {
|
|
44
|
+
S2Point norm = S2::RobustCrossProd(*a_, *b_).Normalize();
|
|
45
|
+
a_tangent_ = a_->CrossProd(norm);
|
|
46
|
+
b_tangent_ = norm.CrossProd(*b_);
|
|
47
|
+
have_tangents_ = true;
|
|
48
|
+
}
|
|
49
|
+
// The error in RobustCrossProd() is insignificant. The maximum error in
|
|
50
|
+
// the call to CrossProd() (i.e., the maximum norm of the error vector) is
|
|
51
|
+
// (0.5 + 1/sqrt(3)) * DBL_EPSILON. The maximum error in each call to
|
|
52
|
+
// DotProd() below is DBL_EPSILON. (There is also a small relative error
|
|
53
|
+
// term that is insignificant because we are comparing the result against a
|
|
54
|
+
// constant that is very close to zero.)
|
|
55
|
+
static const double kError = (1.5 + 1/sqrt(3)) * DBL_EPSILON;
|
|
56
|
+
if ((c_->DotProd(a_tangent_) > kError && d.DotProd(a_tangent_) > kError) ||
|
|
57
|
+
(c_->DotProd(b_tangent_) > kError && d.DotProd(b_tangent_) > kError)) {
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Otherwise, eliminate the cases where two vertices from different edges
|
|
62
|
+
// are equal. (These cases could be handled in the code below, but we would
|
|
63
|
+
// rather avoid calling ExpensiveSign whenever possible.)
|
|
64
|
+
if (*a_ == *c_ || *a_ == d || *b_ == *c_ || *b_ == d) return 0;
|
|
65
|
+
|
|
66
|
+
// Eliminate cases where an input edge is degenerate. (Note that in most
|
|
67
|
+
// cases, if CD is degenerate then this method is not even called because
|
|
68
|
+
// acb_ and bda have different signs.)
|
|
69
|
+
if (*a_ == *b_ || *c_ == d) return -1;
|
|
70
|
+
|
|
71
|
+
// Otherwise it's time to break out the big guns.
|
|
72
|
+
if (acb_ == 0) acb_ = -s2pred::ExpensiveSign(*a_, *b_, *c_);
|
|
73
|
+
S2_DCHECK_NE(acb_, 0);
|
|
74
|
+
if (bda_ == 0) bda_ = s2pred::ExpensiveSign(*a_, *b_, d);
|
|
75
|
+
S2_DCHECK_NE(bda_, 0);
|
|
76
|
+
if (bda_ != acb_) return -1;
|
|
77
|
+
|
|
78
|
+
Vector3_d c_cross_d = c_->CrossProd(d);
|
|
79
|
+
int cbd = -s2pred::Sign(*c_, d, *b_, c_cross_d);
|
|
80
|
+
S2_DCHECK_NE(cbd, 0);
|
|
81
|
+
if (cbd != acb_) return -1;
|
|
82
|
+
int dac = s2pred::Sign(*c_, d, *a_, c_cross_d);
|
|
83
|
+
S2_DCHECK_NE(dac, 0);
|
|
84
|
+
return (dac != acb_) ? -1 : 1;
|
|
85
|
+
}
|