@pilotlab/lux-types
Version:
A luxurious user experience framework, developed by your friends at Pilot.
131 lines • 5.99 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var lux_is_1 = require("@pilotlab/lux-is");
var lux_attributes_1 = require("@pilotlab/lux-attributes");
var point_1 = require("./point");
var Rectangle = (function (_super) {
__extends(Rectangle, _super);
function Rectangle(x, y, width, height) {
var _this = _super.call(this, 'Rectangle', null, lux_attributes_1.DataType.COLLECTION, null, true) || this;
_this.p_x = _this.children.set('x', lux_is_1.default.notEmpty(x) ? x : 0, lux_attributes_1.DataType.NUMBER_DOUBLE, lux_attributes_1.AttributeChangeOptions.zero).node;
_this.p_y = _this.children.set('y', lux_is_1.default.notEmpty(y) ? y : 0, lux_attributes_1.DataType.NUMBER_DOUBLE, lux_attributes_1.AttributeChangeOptions.zero).node;
_this.p_width = _this.children.set('width', lux_is_1.default.notEmpty(width) ? width : 0, lux_attributes_1.DataType.NUMBER_DOUBLE, lux_attributes_1.AttributeChangeOptions.zero).node;
_this.p_height = _this.children.set('height', lux_is_1.default.notEmpty(height) ? height : 0, lux_attributes_1.DataType.NUMBER_DOUBLE, lux_attributes_1.AttributeChangeOptions.zero).node;
return _this;
}
Object.defineProperty(Rectangle.prototype, "copy", {
get: function () { return new Rectangle(this.x, this.y, this.width, this.height); },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "x", {
get: function () { return this.p_x.value; },
set: function (value) { this.p_x.set(value, lux_attributes_1.AttributeChangeOptions.saveAndSignal.durationZero); },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "left", {
get: function () { return this.x; },
set: function (value) { this.x = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "right", {
get: function () { return this.x + this.width; },
set: function (value) { this.x = value - this.width; },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "y", {
get: function () { return this.p_y.value; },
set: function (value) { this.p_y.set(value, lux_attributes_1.AttributeChangeOptions.saveAndSignal.durationZero); },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "top", {
get: function () { return this.y; },
set: function (value) { this.y = value; },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "bottom", {
get: function () { return this.y + this.height; },
set: function (value) { this.y = value - this.height; },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "width", {
get: function () { return this.p_width.value; },
set: function (value) { this.p_width.set(value, lux_attributes_1.AttributeChangeOptions.saveAndSignal.durationZero); },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "height", {
get: function () { return this.p_height.value; },
set: function (value) { this.p_height.set(value, lux_attributes_1.AttributeChangeOptions.saveAndSignal.durationZero); },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "topLeft", {
get: function () { return new point_1.default(this.left, this.top); },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "topRight", {
get: function () { return new point_1.default(this.right, this.top); },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "bottomLeft", {
get: function () { return new point_1.default(this.left, this.bottom); },
enumerable: true,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "bottomRight", {
get: function () { return new point_1.default(this.right, this.bottom); },
enumerable: true,
configurable: true
});
Rectangle.prototype.intersects = function (rectangle) {
return !(rectangle.left > this.right
|| rectangle.right < this.left
|| rectangle.top > this.bottom
|| rectangle.bottom < this.top);
};
Rectangle.prototype.contains = function (rectangle) {
return (rectangle.left > this.left
&& rectangle.right < this.right
&& rectangle.top > this.top
&& rectangle.bottom < this.bottom);
};
Rectangle.prototype.canFit = function (rectangle) {
return (this.width >= rectangle.width
&& this.height >= rectangle.height);
};
Object.defineProperty(Rectangle, "empty", {
get: function () {
var rectangle = new Rectangle();
rectangle.x = null;
rectangle.y = null;
rectangle.width = null;
rectangle.height = null;
return rectangle;
},
enumerable: true,
configurable: true
});
return Rectangle;
}(lux_attributes_1.Attribute));
exports.Rectangle = Rectangle;
exports.default = Rectangle;
//# sourceMappingURL=rectangle.js.map