Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-20.2: geomfn: fix st_simplify with NaN #63798

Merged
merged 1 commit into from Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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