Skip to content

Commit

Permalink
Merge pull request #63798 from rafiss/backport20.2-63760
Browse files Browse the repository at this point in the history
release-20.2: geomfn: fix st_simplify with NaN
  • Loading branch information
rafiss committed Apr 19, 2021
2 parents dfe5778 + b35a9c8 commit faf9305
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/geo/geomfn/topology_operations.go
Expand Up @@ -11,7 +11,10 @@
package geomfn

import (
"math"

"github.com/cockroachdb/cockroach/pkg/geo"
"github.com/cockroachdb/cockroach/pkg/geo/geopb"
"github.com/cockroachdb/cockroach/pkg/geo/geos"
)

Expand Down Expand Up @@ -76,6 +79,9 @@ func Difference(a, b geo.Geometry) (geo.Geometry, error) {

// Simplify returns a simplified Geometry.
func Simplify(g geo.Geometry, tolerance float64) (geo.Geometry, error) {
if math.IsNaN(tolerance) || g.ShapeType() == geopb.ShapeType_Point || g.ShapeType() == geopb.ShapeType_MultiPoint {
return g, nil
}
simplifiedEWKB, err := geos.Simplify(g.EWKB(), tolerance)
if err != nil {
return geo.Geometry{}, err
Expand Down
16 changes: 16 additions & 0 deletions pkg/geo/geomfn/topology_operations_test.go
Expand Up @@ -12,6 +12,7 @@ package geomfn

import (
"fmt"
"math"
"testing"

"github.com/cockroachdb/cockroach/pkg/geo"
Expand Down Expand Up @@ -172,6 +173,21 @@ func TestSimplify(t *testing.T) {
tolerance: 3,
expected: "POLYGON ((5 7, 16 11, 18 7, 2 5, 5 7))",
},
{
wkt: "POLYGON ((5 7, 2 5, 5 4, 13 4, 18 7, 16 11, 7 9, 11 7, 5 7), (13 8, 13 6, 14 6, 15 9, 13 8))",
tolerance: math.NaN(),
expected: "POLYGON ((5 7, 2 5, 5 4, 13 4, 18 7, 16 11, 7 9, 11 7, 5 7), (13 8, 13 6, 14 6, 15 9, 13 8))",
},
{
wkt: "MULTIPOINT (1 1, 1 1)",
tolerance: 2,
expected: "MULTIPOINT (1 1, 1 1)",
},
{
wkt: "POINT (1 1)",
tolerance: 2,
expected: "POINT (1 1)",
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit faf9305

Please sign in to comment.