Skip to content

Commit d7b839d

Browse files
committed
Import new google3 version.
* Generalize and modernize S2ClosestEdgeQuery implementation. * Add Span to interfaces. * Use pointer args for query classes when a pointer is stored. * Add NOTICE file. * Move LICENSE-2.0.txt to LICENSE. * Add license header to python file.
1 parent d48cbfd commit d7b839d

36 files changed

+2093
-822
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ install(FILES src/s2/base/casts.h
109109
src/s2/base/mutex.h
110110
src/s2/base/port.h
111111
src/s2/base/spinlock.h
112-
src/s2/base/stringprintf.h
113112
DESTINATION include/s2/base)
114113
install(FILES src/s2/third_party/absl/algorithm/algorithm.h
115114
DESTINATION include/s2/third_party/absl/algorithm)
@@ -135,6 +134,8 @@ install(FILES src/s2/third_party/absl/strings/string_view.h
135134
DESTINATION include/s2/third_party/absl/strings)
136135
install(FILES src/s2/third_party/absl/strings/internal/fastmem.h
137136
DESTINATION include/s2/third_party/absl/strings/internal)
137+
install(FILES src/s2/third_party/absl/types/span.h
138+
DESTINATION include/s2/third_party/absl/types)
138139
install(FILES src/s2/util/bits/bits.h
139140
DESTINATION include/s2/util/bits)
140141
install(FILES src/s2/util/btree/btree.h

LICENSE-2.0.txt LICENSE

File renamed without changes.

NOTICE

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
S2 Geometry Library
2+
Copyright 2017 Google Inc. All Rights Reserved.
3+
4+
This product includes software developed at
5+
Google (https://www.google.com/).

src/s2/pywraps2_test.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1+
#
12
# Copyright 2006 Google Inc. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS-IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
216

317

418

src/s2/s2builder.cc

+17-17
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//
2323
// For each input edge, we then determine the sequence of Voronoi regions
2424
// 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.)
2626
//
2727
// The sites are chosen by starting with the set of input vertices, optionally
2828
// snapping them to discrete point set (such as S2CellId centers or lat/lng E7
@@ -55,8 +55,10 @@
5555
// Voronoi sites:
5656
//
5757
// - Vertices from all layers contribute to the initial selection of sites.
58+
//
5859
// - Edges in any layer that pass too close to a site can cause new sites to
5960
// be added (which affects snapping in all layers).
61+
//
6062
// - Simplification can be thought of as removing sites. A site can be
6163
// removed only if the snapped edges stay within the error bounds of the
6264
// corresponding input edges in all layers.
@@ -633,9 +635,9 @@ void S2Builder::AddForcedSites(S2PointIndex<SiteId>* site_index) {
633635
void S2Builder::ChooseInitialSites(
634636
S2PointIndex<SiteId>* site_index,
635637
S2PointIndex<InputVertexId>* rejected_vertex_index) {
636-
S2ClosestPointQuery<SiteId> site_query(*site_index);
638+
S2ClosestPointQuery<SiteId> site_query(site_index);
637639
site_query.set_max_distance(snap_radius_);
638-
S2ClosestPointQuery<InputVertexId> vertex_query(*rejected_vertex_index);
640+
S2ClosestPointQuery<InputVertexId> vertex_query(rejected_vertex_index);
639641
vertex_query.set_max_distance(min_site_separation_);
640642

641643
// For each input vertex, check whether all existing sites are further away
@@ -720,9 +722,9 @@ void S2Builder::CollectSiteEdges(
720722
S2PointIndex<SiteId> const& site_index,
721723
S2PointIndex<InputVertexId> const& rejected_vertex_index) {
722724
edge_sites_.resize(input_edges_.size());
723-
S2ClosestPointQuery<SiteId> site_query(site_index);
725+
S2ClosestPointQuery<SiteId> site_query(&site_index);
724726
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);
726728
vertex_query.set_max_distance(min_edge_site_separation_);
727729
for (InputEdgeId e = 0; e < input_edges_.size(); ++e) {
728730
InputEdge const& edge = input_edges_[e];
@@ -876,11 +878,12 @@ void S2Builder::AddExtraSite(S2Point const& new_site,
876878
vector<InputEdgeId>* snap_queue) {
877879
SiteId new_site_id = sites_.size();
878880
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;
884887
auto* site_ids = &edge_sites_[e];
885888
site_ids->push_back(new_site_id);
886889
SortSitesByDistance(input_vertices_[input_edges_[e].first], site_ids);
@@ -970,14 +973,13 @@ void S2Builder::SnapEdge(InputEdgeId e, vector<SiteId>* chain) const {
970973
return;
971974
}
972975

976+
S2Point const& x = input_vertices_[edge.first];
977+
S2Point const& y = input_vertices_[edge.second];
978+
973979
// Optimization: if there is only one nearby site, return.
974980
// Optimization: if there are exactly two nearby sites, and one is close
975981
// enough to each vertex, then return.
976982

977-
// Compute the edge normal.
978-
S2Point const& x = input_vertices_[edge.first];
979-
S2Point const& y = input_vertices_[edge.second];
980-
981983
// Now iterate through the sites. We keep track of the sequence of sites
982984
// that are visited.
983985
auto const& candidates = edge_sites_[e];
@@ -1052,9 +1054,7 @@ void S2Builder::SnapEdge(InputEdgeId e, vector<SiteId>* chain) const {
10521054
}
10531055
if (s2builder_verbose) {
10541056
std::cout << "(" << edge.first << "," << edge.second << "): ";
1055-
for (SiteId id : *chain) {
1056-
std::cout << id << " ";
1057-
}
1057+
for (SiteId id : *chain) std::cout << id << " ";
10581058
std::cout << std::endl;
10591059
}
10601060
}

src/s2/s2builderutil_layers_test.cc

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "s2/s2builderutil_snap_functions.h"
3030
#include "s2/s2debug.h"
3131
#include "s2/s2textformat.h"
32-
#include "s2/util/gtl/stl_util.h"
3332

3433
using absl::MakeUnique;
3534
using s2builderutil::IndexedS2PointVectorLayer;

src/s2/s2cell_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ static S1ChordAngle GetDistanceToEdgeBruteForce(
565565
S2Loop loop(cell);
566566
S2ShapeIndex index;
567567
index.Add(absl::MakeUnique<S2Loop::Shape>(&loop));
568-
S2CrossingEdgeQuery query(index);
568+
S2CrossingEdgeQuery query(&index);
569569
vector<int> edges;
570570
if (query.GetCrossings(a, b, index.shape(0), s2shapeutil::CrossingType::ALL,
571571
&edges)) {

0 commit comments

Comments
 (0)