Skip to content

Commit

Permalink
Merge #62488
Browse files Browse the repository at this point in the history
62488: geo/geomfn: fix st_shortestline and st_longestline for ZM coords r=otan a=andyyang890

Previously, we were appending the coords slice for the two endpoints,
which would result in incorrect behaviour when the geometry had
more than two dimensions.

Fixes #62319.

Release note: None

Co-authored-by: Andy Yang <[email protected]>
  • Loading branch information
craig[bot] and Andy Yang committed Mar 24, 2021
2 parents a56498f + 7958352 commit fb3fc30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/geo/geomfn/distance.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ func distanceLineStringInternal(
default:
return geo.Geometry{}, errors.Newf("programmer error: unknown behavior")
}
lineString := geom.NewLineStringFlat(geom.XY, append(coordA, coordB...)).SetSRID(int(a.SRID()))
lineCoords := []float64{coordA.X(), coordA.Y(), coordB.X(), coordB.Y()}
lineString := geom.NewLineStringFlat(geom.XY, lineCoords).SetSRID(int(a.SRID()))
return geo.MakeGeometryFromGeomT(lineString)
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/geo/geomfn/distance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ var distanceTestCases = []struct {
"LINESTRING (1 1, 1 1)",
"LINESTRING (1 1, 1 1)",
},
{
"Same 3D POINTs",
"POINT(1.0 2.0 3.0)",
"POINT(1.0 2.0 3.0)",
0,
0,
"LINESTRING (1 2, 1 2)",
"LINESTRING (1 2, 1 2)",
},
{
"Different POINTs",
"POINT(1.0 1.0)",
Expand All @@ -47,6 +56,15 @@ var distanceTestCases = []struct {
"LINESTRING(1.0 1.0, 2.0 1.0)",
"LINESTRING (1 1, 2 1)",
},
{
"Different 3D POINTs",
"POINT(0.0 1.0 2.0)",
"POINT(0.0 3.0 5.0)",
2,
2,
"LINESTRING (0 1, 0 3)",
"LINESTRING (0 1, 0 3)",
},
{
"POINT on LINESTRING",
"POINT(0.5 0.5)",
Expand Down

0 comments on commit fb3fc30

Please sign in to comment.