igniteui-react-core
Version:
Ignite UI React Core.
572 lines (571 loc) • 17.7 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, __values } from "tslib";
import { Base, Point_$type, fromEnum, markType } from "./type";
import { Rect } from "./Rect";
import { CoreGeometryUtil } from "./CoreGeometryUtil";
import { MathUtil } from "./MathUtil";
import { List$1 } from "./List$1";
import { Tuple$2 } from "./Tuple$2";
import { isNaN_, isInfinity } from "./number";
/**
* @hidden
*/
var GeometryUtil = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(GeometryUtil, _super);
function GeometryUtil() {
return _super !== null && _super.apply(this, arguments) || this;
}
GeometryUtil.n = function (a) {
if (isNaN_(a) || isInfinity(a)) {
return a;
}
while (a > 360) {
a -= 360;
}
while (a < 0) {
a += 360;
}
return a;
};
GeometryUtil.g = function (a) {
return Math.atan(a);
};
GeometryUtil.o = function (a, b) {
return (b.y - a.y) / (b.x - a.x);
};
GeometryUtil.i = function (a) {
return 1 - Math.pow(a.height / 2, 2) / Math.pow(a.width / 2, 2);
};
GeometryUtil.x = function (a, b, c, d, e) {
var f = Math.cos(a);
var g = Math.sin(a);
var h = Math.sqrt(d * d / (1 - (b * Math.pow(f, 2))));
h *= e;
return { $type: Point_$type, x: h * f + c.x, y: h * g + c.y };
};
GeometryUtil.t = function (a, b, c, d, e) {
var f;
if (c) {
f = GeometryUtil.u({ $type: Point_$type, x: a / 2, y: b / 2 }, d, e);
}
else {
f = { $type: Point_$type, x: a / 2, y: b / 2 };
}
return f;
};
GeometryUtil.u = function (a, b, c) {
b = b / 180 * Math.PI;
var d = a.y + c * Math.sin(b);
var e = a.x + c * Math.cos(b);
return { $type: Point_$type, x: e, y: d };
};
GeometryUtil.w = function (a, b, c) {
var d = b.x - a.x;
var e = b.y - a.y;
var f = Math.sqrt(d * d + e * e);
d = d / f * c;
e = e / f * c;
return { $type: Point_$type, x: a.x + d, y: a.y + e };
};
GeometryUtil.k = function (a, b) {
var c = Math.abs(b.x - a.x);
var d = Math.abs(b.y - a.y);
return Math.sqrt(c * c + d * d);
};
GeometryUtil.v = function (a, b, c, d, e) {
return CoreGeometryUtil.c(a, b, c, d, e);
};
GeometryUtil.j = function (a, b) {
var c = Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
var d = Math.acos((b.x - a.x) / c);
if ((b.y - a.y) < 0) {
d = (2 * Math.PI) - d;
}
return d;
};
GeometryUtil.f = function (a, b, c, d, e, f) {
if (isNaN_(c) || isNaN_(d) || isNaN_(e)) {
return false;
}
var g = e * e;
var h = f * f;
var i = a.x - b.x;
var j = a.y - b.y;
if (i > g || j > g) {
return false;
}
var k = i * i + j * j;
if (k > g) {
return false;
}
if (k < h) {
return false;
}
var l = Math.atan2(j, i);
return GeometryUtil.b(l, c, d);
};
GeometryUtil.b = function (a, b, c) {
var d = MathUtil.f(a);
var e = MathUtil.f(b);
var f = MathUtil.f(c);
d = GeometryUtil.n(d);
var g = Math.min(e, f);
var h = Math.max(e, f);
return (d > g && d < h) || (d - 360 > g && d - 360 < h) || (d + 360 > g && d + 360 < h);
};
GeometryUtil.y = function (a, b, c, d) {
var e_1, _a;
var e = { $type: Point_$type, x: a.x + Math.cos(b) * d, y: a.y + Math.sin(b) * d };
var f = { $type: Point_$type, x: a.x + Math.cos(c) * d, y: a.y + Math.sin(c) * d };
var g = new List$1(Point_$type, 0);
g.add(e);
g.add(f);
g.add(a);
var h = MathUtil.f(b);
var i = MathUtil.f(c);
h = GeometryUtil.n(h);
i = GeometryUtil.n(i);
if ((0 > h && 0 < i) || (360 > h && 360 < i) || (i < h)) {
g.add(GeometryUtil.u(a, 0, d));
}
if (90 > h && 90 < i) {
g.add(GeometryUtil.u(a, 90, d));
}
if (180 > h && 180 < i) {
g.add(GeometryUtil.u(a, 180, d));
}
if (270 > h && 270 < i) {
g.add(GeometryUtil.u(a, 270, d));
}
var j = 1.7976931348623157E+308;
var k = 1.7976931348623157E+308;
var l = -1.7976931348623157E+308;
var m = -1.7976931348623157E+308;
try {
for (var _b = __values(fromEnum(g)), _c = _b.next(); !_c.done; _c = _b.next()) {
var n = _c.value;
j = Math.min(j, n.x);
k = Math.min(k, n.y);
l = Math.max(l, n.x);
m = Math.max(m, n.y);
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_1)
throw e_1.error;
}
}
return new Rect(0, j, k, l - j, m - k);
};
GeometryUtil.c = function (a, b, c) {
var d = a.x - b.x;
var e = a.y - b.y;
var f = d * d + e * e;
var g = c * c;
return f < g;
};
GeometryUtil.r = function (a, b, c, d) {
var e = a.x - c.x;
var f = a.y - c.y;
var g = b.x - c.x;
var h = b.y - c.y;
var i = g - e;
var j = h - f;
var k = Math.sqrt(i * i + j * j);
var l = e * h - g * f;
var m = d * d;
var n = k * k;
var o = l * l;
var p = m * n - o;
if (p < 0) {
return new Tuple$2(Point_$type, Point_$type, { $type: Point_$type, x: NaN, y: NaN }, { $type: Point_$type, x: NaN, y: NaN });
}
var q = 1;
if (j < 0) {
q = -1;
}
var r = (l * j + q * i * Math.sqrt(p)) / n;
var s = (l * j - q * i * Math.sqrt(p)) / n;
var t = (-1 * l * i + Math.abs(j) * Math.sqrt(p)) / n;
var u = (-1 * l * i - Math.abs(j) * Math.sqrt(p)) / n;
return new Tuple$2(Point_$type, Point_$type, { $type: Point_$type, x: r + c.x, y: t + c.y }, { $type: Point_$type, x: s + c.x, y: u + c.y });
};
GeometryUtil.d = function (a, b, c, d) {
var e = d * d;
var f = b.x;
var g = b.y;
var h = c.x;
var i = c.y;
var j = a.x;
var k = a.y;
if (g == i) {
var l = Math.abs(g - k) < d;
var m = j >= Math.min(f, h) - d && j <= Math.max(f, h) + d;
if (l && m) {
return true;
}
else {
return false;
}
}
if (f == h) {
var n = Math.abs(f - j) < d;
var o = k >= Math.min(g, i) - d && k <= Math.max(g, i) + d;
if (n && o) {
return true;
}
else {
return false;
}
}
var p = h - f;
var q = i - g;
var r = p * p + q * q;
if (r == 0) {
return (j - f) * (j - f) + (k - g) * (k - g) < e;
}
var s = ((j - f) * p + (k - g) * q) / r;
s = s < 0 ? 0 : (s > 1 ? 1 : s);
var t = f + p * s;
var u = g + q * s;
var v = (t - j) * (t - j) + (u - k) * (u - k);
if (v < e) {
return true;
}
return false;
};
GeometryUtil.h = function (a, b, c) {
var d = b.x;
var e = b.y;
var f = c.x;
var g = c.y;
var h = a.x;
var i = a.y;
var j = f - d;
var k = g - e;
var l = j * j + k * k;
if (l == 0) {
return (h - d) * (h - d) + (i - e) * (i - e);
}
var m = ((h - d) * j + (i - e) * k) / l;
m = m < 0 ? 0 : (m > 1 ? 1 : m);
var n = d + j * m;
var o = e + k * m;
var p = (n - h) * (n - h) + (o - i) * (o - i);
return p;
};
GeometryUtil.m = function (a, b, c) {
var d = b.x;
var e = b.y;
var f = c.x;
var g = c.y;
var h = a.x;
var i = a.y;
var j = f - d;
var k = g - e;
var l = j * j + k * k;
if (l == 0) {
return 0;
}
var m = ((h - d) * j + (i - e) * k) / l;
m = m < 0 ? 0 : (m > 1 ? 1 : m);
return m;
};
GeometryUtil.e = function (a, b, c, d) {
var e;
var f;
var g = d * d;
var h = c.count;
if (h == 0) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) < g;
}
var i = a.x;
var j = a.y;
for (var k = 0; k < h; k++) {
if (k == 0) {
f = c.item(k);
e = b;
}
else {
f = c.item(k);
e = c.item(k - 1);
}
var l = e.x;
var m = e.y;
var n = f.x;
var o = f.y;
if (m == o) {
var p = Math.abs(m - j) < d;
var q = i >= Math.min(l, n) - d && i <= Math.max(l, n) + d;
if (p && q) {
return true;
}
else {
continue;
}
}
if (l == n) {
var r = Math.abs(l - i) < d;
var s = j >= Math.min(m, o) - d && j <= Math.max(m, o) + d;
if (r && s) {
return true;
}
else {
continue;
}
}
var t = n - l;
var u = o - m;
var v = t * t + u * u;
if (v == 0) {
return (i - l) * (i - l) + (j - m) * (j - m) < g;
}
var w = ((i - l) * t + (j - m) * u) / v;
w = w < 0 ? 0 : (w > 1 ? 1 : w);
var x = l + t * w;
var y = m + u * w;
var z = (x - i) * (x - i) + (y - j) * (y - j);
if (z < g) {
return true;
}
}
return false;
};
GeometryUtil.l = function (a, b, c, d) {
var e = Math.abs(Math.cos(b));
var f = Math.abs(Math.sin(b));
var g = c * 0.5;
var h = d * 0.5;
var i = e * h - f * g;
if (a * a >= i * i) {
var j = e * g + f * h + Math.sqrt(a * a - i * i);
var k = j * e - g;
var l = j * f - h;
if (k > 0 && l > 0) {
return j;
}
else if (k > 0) {
return (a + g) / e;
}
else if (l > 0) {
return (a + h) / f;
}
else {
return 0;
}
}
else {
if (i > 0) {
return (a + g) / e;
}
else if (i < 0) {
return (a + h) / f;
}
else {
return 0;
}
}
};
GeometryUtil.q = function (a, b, c, d, e, f, g) {
var h, i, j, k, l, m, n;
h = e.x - d.x;
i = e.y - d.y;
j = h * h + i * i;
k = 2 * (h * (d.x - a) + i * (d.y - b));
l = (d.x - a) * (d.x - a) + (d.y - b) * (d.y - b) - c * c;
m = k * k - 4 * j * l;
if ((j <= 1E-07) || (m < 0)) {
f = { $type: Point_$type, x: NaN, y: NaN };
g = { $type: Point_$type, x: NaN, y: NaN };
return {
ret: 0,
p5: f,
p6: g
};
}
else if (m == 0) {
n = -k / (2 * j);
f = { $type: Point_$type, x: d.x + n * h, y: d.y + n * i };
g = { $type: Point_$type, x: NaN, y: NaN };
return {
ret: 1,
p5: f,
p6: g
};
}
else {
n = ((-k + Math.sqrt(m)) / (2 * j));
f = { $type: Point_$type, x: d.x + n * h, y: d.y + n * i };
n = ((-k - Math.sqrt(m)) / (2 * j));
g = { $type: Point_$type, x: d.x + n * h, y: d.y + n * i };
return {
ret: 2,
p5: f,
p6: g
};
}
};
GeometryUtil.p = function (a, b, c, d, e, f, g) {
var h, i, j, k, l, m;
h = e.x - d.x;
i = e.y - d.y;
j = h * h + i * i;
k = 2 * (h * (d.x - a) + i * (d.y - b));
l = (d.x - a) * (d.x - a) + (d.y - b) * (d.y - b) - c * c;
m = k * k - 4 * j * l;
if ((j <= 1E-07) || (m < 0) || (m == 0)) {
f = { $type: Point_$type, x: NaN, y: NaN };
g = { $type: Point_$type, x: NaN, y: NaN };
return {
ret: 0,
p5: f,
p6: g
};
}
else {
var n = 0;
var o = ((-k + Math.sqrt(m)) / (2 * j));
var p = ((-k - Math.sqrt(m)) / (2 * j));
if (o >= 0 && o <= 1) {
n++;
f = { $type: Point_$type, x: d.x + o * h, y: d.y + o * i };
if (p >= 0 && p <= 1) {
n++;
g = { $type: Point_$type, x: d.x + p * h, y: d.y + p * i };
}
else {
g = { $type: Point_$type, x: NaN, y: NaN };
}
}
else {
g = { $type: Point_$type, x: NaN, y: NaN };
if (p >= 0 && p <= 1) {
n++;
f = { $type: Point_$type, x: d.x + p * h, y: d.y + p * i };
}
else {
f = { $type: Point_$type, x: NaN, y: NaN };
}
}
return {
ret: n,
p5: f,
p6: g
};
}
};
GeometryUtil.s = function (a, b, c, d, e) {
var f = new List$1(Point_$type, 0);
var g = { $type: Point_$type, x: a.left, y: a.bottom };
var h = { $type: Point_$type, x: a.right, y: a.bottom };
var i = { $type: Point_$type, x: a.left, y: a.top };
var j = { $type: Point_$type, x: a.right, y: a.top };
var k = c.y - a.bottom;
var l = c.y - a.top;
var m = c.x - a.left;
var n = c.x - a.right;
if (Math.sqrt(k * k + m * m) < b) {
f.add(g);
}
if (Math.sqrt(k * k + n * n) < b) {
f.add(h);
}
if (Math.sqrt(l * l + m * m) < b) {
f.add(i);
}
if (Math.sqrt(l * l + n * n) < b) {
f.add(j);
}
var o, p;
var q = ((function () { var r = GeometryUtil.p(c.x, c.y, b, g, h, o, p); o = r.p5; p = r.p6; return r.ret; })());
if (q > 0) {
f.add(o);
}
if (q > 1) {
f.add(p);
}
q = ((function () { var r = GeometryUtil.p(c.x, c.y, b, g, i, o, p); o = r.p5; p = r.p6; return r.ret; })());
if (q > 0) {
f.add(o);
}
if (q > 1) {
f.add(p);
}
q = ((function () { var r = GeometryUtil.p(c.x, c.y, b, j, i, o, p); o = r.p5; p = r.p6; return r.ret; })());
if (q > 0) {
f.add(o);
}
if (q > 1) {
f.add(p);
}
q = ((function () { var r = GeometryUtil.p(c.x, c.y, b, j, h, o, p); o = r.p5; p = r.p6; return r.ret; })());
if (q > 0) {
f.add(o);
}
if (q > 1) {
f.add(p);
}
if (f.count == 0) {
d = -1;
e = -1;
return {
p3: d,
p4: e
};
}
d = 1.7976931348623157E+308;
e = -1.7976931348623157E+308;
var r = 1.7976931348623157E+308;
var s = -1.7976931348623157E+308;
for (var t = 0; t < f.count; t++) {
var u = GeometryUtil.j(c, f._inner[t]);
if (u < d) {
d = u;
}
if (u > e) {
e = u;
}
if (u < Math.PI && u > s) {
s = u;
}
if (u > Math.PI && u < s) {
r = u;
}
}
if (e - d > Math.PI) {
d = r;
e = s;
}
return {
p3: d,
p4: e
};
};
GeometryUtil.a = function (a, b, c, d) {
var e = ((b.x - a.x) * (d.y - c.y)) - ((b.y - a.y) * (d.x - c.x));
var f = ((a.y - c.y) * (d.x - c.x)) - ((a.x - c.x) * (d.y - c.y));
var g = ((a.y - c.y) * (b.x - a.x)) - ((a.x - c.x) * (b.y - a.y));
if (e == 0) {
return f == 0 && g == 0;
}
var h = f / e;
var i = g / e;
return (h >= 0 && h <= 1) && (i >= 0 && i <= 1);
};
GeometryUtil.$t = markType(GeometryUtil, 'GeometryUtil');
return GeometryUtil;
}(Base));
export { GeometryUtil };