igniteui-react-charts
Version:
Ignite UI React charting components for building rich data visualizations using TypeScript APIs.
503 lines (502 loc) • 14 kB
JavaScript
/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends } from "tslib";
import { Base, EventArgs, runOn, markType } from "igniteui-react-core";
import { KDTreeNode2D } from "./KDTreeNode2D";
import { KDTreeThunk } from "./KDTreeThunk";
import { Stack$1 } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { KNearestResult } from "./KNearestResult";
import { SearchData } from "./SearchData";
import { intDivide, isNaN_ } from "igniteui-react-core";
/**
* @hidden
*/
var KDTree2D = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(KDTree2D, _super);
function KDTree2D(a) {
var _rest = [];
for (var _i = 1; _i < arguments.length; _i++) {
_rest[_i - 1] = arguments[_i];
}
var _this = _super.call(this) || this;
_this.a = null;
_this.j = null;
_this.i = null;
_this.m = 0;
_this.q = {};
_this.progressiveThunkCompleted = null;
_this.g = false;
_this.e = null;
_this.f = null;
_this.d = null;
a = (a == void 0) ? 0 : a;
switch (a) {
case 0:
{
var c = _rest[0];
var d = _rest[1];
var e = _rest[2];
_this.f = e;
_this.d = _this.c(c, 0, c.length - 1, 0, d);
}
break;
case 1:
{
var c = _rest[0];
_this.f = c;
}
break;
}
return _this;
}
Object.defineProperty(KDTree2D.prototype, "r", {
get: function () {
return this.q;
},
enumerable: false,
configurable: true
});
KDTree2D.b = function (a, b, c) {
var d = new KDTree2D(1, c);
d.d = new KDTreeNode2D();
d.d.g = true;
d.a = a;
d.j = new Stack$1(KDTreeThunk.$);
d.i = new List$1(KDTreeThunk.$, 0);
var e = new KDTreeThunk();
e.e = 0;
e.b = a.length - 1;
e.c = 0;
e.d = b;
e.a = d.d;
d.j.h(e);
return d;
};
KDTree2D.prototype.h = function (a) {
if (this.j.f == 0 && this.i.count == 0) {
this.a = null;
return false;
}
if (this.j.f == 0 && this.i.count > 0) {
return true;
}
this.m = this.j.d().c;
while (this.j.f > 0 && this.j.d().c == this.m) {
this.i.add(this.j.e());
}
if (a != null) {
a.setTimeout(runOn(this, this.z), 0);
}
else {
window.setTimeout(runOn(this, this.z), 0);
}
return true;
};
KDTree2D.prototype.t = function () {
this.g = true;
};
KDTree2D.prototype.z = function () {
var a;
for (var b = 0; b < this.i.count; b++) {
if (this.g || this.a == null) {
return;
}
if (this.a.length == 0) {
continue;
}
a = this.i._inner[b];
this.w(a.a, this.a, a.e, a.b, a.c, a.d);
}
this.i.clear();
if (this.progressiveThunkCompleted != null) {
this.progressiveThunkCompleted(this, new EventArgs());
}
};
KDTree2D.prototype.w = function (a, b, c, d, e, f) {
a.g = false;
a.f = (e % 2) == 0;
a.h = (d - c);
if (c == d) {
a.b = b[c];
return;
}
if (c > d) {
a.g = true;
return;
}
if ((d - c) + 1 <= f) {
a.b = b[c];
a.a = new Array((d - c) + 1);
var g = 0;
for (var h = c; h <= d; h++) {
a.a[g++] = b[h];
}
return;
}
var i = Math.max(intDivide((d - c), 2), 1);
var j = this.o(b, c, d, a.f, i);
a.b = b[j];
if (c <= j - 1) {
a.c = ((function () {
var $ret = new KDTreeNode2D();
$ret.g = true;
return $ret;
})());
a.c.h = ((j - 1) - c) + 1;
this.j.h(((function () {
var $ret = new KDTreeThunk();
$ret.e = c;
$ret.b = j - 1;
$ret.c = e + 1;
$ret.d = f;
$ret.a = a.c;
return $ret;
})()));
}
else {
a.c = null;
}
if (j + 1 <= d) {
a.d = ((function () {
var $ret = new KDTreeNode2D();
$ret.g = true;
return $ret;
})());
a.d.h = (d - (j + 1)) + 1;
this.j.h(((function () {
var $ret = new KDTreeThunk();
$ret.e = j + 1;
$ret.b = d;
$ret.c = e + 1;
$ret.d = f;
$ret.a = a.d;
return $ret;
})()));
}
else {
a.d = null;
}
};
KDTree2D.prototype.c = function (a, b, c, d, e) {
var f = new KDTreeNode2D();
f.f = (d % 2) == 0;
f.h = (c - b);
if (b == c) {
f.b = a[b];
return f;
}
if (b > c) {
return null;
}
if ((c - b) + 1 <= e) {
f.b = a[b];
f.a = new Array(c - b + 1);
var g = 0;
for (var h = b; h <= c; h++) {
f.a[g++] = a[h];
}
return f;
}
var i = Math.max(intDivide((c - b), 2), 1);
var j = this.o(a, b, c, f.f, i);
f.b = a[j];
f.c = this.c(a, b, j - 1, d + 1, e);
f.d = this.c(a, j + 1, c, d + 1, e);
return f;
};
KDTree2D.prototype.n = function (a, b, c, d, e) {
var f = b ? a[e].a : a[e].b;
var g = a[e];
a[e] = a[d];
a[d] = g;
var h = c;
for (var i = c; i < d; i++) {
var j = void 0;
if (b) {
j = a[i].a;
}
else {
j = a[i].b;
}
if (j <= f) {
g = a[h];
a[h] = a[i];
a[i] = g;
h++;
}
}
g = a[d];
a[d] = a[h];
a[h] = g;
return h;
};
KDTree2D.prototype.o = function (a, b, c, d, e) {
if (b == c) {
return b;
}
if (this.e == null) {
this.e = this.f.getGenerator("KDTreePivot");
}
var f = this.e.next(b, c);
var g = this.n(a, d, b, c, f);
var h = g - b + 1;
if (h == e) {
return g;
}
else if (e < h) {
return this.o(a, b, g - 1, d, e);
}
else {
return this.o(a, g + 1, c, d, e - h);
}
};
KDTree2D.prototype.x = function (a, b, c, d) {
this.y(a, b, c, d, this.d);
};
KDTree2D.prototype.y = function (a, b, c, d, e) {
if (e == null || e.g) {
return;
}
if (e.c == null && e.d == null) {
this.s(a, b, c, e, e.b, true, 0, d);
if (a.a) {
return;
}
if (e.a != null && e.a.length > 0) {
for (var f = 0; f < e.a.length; f++) {
this.s(a, b, c, e, e.a[f], false, f, d);
if (a.a) {
return;
}
}
}
return;
}
this.s(a, b, c, e, e.b, true, 0, d);
if (a.a) {
return;
}
if (e.f) {
if (b <= e.b.a) {
this.y(a, b, c, d, e.c);
if (a.a) {
return;
}
if (this.k(b, c, e.b.a, c) < a.c) {
this.y(a, b, c, d, e.d);
}
if (a.a) {
return;
}
}
else {
this.y(a, b, c, d, e.d);
if (a.a) {
return;
}
if (this.k(b, c, e.b.a, c) < a.c) {
this.y(a, b, c, d, e.c);
}
if (a.a) {
return;
}
}
}
else {
if (c <= e.b.b) {
this.y(a, b, c, d, e.c);
if (a.a) {
return;
}
if (this.k(b, c, b, e.b.b) < a.c) {
this.y(a, b, c, d, e.d);
}
if (a.a) {
return;
}
}
else {
this.y(a, b, c, d, e.d);
if (a.a) {
return;
}
if (this.k(b, c, b, e.b.b) < a.c) {
this.y(a, b, c, d, e.c);
}
if (a.a) {
return;
}
}
}
};
KDTree2D.prototype.s = function (a, b, c, d, e, f, g, h) {
if (a.a) {
return;
}
if (a.e > a.f) {
a.a = true;
return;
}
if (a.b.count < h) {
if (isNaN_(a.d)) {
a.d = this.k(b, c, e.a, e.b);
a.c = a.d;
a.g = 0;
}
a.b.add(((function () {
var $ret = new KNearestResult();
$ret.b = f;
$ret.e = g;
$ret.a = d;
$ret.c = e.a;
$ret.d = e.b;
return $ret;
})()));
a.e++;
var i = this.k(b, c, e.a, e.b);
if (i < a.d) {
a.d = i;
}
if (i > a.c) {
a.c = i;
a.g = a.b.count - 1;
}
return;
}
var j = 0;
if (j < a.c) {
if (j < a.d) {
a.d = j;
}
a.b._inner[a.g] = ((function () {
var $ret = new KNearestResult();
$ret.b = f;
$ret.e = g;
$ret.a = d;
$ret.c = e.a;
$ret.d = e.b;
return $ret;
})());
var k = 0;
var l = 0;
for (var m = 0; m < a.b.count; m++) {
var n = this.k(b, c, a.b._inner[m].c, a.b._inner[m].d);
if (n > k) {
k = n;
l = m;
}
}
a.e++;
}
};
KDTree2D.prototype.k = function (a, b, c, d) {
return (a - c) * (a - c) + (b - d) * (b - d);
};
KDTree2D.prototype.u = function (a, b, c, d, e, f) {
this.v(a, this.d, b, c, d, e, f, false, 0);
};
KDTree2D.prototype.v = function (a, b, c, d, e, f, g, h, i) {
if (b == null) {
return;
}
var j = b.e;
if (i > c.g || ((g - f) < c.f && (e - d) < c.e)) {
if (b.e == null) {
b.e = new SearchData();
}
j = b.e;
j.a = true;
j.d = d;
j.b = e;
j.e = f;
j.c = g;
a.add(b);
return;
}
if (j != null) {
j.a = false;
}
if (b.c == null && b.d == null) {
a.add(b);
return;
}
var k;
var l;
var m;
var n;
var o;
var p;
var q;
var r;
if (b.f) {
k = d;
l = b.b.a;
m = f;
n = g;
o = b.b.a;
p = e;
q = f;
r = g;
}
else {
k = d;
l = e;
m = f;
n = b.b.b;
o = d;
p = e;
q = b.b.b;
r = g;
}
if (h) {
a.add(b);
this.v(a, b.c, c, k, l, m, n, true, i + 1);
this.v(a, b.d, c, o, p, q, r, true, i + 1);
}
else {
var s = false;
if (k >= c.c && l <= c.a && m >= c.d && n <= c.b) {
s = true;
a.add(b);
this.v(a, b.c, c, k, l, m, n, true, i + 1);
}
else if (!(c.c > l || c.a < k || c.d > n || c.b < m)) {
s = true;
a.add(b);
this.v(a, b.c, c, k, l, m, n, false, i + 1);
}
if (o >= c.c && p <= c.a && q >= c.d && r <= c.b) {
if (!s) {
a.add(b);
}
this.v(a, b.d, c, o, p, q, r, true, i + 1);
}
else if (!(c.c > p || c.a < o || c.d > r || c.b < q)) {
if (!s) {
a.add(b);
}
this.v(a, b.d, c, o, p, q, r, false, i + 1);
}
}
};
KDTree2D.prototype.aa = function () {
this.p(this.d);
};
KDTree2D.prototype.p = function (a) {
if (a == null) {
return 0;
}
if (this.p(a.c) + this.p(a.d) != a.h) {
var b = 0;
}
return a.h + 1;
};
KDTree2D.$t = markType(KDTree2D, 'KDTree2D');
return KDTree2D;
}(Base));
export { KDTree2D };