Skip to content

Commit 57151fc

Browse files
S2 AuthorsTorreyHoffman
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 795216560
1 parent 4a6abc1 commit 57151fc

102 files changed

Lines changed: 10883 additions & 2290 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,36 @@ varying degrees of completeness and maturity. This Java implementation is
5757
heavily used within Google and is generally mature, aside from the newest
5858
features, but is not as complete as C++.
5959

60+
## 2025 Q3 Release Highlights
61+
62+
* S2Polygon operations have migrated from the old implementations to
63+
S2BooleanOperation, matching the C++ implementation. The old implementations
64+
are still available, as fragile tests or code may depend on their specific
65+
behaviors, but are deprecated and will eventually be removed.
66+
67+
* S2BufferOperation, S2WindingOperation, and supporting classes have been
68+
ported from C++.
69+
70+
* Bug fixes & correctness improvements in S2ContainPointQuery, S2EdgeUtil,
71+
S2Builder, and S2Predicates.
72+
73+
* Renamed S2EdgeQuery to S2CrossingEdgeQuery, matching the C++ implementation.
74+
75+
* Substantial reworking of S2DensityClusterQuery.
76+
77+
* Renamed S2Point.ORIGIN to S2Point.ZERO
78+
79+
* More migration from the internal "primitives" library to FastUtil.
80+
81+
* Many improvements, clarifications, and corrections to Javadoc.
82+
83+
* Migrated from com.google.common.base.Objects to java.util.Objects
84+
85+
* Internal migration from deprecated S2EdgeUtil.getClosestPoint() to
86+
project().
87+
88+
* S2EdgeUtil.getMinDistanceMaxError() renamed getUpdateMinDistanceMaxError().
89+
6090
## 2025 Q2 Release Highlights
6191

6292
Over 100 additional classes have been ported from C++, as well as more methods
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2025 Google Inc.
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+
*/
16+
package com.google.common.geometry.benchmarks;
17+
18+
import static com.google.common.geometry.TestDataGenerator.DEFAULT_LOOP_RADIUS;
19+
import static java.util.concurrent.TimeUnit.MICROSECONDS;
20+
import static java.util.concurrent.TimeUnit.SECONDS;
21+
22+
import com.google.common.geometry.S2ContainsVertexQuery;
23+
import com.google.common.geometry.S2Loop;
24+
import com.google.common.geometry.S2Point;
25+
import com.google.common.geometry.S2Polygon;
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
import org.openjdk.jmh.annotations.Benchmark;
29+
import org.openjdk.jmh.annotations.BenchmarkMode;
30+
import org.openjdk.jmh.annotations.Level;
31+
import org.openjdk.jmh.annotations.Measurement;
32+
import org.openjdk.jmh.annotations.Mode;
33+
import org.openjdk.jmh.annotations.OutputTimeUnit;
34+
import org.openjdk.jmh.annotations.Param;
35+
import org.openjdk.jmh.annotations.Scope;
36+
import org.openjdk.jmh.annotations.Setup;
37+
import org.openjdk.jmh.annotations.State;
38+
import org.openjdk.jmh.annotations.Warmup;
39+
40+
/**
41+
* A simple benchmark for S2ContainsVertexQuery.
42+
*/
43+
public class S2ContainsVertexQueryBenchmark {
44+
45+
private S2ContainsVertexQueryBenchmark() {}
46+
47+
/**
48+
* Benchmark state consisting of a polygon of many triangles, all around a common center point,
49+
* forming a fan or windmill shape.
50+
*/
51+
@State(Scope.Thread)
52+
@BenchmarkMode(Mode.AverageTime)
53+
@OutputTimeUnit(MICROSECONDS)
54+
@Warmup(iterations = 3, time = 5, timeUnit = SECONDS)
55+
@Measurement(iterations = 5, time = 5, timeUnit = SECONDS)
56+
public static class PolygonState extends S2BenchmarkBaseState {
57+
@Param({"4", "8", "64", "512", "4096", "32768"})
58+
int numTriangles;
59+
60+
private S2Polygon polygon;
61+
private S2Point center;
62+
63+
@Setup(Level.Trial)
64+
@Override
65+
public void setup() {
66+
super.setup();
67+
center = data.getRandomPoint();
68+
List<S2Point> regularVertices = S2Loop.makeRegularVertices(
69+
center, DEFAULT_LOOP_RADIUS, numTriangles * 2);
70+
71+
List<S2Loop> loops = new ArrayList<>();
72+
for (int tri = 0; tri < numTriangles; tri++) {
73+
List<S2Point> loopVertices = new ArrayList<>();
74+
loopVertices.add(center);
75+
loopVertices.add(regularVertices.get(tri * 2 + 0));
76+
loopVertices.add(regularVertices.get(tri * 2 + 1));
77+
loops.add(new S2Loop(loopVertices));
78+
}
79+
80+
polygon = new S2Polygon(loops);
81+
}
82+
83+
/**
84+
* Measures the average time to create an S2ContainsVertexQuery, add all the incoming and
85+
* outgoing edges of the polygon (w.r.t. the center point), and determine if the center point is
86+
* contained or not.
87+
*/
88+
@Benchmark
89+
public int query() {
90+
S2ContainsVertexQuery query = new S2ContainsVertexQuery(center);
91+
92+
for (S2Loop loop : polygon.getLoops()) {
93+
// Loop vertex 0 is the center point.
94+
query.addOutgoing(loop.vertex(1)); // The first loop edge is outgoing from the center.
95+
// The edge from vertex 1 to vertex 2 isn't incident on the center.
96+
query.addIncoming(loop.vertex(2)); // The third loop edge is incoming to the center.
97+
}
98+
99+
return query.containsSign();
100+
}
101+
}
102+
103+
104+
}

google3/javatests/com/google/common/geometry/primitives/IntVectorBenchmark.java renamed to benchmarks/src/com/google/common/geometry/primitives/IntVectorBenchmark.java

File renamed without changes.

google3/javatests/com/google/common/geometry/primitives/SequenceLexiconBenchmark.java renamed to benchmarks/src/com/google/common/geometry/primitives/SequenceLexiconBenchmark.java

File renamed without changes.

library/src/com/google/common/geometry/BigPoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package com.google.common.geometry;
1717

18-
import com.google.common.base.Objects;
1918
import java.math.BigDecimal;
19+
import java.util.Objects;
2020

2121
/** A point consisting of BigDecimal coordinates. */
2222
final class BigPoint implements Comparable<BigPoint> {
@@ -109,6 +109,6 @@ public boolean equals(Object that) {
109109

110110
@Override
111111
public int hashCode() {
112-
return Objects.hashCode(x, y, z);
112+
return Objects.hash(x, y, z);
113113
}
114114
}

0 commit comments

Comments
 (0)