UNPKG

@rickosborne/rebound

Version:

Rick Osborne's utilities for working with bounded numbers

35 lines (34 loc) 1.43 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { NumberRange } from "./number-range.mjs"; const _RealRange = class _RealRange extends NumberRange { discreteIntegers = void 0; step = Number.MIN_VALUE; constructor(isLowerInc, lower, upper, isUpperInc) { super(isLowerInc, lower, false, upper, isUpperInc); } scaleValueFrom(value, other) { if (this.isSingleton) { return this.isLowerInc ? this.lower : this.upper; } super.assertCanScaleFrom(other); if (other.discreteIntegers != null) { const units = other.discreteIntegers + (this.isLowerInc && this.isUpperInc ? -1 : 0); const divisor = (this.upper - this.lower) / units; const inset = this.isLowerInc ? 0 : this.isUpperInc ? divisor : divisor / 2; const percent = (value - other.lower) / units; return this.lower + inset + percent * (this.upper - this.lower); } if (this.isLowerInc !== other.isLowerInc || this.isUpperInc !== other.isUpperInc) { throw new RangeError(`Incompatible bounds for scaling: ${this.label} vs ${other.label}`); } const factor = (this.upper - this.lower) / (other.upper - other.lower); return (value - other.lower) * factor + this.lower; } }; __name(_RealRange, "RealRange"); let RealRange = _RealRange; export { RealRange }; //# sourceMappingURL=real-range.mjs.map