Skip to content

Commit c83fcf8

Browse files
committed
Import new google3 version.
* Fix python. * Update docs. * Add s2region_term_indexer.
1 parent c84fc2a commit c83fcf8

33 files changed

+3993
-223
lines changed

CMakeLists.txt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ add_library(s2 SHARED
8282
src/s2/s2projections.cc
8383
src/s2/s2r2rect.cc
8484
src/s2/s2region.cc
85+
src/s2/s2region_term_indexer.cc
8586
src/s2/s2regioncoverer.cc
8687
src/s2/s2regionintersection.cc
8788
src/s2/s2regionunion.cc
@@ -102,6 +103,8 @@ add_library(s2 SHARED
102103
src/s2/third_party/absl/numeric/int128.cc
103104
src/s2/third_party/absl/strings/ascii.cc
104105
src/s2/third_party/absl/strings/match.cc
106+
src/s2/third_party/absl/strings/numbers.cc
107+
src/s2/third_party/absl/strings/str_cat.cc
105108
src/s2/third_party/absl/strings/str_split.cc
106109
src/s2/third_party/absl/strings/string_view.cc
107110
src/s2/third_party/absl/strings/string_view_utils.cc
@@ -190,6 +193,7 @@ install(FILES src/s2/_fpcontractoff.h
190193
src/s2/s2projections.h
191194
src/s2/s2r2rect.h
192195
src/s2/s2region.h
196+
src/s2/s2region_term_indexer.h
193197
src/s2/s2regioncoverer.h
194198
src/s2/s2regionintersection.h
195199
src/s2/s2regionunion.h
@@ -240,6 +244,7 @@ install(FILES src/s2/third_party/absl/meta/type_traits.h
240244
DESTINATION include/s2/third_party/absl/meta)
241245
install(FILES src/s2/third_party/absl/numeric/int128.h
242246
src/s2/third_party/absl/numeric/int128_have_intrinsic.inc
247+
src/s2/third_party/absl/numeric/int128_no_intrinsic.inc
243248
DESTINATION include/s2/third_party/absl/numeric)
244249
install(FILES src/s2/third_party/absl/strings/string_view.h
245250
DESTINATION include/s2/third_party/absl/strings)
@@ -347,6 +352,7 @@ if (GTEST_ROOT)
347352
src/s2/s2projections_test.cc
348353
src/s2/s2r2rect_test.cc
349354
src/s2/s2region_test.cc
355+
src/s2/s2region_term_indexer_test.cc
350356
src/s2/s2regioncoverer_test.cc
351357
src/s2/s2regionunion_test.cc
352358
src/s2/s2shapeindex_buffered_region_test.cc
@@ -375,17 +381,8 @@ if (GTEST_ROOT)
375381
endforeach()
376382
endif()
377383

384+
add_subdirectory("doc/examples" examples)
385+
378386
if (${SWIG_FOUND} AND ${PYTHONLIBS_FOUND})
379-
include(${SWIG_USE_FILE})
380-
include_directories(${PYTHON_INCLUDE_PATH})
381-
set(CMAKE_SWIG_FLAGS "")
382-
set_property(SOURCE src/s2/s2.i PROPERTY SWIG_FLAGS "-module" "pywraps2")
383-
set_property(SOURCE src/s2/s2.i PROPERTY CPLUSPLUS ON)
384-
swig_add_module(pywraps2 python src/s2/s2.i)
385-
swig_link_libraries(pywraps2 ${PYTHON_LIBRARIES} s2)
386-
enable_testing()
387-
add_test(NAME pywraps2_test COMMAND
388-
${PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/src/s2/pywraps2_test.py")
389-
set_property(TEST pywraps2_test PROPERTY ENVIRONMENT
390-
"PYTHONPATH=$ENV{PYTHONPATH}:${PROJECT_BINARY_DIR}")
387+
add_subdirectory("src/python" python)
391388
endif()

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,22 @@ Requirements for End Users
2424
(to build tests, optional)
2525
* A POSIX system (for getrusage).
2626

27-
On Ubuntu, all of these can be installed via apt-get. Otherwise, you may need
28-
to install some from source.
27+
On Ubuntu, all of these can be installed via apt-get:
28+
```
29+
sudo apt-get install cmake libgflags-dev libgoogle-glog-dev libgtest-dev openssl
30+
```
31+
Otherwise, you may need to install some from source. On OS X, use
32+
[MacPorts](http://www.macports.org/) or [Homebrew](http://brew.sh/).
2933

3034
Thorough testing has only been done on Ubuntu 14.04.3.
3135

3236
Build and Install
3337
-----------------
3438

3539
```
36-
cd $S2_DIR
40+
mkdir s2-geometry-library
41+
cd s2-geometry-library
42+
tar zxvf $PATH_TO_DOWNLOADED_TGZ
3743
mkdir build
3844
cd build
3945
cmake -DGTEST_ROOT=/usr/src/gtest .. # Omit -DGTEST_ROOT to skip tests.

doc/basic_types.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ operators.
168168
## S2Region
169169
170170
An `S2Region` represents a two-dimensional region over the unit sphere. It is an
171-
abstract interface with various concrete subtypes.
171+
abstract interface with various concrete subtypes, such as discs, rectangles,
172+
polylines, polygons, geometry collections, buffered shapes, etc.
172173
173174
The main purpose of this interface is to allow complex regions to be
174175
approximated as simpler regions. So rather than having a wide variety of virtual
@@ -207,12 +208,17 @@ class S2Region {
207208
// subtypes may relax this restriction.
208209
virtual bool Contains(const S2Point& p) const = 0;
209210
210-
// Use encoder to generate a serialized representation of this region.
211-
virtual void Encode(Encoder* const encoder) const = 0;
211+
//////////////////////////////////////////////////////////////////////////
212+
// Many S2Region subtypes also define the following non-virtual methods.
212213
213-
// Reconstruct a region from the serialized representation generated by
214-
// Encode().
215-
virtual bool Decode(Decoder* const decoder) = 0;
214+
// Appends a serialized representation of the region to "encoder".
215+
void Encode(Encoder* const encoder) const;
216+
217+
// Decodes an S2Region encoded with Encode(). Note that this method
218+
// requires that an S2Region object of the appropriate concrete type has
219+
// already been constructed. It is not possible to decode regions of
220+
// unknown type.
221+
bool Decode(Decoder* const decoder);
216222
};
217223
```
218224

@@ -431,7 +437,7 @@ exact predicates needed for robust geometric algorithms. `S1ChordAngle`
431437
supports many of the same methods as `S1Angle`, and it is also easy to
432438
convert back and forth as required.
433439
434-
## S2Cap ("S2Disc")
440+
## S2Cap
435441
436442
An `S2Cap` represents a spherical cap, i.e. a portion of a sphere cut off by a
437443
plane. This is the equivalent of a *closed disc* in planar geometry (i.e., a

doc/coverer/coverer.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ with a 5 km radius cap. When you try to cover that cap with just one
1212
cell, you often end up with a large amount of extra space. Notice the
1313
large cell compared to the circle.
1414

15-
![](kirkland_1.gif)\
15+
![](kirkland_1.gif)
1616

1717
Same configuration, except we allow the use of 2 cells.
1818

@@ -58,7 +58,7 @@ cap size of about 500 km and limit of 4 cells. The ratio of "area
5858
covered by the cells" to "area covered by the cap" is about 10, which is
5959
about the worst case value when you have at least 4 cells. (The ratio
6060
can be quite large, on the order of 10\^15, if you limit the covering to
61-
fewer than 4 cells.)\
61+
fewer than 4 cells.)
6262

6363
![](edge_4.gif)
6464

@@ -135,3 +135,16 @@ date line.
135135
Same configuration, except we allow the use of 500 cells.
136136

137137
![](polar_500.gif)
138+
139+
Finally, here are some examples of geographic coverings. This is a covering of
140+
Hawaii using 25 cells.
141+
142+
![](hawaii.gif)
143+
144+
Here is a covering of Florida using 22 cells.
145+
146+
![](florida1.gif)
147+
148+
And Florida using 152 cells.
149+
150+
![](florida2.gif)

doc/coverer/edge_4.gif

-200 KB
Loading

doc/coverer/florida1.gif

31.4 KB
Loading

doc/coverer/florida2.gif

31.6 KB
Loading

doc/coverer/hawaii.gif

9.91 KB
Loading

doc/examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_executable(point_index point_index.cc)
2+
target_link_libraries(point_index LINK_PUBLIC s2testing s2)
3+
add_executable(term_index term_index.cc)
4+
target_link_libraries(term_index LINK_PUBLIC s2testing s2)

doc/examples/point_index.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2017 Google Inc. All Rights Reserved.
2+
// Author: [email protected] (Eric Veach)
3+
//
4+
// This example shows how to build and query an in-memory index of points
5+
// using S2PointIndex.
6+
7+
#include <cstdio>
8+
#include <gflags/gflags.h>
9+
#include "s2/s2earth.h"
10+
#include "s2/s1chordangle.h"
11+
#include "s2/s2closestpointquery.h"
12+
#include "s2/s2pointindex.h"
13+
#include "s2/s2testing.h"
14+
15+
DEFINE_int32(num_index_points, 10000, "Number of points to index");
16+
DEFINE_int32(num_queries, 10000, "Number of queries");
17+
DEFINE_double(query_radius_km, 100, "Query radius in kilometers");
18+
19+
int main(int argc, char **argv) {
20+
// Build an index containing random points anywhere on the Earth.
21+
S2PointIndex<int> index;
22+
for (int i = 0; i < FLAGS_num_index_points; ++i) {
23+
index.Add(S2Testing::RandomPoint(), i);
24+
}
25+
26+
// Create a query to search within the given radius of a target point.
27+
S2ClosestPointQuery<int> query(&index);
28+
query.mutable_options()->set_max_distance(
29+
S1Angle::Radians(S2Earth::KmToRadians(FLAGS_query_radius_km)));
30+
31+
// Repeatedly choose a random target point, and count how many index points
32+
// are within the given radius of that point.
33+
int64 num_found = 0;
34+
for (int i = 0; i < FLAGS_num_queries; ++i) {
35+
S2ClosestPointQuery<int>::PointTarget target(S2Testing::RandomPoint());
36+
num_found += query.FindClosestPoints(&target).size();
37+
}
38+
39+
std::printf("Found %lld points in %d queries\n",
40+
num_found, FLAGS_num_queries);
41+
return 0;
42+
}

0 commit comments

Comments
 (0)