UNPKG

math-interval-2

Version:

Create math intervals like '(-∞, 100]' and test values

136 lines 4.55 kB
"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 Bound = /** @class */ (function () { function Bound(value) { this.endpoint = value; } Bound.lowerClosedBound = function (endpoint) { return new LowerClosedBound(endpoint); }; Bound.lowerOpenBound = function (endpoint) { return new LowerOpenBound(endpoint); }; Bound.upperClosedBound = function (endpoint) { return new UpperClosedBound(endpoint); }; Bound.upperOpenBound = function (endpoint) { return new UpperOpenBound(endpoint); }; Bound.prototype.equals = function (other) { return this.endpoint === other.endpoint && this.closed === other.closed; }; return Bound; }()); exports.Bound = Bound; var LowerBound = /** @class */ (function (_super) { __extends(LowerBound, _super); function LowerBound() { return _super !== null && _super.apply(this, arguments) || this; } LowerBound.prototype.compareTo = function (other) { // TODO: throw if not isinsteaceof? if (this.endpoint === other.endpoint) { return this.closed ? 1 : -1; } else { return this.endpoint < other.endpoint ? 1 : -1; } }; return LowerBound; }(Bound)); var UpperBound = /** @class */ (function (_super) { __extends(UpperBound, _super); function UpperBound() { return _super !== null && _super.apply(this, arguments) || this; } UpperBound.prototype.compareTo = function (other) { // TODO: throw if not isinsteaceof? if (this.endpoint === other.endpoint) { return this.closed ? 1 : -1; } else { return this.endpoint > other.endpoint ? 1 : -1; } }; return UpperBound; }(Bound)); var LowerClosedBound = /** @class */ (function (_super) { __extends(LowerClosedBound, _super); function LowerClosedBound() { return _super !== null && _super.apply(this, arguments) || this; } LowerClosedBound.prototype.test = function (n) { return n >= this.endpoint; }; Object.defineProperty(LowerClosedBound.prototype, "closed", { get: function () { return true; }, enumerable: true, configurable: true }); return LowerClosedBound; }(LowerBound)); var LowerOpenBound = /** @class */ (function (_super) { __extends(LowerOpenBound, _super); function LowerOpenBound() { return _super !== null && _super.apply(this, arguments) || this; } LowerOpenBound.prototype.test = function (n) { return n > this.endpoint; }; Object.defineProperty(LowerOpenBound.prototype, "closed", { get: function () { return false; }, enumerable: true, configurable: true }); return LowerOpenBound; }(LowerBound)); var UpperClosedBound = /** @class */ (function (_super) { __extends(UpperClosedBound, _super); function UpperClosedBound() { return _super !== null && _super.apply(this, arguments) || this; } UpperClosedBound.prototype.test = function (n) { return n <= this.endpoint; }; Object.defineProperty(UpperClosedBound.prototype, "closed", { get: function () { return true; }, enumerable: true, configurable: true }); return UpperClosedBound; }(UpperBound)); var UpperOpenBound = /** @class */ (function (_super) { __extends(UpperOpenBound, _super); function UpperOpenBound() { return _super !== null && _super.apply(this, arguments) || this; } UpperOpenBound.prototype.test = function (n) { return n < this.endpoint; }; Object.defineProperty(UpperOpenBound.prototype, "closed", { get: function () { return false; }, enumerable: true, configurable: true }); return UpperOpenBound; }(UpperBound)); //# sourceMappingURL=/home/travis/build/harunurhan/math-interval/src/bound.js.map