Skip to content

Commit

Permalink
Add type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Mar 13, 2015
1 parent 78e0772 commit f57d8d1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[ignore]
.*node_modules/flow-bin.*
.*node_modules/jsxhint.*
.*build.*

[include]
Expand Down
12 changes: 6 additions & 6 deletions src/ContigInterval.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ class ContigInterval {
}

// TODO: make these getter methods & switch to Babel.
start() {
start(): number {
return this.interval.start;
}
stop() {
stop(): number {
return this.interval.stop;
}
length() {
length(): number {
return this.interval.length();
}

intersects(other) {
return (this.contig == other.contig &&
intersects(other: ContigInterval): boolean {
return (this.contig === other.contig &&
this.interval.intersects(other.interval));
}

toString() {
toString(): string {
return `${this.contig}:${this.start()}-${this.stop()}`;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/Interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ class Interval {
}

// TODO: make this a getter method & switch to Babel.
length() {
length(): number {
return Math.max(0, this.stop - this.start + 1);
}

intersect(otherInterval) {
return new Interval(Math.max(this.start, otherInterval.start),
Math.min(this.stop, otherInterval.stop));
intersect(other: Interval): Interval {
return new Interval(Math.max(this.start, other.start),
Math.min(this.stop, other.stop));
}

intersects(otherInterval) {
return this.start <= otherInterval.stop && otherInterval.start <= this.stop;
intersects(other: Interval): boolean {
return this.start <= other.stop && other.start <= this.stop;
}

contains(value) {
contains(value: number): boolean {
return value >= this.start && value <= this.stop;
}

clone() {
clone(): Interval {
return new Interval(this.start, this.stop);
}

Expand Down Expand Up @@ -60,7 +60,7 @@ class Interval {
return result;
}

toString() {
toString(): string {
return `[${this.start}, ${this.stop}]`;
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* @flow
*/


// Compare two tuples of equal length. Is t1 <= t2?
function tupleLessOrEqual(t1, t2) {
// TODO: make this tupleLessOrEqual<T> -- it works with strings or booleans, too.
function tupleLessOrEqual(t1: Array<number>, t2: Array<number>): boolean {
if (t1.length != t2.length) throw new Error('Comparing non-equal length tuples');
for (var i = 0; i < t1.length; i++) {
if (t1[i] > t2[i]) {
Expand All @@ -17,7 +19,9 @@ function tupleLessOrEqual(t1, t2) {
}

// Do two ranges of tuples overlap?
function tupleRangeOverlaps(tupleRange1: Array, tupleRange2: Array): boolean {
// TODO: make this tupleRangeOverlaps<T> -- it works with strings or booleans, too.
function tupleRangeOverlaps(tupleRange1: Array<Array<number>>,
tupleRange2: Array<Array<number>>): boolean {
return (
// Are the ranges overlapping?
tupleLessOrEqual(tupleRange1[0], tupleRange2[1]) &&
Expand Down

0 comments on commit f57d8d1

Please sign in to comment.