|
22 | 22 | //
|
23 | 23 | // For each input edge, we then determine the sequence of Voronoi regions
|
24 | 24 | // crossed by that edge, and snap the edge to the corresponding sequence of
|
25 |
| -// sites. (In other words, each input each is replaced by an edge chain.) |
| 25 | +// sites. (In other words, each input edge is replaced by an edge chain.) |
26 | 26 | //
|
27 | 27 | // The sites are chosen by starting with the set of input vertices, optionally
|
28 | 28 | // snapping them to discrete point set (such as S2CellId centers or lat/lng E7
|
|
55 | 55 | // Voronoi sites:
|
56 | 56 | //
|
57 | 57 | // - Vertices from all layers contribute to the initial selection of sites.
|
| 58 | +// |
58 | 59 | // - Edges in any layer that pass too close to a site can cause new sites to
|
59 | 60 | // be added (which affects snapping in all layers).
|
| 61 | +// |
60 | 62 | // - Simplification can be thought of as removing sites. A site can be
|
61 | 63 | // removed only if the snapped edges stay within the error bounds of the
|
62 | 64 | // corresponding input edges in all layers.
|
@@ -633,9 +635,9 @@ void S2Builder::AddForcedSites(S2PointIndex<SiteId>* site_index) {
|
633 | 635 | void S2Builder::ChooseInitialSites(
|
634 | 636 | S2PointIndex<SiteId>* site_index,
|
635 | 637 | S2PointIndex<InputVertexId>* rejected_vertex_index) {
|
636 |
| - S2ClosestPointQuery<SiteId> site_query(*site_index); |
| 638 | + S2ClosestPointQuery<SiteId> site_query(site_index); |
637 | 639 | site_query.set_max_distance(snap_radius_);
|
638 |
| - S2ClosestPointQuery<InputVertexId> vertex_query(*rejected_vertex_index); |
| 640 | + S2ClosestPointQuery<InputVertexId> vertex_query(rejected_vertex_index); |
639 | 641 | vertex_query.set_max_distance(min_site_separation_);
|
640 | 642 |
|
641 | 643 | // For each input vertex, check whether all existing sites are further away
|
@@ -720,9 +722,9 @@ void S2Builder::CollectSiteEdges(
|
720 | 722 | S2PointIndex<SiteId> const& site_index,
|
721 | 723 | S2PointIndex<InputVertexId> const& rejected_vertex_index) {
|
722 | 724 | edge_sites_.resize(input_edges_.size());
|
723 |
| - S2ClosestPointQuery<SiteId> site_query(site_index); |
| 725 | + S2ClosestPointQuery<SiteId> site_query(&site_index); |
724 | 726 | site_query.set_max_distance(edge_site_query_radius_);
|
725 |
| - S2ClosestPointQuery<InputVertexId> vertex_query(rejected_vertex_index); |
| 727 | + S2ClosestPointQuery<InputVertexId> vertex_query(&rejected_vertex_index); |
726 | 728 | vertex_query.set_max_distance(min_edge_site_separation_);
|
727 | 729 | for (InputEdgeId e = 0; e < input_edges_.size(); ++e) {
|
728 | 730 | InputEdge const& edge = input_edges_[e];
|
@@ -876,11 +878,12 @@ void S2Builder::AddExtraSite(S2Point const& new_site,
|
876 | 878 | vector<InputEdgeId>* snap_queue) {
|
877 | 879 | SiteId new_site_id = sites_.size();
|
878 | 880 | sites_.push_back(new_site);
|
879 |
| - S2ClosestEdgeQuery query(input_edge_index); |
880 |
| - query.set_max_distance(edge_site_query_radius_); |
881 |
| - query.FindClosestEdges(new_site); |
882 |
| - for (int k = 0; k < query.num_edges(); ++k) { |
883 |
| - InputEdgeId e = query.edge_id(k); |
| 881 | + S2ClosestEdgeQuery::Options options; |
| 882 | + options.set_max_distance(edge_site_query_radius_); |
| 883 | + S2ClosestEdgeQuery query(&input_edge_index, options); |
| 884 | + S2ClosestEdgeQuery::PointTarget target(new_site); |
| 885 | + for (auto const& result : query.FindClosestEdges(target)) { |
| 886 | + InputEdgeId e = result.edge_id; |
884 | 887 | auto* site_ids = &edge_sites_[e];
|
885 | 888 | site_ids->push_back(new_site_id);
|
886 | 889 | SortSitesByDistance(input_vertices_[input_edges_[e].first], site_ids);
|
@@ -970,14 +973,13 @@ void S2Builder::SnapEdge(InputEdgeId e, vector<SiteId>* chain) const {
|
970 | 973 | return;
|
971 | 974 | }
|
972 | 975 |
|
| 976 | + S2Point const& x = input_vertices_[edge.first]; |
| 977 | + S2Point const& y = input_vertices_[edge.second]; |
| 978 | + |
973 | 979 | // Optimization: if there is only one nearby site, return.
|
974 | 980 | // Optimization: if there are exactly two nearby sites, and one is close
|
975 | 981 | // enough to each vertex, then return.
|
976 | 982 |
|
977 |
| - // Compute the edge normal. |
978 |
| - S2Point const& x = input_vertices_[edge.first]; |
979 |
| - S2Point const& y = input_vertices_[edge.second]; |
980 |
| - |
981 | 983 | // Now iterate through the sites. We keep track of the sequence of sites
|
982 | 984 | // that are visited.
|
983 | 985 | auto const& candidates = edge_sites_[e];
|
@@ -1052,9 +1054,7 @@ void S2Builder::SnapEdge(InputEdgeId e, vector<SiteId>* chain) const {
|
1052 | 1054 | }
|
1053 | 1055 | if (s2builder_verbose) {
|
1054 | 1056 | std::cout << "(" << edge.first << "," << edge.second << "): ";
|
1055 |
| - for (SiteId id : *chain) { |
1056 |
| - std::cout << id << " "; |
1057 |
| - } |
| 1057 | + for (SiteId id : *chain) std::cout << id << " "; |
1058 | 1058 | std::cout << std::endl;
|
1059 | 1059 | }
|
1060 | 1060 | }
|
|
0 commit comments