|
Last change
on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | export default function(x, y) {
|
|---|
| 2 | if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
|
|---|
| 3 |
|
|---|
| 4 | var x0 = this._x0,
|
|---|
| 5 | y0 = this._y0,
|
|---|
| 6 | x1 = this._x1,
|
|---|
| 7 | y1 = this._y1;
|
|---|
| 8 |
|
|---|
| 9 | // If the quadtree has no extent, initialize them.
|
|---|
| 10 | // Integer extent are necessary so that if we later double the extent,
|
|---|
| 11 | // the existing quadrant boundaries don’t change due to floating point error!
|
|---|
| 12 | if (isNaN(x0)) {
|
|---|
| 13 | x1 = (x0 = Math.floor(x)) + 1;
|
|---|
| 14 | y1 = (y0 = Math.floor(y)) + 1;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | // Otherwise, double repeatedly to cover.
|
|---|
| 18 | else {
|
|---|
| 19 | var z = x1 - x0 || 1,
|
|---|
| 20 | node = this._root,
|
|---|
| 21 | parent,
|
|---|
| 22 | i;
|
|---|
| 23 |
|
|---|
| 24 | while (x0 > x || x >= x1 || y0 > y || y >= y1) {
|
|---|
| 25 | i = (y < y0) << 1 | (x < x0);
|
|---|
| 26 | parent = new Array(4), parent[i] = node, node = parent, z *= 2;
|
|---|
| 27 | switch (i) {
|
|---|
| 28 | case 0: x1 = x0 + z, y1 = y0 + z; break;
|
|---|
| 29 | case 1: x0 = x1 - z, y1 = y0 + z; break;
|
|---|
| 30 | case 2: x1 = x0 + z, y0 = y1 - z; break;
|
|---|
| 31 | case 3: x0 = x1 - z, y0 = y1 - z; break;
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | if (this._root && this._root.length) this._root = node;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | this._x0 = x0;
|
|---|
| 39 | this._y0 = y0;
|
|---|
| 40 | this._x1 = x1;
|
|---|
| 41 | this._y1 = y1;
|
|---|
| 42 | return this;
|
|---|
| 43 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.