all files / diagram/primitives/ rect.js

100% Statements 93/93
100% Branches 38/38
100% Functions 24/24
100% Lines 92/92
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179   5147930× 5147930× 5147930× 5147930× 5147930× 3576676× 3576676×     1571254× 970×   1571254× 714×     5147930× 5147930× 5147930× 5147930×     19476639×           19527952×           10877952×           11541865×           644493×           644242×           644084×           644086×           965222×           965274×           966455×           1189193×           647699×         32908×   729832× 729832× 729832× 729832× 729832× 729832× 729832×   6693341× 1706424× 1706424× 1706424×   4986917× 4986917× 4986917× 4986917× 4986917× 4986917× 4986917× 4986917×   41513× 41513× 41513× 41513× 41513×   143801× 111294×   32507×   661×   2533336× 2533336×     1706424× 1706424× 6693341× 6693341×   1706424×        
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Rect = (function () {
        function Rect(x, y, width, height) {
            this.x = Number.MAX_VALUE;
            this.y = Number.MAX_VALUE;
            this.width = 0;
            this.height = 0;
            if (x === undefined || y === undefined) {
                x = y = Number.MAX_VALUE;
                width = height = 0;
            }
            else {
                if (width === undefined) {
                    width = 0;
                }
                if (height === undefined) {
                    height = 0;
                }
            }
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
        }
        Object.defineProperty(Rect.prototype, "left", {
            get: function () {
                return this.x;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "right", {
            get: function () {
                return this.x + this.width;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "top", {
            get: function () {
                return this.y;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "bottom", {
            get: function () {
                return this.y + this.height;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "topLeft", {
            get: function () {
                return { x: this.left, y: this.top };
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "topRight", {
            get: function () {
                return { x: this.right, y: this.top };
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "bottomLeft", {
            get: function () {
                return { x: this.left, y: this.bottom };
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "bottomRight", {
            get: function () {
                return { x: this.right, y: this.bottom };
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "middleLeft", {
            get: function () {
                return { x: this.left, y: this.y + this.height / 2 };
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "middleRight", {
            get: function () {
                return { x: this.right, y: this.y + this.height / 2 };
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "topCenter", {
            get: function () {
                return { x: this.x + this.width / 2, y: this.top };
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "bottomCenter", {
            get: function () {
                return { x: this.x + this.width / 2, y: this.bottom };
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Rect.prototype, "center", {
            get: function () {
                return { x: this.x + this.width / 2, y: this.y + this.height / 2 };
            },
            enumerable: true,
            configurable: true
        });
        Rect.prototype.equals = function (rect1, rect2) {
            return rect1.x === rect2.x && rect1.y === rect2.y && rect1.width === rect2.width && rect1.height === rect2.height;
        };
        Rect.prototype.uniteRect = function (rect) {
            var right = Math.max(isNaN(this.right) || this.x === Number.MAX_VALUE ? rect.right : this.right, rect.right);
            var bottom = Math.max(isNaN(this.bottom) || this.y === Number.MAX_VALUE ? rect.bottom : this.bottom, rect.bottom);
            this.x = Math.min(this.left, rect.left);
            this.y = Math.min(this.top, rect.top);
            this.width = right - this.x;
            this.height = bottom - this.y;
            return this;
        };
        Rect.prototype.unitePoint = function (point) {
            if (this.x === Number.MAX_VALUE) {
                this.x = point.x;
                this.y = point.y;
                return;
            }
            var x = Math.min(this.left, point.x);
            var y = Math.min(this.top, point.y);
            var right = Math.max(this.right, point.x);
            var bottom = Math.max(this.bottom, point.y);
            this.x = x;
            this.y = y;
            this.width = right - this.x;
            this.height = bottom - this.y;
        };
        Rect.prototype.Inflate = function (padding) {
            this.x -= padding;
            this.y -= padding;
            this.width += padding * 2;
            this.height += padding * 2;
            return this;
        };
        Rect.prototype.intersects = function (rect) {
            if (this.right < rect.left || this.left > rect.right || this.top > rect.bottom || this.bottom < rect.top) {
                return false;
            }
            return true;
        };
        Rect.prototype.containsRect = function (rect) {
            return this.left <= rect.left && this.right >= rect.right && this.top <= rect.top && this.bottom >= rect.bottom;
        };
        Rect.prototype.containsPoint = function (point, padding) {
            if (padding === void 0) { padding = 0; }
            return this.left - padding <= point.x && this.right + padding >= point.x
                && this.top - padding <= point.y && this.bottom + padding >= point.y;
        };
        Rect.toBounds = function (points) {
            var rect = new Rect();
            for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
                var pt = points_1[_i];
                rect.unitePoint(pt);
            }
            return rect;
        };
        Rect.empty = new Rect(Number.MAX_VALUE, Number.MIN_VALUE, 0, 0);
        return Rect;
    }());
    exports.Rect = Rect;
});