diff --git a/pkg/geo/geomfn/distance.go b/pkg/geo/geomfn/distance.go index 59bf0112f7d8..a2a0ff188cc5 100644 --- a/pkg/geo/geomfn/distance.go +++ b/pkg/geo/geomfn/distance.go @@ -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) } diff --git a/pkg/geo/geomfn/distance_test.go b/pkg/geo/geomfn/distance_test.go index 50532354f0bd..a028ee50e73c 100644 --- a/pkg/geo/geomfn/distance_test.go +++ b/pkg/geo/geomfn/distance_test.go @@ -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)", @@ -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)",