1. No need to rebuild the whole tree every few ms? In Javascript, would that be very slow to do?
I suppose it depends on what you use it for; but yes, an example of an author’s collision detection in his blog post about its implementation, QuadTree will clear the tree and repeat it about 24 times per second (for example, about once in 40 ms). You yourself can judge that it is "very slow"; on my car it looks pretty smooth. (And even if not, I would expect that restoring QuadTree would actually be cheaper / faster than redrawing all the circles on the canvas.)
2. [& hellip;] I have a rectangle that falls into 3 different quads, is there a way to make it display as a child from all three of these squares?
I'm not sure what you mean by “mapping”, but: if you call the constructor with the pointQuad
parameter set to false
, then the elements are two-dimensional (that is, have width
and height
in addition to x
and y
), and each element will be a child of the smallest square that fits completely inside. In your example, since the rectangle intersects the vertical midline of the canvas, it will be a direct descendant of the root square.
3. The 144 from the above example says this Node.prototype._classConstructor = Node ;, I'm just wondering what is happening. [& Hellip;]
Node
"class" has a "subclass" named BoundsNode
(used when elements are two-dimensional), and BoundsNode.prototype._classConstructor
is BoundsNode
(which overrides the inherited Node.prototype._classConstructor
). This allows the Node
subdivide
method to write new this._classConstructor(...)
to build a new BoundsNode
if this
is a BoundsNode
, and a new simple Node
if this
is a simple Node
.
ruakh source share