Created
January 3, 2020 07:22
-
-
Save princegoyal1987/5857c398e8bedde3fe8e45fae54263c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"strconv" | |
"github.com/dhconnelly/rtreego" | |
) | |
type Thing struct { | |
where *rtreego.Rect | |
name string | |
} | |
func (t *Thing) Bounds() *rtreego.Rect { | |
return t.where | |
} | |
func main() { | |
rt := rtreego.NewTree(2, 1000, 1000000) | |
objSlice := make([]*Thing, 0) | |
for i := 0; i < 10000; i++ { | |
x := -5 + rand.Float64()*10 | |
y := -5 + rand.Float64()*10 | |
p1 := rtreego.Point{x, y} | |
r1, _ := rtreego.NewRect(p1, []float64{0, 0}) | |
str1 := "foo" + strconv.Itoa(i) | |
thing1 := &Thing{r1, str1} | |
rt.Insert(thing1) | |
objSlice = append(objSlice, thing1) | |
} | |
size := rt.Size() // returns 2 | |
fmt.Println("tree size = ", size) | |
bb, _ := rtreego.NewRect(rtreego.Point{-5, -5}, []float64{.01, .01}) | |
// Get a slice of the objects in rt that intersect bb: | |
results := rt.SearchIntersect(bb) | |
for _, obj := range results { | |
if thing, ok := obj.(*Thing); ok { | |
fmt.Println("results = ", thing.name) | |
} | |
} | |
//delete half of the objects | |
fmt.Println("==Deleting thing2==") | |
for i, obj := range objSlice { | |
if i < len(objSlice)/2 { | |
rt.Delete(obj) | |
} | |
} | |
results2 := rt.SearchIntersect(bb) | |
for _, obj := range results2 { | |
if thing, ok := obj.(*Thing); ok { | |
fmt.Println("results = ", thing.name) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code tests out the performance of rtree implementation.