Skip to content

Commit 29de3e1

Browse files
authored
Merge pull request golang#112 from jmr/update-2025-03-17
Export latest google3 version
2 parents 6adc566 + 029bad8 commit 29de3e1

Some content is hidden

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

49 files changed

+1286
-785
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/golang/geo
22

3-
go 1.18
3+
go 1.21
4+
5+
require github.com/google/go-cmp v0.7.0 // indirect

s1/chordangle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// There are several different ways to measure this error, including the
3030
// representational error (i.e., how accurately ChordAngle can represent
3131
// angles near π radians), the conversion error (i.e., how much precision is
32-
// lost when an Angle is converted to an ChordAngle), and the measurement
32+
// lost when an Angle is converted to a ChordAngle), and the measurement
3333
// error (i.e., how accurate the ChordAngle(a, b) constructor is when the
3434
// points A and B are separated by angles close to π radians). All of these
3535
// errors differ by a small constant factor.

s2/builder_snapper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (sf CellIDSnapper) minSnapRadiusForLevel(level int) s1.Angle {
231231
// snapRadius needs to be an upper bound on the true distance that a
232232
// point can move when snapped, taking into account numerical errors.
233233
//
234-
// The maximum error when converting from an Point to a CellID is
234+
// The maximum error when converting from a Point to a CellID is
235235
// MaxDiagMetric.Deriv * dblEpsilon. The maximum error when converting a
236236
// CellID center back to a Point is 1.5 * dblEpsilon. These add up to
237237
// just slightly less than 4 * dblEpsilon.
@@ -248,7 +248,7 @@ func (sf CellIDSnapper) minSnapRadiusForLevel(level int) s1.Angle {
248248
//
249249
// sf := CellIDSnapperForLevel(f.levelForMaxSnapRadius(distance));
250250
func (sf CellIDSnapper) levelForMaxSnapRadius(snapRadius s1.Angle) int {
251-
// When choosing a level, we need to acount for the error bound of
251+
// When choosing a level, we need to account for the error bound of
252252
// 4 * dblEpsilon that is added by MinSnapRadiusForLevel.
253253
return MaxDiagMetric.MinLevel(2 * (snapRadius.Radians() - 4*dblEpsilon))
254254
}
@@ -310,7 +310,7 @@ func (sf CellIDSnapper) MinEdgeVertexSeparation() s1.Angle {
310310
// (b) Otherwise, for arbitrary snap radii the worst-case configuration
311311
// in the plane has an edge-vertex separation of sqrt(3/19) *
312312
// MinDiagMetric.Value(level), where sqrt(3/19) is about 0.3973597071. The unit
313-
// test verifies that the bound is slighty better on the sphere:
313+
// test verifies that the bound is slightly better on the sphere:
314314
// 0.3973595687 * MinDiagMetric.Value(level).
315315
//
316316
// 2. Proportional bound: In the plane, the worst-case configuration has an
@@ -434,7 +434,7 @@ func (sf IntLatLngSnapper) minSnapRadiusForExponent(exponent int) s1.Angle {
434434
// exponent for snapping. The return value is always a valid exponent (out of
435435
// range values are silently clamped).
436436
func (sf IntLatLngSnapper) exponentForMaxSnapRadius(snapRadius s1.Angle) int {
437-
// When choosing an exponent, we need to acount for the error bound of
437+
// When choosing an exponent, we need to account for the error bound of
438438
// (9 * sqrt(2) + 1.5) * dblEpsilon added by minSnapRadiusForExponent.
439439
snapRadius -= (9*math.Sqrt2 + 1.5) * dblEpsilon
440440
snapRadius = s1.Angle(math.Max(float64(snapRadius), 1e-30))

s2/cap_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ var (
3535
fullHeight = 2.0
3636
emptyHeight = -1.0
3737

38-
xAxisPt = Point{r3.Vector{1, 0, 0}}
39-
yAxisPt = Point{r3.Vector{0, 1, 0}}
38+
xAxisPt = Point{r3.Vector{X: 1, Y: 0, Z: 0}}
39+
yAxisPt = Point{r3.Vector{X: 0, Y: 1, Z: 0}}
4040

4141
xAxis = CapFromPoint(xAxisPt)
4242
yAxis = CapFromPoint(yAxisPt)
@@ -157,14 +157,14 @@ func TestCapContains(t *testing.T) {
157157
}
158158

159159
func TestCapContainsPoint(t *testing.T) {
160-
tangent := tiny.center.Cross(r3.Vector{3, 2, 1}).Normalize()
160+
tangent := tiny.center.Cross(r3.Vector{X: 3, Y: 2, Z: 1}).Normalize()
161161
tests := []struct {
162162
c Cap
163163
p Point
164164
want bool
165165
}{
166166
{xAxis, xAxisPt, true},
167-
{xAxis, Point{r3.Vector{1, 1e-20, 0}}, false},
167+
{xAxis, Point{r3.Vector{X: 1, Y: 1e-20, Z: 0}}, false},
168168
{yAxis, xAxis.center, false},
169169
{xComp, xAxis.center, true},
170170
{xComp.Complement(), xAxis.center, false},
@@ -208,9 +208,9 @@ func TestCapInteriorIntersects(t *testing.T) {
208208
}
209209

210210
func TestCapInteriorContains(t *testing.T) {
211-
if hemi.InteriorContainsPoint(Point{r3.Vector{1, 0, -(1 + epsilon)}}) {
211+
if hemi.InteriorContainsPoint(Point{r3.Vector{X: 1, Y: 0, Z: -(1 + epsilon)}}) {
212212
t.Errorf("hemi (%v) should not contain point just past half way(%v)", hemi,
213-
Point{r3.Vector{1, 0, -(1 + epsilon)}})
213+
Point{r3.Vector{X: 1, Y: 0, Z: -(1 + epsilon)}})
214214
}
215215
}
216216

@@ -316,7 +316,7 @@ func TestCapRectBounds(t *testing.T) {
316316
},
317317
{
318318
"The eastern hemisphere.",
319-
CapFromCenterAngle(Point{r3.Vector{0, 1, 0}}, s1.Radian*(math.Pi/2+2e-16)),
319+
CapFromCenterAngle(Point{r3.Vector{X: 0, Y: 1, Z: 0}}, s1.Radian*(math.Pi/2+2e-16)),
320320
-90, 90, -180, 180, true,
321321
},
322322
{
@@ -376,34 +376,34 @@ func TestCapAddPoint(t *testing.T) {
376376
{yAxis, yAxisPt, yAxis},
377377

378378
// Cap plus opposite point equals full.
379-
{xAxis, Point{r3.Vector{-1, 0, 0}}, fullCap},
380-
{yAxis, Point{r3.Vector{0, -1, 0}}, fullCap},
379+
{xAxis, Point{r3.Vector{X: -1, Y: 0, Z: 0}}, fullCap},
380+
{yAxis, Point{r3.Vector{X: 0, Y: -1, Z: 0}}, fullCap},
381381

382382
// Cap plus orthogonal axis equals half cap.
383-
{xAxis, Point{r3.Vector{0, 0, 1}}, CapFromCenterAngle(xAxisPt, s1.Angle(math.Pi/2.0))},
384-
{xAxis, Point{r3.Vector{0, 0, -1}}, CapFromCenterAngle(xAxisPt, s1.Angle(math.Pi/2.0))},
383+
{xAxis, Point{r3.Vector{X: 0, Y: 0, Z: 1}}, CapFromCenterAngle(xAxisPt, s1.Angle(math.Pi/2.0))},
384+
{xAxis, Point{r3.Vector{X: 0, Y: 0, Z: -1}}, CapFromCenterAngle(xAxisPt, s1.Angle(math.Pi/2.0))},
385385

386386
// The 45 degree angled hemisphere plus some points.
387387
{
388388
hemi,
389389
PointFromCoords(0, 1, -1),
390-
CapFromCenterAngle(Point{r3.Vector{1, 0, 1}},
390+
CapFromCenterAngle(Point{r3.Vector{X: 1, Y: 0, Z: 1}},
391391
s1.Angle(120.0)*s1.Degree),
392392
},
393393
{
394394
hemi,
395395
PointFromCoords(0, -1, -1),
396-
CapFromCenterAngle(Point{r3.Vector{1, 0, 1}},
396+
CapFromCenterAngle(Point{r3.Vector{X: 1, Y: 0, Z: 1}},
397397
s1.Angle(120.0)*s1.Degree),
398398
},
399399
{
400400
hemi,
401401
PointFromCoords(-1, -1, -1),
402-
CapFromCenterAngle(Point{r3.Vector{1, 0, 1}},
402+
CapFromCenterAngle(Point{r3.Vector{X: 1, Y: 0, Z: 1}},
403403
s1.Angle(math.Acos(-math.Sqrt(2.0/3.0)))),
404404
},
405-
{hemi, Point{r3.Vector{0, 1, 1}}, hemi},
406-
{hemi, Point{r3.Vector{1, 0, 0}}, hemi},
405+
{hemi, Point{r3.Vector{X: 0, Y: 1, Z: 1}}, hemi},
406+
{hemi, Point{r3.Vector{X: 1, Y: 0, Z: 0}}, hemi},
407407
}
408408

409409
for _, test := range tests {
@@ -684,8 +684,8 @@ func TestCapUnion(t *testing.T) {
684684
t.Errorf("%v.Radius = %v, want %v", aUnionE, got, want)
685685
}
686686

687-
p1 := Point{r3.Vector{0, 0, 1}}
688-
p2 := Point{r3.Vector{0, 1, 0}}
687+
p1 := Point{r3.Vector{X: 0, Y: 0, Z: 1}}
688+
p2 := Point{r3.Vector{X: 0, Y: 1, Z: 0}}
689689
// Two very large caps, whose radius sums to in excess of 180 degrees, and
690690
// whose centers are not antipodal.
691691
f := CapFromCenterAngle(p1, s1.Degree*150)

s2/cell.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,17 @@ func (c Cell) RectBound() Rect {
337337
var bound Rect
338338
switch c.face {
339339
case 0:
340-
bound = Rect{r1.Interval{-math.Pi / 4, math.Pi / 4}, s1.Interval{-math.Pi / 4, math.Pi / 4}}
340+
bound = Rect{r1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}, s1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}}
341341
case 1:
342-
bound = Rect{r1.Interval{-math.Pi / 4, math.Pi / 4}, s1.Interval{math.Pi / 4, 3 * math.Pi / 4}}
342+
bound = Rect{r1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}, s1.Interval{Lo: math.Pi / 4, Hi: 3 * math.Pi / 4}}
343343
case 2:
344-
bound = Rect{r1.Interval{poleMinLat, math.Pi / 2}, s1.FullInterval()}
344+
bound = Rect{r1.Interval{Lo: poleMinLat, Hi: math.Pi / 2}, s1.FullInterval()}
345345
case 3:
346-
bound = Rect{r1.Interval{-math.Pi / 4, math.Pi / 4}, s1.Interval{3 * math.Pi / 4, -3 * math.Pi / 4}}
346+
bound = Rect{r1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}, s1.Interval{Lo: 3 * math.Pi / 4, Hi: -3 * math.Pi / 4}}
347347
case 4:
348-
bound = Rect{r1.Interval{-math.Pi / 4, math.Pi / 4}, s1.Interval{-3 * math.Pi / 4, -math.Pi / 4}}
348+
bound = Rect{r1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}, s1.Interval{Lo: -3 * math.Pi / 4, Hi: -math.Pi / 4}}
349349
default:
350-
bound = Rect{r1.Interval{-math.Pi / 2, -poleMinLat}, s1.FullInterval()}
350+
bound = Rect{r1.Interval{Lo: -math.Pi / 2, Hi: -poleMinLat}, s1.FullInterval()}
351351
}
352352

353353
// Finally, we expand the bound to account for the error when a point P is
@@ -456,8 +456,8 @@ func (c Cell) uEdgeIsClosest(p Point, vHi bool) bool {
456456
}
457457
// These are the normals to the planes that are perpendicular to the edge
458458
// and pass through one of its two endpoints.
459-
dir0 := r3.Vector{v*v + 1, -u0 * v, -u0}
460-
dir1 := r3.Vector{v*v + 1, -u1 * v, -u1}
459+
dir0 := r3.Vector{X: v*v + 1, Y: -u0 * v, Z: -u0}
460+
dir1 := r3.Vector{X: v*v + 1, Y: -u1 * v, Z: -u1}
461461
return p.Dot(dir0) > 0 && p.Dot(dir1) < 0
462462
}
463463

@@ -470,8 +470,8 @@ func (c Cell) vEdgeIsClosest(p Point, uHi bool) bool {
470470
if uHi {
471471
u = c.uv.X.Hi
472472
}
473-
dir0 := r3.Vector{-u * v0, u*u + 1, -v0}
474-
dir1 := r3.Vector{-u * v1, u*u + 1, -v1}
473+
dir0 := r3.Vector{X: -u * v0, Y: u*u + 1, Z: -v0}
474+
dir1 := r3.Vector{X: -u * v1, Y: u*u + 1, Z: -v1}
475475
return p.Dot(dir0) > 0 && p.Dot(dir1) < 0
476476
}
477477

@@ -682,7 +682,7 @@ func (c Cell) MaxDistanceToCell(target Cell) s1.ChordAngle {
682682
// Need to check the antipodal target for intersection with the cell. If it
683683
// intersects, the distance is the straight ChordAngle.
684684
// antipodalUV is the transpose of the original UV, interpreted within the opposite face.
685-
antipodalUV := r2.Rect{target.uv.Y, target.uv.X}
685+
antipodalUV := r2.Rect{X: target.uv.Y, Y: target.uv.X}
686686
if int(c.face) == oppositeFace(int(target.face)) && c.uv.Intersects(antipodalUV) {
687687
return s1.StraightChordAngle
688688
}

s2/cell_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ func testCellChildren(t *testing.T, cell Cell) {
236236
// where the cell size at a given level is maximal.
237237
maxSizeUV := 0.3964182625366691
238238
specialUV := []r2.Point{
239-
{dblEpsilon, dblEpsilon}, // Face center
240-
{dblEpsilon, 1}, // Edge midpoint
241-
{1, 1}, // Face corner
242-
{maxSizeUV, maxSizeUV}, // Largest cell area
243-
{dblEpsilon, maxSizeUV}, // Longest edge/diagonal
239+
{X: dblEpsilon, Y: dblEpsilon}, // Face center
240+
{X: dblEpsilon, Y: 1}, // Edge midpoint
241+
{X: 1, Y: 1}, // Face corner
242+
{X: maxSizeUV, Y: maxSizeUV}, // Largest cell area
243+
{X: dblEpsilon, Y: maxSizeUV}, // Longest edge/diagonal
244244
}
245245
forceSubdivide := false
246246
for _, uv := range specialUV {

s2/cellid.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ func stToIJ(s float64) int {
650650
//
651651
// is always true.
652652
func cellIDFromPoint(p Point) CellID {
653-
f, u, v := xyzToFaceUV(r3.Vector{p.X, p.Y, p.Z})
653+
f, u, v := xyzToFaceUV(r3.Vector{X: p.X, Y: p.Y, Z: p.Z})
654654
i := stToIJ(uvToST(u))
655655
j := stToIJ(uvToST(v))
656656
return cellIDFromFaceIJ(f, i, j)
@@ -788,7 +788,7 @@ func (ci CellID) Advance(steps int64) CellID {
788788
// centerST return the center of the CellID in (s,t)-space.
789789
func (ci CellID) centerST() r2.Point {
790790
_, si, ti := ci.faceSiTi()
791-
return r2.Point{siTiToST(si), siTiToST(ti)}
791+
return r2.Point{X: siTiToST(si), Y: siTiToST(ti)}
792792
}
793793

794794
// sizeST returns the edge length of this CellID in (s,t)-space at the given level.
@@ -799,7 +799,7 @@ func (ci CellID) sizeST(level int) float64 {
799799
// boundST returns the bound of this CellID in (s,t)-space.
800800
func (ci CellID) boundST() r2.Rect {
801801
s := ci.sizeST(ci.Level())
802-
return r2.RectFromCenterSize(ci.centerST(), r2.Point{s, s})
802+
return r2.RectFromCenterSize(ci.centerST(), r2.Point{X: s, Y: s})
803803
}
804804

805805
// centerUV returns the center of this CellID in (u,v)-space. Note that
@@ -808,7 +808,7 @@ func (ci CellID) boundST() r2.Rect {
808808
// the (u,v) rectangle covered by the cell.
809809
func (ci CellID) centerUV() r2.Point {
810810
_, si, ti := ci.faceSiTi()
811-
return r2.Point{stToUV(siTiToST(si)), stToUV(siTiToST(ti))}
811+
return r2.Point{X: stToUV(siTiToST(si)), Y: stToUV(siTiToST(ti))}
812812
}
813813

814814
// boundUV returns the bound of this CellID in (u,v)-space.
@@ -837,7 +837,7 @@ func expandEndpoint(u, maxV, sinDist float64) float64 {
837837
// of the boundary.
838838
//
839839
// Distances are measured *on the sphere*, not in (u,v)-space. For example,
840-
// you can use this method to expand the (u,v)-bound of an CellID so that
840+
// you can use this method to expand the (u,v)-bound of a CellID so that
841841
// it contains all points within 5km of the original cell. You can then
842842
// test whether a point lies within the expanded bounds like this:
843843
//
@@ -862,10 +862,10 @@ func expandedByDistanceUV(uv r2.Rect, distance s1.Angle) r2.Rect {
862862
maxV := math.Max(math.Abs(uv.Y.Lo), math.Abs(uv.Y.Hi))
863863
sinDist := math.Sin(float64(distance))
864864
return r2.Rect{
865-
X: r1.Interval{expandEndpoint(uv.X.Lo, maxV, -sinDist),
866-
expandEndpoint(uv.X.Hi, maxV, sinDist)},
867-
Y: r1.Interval{expandEndpoint(uv.Y.Lo, maxU, -sinDist),
868-
expandEndpoint(uv.Y.Hi, maxU, sinDist)}}
865+
X: r1.Interval{Lo: expandEndpoint(uv.X.Lo, maxV, -sinDist),
866+
Hi: expandEndpoint(uv.X.Hi, maxV, sinDist)},
867+
Y: r1.Interval{Lo: expandEndpoint(uv.Y.Lo, maxU, -sinDist),
868+
Hi: expandEndpoint(uv.Y.Hi, maxU, sinDist)}}
869869
}
870870

871871
// MaxTile returns the largest cell with the same RangeMin such that

0 commit comments

Comments
 (0)