Skip to content

Export latest google3 version #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/golang/geo

go 1.18
go 1.21

require github.com/google/go-cmp v0.7.0 // indirect
2 changes: 1 addition & 1 deletion s1/chordangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// There are several different ways to measure this error, including the
// representational error (i.e., how accurately ChordAngle can represent
// angles near π radians), the conversion error (i.e., how much precision is
// lost when an Angle is converted to an ChordAngle), and the measurement
// lost when an Angle is converted to a ChordAngle), and the measurement
// error (i.e., how accurate the ChordAngle(a, b) constructor is when the
// points A and B are separated by angles close to π radians). All of these
// errors differ by a small constant factor.
Expand Down
8 changes: 4 additions & 4 deletions s2/builder_snapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (sf CellIDSnapper) minSnapRadiusForLevel(level int) s1.Angle {
// snapRadius needs to be an upper bound on the true distance that a
// point can move when snapped, taking into account numerical errors.
//
// The maximum error when converting from an Point to a CellID is
// The maximum error when converting from a Point to a CellID is
// MaxDiagMetric.Deriv * dblEpsilon. The maximum error when converting a
// CellID center back to a Point is 1.5 * dblEpsilon. These add up to
// just slightly less than 4 * dblEpsilon.
Expand All @@ -248,7 +248,7 @@ func (sf CellIDSnapper) minSnapRadiusForLevel(level int) s1.Angle {
//
// sf := CellIDSnapperForLevel(f.levelForMaxSnapRadius(distance));
func (sf CellIDSnapper) levelForMaxSnapRadius(snapRadius s1.Angle) int {
// When choosing a level, we need to acount for the error bound of
// When choosing a level, we need to account for the error bound of
// 4 * dblEpsilon that is added by MinSnapRadiusForLevel.
return MaxDiagMetric.MinLevel(2 * (snapRadius.Radians() - 4*dblEpsilon))
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func (sf CellIDSnapper) MinEdgeVertexSeparation() s1.Angle {
// (b) Otherwise, for arbitrary snap radii the worst-case configuration
// in the plane has an edge-vertex separation of sqrt(3/19) *
// MinDiagMetric.Value(level), where sqrt(3/19) is about 0.3973597071. The unit
// test verifies that the bound is slighty better on the sphere:
// test verifies that the bound is slightly better on the sphere:
// 0.3973595687 * MinDiagMetric.Value(level).
//
// 2. Proportional bound: In the plane, the worst-case configuration has an
Expand Down Expand Up @@ -434,7 +434,7 @@ func (sf IntLatLngSnapper) minSnapRadiusForExponent(exponent int) s1.Angle {
// exponent for snapping. The return value is always a valid exponent (out of
// range values are silently clamped).
func (sf IntLatLngSnapper) exponentForMaxSnapRadius(snapRadius s1.Angle) int {
// When choosing an exponent, we need to acount for the error bound of
// When choosing an exponent, we need to account for the error bound of
// (9 * sqrt(2) + 1.5) * dblEpsilon added by minSnapRadiusForExponent.
snapRadius -= (9*math.Sqrt2 + 1.5) * dblEpsilon
snapRadius = s1.Angle(math.Max(float64(snapRadius), 1e-30))
Expand Down
36 changes: 18 additions & 18 deletions s2/cap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ var (
fullHeight = 2.0
emptyHeight = -1.0

xAxisPt = Point{r3.Vector{1, 0, 0}}
yAxisPt = Point{r3.Vector{0, 1, 0}}
xAxisPt = Point{r3.Vector{X: 1, Y: 0, Z: 0}}
yAxisPt = Point{r3.Vector{X: 0, Y: 1, Z: 0}}

xAxis = CapFromPoint(xAxisPt)
yAxis = CapFromPoint(yAxisPt)
Expand Down Expand Up @@ -157,14 +157,14 @@ func TestCapContains(t *testing.T) {
}

func TestCapContainsPoint(t *testing.T) {
tangent := tiny.center.Cross(r3.Vector{3, 2, 1}).Normalize()
tangent := tiny.center.Cross(r3.Vector{X: 3, Y: 2, Z: 1}).Normalize()
tests := []struct {
c Cap
p Point
want bool
}{
{xAxis, xAxisPt, true},
{xAxis, Point{r3.Vector{1, 1e-20, 0}}, false},
{xAxis, Point{r3.Vector{X: 1, Y: 1e-20, Z: 0}}, false},
{yAxis, xAxis.center, false},
{xComp, xAxis.center, true},
{xComp.Complement(), xAxis.center, false},
Expand Down Expand Up @@ -208,9 +208,9 @@ func TestCapInteriorIntersects(t *testing.T) {
}

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

Expand Down Expand Up @@ -316,7 +316,7 @@ func TestCapRectBounds(t *testing.T) {
},
{
"The eastern hemisphere.",
CapFromCenterAngle(Point{r3.Vector{0, 1, 0}}, s1.Radian*(math.Pi/2+2e-16)),
CapFromCenterAngle(Point{r3.Vector{X: 0, Y: 1, Z: 0}}, s1.Radian*(math.Pi/2+2e-16)),
-90, 90, -180, 180, true,
},
{
Expand Down Expand Up @@ -376,34 +376,34 @@ func TestCapAddPoint(t *testing.T) {
{yAxis, yAxisPt, yAxis},

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

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

// The 45 degree angled hemisphere plus some points.
{
hemi,
PointFromCoords(0, 1, -1),
CapFromCenterAngle(Point{r3.Vector{1, 0, 1}},
CapFromCenterAngle(Point{r3.Vector{X: 1, Y: 0, Z: 1}},
s1.Angle(120.0)*s1.Degree),
},
{
hemi,
PointFromCoords(0, -1, -1),
CapFromCenterAngle(Point{r3.Vector{1, 0, 1}},
CapFromCenterAngle(Point{r3.Vector{X: 1, Y: 0, Z: 1}},
s1.Angle(120.0)*s1.Degree),
},
{
hemi,
PointFromCoords(-1, -1, -1),
CapFromCenterAngle(Point{r3.Vector{1, 0, 1}},
CapFromCenterAngle(Point{r3.Vector{X: 1, Y: 0, Z: 1}},
s1.Angle(math.Acos(-math.Sqrt(2.0/3.0)))),
},
{hemi, Point{r3.Vector{0, 1, 1}}, hemi},
{hemi, Point{r3.Vector{1, 0, 0}}, hemi},
{hemi, Point{r3.Vector{X: 0, Y: 1, Z: 1}}, hemi},
{hemi, Point{r3.Vector{X: 1, Y: 0, Z: 0}}, hemi},
}

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

p1 := Point{r3.Vector{0, 0, 1}}
p2 := Point{r3.Vector{0, 1, 0}}
p1 := Point{r3.Vector{X: 0, Y: 0, Z: 1}}
p2 := Point{r3.Vector{X: 0, Y: 1, Z: 0}}
// Two very large caps, whose radius sums to in excess of 180 degrees, and
// whose centers are not antipodal.
f := CapFromCenterAngle(p1, s1.Degree*150)
Expand Down
22 changes: 11 additions & 11 deletions s2/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,17 @@ func (c Cell) RectBound() Rect {
var bound Rect
switch c.face {
case 0:
bound = Rect{r1.Interval{-math.Pi / 4, math.Pi / 4}, s1.Interval{-math.Pi / 4, math.Pi / 4}}
bound = Rect{r1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}, s1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}}
case 1:
bound = Rect{r1.Interval{-math.Pi / 4, math.Pi / 4}, s1.Interval{math.Pi / 4, 3 * math.Pi / 4}}
bound = Rect{r1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}, s1.Interval{Lo: math.Pi / 4, Hi: 3 * math.Pi / 4}}
case 2:
bound = Rect{r1.Interval{poleMinLat, math.Pi / 2}, s1.FullInterval()}
bound = Rect{r1.Interval{Lo: poleMinLat, Hi: math.Pi / 2}, s1.FullInterval()}
case 3:
bound = Rect{r1.Interval{-math.Pi / 4, math.Pi / 4}, s1.Interval{3 * math.Pi / 4, -3 * math.Pi / 4}}
bound = Rect{r1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}, s1.Interval{Lo: 3 * math.Pi / 4, Hi: -3 * math.Pi / 4}}
case 4:
bound = Rect{r1.Interval{-math.Pi / 4, math.Pi / 4}, s1.Interval{-3 * math.Pi / 4, -math.Pi / 4}}
bound = Rect{r1.Interval{Lo: -math.Pi / 4, Hi: math.Pi / 4}, s1.Interval{Lo: -3 * math.Pi / 4, Hi: -math.Pi / 4}}
default:
bound = Rect{r1.Interval{-math.Pi / 2, -poleMinLat}, s1.FullInterval()}
bound = Rect{r1.Interval{Lo: -math.Pi / 2, Hi: -poleMinLat}, s1.FullInterval()}
}

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

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

Expand Down Expand Up @@ -682,7 +682,7 @@ func (c Cell) MaxDistanceToCell(target Cell) s1.ChordAngle {
// Need to check the antipodal target for intersection with the cell. If it
// intersects, the distance is the straight ChordAngle.
// antipodalUV is the transpose of the original UV, interpreted within the opposite face.
antipodalUV := r2.Rect{target.uv.Y, target.uv.X}
antipodalUV := r2.Rect{X: target.uv.Y, Y: target.uv.X}
if int(c.face) == oppositeFace(int(target.face)) && c.uv.Intersects(antipodalUV) {
return s1.StraightChordAngle
}
Expand Down
10 changes: 5 additions & 5 deletions s2/cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ func testCellChildren(t *testing.T, cell Cell) {
// where the cell size at a given level is maximal.
maxSizeUV := 0.3964182625366691
specialUV := []r2.Point{
{dblEpsilon, dblEpsilon}, // Face center
{dblEpsilon, 1}, // Edge midpoint
{1, 1}, // Face corner
{maxSizeUV, maxSizeUV}, // Largest cell area
{dblEpsilon, maxSizeUV}, // Longest edge/diagonal
{X: dblEpsilon, Y: dblEpsilon}, // Face center
{X: dblEpsilon, Y: 1}, // Edge midpoint
{X: 1, Y: 1}, // Face corner
{X: maxSizeUV, Y: maxSizeUV}, // Largest cell area
{X: dblEpsilon, Y: maxSizeUV}, // Longest edge/diagonal
}
forceSubdivide := false
for _, uv := range specialUV {
Expand Down
18 changes: 9 additions & 9 deletions s2/cellid.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func stToIJ(s float64) int {
//
// is always true.
func cellIDFromPoint(p Point) CellID {
f, u, v := xyzToFaceUV(r3.Vector{p.X, p.Y, p.Z})
f, u, v := xyzToFaceUV(r3.Vector{X: p.X, Y: p.Y, Z: p.Z})
i := stToIJ(uvToST(u))
j := stToIJ(uvToST(v))
return cellIDFromFaceIJ(f, i, j)
Expand Down Expand Up @@ -788,7 +788,7 @@ func (ci CellID) Advance(steps int64) CellID {
// centerST return the center of the CellID in (s,t)-space.
func (ci CellID) centerST() r2.Point {
_, si, ti := ci.faceSiTi()
return r2.Point{siTiToST(si), siTiToST(ti)}
return r2.Point{X: siTiToST(si), Y: siTiToST(ti)}
}

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

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

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

// MaxTile returns the largest cell with the same RangeMin such that
Expand Down
Loading