Skip to content

Commit

Permalink
fix equal for types with the same geojson type
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmach committed Feb 9, 2018
1 parent e55a300 commit 5947c36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
18 changes: 15 additions & 3 deletions equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,27 @@ func Equal(g1, g2 Geometry) bool {
case MultiLineString:
return g1.Equal(g2.(MultiLineString))
case Ring:
return g1.Equal(g2.(Ring))
g2, ok := g2.(Ring)
if !ok {
return false
}
return g1.Equal(g2)
case Polygon:
return g1.Equal(g2.(Polygon))
g2, ok := g2.(Polygon)
if !ok {
return false
}
return g1.Equal(g2)
case MultiPolygon:
return g1.Equal(g2.(MultiPolygon))
case Collection:
return g1.Equal(g2.(Collection))
case Bound:
return g1.Equal(g2.(Bound))
g2, ok := g2.(Bound)
if !ok {
return false
}
return g1.Equal(g2)
}

panic(fmt.Sprintf("geometry type not supported: %T", g1))
Expand Down
18 changes: 18 additions & 0 deletions equal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ func TestEqual(t *testing.T) {
}(g)
}
}

func TestEqualRing(t *testing.T) {
if Equal(Ring{}, Polygon{}) {
t.Errorf("should return false since different types ")
}

if Equal(Polygon{}, Ring{}) {
t.Errorf("should return false since different types ")
}

if Equal(Polygon{}, Bound{}) {
t.Errorf("should return false since different types ")
}

if Equal(Bound{}, Polygon{}) {
t.Errorf("should return false since different types ")
}
}

0 comments on commit 5947c36

Please sign in to comment.