Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
51009: geo: rename functions *FromGeom( to *FromGeomT( r=sumeerbhola a=otan

Cosmetic change for more consistent naming.

Release note: None

Co-authored-by: Oliver Tan <[email protected]>
  • Loading branch information
craig[bot] and otan committed Jul 7, 2020
2 parents d7761ab + 9cd3c1b commit 9304ecd
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pkg/geo/bbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func boundingBoxFromGeomTGeographyType(g geom.T) (s2.Rect, error) {
if g.Empty() {
return s2.EmptyRect(), nil
}
regions, err := S2RegionsFromGeom(g, EmptyBehaviorOmit)
regions, err := S2RegionsFromGeomT(g, EmptyBehaviorOmit)
if err != nil {
return s2.EmptyRect(), err
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/geo/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func NewGeometryFromPointCoords(x, y float64) (*Geometry, error) {
return NewGeometry(s)
}

// NewGeometryFromGeom creates a new Geometry object from a geom.T object.
func NewGeometryFromGeom(g geom.T) (*Geometry, error) {
// NewGeometryFromGeomT creates a new Geometry object from a geom.T object.
func NewGeometryFromGeomT(g geom.T) (*Geometry, error) {
spatialObject, err := spatialObjectFromGeomT(g, geopb.SpatialObjectType_GeometryType)
if err != nil {
return nil, err
Expand Down Expand Up @@ -309,18 +309,18 @@ func NewGeographyUnsafe(spatialObject geopb.SpatialObject) *Geography {
return &Geography{spatialObject: spatialObject}
}

// NewGeographyFromGeom creates a new Geography from a geom.T object.
func NewGeographyFromGeom(g geom.T) (*Geography, error) {
// NewGeographyFromGeomT creates a new Geography from a geom.T object.
func NewGeographyFromGeomT(g geom.T) (*Geography, error) {
spatialObject, err := spatialObjectFromGeomT(g, geopb.SpatialObjectType_GeographyType)
if err != nil {
return nil, err
}
return NewGeography(spatialObject)
}

// MustNewGeographyFromGeom enforces no error from NewGeographyFromGeom.
func MustNewGeographyFromGeom(g geom.T) *Geography {
ret, err := NewGeographyFromGeom(g)
// MustNewGeographyFromGeomT enforces no error from NewGeographyFromGeomT.
func MustNewGeographyFromGeomT(g geom.T) *Geography {
ret, err := NewGeographyFromGeomT(g)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -469,7 +469,7 @@ func (g *Geography) AsS2(emptyBehavior EmptyBehavior) ([]s2.Region, error) {
return nil, err
}
// TODO(otan): convert by reading from EWKB to S2 directly.
return S2RegionsFromGeom(geomRepr, emptyBehavior)
return S2RegionsFromGeomT(geomRepr, emptyBehavior)
}

// BoundingRect returns the bounding s2.Rect of the given Geography.
Expand Down Expand Up @@ -531,11 +531,11 @@ func IsLinearRingCCW(linearRing *geom.LinearRing) bool {
return areaSign > 0
}

// S2RegionsFromGeom converts an geom representation of an object
// S2RegionsFromGeomT converts an geom representation of an object
// to s2 regions.
// As S2 does not really handle empty geometries well, we need to ingest emptyBehavior and
// react appropriately.
func S2RegionsFromGeom(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Region, error) {
func S2RegionsFromGeomT(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Region, error) {
var regions []s2.Region
if geomRepr.Empty() {
switch emptyBehavior {
Expand Down Expand Up @@ -584,31 +584,31 @@ func S2RegionsFromGeom(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Regio
}
case *geom.GeometryCollection:
for _, geom := range repr.Geoms() {
subRegions, err := S2RegionsFromGeom(geom, emptyBehavior)
subRegions, err := S2RegionsFromGeomT(geom, emptyBehavior)
if err != nil {
return nil, err
}
regions = append(regions, subRegions...)
}
case *geom.MultiPoint:
for i := 0; i < repr.NumPoints(); i++ {
subRegions, err := S2RegionsFromGeom(repr.Point(i), emptyBehavior)
subRegions, err := S2RegionsFromGeomT(repr.Point(i), emptyBehavior)
if err != nil {
return nil, err
}
regions = append(regions, subRegions...)
}
case *geom.MultiLineString:
for i := 0; i < repr.NumLineStrings(); i++ {
subRegions, err := S2RegionsFromGeom(repr.LineString(i), emptyBehavior)
subRegions, err := S2RegionsFromGeomT(repr.LineString(i), emptyBehavior)
if err != nil {
return nil, err
}
regions = append(regions, subRegions...)
}
case *geom.MultiPolygon:
for i := 0; i < repr.NumPolygons(); i++ {
subRegions, err := S2RegionsFromGeom(repr.Polygon(i), emptyBehavior)
subRegions, err := S2RegionsFromGeomT(repr.Polygon(i), emptyBehavior)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/geo/geogfn/segmentize.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Segmentize(geography *geo.Geography, segmentMaxLength float64) (*geo.Geogra
if err != nil {
return nil, err
}
return geo.NewGeographyFromGeom(segGeometry)
return geo.NewGeographyFromGeomT(segGeometry)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/geo/geogfn/topology_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func Centroid(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (*geo.G
return nil, err
}
if geomRepr.Empty() {
return geo.NewGeographyFromGeom(geom.NewGeometryCollection().SetSRID(geomRepr.SRID()))
return geo.NewGeographyFromGeomT(geom.NewGeometryCollection().SetSRID(geomRepr.SRID()))
}
switch geomRepr.(type) {
case *geom.Point, *geom.LineString, *geom.Polygon, *geom.MultiPoint, *geom.MultiLineString, *geom.MultiPolygon:
default:
return nil, errors.Newf("unhandled geography type %s", g.ShapeType().String())
}

regions, err := geo.S2RegionsFromGeom(geomRepr, geo.EmptyBehaviorOmit)
regions, err := geo.S2RegionsFromGeomT(geomRepr, geo.EmptyBehaviorOmit)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -118,5 +118,5 @@ func Centroid(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (*geo.G
}
latLng := s2.LatLngFromPoint(s2.Point{Vector: centroidVector.Normalize()})
centroid := geom.NewPointFlat(geom.XY, []float64{latLng.Lng.Degrees(), latLng.Lat.Degrees()}).SetSRID(int(g.SRID()))
return geo.NewGeographyFromGeom(centroid)
return geo.NewGeographyFromGeomT(centroid)
}
6 changes: 3 additions & 3 deletions pkg/geo/geogfn/unary_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Perimeter(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float
default:
return 0, nil
}
regions, err := geo.S2RegionsFromGeom(gt, geo.EmptyBehaviorOmit)
regions, err := geo.S2RegionsFromGeomT(gt, geo.EmptyBehaviorOmit)
if err != nil {
return 0, err
}
Expand All @@ -93,7 +93,7 @@ func Length(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float64,
default:
return 0, nil
}
regions, err := geo.S2RegionsFromGeom(gt, geo.EmptyBehaviorOmit)
regions, err := geo.S2RegionsFromGeomT(gt, geo.EmptyBehaviorOmit)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func Project(g *geo.Geography, distance float64, azimuth s1.Angle) (*geo.Geograp
geo.NormalizeLatitudeDegrees(projected.Lat.Degrees()),
},
).SetSRID(point.SRID())
return geo.NewGeographyFromGeom(ret)
return geo.NewGeographyFromGeomT(ret)
}

// length returns the sum of the lengtsh and perimeters in the shapes of the Geography.
Expand Down
8 changes: 4 additions & 4 deletions pkg/geo/geogfn/unary_operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,17 @@ func TestProject(t *testing.T) {
}{
{
"POINT(0 0), 100000, radians(45)",
geo.MustNewGeographyFromGeom(geom.NewPointFlat(geom.XY, []float64{0, 0}).SetSRID(4326)),
geo.MustNewGeographyFromGeomT(geom.NewPointFlat(geom.XY, []float64{0, 0}).SetSRID(4326)),
100000,
45 * math.Pi / 180.0,
geo.MustNewGeographyFromGeom(geom.NewPointFlat(geom.XY, []float64{0.6352310291255374, 0.6394723347291977}).SetSRID(4326)),
geo.MustNewGeographyFromGeomT(geom.NewPointFlat(geom.XY, []float64{0.6352310291255374, 0.6394723347291977}).SetSRID(4326)),
},
{
"SRID=4004;POINT(0 0), 100000, radians(45)",
geo.MustNewGeographyFromGeom(geom.NewPointFlat(geom.XY, []float64{0, 0}).SetSRID(4004)),
geo.MustNewGeographyFromGeomT(geom.NewPointFlat(geom.XY, []float64{0, 0}).SetSRID(4004)),
100000,
45 * math.Pi / 180.0,
geo.MustNewGeographyFromGeom(geom.NewPointFlat(geom.XY, []float64{0.6353047281438549, 0.6395336363116583}).SetSRID(4004)),
geo.MustNewGeographyFromGeomT(geom.NewPointFlat(geom.XY, []float64{0.6353047281438549, 0.6395336363116583}).SetSRID(4004)),
},
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/geo/geoindex/s2_geometry_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *s2GeometryIndex) InvertedIndexKeys(c context.Context, g *geo.Geometry)
}
var keys []Key
if gt != nil {
r := s.s2RegionsFromPlanarGeom(gt)
r := s.s2RegionsFromPlanarGeomT(gt)
keys = invertedIndexKeys(c, s.rc, r)
}
if clipped {
Expand All @@ -115,7 +115,7 @@ func (s *s2GeometryIndex) CoveredBy(c context.Context, g *geo.Geometry) (RPKeyEx
}
var expr RPKeyExpr
if gt != nil {
r := s.s2RegionsFromPlanarGeom(gt)
r := s.s2RegionsFromPlanarGeomT(gt)
expr = coveredBy(c, s.rc, r)
}
if clipped {
Expand All @@ -138,7 +138,7 @@ func (s *s2GeometryIndex) Intersects(c context.Context, g *geo.Geometry) (UnionK
}
var spans UnionKeySpans
if gt != nil {
r := s.s2RegionsFromPlanarGeom(gt)
r := s.s2RegionsFromPlanarGeomT(gt)
spans = intersects(c, s.rc, r)
}
if clipped {
Expand Down Expand Up @@ -290,10 +290,10 @@ func (s *s2GeometryIndex) planarPointToS2Point(x float64, y float64) s2.Point {
return face0UVToXYZPoint(u, v)
}

// TODO(sumeer): this is similar to s2RegionsFromGeom() but needs to do
// TODO(sumeer): this is similar to s2RegionsFromGeomT() but needs to do
// a different point conversion. If these functions do not diverge further,
// and turn out not to be performance critical, merge the two implementations.
func (s *s2GeometryIndex) s2RegionsFromPlanarGeom(geomRepr geom.T) []s2.Region {
func (s *s2GeometryIndex) s2RegionsFromPlanarGeomT(geomRepr geom.T) []s2.Region {
var regions []s2.Region
switch repr := geomRepr.(type) {
case *geom.Point:
Expand Down Expand Up @@ -332,19 +332,19 @@ func (s *s2GeometryIndex) s2RegionsFromPlanarGeom(geomRepr geom.T) []s2.Region {
}
case *geom.GeometryCollection:
for _, geom := range repr.Geoms() {
regions = append(regions, s.s2RegionsFromPlanarGeom(geom)...)
regions = append(regions, s.s2RegionsFromPlanarGeomT(geom)...)
}
case *geom.MultiPoint:
for i := 0; i < repr.NumPoints(); i++ {
regions = append(regions, s.s2RegionsFromPlanarGeom(repr.Point(i))...)
regions = append(regions, s.s2RegionsFromPlanarGeomT(repr.Point(i))...)
}
case *geom.MultiLineString:
for i := 0; i < repr.NumLineStrings(); i++ {
regions = append(regions, s.s2RegionsFromPlanarGeom(repr.LineString(i))...)
regions = append(regions, s.s2RegionsFromPlanarGeomT(repr.LineString(i))...)
}
case *geom.MultiPolygon:
for i := 0; i < repr.NumPolygons(); i++ {
regions = append(regions, s.s2RegionsFromPlanarGeom(repr.Polygon(i))...)
regions = append(regions, s.s2RegionsFromPlanarGeomT(repr.Polygon(i))...)
}
}
return regions
Expand All @@ -355,6 +355,6 @@ func (s *s2GeometryIndex) TestingInnerCovering(g *geo.Geometry) s2.CellUnion {
if err != nil || gt == nil {
return nil
}
r := s.s2RegionsFromPlanarGeom(gt)
r := s.s2RegionsFromPlanarGeomT(gt)
return innerCovering(s.rc, r)
}
2 changes: 1 addition & 1 deletion pkg/geo/geomfn/distance.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func distanceLineStringInternal(
return nil, errors.Newf("programmer error: unknown behavior")
}
lineString := geom.NewLineStringFlat(geom.XY, append(coordA, coordB...)).SetSRID(int(a.SRID()))
return geo.NewGeometryFromGeom(lineString)
return geo.NewGeometryFromGeomT(lineString)
}

// maxDistanceInternal finds the maximum distance between two geometries.
Expand Down
2 changes: 1 addition & 1 deletion pkg/geo/geomfn/linear_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func LineInterpolatePoints(g *geo.Geometry, fraction float64, repeat bool) (*geo
return nil, err
}
}
return geo.NewGeometryFromGeom(interpolatedPoints)
return geo.NewGeometryFromGeomT(interpolatedPoints)
}
interpolatedPointEWKB, err := geos.InterpolateLine(g.EWKB(), fraction*lengthOfLineString)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/geo/geomfn/segmentize.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Segmentize(g *geo.Geometry, segmentMaxLength float64) (*geo.Geometry, error
if err != nil {
return nil, err
}
return geo.NewGeometryFromGeom(segGeometry)
return geo.NewGeometryFromGeomT(segGeometry)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/geo/geotransform/geotransform.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Transform(
if err != nil {
return nil, err
}
return geo.NewGeometryFromGeom(newT)
return geo.NewGeometryFromGeomT(newT)
}

// transform performs the projection operation on a geom.T object.
Expand Down
18 changes: 9 additions & 9 deletions pkg/sql/sem/builtins/geo_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ Negative azimuth values and values greater than 2π (360 degrees) are supported.
return tree.DNull, nil
}
coord := t.Coord(0)
retG, err := geo.NewGeometryFromGeom(
retG, err := geo.NewGeometryFromGeomT(
geom.NewPointFlat(geom.XY, []float64{coord.X(), coord.Y()}).SetSRID(t.SRID()),
)
if err != nil {
Expand Down Expand Up @@ -1270,7 +1270,7 @@ Flags shown square brackets after the geometry type have the following meaning:
return tree.DNull, nil
}
coord := t.Coord(t.NumCoords() - 1)
retG, err := geo.NewGeometryFromGeom(
retG, err := geo.NewGeometryFromGeomT(
geom.NewPointFlat(geom.XY, []float64{coord.X(), coord.Y()}).SetSRID(t.SRID()),
)
if err != nil {
Expand Down Expand Up @@ -1352,7 +1352,7 @@ Flags shown square brackets after the geometry type have the following meaning:
ring := t.LinearRing(0)
lineString = geom.NewLineStringFlat(t.Layout(), ring.FlatCoords())
}
ret, err := geo.NewGeometryFromGeom(lineString.SetSRID(t.SRID()))
ret, err := geo.NewGeometryFromGeomT(lineString.SetSRID(t.SRID()))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1387,7 +1387,7 @@ Flags shown square brackets after the geometry type have the following meaning:
}
ring := t.LinearRing(n)
lineString := geom.NewLineStringFlat(t.Layout(), ring.FlatCoords()).SetSRID(t.SRID())
ret, err := geo.NewGeometryFromGeom(lineString)
ret, err := geo.NewGeometryFromGeomT(lineString)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1421,7 +1421,7 @@ Flags shown square brackets after the geometry type have the following meaning:
if n >= t.NumCoords() {
return tree.DNull, nil
}
g, err := geo.NewGeometryFromGeom(geom.NewPointFlat(t.Layout(), t.Coord(n)).SetSRID(t.SRID()))
g, err := geo.NewGeometryFromGeomT(geom.NewPointFlat(t.Layout(), t.Coord(n)).SetSRID(t.SRID()))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1460,7 +1460,7 @@ Flags shown square brackets after the geometry type have the following meaning:
if n >= t.NumPoints() {
return tree.DNull, nil
}
g, err := geo.NewGeometryFromGeom(t.Point(n).SetSRID(t.SRID()))
g, err := geo.NewGeometryFromGeomT(t.Point(n).SetSRID(t.SRID()))
if err != nil {
return nil, err
}
Expand All @@ -1469,7 +1469,7 @@ Flags shown square brackets after the geometry type have the following meaning:
if n >= t.NumLineStrings() {
return tree.DNull, nil
}
g, err := geo.NewGeometryFromGeom(t.LineString(n).SetSRID(t.SRID()))
g, err := geo.NewGeometryFromGeomT(t.LineString(n).SetSRID(t.SRID()))
if err != nil {
return nil, err
}
Expand All @@ -1478,7 +1478,7 @@ Flags shown square brackets after the geometry type have the following meaning:
if n >= t.NumPolygons() {
return tree.DNull, nil
}
g, err := geo.NewGeometryFromGeom(t.Polygon(n).SetSRID(t.SRID()))
g, err := geo.NewGeometryFromGeomT(t.Polygon(n).SetSRID(t.SRID()))
if err != nil {
return nil, err
}
Expand All @@ -1487,7 +1487,7 @@ Flags shown square brackets after the geometry type have the following meaning:
if n >= t.NumGeoms() {
return tree.DNull, nil
}
g, err := geo.NewGeometryFromGeom(t.Geom(n))
g, err := geo.NewGeometryFromGeomT(t.Geom(n))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9304ecd

Please sign in to comment.