/*
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 { IDetectsCollisions_$type } from "./IDetectsCollisions";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { Base, markType } from "igniteui-react-core/ES5/type";
var CollisionAvoider = /** @class */ (function (_super) {
    tslib_1.__extends(CollisionAvoider, _super);
    function CollisionAvoider() {
        var _this = _super.call(this) || this;
        _this.a = new List$1(Rect.$, 0);
        return _this;
    }
    CollisionAvoider.prototype.tryAdd = function (a) {
        for (var b = this.a.count - 1; b >= 0; --b) {
            if (a.left > this.a._inner[b].right) {
                break;
            }
            if (this.a._inner[b].intersectsWith(a)) {
                return false;
            }
        }
        if (this.a.count == 0 || a.right >= this.a._inner[this.a.count - 1].right) {
            this.a.add(a);
        }
        else {
            this.a.add(a);
            this.a.aa(function (c, d) { return Math.sign(c.right - d.right); });
        }
        return true;
    };
    CollisionAvoider.prototype.clear = function () {
        this.a.clear();
    };
    CollisionAvoider.$t = markType(CollisionAvoider, 'CollisionAvoider', Base.$, [IDetectsCollisions_$type]);
    return CollisionAvoider;
}(Base));
export { CollisionAvoider };
