-
Notifications
You must be signed in to change notification settings - Fork 43
Delete, Delete in range and Move implemented #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete, Delete in range and Move implemented #42
Conversation
This looks really good! Would it be possible to write a test or two for these changes? |
this.x = x; | ||
this.y = y; | ||
this.w = w; | ||
this.h = h; | ||
this.userData = data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like below you're using the userData
of each Point to store an id. Is userData
on a Rectangle part of it that I didn't see?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this just needs to be removed because it's not being used in the code that I can see.
for(var i = 0; i < deleteArray.length; i++){ | ||
this.points.splice(i-delta,1); | ||
delta++ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One approach I like for deleting from an array is to loop backwards thru an array to get around the index changes. Just a tip!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a recommendation to simplify this a bit by running backwards thru the array:
for( var i = this.points.length; i--;){
var p = this.points[i];
if (range.contains(p)) {
this.points.splice(i, 1);
}
}
With ES6 we can now try to use a filter, which might be cleaner and faster!
Hey! I've gotten upgraded permissions to the repository so I'm trying to do some clean up! Any interest in getting this up to date? |
Of course! What can I do? |
Great! Step 1 is merging with After that, I think we left it with two comments that need addressing and missing some tests. Are there any parts of this you want me to tackle? |
I've been thinking about this a lot and I think this approach needs some tweaks. Since the QuadTree isn't providing the IDs, I'm skeptical about relying on IDs for deleting points. Also based on this usage guide for a different implementation of QuadTrees, QuadTrees are more useful to be snapshots and not live systems. Here's what I propose (and will implement with help from your great code above):
|
Incorporated into #62, now merged. |
#8
Added Delete, Delete in Range and Move a point(or a rectangle/circle).
It's pretty simple and maybe not optimized.
Hope it helps someone that just like me need it for a game or something like that.