Skip to content

Commit

Permalink
geo/geomfn: fix st_shortestline and st_longestline for ZM coords
Browse files Browse the repository at this point in the history
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.

Release note: None
  • Loading branch information
Andy Yang committed Mar 23, 2021
1 parent 35a64c6 commit 7958352
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 7958352

Please sign in to comment.