UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

28 lines (27 loc) 782 B
import { lerp } from './math'; export class NumberRange { start; end; constructor(start, end) { if (start > end) { throw new Error('Invalid range: start bound must be less than or equal to end bound.'); } this.start = start; this.end = end; } getSize() { return this.end - this.start; } lerp(alpha) { return lerp(this.start, this.end, alpha); } includes(value) { return value >= this.start && value <= this.end; } contains(range) { return this.includes(range.start) && this.includes(range.end); } overlaps(range) { return (this.includes(range.start) || this.includes(range.end) || range.includes(this.start) || range.includes(this.end)); } }