|
| 1 | +# S2 Geometry Library |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This is a package for manipulating geometric shapes. Unlike many geometry |
| 6 | +libraries, S2 is primarily designed to work with _spherical geometry_, i.e., |
| 7 | +shapes drawn on a sphere rather than on a planar 2D map. This makes it |
| 8 | +especially suitable for working with geographic data. |
| 9 | + |
| 10 | +If you want to learn more about the library, start by reading the |
| 11 | +[overview](http://s2geometry.io/about/overview) and [quick start |
| 12 | +document](http://s2geometry.io/devguide/cpp/quickstart), then read the |
| 13 | +introduction to the [basic types](http://s2geometry.io/devguide/basic_types). |
| 14 | + |
| 15 | +S2 documentation can be found on [s2geometry.io](http://s2geometry.io). |
| 16 | + |
| 17 | +## Build and Install |
| 18 | + |
| 19 | +You may either download the source as a ZIP archive, or [clone the git |
| 20 | +repository](https://help.github.com/articles/cloning-a-repository/). |
| 21 | +The Java packages are built and tested using [Maven](https://maven.apache.org/). |
| 22 | + |
| 23 | +In the directory containing the ```pom.xml``` file, use Maven to |
| 24 | +compile the package, run tests, and install the package. For example: |
| 25 | + |
| 26 | +``` |
| 27 | +mvn clean |
| 28 | +mvn compile |
| 29 | +mvn test |
| 30 | +mvn package |
| 31 | +mvn install |
| 32 | +``` |
| 33 | + |
| 34 | +### Benchmarks |
| 35 | + |
| 36 | +After building packages, a "benchmarks.jar" file may be found in |
| 37 | +```benchmarks/target/```. Benchmarks can then be run with the command |
| 38 | +```java -jar benchmarks/target/benchmarks.jar``` |
| 39 | +Parameters for the benchmarks can be passed on the command line. For example, to |
| 40 | +run just the S2Loop benchmarks, |
| 41 | +```java -jar benchmarks/target/benchmarks.jar S2Loop``` |
| 42 | + |
| 43 | +## S2 implementations |
| 44 | + |
| 45 | +The S2 library has implementations in several languages. In addition to this |
| 46 | +Java implementation, Google provides: |
| 47 | + |
| 48 | +* [C++](https://github.com/google/s2geometry) (The reference implementation |
| 49 | + and the most full featured). |
| 50 | +* [Go](https://github.com/golang/geo) (Approximately 40% complete.) |
| 51 | +* [Python](https://github.com/google/s2geometry/tree/master/src/python) |
| 52 | + |
| 53 | +We (the S2 developers) aim to provide similar classes and APIs across all |
| 54 | +implementations, while adapting to language idioms where that makes sense, and |
| 55 | +changing APIs where required for good performance. The implementations have |
| 56 | +varying degrees of completeness and maturity. This Java implementation is |
| 57 | +heavily used within Google and is generally mature, aside from the newest |
| 58 | +features, but is not as complete as C++. |
| 59 | + |
| 60 | +## 2022 Q4 Release Highlights |
| 61 | + |
| 62 | +Many improvements have been made to the Java implementation of S2 since the last |
| 63 | +release in September 2021. Some highlights: |
| 64 | + |
| 65 | +* Implementations of S2ClosestEdgeQuery and S2FurthestEdgeQuery, as well as |
| 66 | + S2ChainInterpolationQuery and S2HausdorffDistanceQuery. |
| 67 | + |
| 68 | +* New tools for clustering and sharding data: S2RegionSharder and |
| 69 | + S2DensityTree. |
| 70 | + |
| 71 | +* Support for map projections in MercatorProjection, PlateCarreeProjection, |
| 72 | + and S2EdgeTesselator. |
| 73 | + |
| 74 | +* S2Coder implementations are now complete and should be interoperable |
| 75 | + between Go, C++ and Java. |
| 76 | + |
| 77 | +* New Java implementation benchmarks based on JMH, the [Java Microbenchmark |
| 78 | + Harness](https://github.com/openjdk/jmh). |
| 79 | + |
| 80 | +* Addition of S2IndexingHelper, which supports spatial indexing of regions |
| 81 | + in documents and finding document regions that intersect a query region. |
| 82 | + |
| 83 | +* Many new methods on existing classes adding features which had formerly been |
| 84 | + missing in Java compared to the C++ implementation. |
| 85 | + |
| 86 | +* Many Javadoc and other comment improvements. |
| 87 | + |
| 88 | +* Many implementation cleanups. Most should not cause visible changes, but |
| 89 | + there were some bug fixes for improved accuracy. |
| 90 | + |
| 91 | +* @CheckReturnValue is a package-wide default now, set in the newly added |
| 92 | + "package-info.java". |
| 93 | + |
| 94 | +* The "testdatagenerator" subpackage supports generation of test data for both |
| 95 | + benchmarks and unit tests. Note that the APIs in this package are not |
| 96 | + part of the external S2 API and are subject to change without notice. |
| 97 | + |
| 98 | +### Breaking API changes: |
| 99 | + |
| 100 | +* We are now using Java 11, updating from Java 8, and beginning to use Java |
| 101 | + 11 language features. |
| 102 | + |
| 103 | +* Class Matrix3x3 was renamed Matrix. |
| 104 | + |
| 105 | +* S2.simpleCrossing(a, b, c, d) has been removed as redundant; S2EdgeUtil |
| 106 | + provides the same API along with robustCrossing() and the EdgeCrosser class. |
| 107 | + |
| 108 | +* A bug fix for EdgeCrosser.robustCrossing() may break clients that were |
| 109 | + relying on robustCrossing() to detect both repeated vertices in polylines |
| 110 | + and self-intersecting polylines. Specifically, for degenerate edges that |
| 111 | + don't have shared endpoints, robustCrossing now returns -1 to indicate "No |
| 112 | + Crossing" while previously it would return 0. Now, a return value of 0 is |
| 113 | + used only to indicate that two points from different edges are the same, |
| 114 | + i.e. edges touch. This now behaves exactly like the equivalent |
| 115 | + CrossingSign() in C++ for degenerate edges. |
| 116 | + |
| 117 | +* Removed S2CellId.toTokenOld(). |
| 118 | + |
| 119 | +* The nested class RangeIterator was moved from S2ShapeIndex to S2ShapeUtil. |
| 120 | + |
| 121 | +* The nested classes AreaMeasure, CentroidMeasure, and AreaCentroidMeasure |
| 122 | + were removed as they were redundant. Instead, use the methods in |
| 123 | + S2ShapeMeasures to compute centroids and areas for S2Shapes. |
| 124 | + |
| 125 | +* Support for GWT has been removed. Support for J2CL is in progress but |
| 126 | + incomplete. The JS API is not final. |
| 127 | + |
| 128 | +## Disclaimer |
| 129 | + |
| 130 | +This is not an official Google product. |
0 commit comments