asim / quadtree Goto Github PK
View Code? Open in Web Editor NEWGo QuadTree Library
License: MIT License
Go QuadTree Library
License: MIT License
If k is bigger than the actual object count within the search rectangle (or the whole tree?), KNearest returns an empty slice in all of my experiments.
By reducing k to a smaller value, we get the correct results.
See pull-request for a fix for this.
Best regards,
Maurice
I noticed that QuadTree.depth is never updated. So MaxDepth never comes in to play.
QuadTree.divide() simply sets the new depths to the same as the parent:
qt.nodes[0] = New(bb, qt.depth, qt)
What is the license of quadtree please?
Hi, thanks for the quadtree codes and it’s very fast for many points query.
However I wrote a simple program, and found the qtree.KNearest
didn’t return in dist order:
package main
import (
"fmt"
"log"
"github.com/asim/quadtree"
)
func main() {
centerPoint := quadtree.NewPoint(0.0, 0.0, nil)
halfPoint := quadtree.NewPoint(90.0, 180.0, nil)
boundingBox := quadtree.NewAABB(centerPoint, halfPoint)
qtree := quadtree.New(boundingBox, 0, nil)
points := []struct {
Lng float64
Lat float64
ID string
}{
{
Lng: 116.2748,
Lat: 39.9989,
ID: "yi-he-yuan",
},
{
Lng: 116.3202,
Lat: 39.9166,
ID: "yu-yuan-tan",
},
{
Lng: 116.3905,
Lat: 39.9285,
ID: "bei-hai",
},
}
for _, point := range points {
if !qtree.Insert(quadtree.NewPoint(point.Lat, point.Lng, point.ID)) {
log.Fatal("Failed to insert the point")
}
}
center := quadtree.NewPoint(39.9289, 116.3883, nil)
distance := 10000.0 /* Distance to the center point in meters */
bounds := quadtree.NewAABB(center, center.HalfPoint(distance))
maxPoints := 3
for _, point := range qtree.KNearest(bounds, maxPoints, nil) {
fmt.Printf("Found point: %s\n", point.Data().(string))
}
}
Output:
Found point: yi-he-yuan
Found point: yu-yuan-tan
Found point: bei-hai
Expect:
Found point: bei-hai
Found point: yu-yuan-tan
Found point: yi-he-yuan
Is that expect? If so how can set return order?
If k is chosen large, KNearest returns a list of points from the quadtree that contained the same points multiple times.
I'll submit another pull-request for the fix :)
PR: #5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.