do not panic on bad rectangles

This commit is contained in:
Josh Baker 2016-07-18 05:26:26 -07:00
parent 4ab2859944
commit 186213d70e
1 changed files with 7 additions and 1 deletions

View File

@ -37,10 +37,12 @@ func (tr *RTree) Insert(item Item) {
}
min, max := item.Rect(tr.ctx)
if len(min) != len(max) {
return // just return
panic("invalid item rectangle")
}
switch len(min) {
default:
return // just return
panic("invalid dimension")
case 1:
var amin, amax [1]float64
@ -75,10 +77,12 @@ func (tr *RTree) Remove(item Item) {
}
min, max := item.Rect(tr.ctx)
if len(min) != len(max) {
return // just return
panic("invalid item rectangle")
}
switch len(min) {
default:
return // just return
panic("invalid dimension")
case 1:
var amin, amax [1]float64
@ -117,14 +121,16 @@ func (tr *RTree) Count() int {
}
func (tr *RTree) Search(bounds Item, iter Iterator) {
if bounds == nil {
panic("nil item being added to RTree")
panic("nil bounds being used for search")
}
min, max := bounds.Rect(tr.ctx)
if len(min) != len(max) {
return // just return
panic("invalid item rectangle")
}
switch len(min) {
default:
return // just return
panic("invalid dimension")
case 1, 2, 3, 4:
}