From 29be8fd587148fc7c6bc5037f8fc81f77c6b80f6 Mon Sep 17 00:00:00 2001 From: Kyle Zeeuwen Date: Fri, 10 Apr 2020 14:33:35 +1000 Subject: [PATCH] readme: hilight remove fn assumes coords not changed --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 75df47c..3be12f4 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,30 @@ Remove all items: tree.clear(); ``` +**warning** + +The remove implementation relies on the coordinates of the object to be the same as when it was inserted. +This is because the fn is optimised to only look for the object to remove in the sections of the tree it expects them to be in, based on the coordinates of the item being removed. + +This will cause issues + +```js + +// bad +obj.minX += 5 +obj.maxX -= 5 +tree.remove(obj) +tree.insert(obj) + +// you may end up with two copies of the object + +// good +tree.remove(obj) +obj.minX += 5 +obj.maxX -= 5 +tree.insert(obj) +``` + ### Data Format By default, RBush assumes the format of data points to be an object