/*
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 { Base, markType } from "igniteui-react-core/ES2015/type";
import { IDetectsCollisions_$type } from "./IDetectsCollisions";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { Rect } from "igniteui-react-core/ES2015/Rect";
/**
 * @hidden
 */
export class CollisionAvoider extends Base {
    constructor() {
        super();
        this.a = new List$1(Rect.$, 0);
    }
    tryAdd(a) {
        for (let 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((c, d) => Math.sign(c.right - d.right));
        }
        return true;
    }
    clear() {
        this.a.clear();
    }
}
CollisionAvoider.$t = markType(CollisionAvoider, 'CollisionAvoider', Base.$, [IDetectsCollisions_$type]);
