"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SRect = void 0; var SPoint_1 = require("./SPoint"); var SSize_1 = require("./SSize"); var SRect = (function () { function SRect(x, y, width, height) { if (x == undefined) { this.leftTop = new SPoint_1.SPoint(0, 0); this.size = new SSize_1.SSize(0, 0); } else if (x instanceof SPoint_1.SPoint && y instanceof SPoint_1.SPoint) { this.leftTop = new SPoint_1.SPoint(x.x, x.y); this.size = new SSize_1.SSize(y.x - x.x, y.y - x.y); } else if (x instanceof SPoint_1.SPoint && y instanceof SSize_1.SSize) { this.leftTop = new SPoint_1.SPoint(x.x, x.y); this.size = new SSize_1.SSize(y.width, y.height); } else { this.leftTop = new SPoint_1.SPoint(x, y); this.size = new SSize_1.SSize(width, height); } } Object.defineProperty(SRect.prototype, "x", { get: function () { return this.leftTop.x; }, set: function (value) { this.leftTop.x = value; }, enumerable: false, configurable: true }); Object.defineProperty(SRect.prototype, "y", { get: function () { return this.leftTop.y; }, set: function (value) { this.leftTop.y = value; }, enumerable: false, configurable: true }); Object.defineProperty(SRect.prototype, "width", { get: function () { return this.size.width; }, set: function (v) { this.size.width = v; }, enumerable: false, configurable: true }); Object.defineProperty(SRect.prototype, "height", { get: function () { return this.size.height; }, set: function (v) { this.size.height = v; }, enumerable: false, configurable: true }); Object.defineProperty(SRect.prototype, "left", { get: function () { return this.leftTop.x; }, set: function (v) { this.leftTop.x = v; }, enumerable: false, configurable: true }); Object.defineProperty(SRect.prototype, "top", { get: function () { return this.y; }, set: function (v) { this.y = v; }, enumerable: false, configurable: true }); Object.defineProperty(SRect.prototype, "right", { get: function () { return this.x + this.width; }, set: function (right) { this.width = right - this.x; }, enumerable: false, configurable: true }); Object.defineProperty(SRect.prototype, "bottom", { get: function () { return this.y + this.height; }, set: function (value) { this.height = value - this.y; }, enumerable: false, configurable: true }); SRect.prototype.isEmpty = function () { return this.size.isEmpty(); }; SRect.prototype.isNull = function () { return this.size.isNull(); }; SRect.prototype.isValid = function () { return this.size.isValid(); }; SRect.prototype.isIn = function (rect) { return (this.left <= rect.left && this.right >= rect.right && this.bottom >= rect.bottom && this.top <= rect.top); }; SRect.prototype.contains = function (x, y) { return (x >= this.left && x <= this.right && y >= this.top && y <= this.bottom); }; SRect.prototype.center = function () { return new SPoint_1.SPoint(this.x + this.width / 2.0, this.y + this.height / 2.0); }; SRect.prototype.translate = function (dx, dy) { this.x += dx; this.y += dy; }; SRect.prototype.translated = function (dx, dy) { return new SRect(this.x + dx, this.y + dy, this.width, this.height); }; SRect.prototype.adjust = function (dx, dy, dw, dh) { this.x += dx; this.y += dy; this.width += dw; this.height += dh; }; SRect.prototype.adjusted = function (dx, dy, dw, dh) { return new SRect(this.x + dx, this.y + dy, this.width + dw, this.height + dh); }; SRect.prototype.union = function (rect) { var r = this.unioned(rect); this.x = r.x; this.y = r.y; this.width = r.width; this.height = r.height; }; SRect.prototype.unioned = function (rect) { var left = Math.min(this.left, rect.left); var top = Math.min(this.top, rect.top); var right = Math.max(this.right, rect.right); var bottom = Math.max(this.bottom, rect.bottom); return new SRect(left, top, right - left, bottom - top); }; SRect.prototype.intersected = function (rect) { var minX = this.left < rect.left ? this.left : rect.left; var minY = this.top < rect.top ? this.top : rect.top; var maxX = this.right > rect.right ? this.right : rect.right; var maxY = this.bottom > rect.bottom ? this.bottom : rect.bottom; if (this.width + rect.width > maxX - minX && this.height + rect.height > maxY - minY) { return new SRect(); } return new SRect(); }; SRect.prototype.intersect = function (rect) { var left = Math.min(this.left, rect.left); var top = Math.min(this.top, rect.top); var right = Math.max(this.right, rect.right); var bottom = Math.max(this.bottom, rect.bottom); return new SRect(left, top, right - left, bottom - top); }; return SRect; }()); exports.SRect = SRect;