Пример #1
0
def __query(qt, x, y) :
	n, get_coords = qt
	cx = (n.extent.l + n.extent.r) / 2
	cy = (n.extent.t + n.extent.b) / 2
	print here(), cx, cy
	hits = ([ (o, (n, _V)) for o in n.vertical if __within(get_coords(o), y=y) ] +
		[ (o, (n, _H)) for o in n.horizontal if __within(get_coords(o), x=x) ] )
	qi = __q_to_i[x < cx, y < cy]
	if n.quads[qi] != None :
		return hits + __query((n.quads[qi], get_coords), x, y)
	else :
		return hits
Пример #2
0
def qtree_remove(qt, o) :
	root, get_coords = qt
	o_l, o_t, o_r, o_b = get_coords(o)
	hits = __query(qt, (o_l+o_r)/2, (o_t+o_b)/2)
	for o_found, (n, lst) in hits :
		if o == o_found :
			assert(lst in (_V, _H))
			if lst == _V :
				n.vertical.remove(o)
			elif lst == _H :
				n.horizontal.remove(o)
			__gc_node(n)


#def qtree_contains(qt, x, y) :
#	return []


if __name__ == "__main__" :
	qt = qtree_init(2000, 2000, get_obj_coords=lambda o: o[1])
	o0 = ("o0", _rect_t(10, 10, 50, 50))
	qtree_insert(qt, o0)
	print here(), qtree_query(qt, 666, 667)
	print here(), qtree_query(qt, 11, 11)
	qtree_remove(qt, o0)
	print here(), qtree_query(qt, 11, 11)
	qtree_insert(qt, o0)
	print here(), qtree_query(qt, 11, 11)