Skip to content

Commit

Permalink
added remove-in-bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
skelterjohn committed Dec 21, 2011
1 parent 9fa3ac7 commit eb8bc70
Showing 1 changed file with 69 additions and 28 deletions.
97 changes: 69 additions & 28 deletions qtree/qtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,13 @@ func (me *Tree) CollectInside(bounds geom.Rect, collection map[Item]bool) {
for elem := range me.BigElements {
if bounds.ContainsRect(elem.Bounds()) {
collection[elem] = true
return
}
}
}
if me.Elements != nil {
for elem := range me.Elements {
if bounds.ContainsRect(elem.Bounds()) {
collection[elem] = true
return
}
}
}
Expand All @@ -462,59 +460,102 @@ func (me *Tree) CollectInside(bounds geom.Rect, collection map[Item]bool) {
return
}

func (me *Tree) CollectIntersect(bounds geom.Rect, collection map[Item]bool) (found bool) {
str := ""
if geom.RectsIntersect(bounds, me.UpperBounds) {
str = "*"
func (me *Tree) RemoveInside(bounds geom.Rect, collection map[Item]bool) {
if !geom.RectsIntersect(bounds, me.UpperBounds) {
return
}
dbg("looking in %v%s", me.UpperBounds, str)
Indent++
defer func() {
if found {
dbg("found in %v", me.UpperBounds)
if me.BigElements != nil {
for elem := range me.BigElements {
if bounds.ContainsRect(elem.Bounds()) {
delete(me.BigElements, elem)
if collection != nil {
collection[elem] = true
}
}
}
Indent--
}()
}
if me.Elements != nil {
for elem := range me.Elements {
if bounds.ContainsRect(elem.Bounds()) {
delete(me.Elements, elem)
if collection != nil {
collection[elem] = true
}
}
}
}

for _, t := range me.Subtrees {
if t == nil {
continue
}
t.RemoveInside(bounds, collection)
}

return
}

func (me *Tree) CollectIntersect(bounds geom.Rect, collection map[Item]bool) {
if !geom.RectsIntersect(bounds, me.UpperBounds) {
return
}
if me.BigElements != nil {
for elem := range me.BigElements {
str = ""
if geom.RectsIntersect(elem.Bounds(), bounds) {
collection[elem] = true
found = true
str = "*"
}
dbg("big: %v%s", elem.Bounds(), str)
}
}

if me.Elements != nil {
for elem, ok := range me.Elements {
if !ok {
panic("forgot to delete element properly")
}
str = ""
for elem := range me.Elements {
if geom.RectsIntersect(bounds, elem.Bounds()) {
collection[elem] = true
found = true
str = "*"
}
dbg("elems: %v%s", elem.Bounds(), str)
}
}

if me.Subtrees[0] == nil {
dbg("no subtrees")
for _, t := range me.Subtrees {
if t == nil {
continue
}
t.CollectIntersect(bounds, collection)
}

return
}

func (me *Tree) RemoveIntersect(bounds geom.Rect, collection map[Item]bool) {
if !geom.RectsIntersect(bounds, me.UpperBounds) {
return
}
if me.BigElements != nil {
for elem := range me.BigElements {
if geom.RectsIntersect(elem.Bounds(), bounds) {
delete(me.BigElements, elem)
if collection != nil {
collection[elem] = true
}
}
}
}

if me.Elements != nil {
for elem := range me.Elements {
if geom.RectsIntersect(bounds, elem.Bounds()) {
delete(me.Elements, elem)
if collection != nil {
collection[elem] = true
}
}
}
}

for _, t := range me.Subtrees {
if t == nil {
continue
}
found = t.CollectIntersect(bounds, collection) || found
t.RemoveIntersect(bounds, collection)
}

return
Expand Down

0 comments on commit eb8bc70

Please sign in to comment.