/*
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 * as tslib_1 from "tslib";
import { Base, Number_$type, Point_$type, fromEnum, markType, getEnumerator } from "igniteui-react-core/ES5/type";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { Clipper } from "igniteui-react-core/ES5/Clipper";
import { AngleRadiusPair } from "./AngleRadiusPair";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { SpiralFlattener } from "igniteui-react-core/ES5/SpiralFlattener";
import { isNaN_, isInfinity } from "igniteui-react-core/ES5/number";
/**
 * @hidden
 */
var PolarLinePlanner = /** @class */ (function (_super) {
    tslib_1.__extends(PolarLinePlanner, _super);
    function PolarLinePlanner() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.f = false;
        _this.b = 0;
        _this.m = null;
        _this.n = null;
        _this.o = null;
        _this.p = null;
        _this.l = 0;
        _this.q = 0;
        _this.z = null;
        _this.aa = null;
        _this.a = null;
        _this.c = false;
        _this.d = false;
        _this.i = null;
        return _this;
    }
    Object.defineProperty(PolarLinePlanner.prototype, "ab", {
        get: function () {
            return this.z;
        },
        set: function (a) {
            this.z = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PolarLinePlanner.prototype, "ac", {
        get: function () {
            return this.aa;
        },
        set: function (a) {
            this.aa = a;
        },
        enumerable: true,
        configurable: true
    });
    PolarLinePlanner.prototype.g = function () {
        if (this.m == null || this.n == null || this.o == null || this.p == null || Rect.l_op_Equality(this.ab, Rect.empty) || Rect.l_op_Equality(this.ac, Rect.empty)) {
            return false;
        }
        return true;
    };
    PolarLinePlanner.prototype.k = function (a, b, c, d) {
        var e = a(d) - a(c);
        var f = b(d) - b(c);
        return e * e + f * f;
    };
    PolarLinePlanner.prototype.h = function (a) {
        var b = new List$1(AngleRadiusPair.$, 0);
        var c = this.l * this.l;
        var d;
        if (a != null) {
            d = a;
        }
        else {
            var e = new List$1(Number_$type, 0);
            for (var f = 0; f < this.q; f++) {
                e.add(f);
            }
            d = e;
        }
        var g = getEnumerator(d);
        var h = true;
        h = g.moveNext();
        var i = 0;
        if (h) {
            i = g.current;
        }
        while (h) {
            var j = i;
            h = g.moveNext();
            i = g.current;
            while (h && this.k(this.o, this.p, j, i) < c) {
                h = g.moveNext();
                i = g.current;
            }
            var k = new AngleRadiusPair();
            k.c = j;
            if (!this.f) {
                k.a = this.m(j);
                k.b = this.n(j);
            }
            b.add(k);
        }
        return b;
    };
    PolarLinePlanner.prototype.v = function (a) {
        var e_1, _a;
        try {
            for (var _b = tslib_1.__values(fromEnum(this.h(a))), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                if (isNaN_(b.a) || isInfinity(b.a) || isNaN_(b.b) || isInfinity(b.b)) {
                    this.s({ $type: Point_$type, x: NaN, y: NaN });
                    continue;
                }
                this.s({ $type: Point_$type, x: this.o(b.c), y: this.p(b.c) });
            }
        }
        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; }
        }
    };
    PolarLinePlanner.prototype.j = function () {
        return Math.pow(this.l / (Math.max(this.ab.width / this.ac.width, this.ab.height / this.ac.height)), 2);
    };
    PolarLinePlanner.prototype.r = function (a, b) {
        var c = 0.5 + b * Math.cos(a);
        var d = 0.5 + b * Math.sin(a);
        c = this.z.left + this.z.width * (c - this.aa.left) / this.aa.width;
        d = this.z.top + this.z.height * (d - this.aa.top) / this.aa.height;
        this.s({ $type: Point_$type, x: c, y: d });
    };
    PolarLinePlanner.prototype.y = function (a) {
        var b = this.j();
        var c = this.h(a);
        var d = c.item(0).a;
        var e = c.item(0).b;
        var f = c.item(0).c;
        for (var g = 1; g < c.count; g++) {
            var h = c.item(g).a;
            var i = c.item(g).b;
            var j = c.item(g).c;
            if (isNaN_(h) || isInfinity(h) || isNaN_(i) || isInfinity(i)) {
                this.s({ $type: Point_$type, x: NaN, y: NaN });
                if (this.b != 0) {
                    g++;
                    if (g < c.count) {
                        d = c.item(g).a;
                        e = c.item(g).b;
                    }
                }
                continue;
            }
            this.t(h, i, d, e, g, b, f > j);
            d = h;
            e = i;
            f = j;
        }
    };
    PolarLinePlanner.prototype.t = function (a, b, c, d, e, f, g) {
        var h = false;
        if ((a < c && !g) || (a > c && g)) {
            h = true;
            var i = a;
            a = c;
            c = i;
            i = b;
            b = d;
            d = i;
        }
        var j = SpiralFlattener.a(c, d, a, b, f);
        if (h) {
            var k = new List$1(Number_$type, 2, j.count);
            for (var l = j.count - 1; l >= 0; l--) {
                k.add(j._inner[l]);
            }
            j = k;
        }
        for (var m = 0; m < j.count; m++) {
            var n = j._inner[m];
            var o = c + n * (a - c);
            var p = d + n * (b - d);
            this.r(o, p);
        }
    };
    PolarLinePlanner.prototype.u = function (a) {
        var _this = this;
        var b = this.ab.top - 10;
        var c = this.ab.bottom + 10;
        var d = this.ab.left - 10;
        var e = this.ab.right + 10;
        if (this.a == null) {
            this.a = ((function () {
                var $ret = new Clipper(1, d, c, e, b, _this.d);
                $ret.i = a;
                return $ret;
            })());
        }
    };
    PolarLinePlanner.prototype.e = function (a) {
        return !isNaN_(a.x) && !isNaN_(a.y) && !isInfinity(a.x) && !isInfinity(a.y);
    };
    PolarLinePlanner.prototype.s = function (a) {
        if (this.b == 0 && !this.e(a)) {
            return;
        }
        if (this.c) {
            this.i.add(a);
        }
        else {
            this.a.j(a);
        }
    };
    PolarLinePlanner.prototype.w = function (a) {
        this.x(null, null);
    };
    PolarLinePlanner.prototype.x = function (a, b) {
        this.i = a;
        if (!this.g()) {
            return;
        }
        if (this.q > 1) {
            this.u(a);
            if (this.f) {
                this.v(b);
            }
            else {
                this.y(b);
            }
            this.a.i = null;
        }
    };
    PolarLinePlanner.$t = markType(PolarLinePlanner, 'PolarLinePlanner');
    return PolarLinePlanner;
}(Base));
export { PolarLinePlanner };
