rtreelib
rtreelib copied to clipboard
Allow inserting Point entries
The R-tree should allow storing points in addition to rectangles.
When implementing query
, a Point
type was added to allow querying the R-tree using a point location (instead of a rectangle). It seems expected that if one can query using a point, one should be able to store an entry using Point
also.
The initial thought is that RTreeBase.insert
should accept a Location
(which can be either Point
or Rect
), instead of Rect
(which is the only type it accepts currently). Whether something like Point(3, 5)
then gets converted to a degenerate rectangle such as Rect(3, 5, 3, 5)
so it works with the existing algorithms unchanged, or whether the algorithms need to be adjusted, is something that needs to be investigated.
Using a "degenerate" rectangle such as Rect(1, 1, 1, 1)
with the current code does not work with query
, and currently results in unexpected behavior:
my_tree = RTree()
my_tree.insert("A", Rect(1, 1, 1, 1))
my_tree.insert("B", Rect(2, 2, 2, 2))
print(list(my_tree.query(Rect(0, 0, 5, 5)))) # is [] but expected "A" and "B"
# debug
found = list(my_tree.query_nodes(Rect(0, 0, 5, 5))) # returns one node
for x in found:
for b in x.entries:
print(b.rect.intersects(Rect(0, 0, 5, 5))) # always False
Proper handling of "degenerate" rectangles will be handled in #6.