Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ func (r Ring) Dimensions() int {
// ie. 4+ points and the first and last points match.
// NOTE: this will not check for self-intersection.
func (r Ring) Closed() bool {
// first must equal last
return r[0] == r[len(r)-1]
return (len(r) >= 4) && (r[0] == r[len(r)-1])
}

// Reverse changes the direction of the ring.
Expand Down
21 changes: 18 additions & 3 deletions ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,28 @@ func TestRing_Closed(t *testing.T) {
},
{
name: "not closed if last point does not match",
ring: Ring{{0, 0}, {3, 0}, {3, 4}},
ring: Ring{{0, 0}, {3, 0}, {3, 3}, {3, 4}},
closed: false,
},
{
name: "length of ring doesn't matter",
name: "empty ring",
ring: Ring{},
closed: false,
},
{
name: "one vertex ring",
ring: Ring{{3, 0}},
closed: false,
},
{
name: "two vertex ring",
ring: Ring{{3, 0}, {3, 0}},
closed: true,
closed: false,
},
{
name: "three vertex ring",
ring: Ring{{3, 0}, {0, 0}, {3, 0}},
closed: false,
},
}

Expand Down