/*
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 "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { BezierPoint } from "./BezierPoint";
import { Stack$1 } from "igniteui-angular-core";
import { BezierOp } from "./BezierOp";
import { CompareUtil } from "igniteui-angular-core";
/**
 * @hidden
 */
var Bezier = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Bezier, _super);
    function Bezier(a, b, c, d, e, f) {
        var _this = _super.call(this) || this;
        _this.h = 0;
        _this.m = null;
        _this.n = null;
        _this.o = null;
        _this.p = null;
        _this.i = 1.7976931348623157E+308;
        _this.d = false;
        _this.e = null;
        _this.f = null;
        _this.g = new Stack$1(BezierOp.$);
        _this.m = a;
        _this.n = b;
        _this.o = c;
        _this.p = d;
        _this.h = e;
        _this.i = f;
        _this.d = _this.c();
        return _this;
    }
    Object.defineProperty(Bezier.prototype, "j", {
        get: function () {
            return this.h;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Bezier.prototype, "q", {
        get: function () {
            return this.m;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Bezier.prototype, "r", {
        get: function () {
            return this.n;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Bezier.prototype, "s", {
        get: function () {
            return this.o;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Bezier.prototype, "t", {
        get: function () {
            return this.p;
        },
        enumerable: false,
        configurable: true
    });
    Bezier.prototype.a = function (a) {
        var b = 1 - a;
        var c = b * b;
        var d = c * b;
        var e = a * a;
        var f = e * a;
        var g = { $type: Point_$type, x: d * this.m.x + 3 * c * a * this.n.x + 3 * b * e * this.o.x + f * this.p.x, y: d * this.m.y + 3 * c * a * this.n.y + 3 * b * e * this.o.y + f * this.p.y };
        var h = new BezierPoint();
        h.c = g;
        h.a = a;
        return h;
    };
    Bezier.prototype.c = function () {
        var e_1, _a;
        this.e = new List$1(BezierPoint.$, 0);
        this.f = new List$1(BezierPoint.$, 0);
        var a = new BezierOp();
        a.b = 0;
        a.a = 1;
        this.g.g();
        this.g.h(a);
        var b = 0;
        while (this.g.f > 0) {
            var c = this.g.e();
            var d = this.a(c.b);
            var e = this.a(c.a);
            var f = (e.c.x - d.c.x) * (e.c.x - d.c.x) + (e.c.y - d.c.y) * (e.c.y - d.c.y);
            if (f < this.h) {
                d.b = b++;
                e.b = b++;
                this.e.add(d);
                this.e.add(e);
                if (d.c.x > this.i || e.c.x > this.i) {
                    return false;
                }
            }
            else {
                var g = (c.b + c.a) / 2;
                var h = new BezierOp();
                h.b = c.b;
                h.a = g;
                var i = new BezierOp();
                i.b = g;
                i.a = c.a;
                this.g.h(i);
                this.g.h(h);
            }
        }
        try {
            for (var _b = __values(fromEnum(this.e)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var j = _c.value;
                this.f.add(j);
            }
        }
        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;
            }
        }
        this.l();
        return true;
    };
    Bezier.prototype.l = function () {
        this.f.aa(function (a, b) { return CompareUtil.compareToObject(a.c.y, b.c.y); });
    };
    Bezier.prototype.b = function (a) {
        var b = this.k(function (c) {
            if (a < c.c.y) {
                return -1;
            }
            if (a > c.c.y) {
                return 1;
            }
            return 0;
        });
        if (b < 0) {
            b = ~b;
        }
        if (b < 0) {
            b = 0;
        }
        if (b > this.f.count - 1) {
            b = this.f.count - 1;
        }
        var c = 100000001;
        var d = 100000000;
        var e = 100000002;
        d = Math.abs(this.f._inner[b].c.y - a);
        if (b - 1 >= 0) {
            c = Math.abs(this.f._inner[b - 1].c.y - a);
        }
        if (b + 1 < this.f.count) {
            e = Math.abs(this.f._inner[b + 1].c.y - a);
        }
        if (d <= c && d <= e) {
            return this.f._inner[b];
        }
        if (c <= d && c <= e && b - 1 > 0) {
            return this.f._inner[b - 1];
        }
        if (e <= c && e <= d && b + 1 < this.f.count) {
            return this.f._inner[b + 1];
        }
        return this.f._inner[b];
    };
    Bezier.prototype.k = function (a) {
        var b = 0;
        var c = this.f.count - 1;
        while (b <= c) {
            var d = (b + ((c - b) >> 1));
            var e = a(this.f._inner[d]);
            if (e < 0) {
                c = d - 1;
            }
            else if (e > 0) {
                b = d + 1;
            }
            else {
                return d;
            }
        }
        return ~b;
    };
    Bezier.$t = markType(Bezier, 'Bezier');
    return Bezier;
}(Base));
export { Bezier };
//# sourceMappingURL=Bezier.js.map
