/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ //import { * } as _ from '_'; import _ = require('underscore'); export class Rect { public right: number; public bottom: number; public get height(): number { return this.bottom - this.top; } public get width(): number { return this.right - this.left; } constructor(public left: number, public top: number, width: number, height: number) { this.right = left + width; this.bottom = top + height; } public offsetRect(offset: any): Rect { if (!offset) { return this; } var offsetObject = { left: this.isPercent(offset[0]) ? (parseFloat(offset[0]) * this.width) : offset[0], top: this.isPercent(offset[1]) ? (parseFloat(offset[1]) * this.height) : offset[1], right: this.isPercent(offset[2]) ? (parseFloat(offset[2]) * this.width) : offset[2], bottom: this.isPercent(offset[3]) ? (parseFloat(offset[3]) * this.height) : offset[3] }; return new Rect(this.left - offsetObject.left, this.top - offsetObject.top, this.width + offsetObject.left + offsetObject.right, this.height + offsetObject.top + offsetObject.bottom); } private isPercent(n: any): boolean { return _.isString(n) && n.indexOf('%') > 0; } public intersectRect(otherRect: Rect): boolean { return !(otherRect.left > this.right || otherRect.right < this.left || otherRect.top > this.bottom || otherRect.bottom < this.top); } }