@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,799 @@
|
|
|
1
|
+
// Copyright 2016 Google Inc. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS-IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
|
|
16
|
+
// Author: ericv@google.com (Eric Veach)
|
|
17
|
+
|
|
18
|
+
#ifndef S2_S2BUILDER_GRAPH_H_
|
|
19
|
+
#define S2_S2BUILDER_GRAPH_H_
|
|
20
|
+
|
|
21
|
+
#include <array>
|
|
22
|
+
#include <cstddef>
|
|
23
|
+
#include <iterator>
|
|
24
|
+
#include <utility>
|
|
25
|
+
#include <vector>
|
|
26
|
+
#include "s2/base/integral_types.h"
|
|
27
|
+
#include "s2/id_set_lexicon.h"
|
|
28
|
+
#include "s2/s2builder.h"
|
|
29
|
+
#include "s2/s2error.h"
|
|
30
|
+
|
|
31
|
+
// An S2Builder::Graph represents a collection of snapped edges that is passed
|
|
32
|
+
// to a Layer for assembly. (Example layers include polygons, polylines, and
|
|
33
|
+
// polygon meshes.) The Graph object does not own any of its underlying data;
|
|
34
|
+
// it is simply a view of data that is stored elsewhere. You will only
|
|
35
|
+
// need this interface if you want to implement a new Layer subtype.
|
|
36
|
+
//
|
|
37
|
+
// The graph consists of vertices and directed edges. Vertices are numbered
|
|
38
|
+
// sequentially starting from zero. An edge is represented as a pair of
|
|
39
|
+
// vertex ids. The edges are sorted in lexicographic order, therefore all of
|
|
40
|
+
// the outgoing edges from a particular vertex form a contiguous range.
|
|
41
|
+
//
|
|
42
|
+
// S2Builder::Graph is movable and copyable. Note that although this class
|
|
43
|
+
// does not own the underlying vertex and edge data, S2Builder guarantees that
|
|
44
|
+
// all Graph objects passed to S2Builder::Layer::Build() methods will remain
|
|
45
|
+
// valid until all layers have been built.
|
|
46
|
+
//
|
|
47
|
+
// TODO(ericv): Consider pulling out the methods that are helper functions for
|
|
48
|
+
// Layer implementations (such as GetDirectedLoops) into s2builderutil_graph.h.
|
|
49
|
+
class S2Builder::Graph {
|
|
50
|
+
public:
|
|
51
|
+
// Identifies a vertex in the graph. Vertices are numbered sequentially
|
|
52
|
+
// starting from zero.
|
|
53
|
+
using VertexId = int32;
|
|
54
|
+
|
|
55
|
+
// Defines an edge as an (origin, destination) vertex pair.
|
|
56
|
+
using Edge = std::pair<VertexId, VertexId>;
|
|
57
|
+
|
|
58
|
+
// Identifies an edge in the graph. Edges are numbered sequentially
|
|
59
|
+
// starting from zero.
|
|
60
|
+
using EdgeId = int32;
|
|
61
|
+
|
|
62
|
+
// Identifies an S2Builder *input* edge (before snapping).
|
|
63
|
+
using InputEdgeId = S2Builder::InputEdgeId;
|
|
64
|
+
|
|
65
|
+
// Identifies a set of S2Builder input edges.
|
|
66
|
+
using InputEdgeIdSetId = S2Builder::InputEdgeIdSetId;
|
|
67
|
+
|
|
68
|
+
// Identifies a set of edge labels.
|
|
69
|
+
using LabelSetId = S2Builder::LabelSetId;
|
|
70
|
+
|
|
71
|
+
// Determines whether a degenerate polygon is empty or full.
|
|
72
|
+
using IsFullPolygonPredicate = S2Builder::IsFullPolygonPredicate;
|
|
73
|
+
|
|
74
|
+
// The default constructor exists only for the benefit of STL containers.
|
|
75
|
+
// The graph must be initialized (using the assignment operator) before it
|
|
76
|
+
// is used.
|
|
77
|
+
Graph();
|
|
78
|
+
|
|
79
|
+
// Note that most of the parameters are passed by const reference and must
|
|
80
|
+
// exist for the duration of the Graph object. Notes on parameters:
|
|
81
|
+
// "options":
|
|
82
|
+
// - the GraphOptions used to build the Graph. In some cases these
|
|
83
|
+
// can be different than the options provided by the Layer.
|
|
84
|
+
// "vertices":
|
|
85
|
+
// - a vector of S2Points indexed by VertexId.
|
|
86
|
+
// "edges":
|
|
87
|
+
// - a vector of VertexId pairs (sorted in lexicographic order)
|
|
88
|
+
// indexed by EdgeId.
|
|
89
|
+
// "input_edge_id_set_ids":
|
|
90
|
+
// - a vector indexed by EdgeId that allows access to the set of
|
|
91
|
+
// InputEdgeIds that were mapped to the given edge, by looking up the
|
|
92
|
+
// returned value (an InputEdgeIdSetId) in "input_edge_id_set_lexicon".
|
|
93
|
+
// "input_edge_id_set_lexicon":
|
|
94
|
+
// - a class that maps an InputEdgeIdSetId to a set of InputEdgeIds.
|
|
95
|
+
// "label_set_ids":
|
|
96
|
+
// - a vector indexed by InputEdgeId that allows access to the set of
|
|
97
|
+
// labels that were attached to the given input edge, by looking up the
|
|
98
|
+
// returned value (a LabelSetId) in the "label_set_lexicon".
|
|
99
|
+
// "label_set_lexicon":
|
|
100
|
+
// - a class that maps a LabelSetId to a set of S2Builder::Labels.
|
|
101
|
+
// "is_full_polygon_predicate":
|
|
102
|
+
// - a predicate called to determine whether a graph consisting only of
|
|
103
|
+
// polygon degeneracies represents the empty polygon or the full polygon
|
|
104
|
+
// (see s2builder.h for details).
|
|
105
|
+
Graph(const GraphOptions& options,
|
|
106
|
+
const std::vector<S2Point>* vertices,
|
|
107
|
+
const std::vector<Edge>* edges,
|
|
108
|
+
const std::vector<InputEdgeIdSetId>* input_edge_id_set_ids,
|
|
109
|
+
const IdSetLexicon* input_edge_id_set_lexicon,
|
|
110
|
+
const std::vector<LabelSetId>* label_set_ids,
|
|
111
|
+
const IdSetLexicon* label_set_lexicon,
|
|
112
|
+
IsFullPolygonPredicate is_full_polygon_predicate);
|
|
113
|
+
|
|
114
|
+
const GraphOptions& options() const;
|
|
115
|
+
|
|
116
|
+
// Returns the number of vertices in the graph.
|
|
117
|
+
VertexId num_vertices() const;
|
|
118
|
+
|
|
119
|
+
// Returns the vertex at the given index.
|
|
120
|
+
const S2Point& vertex(VertexId v) const;
|
|
121
|
+
|
|
122
|
+
// Returns the entire set of vertices.
|
|
123
|
+
const std::vector<S2Point>& vertices() const;
|
|
124
|
+
|
|
125
|
+
// Returns the total number of edges in the graph.
|
|
126
|
+
EdgeId num_edges() const;
|
|
127
|
+
|
|
128
|
+
// Returns the endpoints of the given edge (as vertex indices).
|
|
129
|
+
const Edge& edge(EdgeId e) const;
|
|
130
|
+
|
|
131
|
+
// Returns the entire set of edges.
|
|
132
|
+
const std::vector<Edge>& edges() const;
|
|
133
|
+
|
|
134
|
+
// Given an edge (src, dst), returns the reverse edge (dst, src).
|
|
135
|
+
static Edge reverse(const Edge& e);
|
|
136
|
+
|
|
137
|
+
// Returns a vector of edge ids sorted in lexicographic order by
|
|
138
|
+
// (destination, origin). All of the incoming edges to each vertex form a
|
|
139
|
+
// contiguous subrange of this ordering.
|
|
140
|
+
std::vector<EdgeId> GetInEdgeIds() const;
|
|
141
|
+
|
|
142
|
+
// Given a graph such that every directed edge has a sibling, returns a map
|
|
143
|
+
// from EdgeId to the sibling EdgeId. This method is identical to
|
|
144
|
+
// GetInEdgeIds() except that (1) it requires edges to have siblings, and
|
|
145
|
+
// (2) undirected degenerate edges are grouped together in pairs such that
|
|
146
|
+
// one edge is the sibling of the other. Handles duplicate edges correctly
|
|
147
|
+
// and is also consistent with GetLeftTurnMap().
|
|
148
|
+
//
|
|
149
|
+
// REQUIRES: An option is chosen that guarantees sibling pairs:
|
|
150
|
+
// (options.sibling_pairs() == { REQUIRE, CREATE } ||
|
|
151
|
+
// options.edge_type() == UNDIRECTED)
|
|
152
|
+
std::vector<EdgeId> GetSiblingMap() const;
|
|
153
|
+
|
|
154
|
+
// Like GetSiblingMap(), but constructs the map starting from the vector of
|
|
155
|
+
// incoming edge ids returned by GetInEdgeIds(). (This operation is a no-op
|
|
156
|
+
// except unless undirected degenerate edges are present, in which case such
|
|
157
|
+
// edges are grouped together in pairs to satisfy the requirement that every
|
|
158
|
+
// edge must have a sibling edge.)
|
|
159
|
+
void MakeSiblingMap(std::vector<EdgeId>* in_edge_ids) const;
|
|
160
|
+
|
|
161
|
+
class VertexOutMap; // Forward declaration
|
|
162
|
+
class VertexInMap; // Forward declaration
|
|
163
|
+
|
|
164
|
+
// A helper class for VertexOutMap that represents the outgoing edges
|
|
165
|
+
// from a given vertex.
|
|
166
|
+
class VertexOutEdges {
|
|
167
|
+
public:
|
|
168
|
+
const Edge* begin() const { return begin_; }
|
|
169
|
+
const Edge* end() const { return end_; }
|
|
170
|
+
size_t size() const { return end_ - begin_; }
|
|
171
|
+
|
|
172
|
+
private:
|
|
173
|
+
friend class VertexOutMap;
|
|
174
|
+
VertexOutEdges(const Edge* begin, const Edge* end);
|
|
175
|
+
const Edge* begin_;
|
|
176
|
+
const Edge* end_;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// A helper class for VertexOutMap that represents the outgoing edge *ids*
|
|
180
|
+
// from a given vertex.
|
|
181
|
+
class VertexOutEdgeIds
|
|
182
|
+
: public std::iterator<std::forward_iterator_tag, EdgeId> {
|
|
183
|
+
public:
|
|
184
|
+
// An iterator over a range of edge ids (like boost::counting_iterator).
|
|
185
|
+
class Iterator {
|
|
186
|
+
public:
|
|
187
|
+
explicit Iterator(EdgeId id) : id_(id) {}
|
|
188
|
+
const EdgeId& operator*() const { return id_; }
|
|
189
|
+
Iterator& operator++() { ++id_; return *this; }
|
|
190
|
+
Iterator operator++(int) { return Iterator(id_++); }
|
|
191
|
+
size_t operator-(const Iterator& x) const { return id_ - x.id_; }
|
|
192
|
+
bool operator==(const Iterator& x) const { return id_ == x.id_; }
|
|
193
|
+
bool operator!=(const Iterator& x) const { return id_ != x.id_; }
|
|
194
|
+
|
|
195
|
+
private:
|
|
196
|
+
EdgeId id_;
|
|
197
|
+
};
|
|
198
|
+
Iterator begin() const { return Iterator(begin_); }
|
|
199
|
+
Iterator end() const { return Iterator(end_); }
|
|
200
|
+
size_t size() const { return end_ - begin_; }
|
|
201
|
+
|
|
202
|
+
private:
|
|
203
|
+
friend class VertexOutMap;
|
|
204
|
+
VertexOutEdgeIds(EdgeId begin, EdgeId end);
|
|
205
|
+
EdgeId begin_, end_;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// A class that maps vertices to their outgoing edge ids. Example usage:
|
|
209
|
+
// VertexOutMap out(g);
|
|
210
|
+
// for (Graph::EdgeId e : out.edge_ids(v)) { ... }
|
|
211
|
+
// for (const Graph::Edge& edge : out.edges(v)) { ... }
|
|
212
|
+
class VertexOutMap {
|
|
213
|
+
public:
|
|
214
|
+
VertexOutMap() = default;
|
|
215
|
+
explicit VertexOutMap(const Graph& g) { Init(g); }
|
|
216
|
+
void Init(const Graph& g);
|
|
217
|
+
|
|
218
|
+
int degree(VertexId v) const;
|
|
219
|
+
VertexOutEdges edges(VertexId v) const;
|
|
220
|
+
VertexOutEdgeIds edge_ids(VertexId v) const;
|
|
221
|
+
|
|
222
|
+
// Return the edges (or edge ids) between a specific pair of vertices.
|
|
223
|
+
VertexOutEdges edges(VertexId v0, VertexId v1) const;
|
|
224
|
+
VertexOutEdgeIds edge_ids(VertexId v0, VertexId v1) const;
|
|
225
|
+
|
|
226
|
+
private:
|
|
227
|
+
const std::vector<Edge>* edges_;
|
|
228
|
+
std::vector<EdgeId> edge_begins_;
|
|
229
|
+
VertexOutMap(const VertexOutMap&) = delete;
|
|
230
|
+
void operator=(const VertexOutMap&) = delete;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// A helper class for VertexInMap that represents the incoming edge *ids*
|
|
234
|
+
// to a given vertex.
|
|
235
|
+
class VertexInEdgeIds {
|
|
236
|
+
public:
|
|
237
|
+
const EdgeId* begin() const { return begin_; }
|
|
238
|
+
const EdgeId* end() const { return end_; }
|
|
239
|
+
size_t size() const { return end_ - begin_; }
|
|
240
|
+
|
|
241
|
+
private:
|
|
242
|
+
friend class VertexInMap;
|
|
243
|
+
VertexInEdgeIds(const EdgeId* begin, const EdgeId* end);
|
|
244
|
+
const EdgeId* begin_;
|
|
245
|
+
const EdgeId* end_;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// A class that maps vertices to their incoming edge ids. Example usage:
|
|
249
|
+
// VertexInMap in(g);
|
|
250
|
+
// for (Graph::EdgeId e : in.edge_ids(v)) { ... }
|
|
251
|
+
class VertexInMap {
|
|
252
|
+
public:
|
|
253
|
+
VertexInMap() = default;
|
|
254
|
+
explicit VertexInMap(const Graph& g) { Init(g); }
|
|
255
|
+
void Init(const Graph& g);
|
|
256
|
+
|
|
257
|
+
int degree(VertexId v) const;
|
|
258
|
+
VertexInEdgeIds edge_ids(VertexId v) const;
|
|
259
|
+
|
|
260
|
+
// Returns a sorted vector of all incoming edges (see GetInEdgeIds).
|
|
261
|
+
const std::vector<EdgeId>& in_edge_ids() const { return in_edge_ids_; }
|
|
262
|
+
|
|
263
|
+
private:
|
|
264
|
+
std::vector<EdgeId> in_edge_ids_;
|
|
265
|
+
std::vector<EdgeId> in_edge_begins_;
|
|
266
|
+
VertexInMap(const VertexInMap&) = delete;
|
|
267
|
+
void operator=(const VertexInMap&) = delete;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// Defines a value larger than any valid InputEdgeId.
|
|
271
|
+
static const InputEdgeId kMaxInputEdgeId =
|
|
272
|
+
std::numeric_limits<InputEdgeId>::max();
|
|
273
|
+
|
|
274
|
+
// The following value of InputEdgeId means that an edge does not
|
|
275
|
+
// corresponds to any input edge.
|
|
276
|
+
static const InputEdgeId kNoInputEdgeId = kMaxInputEdgeId - 1;
|
|
277
|
+
|
|
278
|
+
// Returns the set of input edge ids that were snapped to the given
|
|
279
|
+
// edge. ("Input edge ids" are assigned to input edges sequentially in
|
|
280
|
+
// the order they are added to the builder.) For example, if input
|
|
281
|
+
// edges 2 and 17 were snapped to edge 12, then input_edge_ids(12)
|
|
282
|
+
// returns a set containing the numbers 2 and 17. Example usage:
|
|
283
|
+
//
|
|
284
|
+
// for (InputEdgeId input_edge_id : g.input_edge_ids(e)) { ... }
|
|
285
|
+
//
|
|
286
|
+
// Please note the following:
|
|
287
|
+
//
|
|
288
|
+
// - When edge chains are simplified, the simplified edge is assigned all
|
|
289
|
+
// the input edge ids associated with edges of the chain.
|
|
290
|
+
//
|
|
291
|
+
// - Edges can also have multiple input edge ids due to edge merging
|
|
292
|
+
// (if DuplicateEdges::MERGE is specified).
|
|
293
|
+
//
|
|
294
|
+
// - Siblings edges automatically created by EdgeType::UNDIRECTED or
|
|
295
|
+
// SiblingPairs::CREATE have an empty set of input edge ids. (However
|
|
296
|
+
// you can use a LabelFetcher to retrieve the set of labels associated
|
|
297
|
+
// with both edges of a given sibling pair.)
|
|
298
|
+
IdSetLexicon::IdSet input_edge_ids(EdgeId e) const;
|
|
299
|
+
|
|
300
|
+
// Low-level method that returns an integer representing the entire set of
|
|
301
|
+
// input edge ids that were snapped to the given edge. The elements of the
|
|
302
|
+
// IdSet can be accessed using input_edge_id_set_lexicon().
|
|
303
|
+
InputEdgeIdSetId input_edge_id_set_id(EdgeId e) const;
|
|
304
|
+
|
|
305
|
+
// Low-level method that returns a vector where each element represents the
|
|
306
|
+
// set of input edge ids that were snapped to a particular output edge.
|
|
307
|
+
const std::vector<InputEdgeIdSetId>& input_edge_id_set_ids() const;
|
|
308
|
+
|
|
309
|
+
// Returns a mapping from an InputEdgeIdSetId to a set of input edge ids.
|
|
310
|
+
const IdSetLexicon& input_edge_id_set_lexicon() const;
|
|
311
|
+
|
|
312
|
+
// Returns the minimum input edge id that was snapped to this edge, or -1 if
|
|
313
|
+
// no input edges were snapped (see SiblingPairs::CREATE). This is
|
|
314
|
+
// useful for layers that wish to preserve the input edge ordering as much
|
|
315
|
+
// as possible (e.g., to ensure idempotency).
|
|
316
|
+
InputEdgeId min_input_edge_id(EdgeId e) const;
|
|
317
|
+
|
|
318
|
+
// Returns a vector containing the minimum input edge id for every edge.
|
|
319
|
+
// If an edge has no input ids, kNoInputEdgeId is used.
|
|
320
|
+
std::vector<InputEdgeId> GetMinInputEdgeIds() const;
|
|
321
|
+
|
|
322
|
+
// Returns a vector of EdgeIds sorted by minimum input edge id. This is an
|
|
323
|
+
// approximation of the input edge ordering.
|
|
324
|
+
std::vector<EdgeId> GetInputEdgeOrder(
|
|
325
|
+
const std::vector<InputEdgeId>& min_input_edge_ids) const;
|
|
326
|
+
|
|
327
|
+
// Convenience class to return the set of labels associated with a given
|
|
328
|
+
// graph edge. Note that due to snapping, one graph edge may correspond to
|
|
329
|
+
// several different input edges and will have all of their labels.
|
|
330
|
+
// This class is the preferred way to retrieve edge labels.
|
|
331
|
+
//
|
|
332
|
+
// The reason this is a class rather than a graph method is because for
|
|
333
|
+
// undirected edges, we need to fetch the labels associated with both
|
|
334
|
+
// siblings. This is because only the original edge of the sibling pair has
|
|
335
|
+
// labels; the automatically generated sibling edge does not.
|
|
336
|
+
class LabelFetcher {
|
|
337
|
+
public:
|
|
338
|
+
LabelFetcher() = default;
|
|
339
|
+
LabelFetcher(const Graph& g, EdgeType edge_type) { Init(g, edge_type); }
|
|
340
|
+
|
|
341
|
+
// Prepares to fetch labels associated with the given edge type. For
|
|
342
|
+
// EdgeType::UNDIRECTED, labels associated with both edges of the sibling
|
|
343
|
+
// pair will be returned. "edge_type" is a parameter (rather than using
|
|
344
|
+
// g.options().edge_type()) so that clients can explicitly control whether
|
|
345
|
+
// labels from one or both siblings are returned.
|
|
346
|
+
void Init(const Graph& g, EdgeType edge_type);
|
|
347
|
+
|
|
348
|
+
// Returns the set of labels associated with edge "e" (and also the labels
|
|
349
|
+
// associated with the sibling of "e" if edge_type() is UNDIRECTED).
|
|
350
|
+
// Labels are sorted and duplicate labels are automatically removed.
|
|
351
|
+
//
|
|
352
|
+
// This method uses an output parameter rather than returning by value in
|
|
353
|
+
// order to avoid allocating a new vector on every call to this method.
|
|
354
|
+
void Fetch(EdgeId e, std::vector<S2Builder::Label>* labels);
|
|
355
|
+
|
|
356
|
+
private:
|
|
357
|
+
const Graph* g_;
|
|
358
|
+
EdgeType edge_type_;
|
|
359
|
+
std::vector<EdgeId> sibling_map_;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// Returns the set of labels associated with a given input edge. Example:
|
|
363
|
+
// for (Label label : g.labels(input_edge_id)) { ... }
|
|
364
|
+
IdSetLexicon::IdSet labels(InputEdgeId e) const;
|
|
365
|
+
|
|
366
|
+
// Low-level method that returns an integer representing the set of
|
|
367
|
+
// labels associated with a given input edge. The elements of
|
|
368
|
+
// the IdSet can be accessed using label_set_lexicon().
|
|
369
|
+
LabelSetId label_set_id(InputEdgeId e) const;
|
|
370
|
+
|
|
371
|
+
// Low-level method that returns a vector where each element represents the
|
|
372
|
+
// set of labels associated with a particular output edge.
|
|
373
|
+
const std::vector<LabelSetId>& label_set_ids() const;
|
|
374
|
+
|
|
375
|
+
// Returns a mapping from a LabelSetId to a set of labels.
|
|
376
|
+
const IdSetLexicon& label_set_lexicon() const;
|
|
377
|
+
|
|
378
|
+
// Convenience method that calls is_full_polygon_predicate() to determine
|
|
379
|
+
// whether a graph that consists only of polygon degeneracies represents the
|
|
380
|
+
// empty polygon or the full polygon (see s2builder.h for details).
|
|
381
|
+
bool IsFullPolygon(S2Error* error) const;
|
|
382
|
+
|
|
383
|
+
// Returns a method that determines whether a graph that consists only of
|
|
384
|
+
// polygon degeneracies represents the empty polygon or the full polygon
|
|
385
|
+
// (see s2builder.h for details).
|
|
386
|
+
const IsFullPolygonPredicate& is_full_polygon_predicate() const;
|
|
387
|
+
|
|
388
|
+
// Returns a map "m" that maps each edge e=(v0,v1) to the following outgoing
|
|
389
|
+
// edge around "v1" in clockwise order. (This corresponds to making a "left
|
|
390
|
+
// turn" at the vertex.) By starting at a given edge and making only left
|
|
391
|
+
// turns, you can construct a loop whose interior does not contain any edges
|
|
392
|
+
// in the same connected component.
|
|
393
|
+
//
|
|
394
|
+
// If the incoming and outgoing edges around a vertex do not alternate
|
|
395
|
+
// perfectly (e.g., there are two incoming edges in a row), then adjacent
|
|
396
|
+
// (incoming, outgoing) pairs are repeatedly matched and removed. This is
|
|
397
|
+
// similar to finding matching parentheses in a string such as "(()())()".
|
|
398
|
+
//
|
|
399
|
+
// For sibling edge pairs, the incoming edge is assumed to immediately
|
|
400
|
+
// follow the outgoing edge in clockwise order. Thus a left turn is made
|
|
401
|
+
// from an edge to its sibling only if there are no other outgoing edges.
|
|
402
|
+
// With respect to the parentheses analogy, a sibling pair is ")(".
|
|
403
|
+
// Similarly, if there are multiple copies of a sibling edge pair then the
|
|
404
|
+
// duplicate incoming and outgoing edges are sorted in alternating order
|
|
405
|
+
// (e.g., ")()(").
|
|
406
|
+
//
|
|
407
|
+
// Degenerate edges (edges from a vertex to itself) are treated as loops
|
|
408
|
+
// consisting of a single edge. This avoids the problem of deciding the
|
|
409
|
+
// connectivity and ordering of such edges when they share a vertex with
|
|
410
|
+
// other edges (possibly including other degenerate edges).
|
|
411
|
+
//
|
|
412
|
+
// If it is not possible to make a left turn from every input edge, this
|
|
413
|
+
// method returns false and sets "error" appropriately. In this situation
|
|
414
|
+
// the left turn map is still valid except that any incoming edge where it
|
|
415
|
+
// is not possible to make a left turn will have its entry set to -1.
|
|
416
|
+
//
|
|
417
|
+
// "in_edge_ids" should be equal to GetInEdgeIds() or GetSiblingMap().
|
|
418
|
+
bool GetLeftTurnMap(const std::vector<EdgeId>& in_edge_ids,
|
|
419
|
+
std::vector<EdgeId>* left_turn_map,
|
|
420
|
+
S2Error* error) const;
|
|
421
|
+
|
|
422
|
+
// Rotates the edges of "loop" if necessary so that the edge(s) with the
|
|
423
|
+
// largest input edge ids are last. This ensures that when an output loop
|
|
424
|
+
// is equivalent to an input loop, their cyclic edge orders are the same.
|
|
425
|
+
// "min_input_ids" is the output of GetMinInputEdgeIds().
|
|
426
|
+
static void CanonicalizeLoopOrder(
|
|
427
|
+
const std::vector<InputEdgeId>& min_input_ids,
|
|
428
|
+
std::vector<EdgeId>* loop);
|
|
429
|
+
|
|
430
|
+
// Sorts the given edge chains (i.e., loops or polylines) by the minimum
|
|
431
|
+
// input edge id of each chains's first edge. This ensures that when the
|
|
432
|
+
// output consists of multiple loops or polylines, they are sorted in the
|
|
433
|
+
// same order as they were provided in the input.
|
|
434
|
+
static void CanonicalizeVectorOrder(
|
|
435
|
+
const std::vector<InputEdgeId>& min_input_ids,
|
|
436
|
+
std::vector<std::vector<EdgeId>>* chains);
|
|
437
|
+
|
|
438
|
+
// A loop consisting of a sequence of edges.
|
|
439
|
+
using EdgeLoop = std::vector<EdgeId>;
|
|
440
|
+
|
|
441
|
+
// Indicates whether loops should be simple cycles (no repeated vertices) or
|
|
442
|
+
// circuits (which allow repeated vertices but not repeated edges). In
|
|
443
|
+
// terms of how the loops are built, this corresponds to closing off a loop
|
|
444
|
+
// at the first repeated vertex vs. the first repeated edge.
|
|
445
|
+
enum class LoopType { SIMPLE, CIRCUIT };
|
|
446
|
+
|
|
447
|
+
// Builds loops from a set of directed edges, turning left at each vertex
|
|
448
|
+
// until either a repeated vertex (for LoopType::SIMPLE) or a repeated edge
|
|
449
|
+
// (for LoopType::CIRCUIT) is found. (Use LoopType::SIMPLE if you intend to
|
|
450
|
+
// construct an S2Loop.)
|
|
451
|
+
//
|
|
452
|
+
// Each loop is represented as a sequence of edges. The edge ordering and
|
|
453
|
+
// loop ordering are automatically canonicalized in order to preserve the
|
|
454
|
+
// input ordering as much as possible. Loops are non-crossing provided that
|
|
455
|
+
// the graph contains no crossing edges. If some edges cannot be turned
|
|
456
|
+
// into loops, returns false and sets "error" appropriately.
|
|
457
|
+
//
|
|
458
|
+
// If any degenerate edges are present, then each such edge is treated as a
|
|
459
|
+
// separate loop. This is mainly useful in conjunction with
|
|
460
|
+
// options.degenerate_edges() == DISCARD_EXCESS, in order to build polygons
|
|
461
|
+
// that preserve degenerate geometry.
|
|
462
|
+
//
|
|
463
|
+
// REQUIRES: options.degenerate_edges() == {DISCARD, DISCARD_EXCESS}
|
|
464
|
+
// REQUIRES: options.edge_type() == DIRECTED
|
|
465
|
+
bool GetDirectedLoops(LoopType loop_type, std::vector<EdgeLoop>* loops,
|
|
466
|
+
S2Error* error) const;
|
|
467
|
+
|
|
468
|
+
// Builds loops from a set of directed edges, turning left at each vertex
|
|
469
|
+
// until a repeated edge is found (i.e., LoopType::CIRCUIT). The loops are
|
|
470
|
+
// further grouped into connected components, where each component consists
|
|
471
|
+
// of one or more loops connected by shared vertices.
|
|
472
|
+
//
|
|
473
|
+
// This method is used to build polygon meshes from directed or undirected
|
|
474
|
+
// input edges. To convert the output of this method into a mesh, the
|
|
475
|
+
// client must determine how the loops in different components are related
|
|
476
|
+
// to each other: for example, several loops from different components may
|
|
477
|
+
// bound the same region on the sphere, in which case all of those loops are
|
|
478
|
+
// combined into a single polygon. (See s2shapeutil::BuildPolygonBoundaries
|
|
479
|
+
// and s2builderutil::LaxPolygonVectorLayer for details.)
|
|
480
|
+
//
|
|
481
|
+
// Note that loops may include both edges of a sibling pair. When several
|
|
482
|
+
// such edges are connected in a chain or a spanning tree, they form a
|
|
483
|
+
// zero-area "filament". The entire loop may be a filament (i.e., a
|
|
484
|
+
// degenerate loop with an empty interior), or the loop may have have
|
|
485
|
+
// non-empty interior with several filaments that extend inside it, or the
|
|
486
|
+
// loop may consist of several "holes" connected by filaments. These
|
|
487
|
+
// filaments do not change the interior of any loop, so if you are only
|
|
488
|
+
// interested in point containment then they can safely be removed by
|
|
489
|
+
// setting the "degenerate_boundaries" parameter to DISCARD. (They can't be
|
|
490
|
+
// removed by setting (options.sibling_pairs() == DISCARD) because the two
|
|
491
|
+
// siblings might belong to different polygons of the mesh.) Note that you
|
|
492
|
+
// can prevent multiple copies of sibling pairs by specifying
|
|
493
|
+
// options.duplicate_edges() == MERGE.
|
|
494
|
+
//
|
|
495
|
+
// Each loop is represented as a sequence of edges. The edge ordering and
|
|
496
|
+
// loop ordering are automatically canonicalized in order to preserve the
|
|
497
|
+
// input ordering as much as possible. Loops are non-crossing provided that
|
|
498
|
+
// the graph contains no crossing edges. If some edges cannot be turned
|
|
499
|
+
// into loops, returns false and sets "error" appropriately.
|
|
500
|
+
//
|
|
501
|
+
// REQUIRES: options.degenerate_edges() == { DISCARD, DISCARD_EXCESS }
|
|
502
|
+
// (but requires DISCARD if degenerate_boundaries == DISCARD)
|
|
503
|
+
// REQUIRES: options.sibling_pairs() == { REQUIRE, CREATE }
|
|
504
|
+
// [i.e., every edge must have a sibling edge]
|
|
505
|
+
enum class DegenerateBoundaries { DISCARD, KEEP };
|
|
506
|
+
using DirectedComponent = std::vector<EdgeLoop>;
|
|
507
|
+
bool GetDirectedComponents(
|
|
508
|
+
DegenerateBoundaries degenerate_boundaries,
|
|
509
|
+
std::vector<DirectedComponent>* components, S2Error* error) const;
|
|
510
|
+
|
|
511
|
+
// Builds loops from a set of undirected edges, turning left at each vertex
|
|
512
|
+
// until either a repeated vertex (for LoopType::SIMPLE) or a repeated edge
|
|
513
|
+
// (for LoopType::CIRCUIT) is found. The loops are further grouped into
|
|
514
|
+
// "components" such that all the loops in a component are connected by
|
|
515
|
+
// shared vertices. Finally, the loops in each component are divided into
|
|
516
|
+
// two "complements" such that every edge in one complement is the sibling
|
|
517
|
+
// of an edge in the other complement. This corresponds to the fact that
|
|
518
|
+
// given any set of non-crossing undirected loops, there are exactly two
|
|
519
|
+
// possible interpretations of the region that those loops represent (where
|
|
520
|
+
// one possibility is the complement of the other). This method does not
|
|
521
|
+
// attempt to resolve this ambiguity, but instead returns both possibilities
|
|
522
|
+
// for each connected component and lets the client choose among them.
|
|
523
|
+
//
|
|
524
|
+
// This method is used to build single polygons. (Use GetDirectedComponents
|
|
525
|
+
// to build polygon meshes, even when the input edges are undirected.) To
|
|
526
|
+
// convert the output of this method into a polygon, the client must choose
|
|
527
|
+
// one complement from each component such that the entire set of loops is
|
|
528
|
+
// oriented consistently (i.e., they define a region such that the interior
|
|
529
|
+
// of the region is always on the left). The non-chosen complements form
|
|
530
|
+
// another set of loops that are also oriented consistently but represent
|
|
531
|
+
// the complementary region on the sphere. Finally, the client needs to
|
|
532
|
+
// choose one of these two sets of loops based on heuristics (e.g., the area
|
|
533
|
+
// of each region), since both sets of loops are equally valid
|
|
534
|
+
// interpretations of the input.
|
|
535
|
+
//
|
|
536
|
+
// Each loop is represented as a sequence of edges. The edge ordering and
|
|
537
|
+
// loop ordering are automatically canonicalized in order to preserve the
|
|
538
|
+
// input ordering as much as possible. Loops are non-crossing provided that
|
|
539
|
+
// the graph contains no crossing edges. If some edges cannot be turned
|
|
540
|
+
// into loops, returns false and sets "error" appropriately.
|
|
541
|
+
//
|
|
542
|
+
// REQUIRES: options.degenerate_edges() == { DISCARD, DISCARD_EXCESS }
|
|
543
|
+
// REQUIRES: options.edge_type() == UNDIRECTED
|
|
544
|
+
// REQUIRES: options.siblings_pairs() == { DISCARD, DISCARD_EXCESS, KEEP }
|
|
545
|
+
// [since REQUIRE, CREATE convert the edge_type() to DIRECTED]
|
|
546
|
+
using UndirectedComponent = std::array<std::vector<EdgeLoop>, 2>;
|
|
547
|
+
bool GetUndirectedComponents(LoopType loop_type,
|
|
548
|
+
std::vector<UndirectedComponent>* components,
|
|
549
|
+
S2Error* error) const;
|
|
550
|
+
|
|
551
|
+
// Indicates whether polylines should be "paths" (which don't allow
|
|
552
|
+
// duplicate vertices, except possibly the first and last vertex) or
|
|
553
|
+
// "walks" (which allow duplicate vertices and edges).
|
|
554
|
+
enum class PolylineType { PATH, WALK };
|
|
555
|
+
|
|
556
|
+
// Builds polylines from a set of edges. If "polyline_type" is PATH, then
|
|
557
|
+
// only vertices of indegree and outdegree 1 (or degree 2 in the case of
|
|
558
|
+
// undirected edges) will appear in the interior of polylines. This
|
|
559
|
+
// essentially generates one polyline for each edge chain in the graph. If
|
|
560
|
+
// "polyline_type" is WALK, then polylines may pass through the same vertex
|
|
561
|
+
// or even the same edge multiple times (if duplicate edges are present),
|
|
562
|
+
// and each polyline will be as long as possible. This option is useful for
|
|
563
|
+
// reconstructing a polyline that has been snapped to a lower resolution,
|
|
564
|
+
// since snapping can cause edges to become identical.
|
|
565
|
+
//
|
|
566
|
+
// This method attempts to preserve the input edge ordering in order to
|
|
567
|
+
// implement idempotency, even when there are repeated edges or loops. This
|
|
568
|
+
// is true whether directed or undirected edges are used. Degenerate edges
|
|
569
|
+
// are also handled appropriately.
|
|
570
|
+
//
|
|
571
|
+
// REQUIRES: options.sibling_pairs() == { DISCARD, DISCARD_EXCESS, KEEP }
|
|
572
|
+
using EdgePolyline = std::vector<EdgeId>;
|
|
573
|
+
std::vector<EdgePolyline> GetPolylines(PolylineType polyline_type) const;
|
|
574
|
+
|
|
575
|
+
////////////////////////////////////////////////////////////////////////
|
|
576
|
+
//////////////// Helper Functions for Creating Graphs //////////////////
|
|
577
|
+
|
|
578
|
+
// Given an unsorted collection of edges, transform them according to the
|
|
579
|
+
// given set of GraphOptions. This includes actions such as discarding
|
|
580
|
+
// degenerate edges; merging duplicate edges; and canonicalizing sibling
|
|
581
|
+
// edge pairs in several possible ways (e.g. discarding or creating them).
|
|
582
|
+
// The output is suitable for passing to the Graph constructor.
|
|
583
|
+
//
|
|
584
|
+
// If options.edge_type() == EdgeType::UNDIRECTED, then all input edges
|
|
585
|
+
// should already have been transformed into a pair of directed edges.
|
|
586
|
+
//
|
|
587
|
+
// "input_ids" is a vector of the same length as "edges" that indicates
|
|
588
|
+
// which input edges were snapped to each edge. This vector is also updated
|
|
589
|
+
// appropriately as edges are discarded, merged, etc.
|
|
590
|
+
//
|
|
591
|
+
// Note that "options" may be modified by this method: in particular, the
|
|
592
|
+
// edge_type() can be changed if sibling_pairs() is CREATE or REQUIRE (see
|
|
593
|
+
// the description of S2Builder::GraphOptions).
|
|
594
|
+
static void ProcessEdges(
|
|
595
|
+
GraphOptions* options, std::vector<Edge>* edges,
|
|
596
|
+
std::vector<InputEdgeIdSetId>* input_ids, IdSetLexicon* id_set_lexicon,
|
|
597
|
+
S2Error* error);
|
|
598
|
+
|
|
599
|
+
// Given a set of vertices and edges, removes all vertices that do not have
|
|
600
|
+
// any edges and returned the new, minimal set of vertices. Also updates
|
|
601
|
+
// each edge in "edges" to correspond to the new vertex numbering. (Note
|
|
602
|
+
// that this method does *not* merge duplicate vertices, it simply removes
|
|
603
|
+
// vertices of degree zero.)
|
|
604
|
+
//
|
|
605
|
+
// The new vertex ordering is a subsequence of the original ordering,
|
|
606
|
+
// therefore if the edges were lexicographically sorted before calling this
|
|
607
|
+
// method then they will still be sorted after calling this method.
|
|
608
|
+
//
|
|
609
|
+
// The extra argument "tmp" points to temporary storage used by this method.
|
|
610
|
+
// All calls to this method from a single thread can reuse the same
|
|
611
|
+
// temporary storage. It should initially point to an empty vector. This
|
|
612
|
+
// can make a big difference to efficiency when this method is called many
|
|
613
|
+
// times (e.g. to extract the vertices for different layers), since the
|
|
614
|
+
// incremental running time for each layer becomes O(edges.size()) rather
|
|
615
|
+
// than O(vertices.size() + edges.size()).
|
|
616
|
+
static std::vector<S2Point> FilterVertices(
|
|
617
|
+
const std::vector<S2Point>& vertices, std::vector<Edge>* edges,
|
|
618
|
+
std::vector<VertexId>* tmp);
|
|
619
|
+
|
|
620
|
+
// A comparison function that allows stable sorting with std::sort (which is
|
|
621
|
+
// fast but not stable). It breaks ties between equal edges by comparing
|
|
622
|
+
// their edge ids.
|
|
623
|
+
static bool StableLessThan(const Edge& a, const Edge& b,
|
|
624
|
+
EdgeId ai, EdgeId bi);
|
|
625
|
+
|
|
626
|
+
private:
|
|
627
|
+
class EdgeProcessor;
|
|
628
|
+
class PolylineBuilder;
|
|
629
|
+
|
|
630
|
+
GraphOptions options_;
|
|
631
|
+
VertexId num_vertices_; // Cached to avoid division by 24.
|
|
632
|
+
|
|
633
|
+
const std::vector<S2Point>* vertices_;
|
|
634
|
+
const std::vector<Edge>* edges_;
|
|
635
|
+
const std::vector<InputEdgeIdSetId>* input_edge_id_set_ids_;
|
|
636
|
+
const IdSetLexicon* input_edge_id_set_lexicon_;
|
|
637
|
+
const std::vector<LabelSetId>* label_set_ids_;
|
|
638
|
+
const IdSetLexicon* label_set_lexicon_;
|
|
639
|
+
IsFullPolygonPredicate is_full_polygon_predicate_;
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
////////////////// Implementation details follow ////////////////////
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
inline S2Builder::Graph::Graph()
|
|
647
|
+
: options_(), num_vertices_(-1), vertices_(nullptr), edges_(nullptr),
|
|
648
|
+
input_edge_id_set_ids_(nullptr), input_edge_id_set_lexicon_(nullptr),
|
|
649
|
+
label_set_ids_(nullptr), label_set_lexicon_(nullptr) {
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
inline const S2Builder::GraphOptions& S2Builder::Graph::options() const {
|
|
653
|
+
return options_;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
inline S2Builder::Graph::VertexId S2Builder::Graph::num_vertices() const {
|
|
657
|
+
return num_vertices_; // vertices_.size() requires division by 24.
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
inline const S2Point& S2Builder::Graph::vertex(VertexId v) const {
|
|
661
|
+
return vertices()[v];
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
inline const std::vector<S2Point>& S2Builder::Graph::vertices() const {
|
|
665
|
+
return *vertices_;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
inline S2Builder::Graph::EdgeId S2Builder::Graph::num_edges() const {
|
|
669
|
+
return static_cast<S2Builder::Graph::EdgeId>(edges().size());
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
inline const S2Builder::Graph::Edge& S2Builder::Graph::edge(EdgeId e) const {
|
|
673
|
+
return edges()[e];
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
inline const std::vector<S2Builder::Graph::Edge>&
|
|
677
|
+
S2Builder::Graph::edges() const {
|
|
678
|
+
return *edges_;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
inline S2Builder::Graph::Edge S2Builder::Graph::reverse(const Edge& e) {
|
|
682
|
+
return Edge(e.second, e.first);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
inline S2Builder::Graph::VertexOutEdges::VertexOutEdges(const Edge* begin,
|
|
686
|
+
const Edge* end)
|
|
687
|
+
: begin_(begin), end_(end) {
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
inline S2Builder::Graph::VertexOutEdges
|
|
691
|
+
S2Builder::Graph::VertexOutMap::edges(VertexId v) const {
|
|
692
|
+
return VertexOutEdges(edges_->data() + edge_begins_[v],
|
|
693
|
+
edges_->data() + edge_begins_[v + 1]);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
inline S2Builder::Graph::VertexOutEdges
|
|
697
|
+
S2Builder::Graph::VertexOutMap::edges(VertexId v0, VertexId v1) const {
|
|
698
|
+
auto range = std::equal_range(edges_->data() + edge_begins_[v0],
|
|
699
|
+
edges_->data() + edge_begins_[v0 + 1],
|
|
700
|
+
Edge(v0, v1));
|
|
701
|
+
return VertexOutEdges(range.first, range.second);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
inline S2Builder::Graph::VertexOutEdgeIds::VertexOutEdgeIds(EdgeId begin,
|
|
705
|
+
EdgeId end)
|
|
706
|
+
: begin_(begin), end_(end) {
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
inline S2Builder::Graph::VertexOutEdgeIds
|
|
710
|
+
S2Builder::Graph::VertexOutMap::edge_ids(VertexId v) const {
|
|
711
|
+
return VertexOutEdgeIds(edge_begins_[v], edge_begins_[v + 1]);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
inline S2Builder::Graph::VertexOutEdgeIds
|
|
715
|
+
S2Builder::Graph::VertexOutMap::edge_ids(VertexId v0, VertexId v1) const {
|
|
716
|
+
auto range = std::equal_range(edges_->data() + edge_begins_[v0],
|
|
717
|
+
edges_->data() + edge_begins_[v0 + 1],
|
|
718
|
+
Edge(v0, v1));
|
|
719
|
+
return VertexOutEdgeIds(
|
|
720
|
+
static_cast<S2Builder::Graph::EdgeId>(range.first - edges_->data()),
|
|
721
|
+
static_cast<S2Builder::Graph::EdgeId>(range.second - edges_->data()));
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
inline int S2Builder::Graph::VertexOutMap::degree(VertexId v) const {
|
|
725
|
+
return static_cast<int>(edge_ids(v).size());
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
inline S2Builder::Graph::VertexInEdgeIds::VertexInEdgeIds(const EdgeId* begin,
|
|
729
|
+
const EdgeId* end)
|
|
730
|
+
: begin_(begin), end_(end) {
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
inline S2Builder::Graph::VertexInEdgeIds
|
|
734
|
+
S2Builder::Graph::VertexInMap::edge_ids(VertexId v) const {
|
|
735
|
+
return VertexInEdgeIds(in_edge_ids_.data() + in_edge_begins_[v],
|
|
736
|
+
in_edge_ids_.data() + in_edge_begins_[v + 1]);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
inline int S2Builder::Graph::VertexInMap::degree(VertexId v) const {
|
|
740
|
+
return static_cast<int>(edge_ids(v).size());
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
inline IdSetLexicon::IdSet S2Builder::Graph::input_edge_ids(EdgeId e) const {
|
|
744
|
+
return input_edge_id_set_lexicon().id_set(input_edge_id_set_ids()[e]);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
inline const std::vector<S2Builder::InputEdgeIdSetId>&
|
|
748
|
+
S2Builder::Graph::input_edge_id_set_ids() const {
|
|
749
|
+
return *input_edge_id_set_ids_;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
inline S2Builder::InputEdgeIdSetId
|
|
753
|
+
S2Builder::Graph::input_edge_id_set_id(EdgeId e) const {
|
|
754
|
+
return input_edge_id_set_ids()[e];
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
inline const IdSetLexicon& S2Builder::Graph::input_edge_id_set_lexicon() const {
|
|
758
|
+
return *input_edge_id_set_lexicon_;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
inline IdSetLexicon::IdSet S2Builder::Graph::labels(LabelSetId id) const {
|
|
762
|
+
return label_set_lexicon().id_set(label_set_ids()[id]);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
inline S2Builder::LabelSetId S2Builder::Graph::label_set_id(EdgeId e) const {
|
|
766
|
+
return label_set_ids()[e];
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
inline const std::vector<S2Builder::LabelSetId>&
|
|
770
|
+
S2Builder::Graph::label_set_ids() const {
|
|
771
|
+
return *label_set_ids_;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
inline const IdSetLexicon& S2Builder::Graph::label_set_lexicon() const {
|
|
775
|
+
return *label_set_lexicon_;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
inline bool S2Builder::Graph::IsFullPolygon(S2Error* error) const {
|
|
779
|
+
return is_full_polygon_predicate_(*this, error);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
inline const S2Builder::IsFullPolygonPredicate&
|
|
783
|
+
S2Builder::Graph::is_full_polygon_predicate() const {
|
|
784
|
+
return is_full_polygon_predicate_;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
inline bool S2Builder::Graph::StableLessThan(
|
|
788
|
+
const Edge& a, const Edge& b, EdgeId ai, EdgeId bi) {
|
|
789
|
+
// The following is simpler but the compiler (2016) doesn't optimize it as
|
|
790
|
+
// well as it should:
|
|
791
|
+
// return make_pair(a, ai) < make_pair(b, bi);
|
|
792
|
+
if (a.first < b.first) return true;
|
|
793
|
+
if (b.first < a.first) return false;
|
|
794
|
+
if (a.second < b.second) return true;
|
|
795
|
+
if (b.second < a.second) return false;
|
|
796
|
+
return ai < bi; // Stable sort.
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
#endif // S2_S2BUILDER_GRAPH_H_
|