Comments (16)
RE the k-nearest neighbours. I think the first thing to fix is the inconsistency with the usage of w
and h
. Watching the video, you use w
and h
to represent the distance from the centre point to each edge. However, it looks like shortly after that there was a contribution that used it to mean the distance from one side to the other.
This causes some issues when trying to dive into the algorithm to adjust it a bit but there are lots of tests that are built working around the inconsistency so it's difficult to unpick it as changing it either way breaks a lot of the tests.
π
from quadtree.
Let me have a play and see if I can come up with something.
from quadtree.
Thanks for cleaning up both the inconsistencies (width
vs. width/2
and also <=
vs <
)!
I'm going to give this a closer look but I think the PR is almost set. I left a couple of comments.
from quadtree.
OK, not creating a PR because I don't know how to make this binary search work. Haha π
The search is even difficult to describe in words. Ideally what you want is the smallest circle at centre point.x, point.y
that contains at least count
points (excluding point
itself).
But... you could have arbitrarily many points at any distance and even at the same distance from point
. So you're not looking for the smallest circe with exactly count
points.
If your current smallest circle has more than count
points. Then you could go smaller to get closer to count
. But potentially a tiny change (infinitesimal, even) could drop you down to 0 if all the points at at the exact radius of the current circle. Or, a big change might not reduce the number at all (you might have more than count points at the exact same place as point
).
My closest "best guess" is to start small with a radius of say maxDistance * 0.5^10
and then reduce the power each loop (effectively doubling the radius of the circle) until you have a circle that contains at least count
points.
If you get to maxDistance
radius then that's because you didn't find a smaller circle with count
points in it.
from quadtree.
I think another approach to this would be to use a k-nearest-neighbours algorithm instead of using a range query lookup.
I donβt know how to do that but Iβll give it a go. π
from quadtree.
Woop! π
OK, got the nearest neighbors algorithm working and it's nice and fast π
Did spot an inconsistency with the Rectangle though. The w, h
properties seem to be used in two way. One is that they are the width and height from the center of the rect, the other is the full width and height.
Going to assume it is the latter though as that's what the tests show π
Expect, when using left, right, top, bottom
to determine if a Rect contains a point some other tests fail.
Will fix those too π
But for now... it's 1am so it's bed time π΄
from quadtree.
OK... it's still not working and one of the issues is due to the inconsistency of how Rectangle width and height are used.
I think I'll make a PR for that first and then work with the rest. π
from quadtree.
Sorry if you've felt like you've been talking in a vacuum! I'd like to hear more about your approach!
The binary search can have issues with the outer limits and if it's also hard to understand, I'd be interested in using a different approach!
from quadtree.
I looked into it more and you're exactly right! If you provide a maxDistance
and it doesn't contain enough points -> infinite loop.
I've created a fix for this problem until we can get a closer look at your search method. How does this sound to you?
from quadtree.
@crhallberg hey, thanks for the reply. For some reason I don't seem to be getting emails from Github so apologies for not replying sooner. That looks like a good fix for now π
from quadtree.
For some info... k-nearest-neighbours iterates over the structure of the quad tree building a list of "neighbours" instead of using a range lookup.
If it finds a node closer than any of the current "neighbours" then it adds that to the list and then removes the furthest one.
It can skip a quadrant (and all of its children) if the quadrant is further away than all of the current neighbours as none of its nodes will be closer than any of the neighbours.
I think it's important too to remove the overlap of each sector. Instead of using <=
and >=
at every border it should use <=
and >
. That way if a node's position is equal to the border it only has one quadrant that is valid.
from quadtree.
Hey, @oliver-foggin! I'm sorry for being away for so long. I was finally able to fix some permissions errors that was preventing me from merging any pull requests!
In review of #51, I wanted to check back in on this. Do you still have your k-nearest-neighbor code? I'd be interested to see the approach, since I think my binary search query method might be a bit hard to grasp for the intent of this library.
from quadtree.
@crhallberg hey, I never got to the point of having the k-nearest-neighbours code working due to the width & height inconsistencies in the repo.
The k-nearest-neighbours algorithm was almost working but because it relies on knowing the width and height of each node it was getting confused and so never actually returned the correct values.
I had a look into fixing them but got to the point where there were too many tests built on top of them and so they would all need updating.
Def happy to have a look at it again. I think the main task first would be to fix the inconsistencies so that "width" and "height" have a definite meaning within the repo.
I'm happy to have a look at that too but it will be a fairly big update not functionally, just due to the number of changes required.
from quadtree.
Regarding the inconsistency... you can see it here...
get left
is defined as ...
x minus half the width.
Whereas the check for if a point is inside the left boundary is ...
x minus the full width.
Likewise for top, right, and bottom.
from quadtree.
Just linking for completeness...
Here's the PR for the fix of the width/height issue.
from quadtree.
New use of k-nearest fixes the infinite loop!
from quadtree.
Related Issues (19)
- Comments HOT 1
- bounding box HOT 1
- Redistribute current points to children when subdividing HOT 5
- Boundary Check HOT 1
- bundle and release as library? HOT 3
- Allow default boundary and capacity HOT 5
- Namespace QuadTree system HOT 2
- Project roadmap HOT 7
- How I delete a point of the quadtree? HOT 2
- npm run testError: Cannot find module '...QuadTree\node'
- [QUESTION] Quadtree for pathfinding? HOT 1
- error in QuadTree.closest() function HOT 3
- License? HOT 2
- Rename main branch HOT 2
- Repl.it Button
- logical problem in "intersect" function HOT 1
- QuadTree operations HOT 5
- Function to clear QuadTree HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quadtree.