Skip to content

Commit 096d475

Browse files
authored
Merge pull request #5 from SliceOSM/zero-area
reject 0 area inputs
2 parents 5c8f222 + af991d0 commit 096d475

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/paulmach/orb/geojson"
1616
"github.com/paulmach/orb/maptile"
1717
"github.com/paulmach/orb/maptile/tilecover"
18+
"github.com/paulmach/orb/planar"
1819
"image"
1920
"image/png"
2021
"io"
@@ -308,6 +309,10 @@ func parseInput(body io.Reader) (orb.Geometry, string, string, json.RawMessage,
308309
return nil, "", "", nil, errors.New("invalid input RegionType")
309310
}
310311

312+
if planar.Area(geom) == 0.0 {
313+
return nil, "", "", nil, errors.New("Input has 0 area")
314+
}
315+
311316
return geom, input.Name, input.RegionType, sanitizedData, nil
312317
}
313318

main_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ func TestInvalidGeoJSON(t *testing.T) {
3434
assert.NotNil(t, err)
3535
}
3636

37+
func TestZeroAreaGeoJSON(t *testing.T) {
38+
_, _, _, _, err := parseInput(strings.NewReader(`{"Name":"a_name", "RegionType":"geojson", "RegionData":{"type":"Polygon","coordinates":[[[0,0],[1,1],[1,1],[0,0]]]}}`))
39+
assert.NotNil(t, err)
40+
}
41+
42+
func TestZeroAreaBbox(t *testing.T) {
43+
_, _, _, _, err := parseInput(strings.NewReader(`{"Name":"a_name", "RegionType":"bbox", "RegionData":[0,0,0,0]}`))
44+
assert.NotNil(t, err)
45+
}
46+
3747
func TestMalformedGeoJSON(t *testing.T) {
3848
_, _, _, _, err := parseInput(strings.NewReader(`{"Name":"a_name", "RegionType":"geojson", "RegionData":[}`))
3949
assert.NotNil(t, err)

0 commit comments

Comments
 (0)