@teselagen/range-utils 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -0
- package/flipContainedRange.d.ts +1 -1
- package/index.cjs +2619 -0
- package/index.d.ts +52 -51
- package/index.js +1791 -6100
- package/index.umd.cjs +2623 -0
- package/package.json +2 -3
- package/src/adjustRangeToDeletionOfAnotherRange.test.js +166 -105
- package/src/adjustRangeToInsert.js +29 -26
- package/src/adjustRangeToInsert.test.js +197 -109
- package/src/adjustRangeToRotation.js +4 -5
- package/src/adjustRangeToRotation.test.js +203 -119
- package/src/checkIfNonCircularRangesOverlap.js +18 -15
- package/src/checkIfNonCircularRangesOverlap.test.js +67 -42
- package/src/checkIfPotentiallyCircularRangesOverlap.js +22 -12
- package/src/checkIfPotentiallyCircularRangesOverlap.test.js +115 -70
- package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.js +72 -41
- package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.js +183 -84
- package/src/convertRangeIndices.js +24 -20
- package/src/convertRangeIndices.test.js +40 -21
- package/src/convertRangeTo0Based.js +7 -4
- package/src/convertRangeTo1Based.js +8 -4
- package/src/doesRangeSpanEntireSequence.js +4 -4
- package/src/doesRangeSpanOrigin.js +3 -3
- package/src/expandOrContractCircularRangeToPosition.js +45 -38
- package/src/expandOrContractNonCircularRangeToPosition.js +24 -21
- package/src/expandOrContractRangeByLength.js +16 -11
- package/src/expandOrContractRangeByLength.test.js +109 -71
- package/src/expandOrContractRangeToPosition.js +17 -9
- package/src/flipContainedRange.js +133 -72
- package/src/flipContainedRange.test.js +143 -117
- package/src/generateRandomRange.js +17 -15
- package/src/generateRandomRange.test.js +21 -21
- package/src/getAnnotationRangeType.js +25 -21
- package/src/getAnnotationRangeType.test.js +56 -57
- package/src/getEachPositionInRangeAsArray.js +13 -13
- package/src/getEachPositionInRangeAsArray.test.js +12 -8
- package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.js +16 -8
- package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.test.js +32 -24
- package/src/getMiddleOfRange.js +1 -1
- package/src/getMiddleOfRange.test.js +5 -13
- package/src/getOverlapOfNonCircularRanges.js +30 -30
- package/src/getOverlapsOfPotentiallyCircularRanges.js +5 -5
- package/src/getOverlapsOfPotentiallyCircularRanges.test.js +3 -23
- package/src/getPositionFromAngle.js +12 -7
- package/src/getRangeAngles.js +1 -1
- package/src/getRangeAngles.test.js +10 -11
- package/src/getRangeLength.test.js +5 -5
- package/src/getRangesBetweenTwoRanges.js +31 -22
- package/src/getSequenceWithinRange.js +13 -13
- package/src/getSequenceWithinRange.test.js +43 -45
- package/src/getShortestDistanceBetweenTwoPositions.js +10 -6
- package/src/getShortestDistanceBetweenTwoPositions.test.js +11 -13
- package/src/getYOffsetForPotentiallyCircularRange.js +33 -21
- package/src/getYOffsetsForPotentiallyCircularRanges.js +26 -19
- package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -29
- package/src/getZeroedRangeOverlaps.js +30 -15
- package/src/getZeroedRangeOverlaps.test.js +75 -36
- package/src/index.js +52 -51
- package/src/index.test.js +6 -8
- package/src/invertRange.test.js +103 -93
- package/src/isPositionCloserToRangeStartThanRangeEnd.js +18 -6
- package/src/isPositionCloserToRangeStartThanRangeEnd.test.js +36 -16
- package/src/isPositionWithinRange.js +4 -4
- package/src/isRangeOrPositionWithinRange.js +18 -12
- package/src/isRangeOrPositionWithinRange.test.js +6 -6
- package/src/isRangeWithinRange.js +2 -3
- package/src/loopEachPositionInRange.js +3 -3
- package/src/modulatePositionByRange.js +8 -8
- package/src/modulatePositionByRange.test.js +10 -11
- package/src/modulateRangeBySequenceLength.js +7 -7
- package/src/modulateRangeBySequenceLength.test.js +39 -16
- package/src/normalizePositionByRangeLength.js +22 -18
- package/src/normalizePositionByRangeLength.test.js +23 -23
- package/src/normalizePositionByRangeLength1Based.js +7 -4
- package/src/normalizePositionByRangeLength1Based.test.js +9 -9
- package/src/normalizeRange.js +7 -7
- package/src/normalizeRange.test.js +9 -9
- package/src/provideInclusiveOptions.js +36 -23
- package/src/reversePositionInRange.js +16 -12
- package/src/splitRangeIntoTwoPartsIfItIsCircular.js +31 -28
- package/src/splitRangeIntoTwoPartsIfItIsCircular.test.js +22 -11
- package/src/translateRange.js +18 -8
- package/src/translateRange.test.js +18 -19
- package/src/trimAnnStartEndToFitSeqLength.js +9 -0
- package/src/trimAnnStartEndToFitSeqLength.test.js +35 -0
- package/src/trimNonCicularRangeByAnotherNonCircularRange.js +45 -42
- package/src/trimNumberToFitWithin0ToAnotherNumber.js +13 -10
- package/src/trimRangeByAnotherRange.js +20 -19
- package/src/trimRangeByAnotherRange.test.js +6 -6
- package/src/zeroSubrangeByContainerRange.js +29 -19
- package/src/zeroSubrangeByContainerRange.test.js +57 -47
- package/trimAnnStartEndToFitSeqLength.d.ts +1 -0
- package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
- package/index.mjs +0 -6928
- package/index.umd.js +0 -6932
@@ -1,59 +1,58 @@
|
|
1
|
-
import getAnnotationRangeType from
|
2
|
-
import chai from
|
1
|
+
import getAnnotationRangeType from "./getAnnotationRangeType";
|
2
|
+
import chai from "chai";
|
3
3
|
chai.should();
|
4
4
|
|
5
|
-
describe(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
});
|
5
|
+
describe("getAnnotationRangeType", function () {
|
6
|
+
it("should get the correct sub range type give a sub range and its enclosing range", function () {
|
7
|
+
getAnnotationRangeType(
|
8
|
+
{ start: 4, end: 7 },
|
9
|
+
{ start: 4, end: 7 },
|
10
|
+
true
|
11
|
+
).should.equal("beginningAndEnd");
|
12
|
+
getAnnotationRangeType(
|
13
|
+
{ start: 4, end: 7 },
|
14
|
+
{ start: 4, end: 7 },
|
15
|
+
false
|
16
|
+
).should.equal("beginningAndEnd");
|
17
|
+
getAnnotationRangeType(
|
18
|
+
{ start: 4, end: 7 },
|
19
|
+
{ start: 4, end: 8 },
|
20
|
+
true
|
21
|
+
).should.equal("start");
|
22
|
+
getAnnotationRangeType(
|
23
|
+
{ start: 4, end: 7 },
|
24
|
+
{ start: 4, end: 8 },
|
25
|
+
false
|
26
|
+
).should.equal("end");
|
27
|
+
getAnnotationRangeType(
|
28
|
+
{ start: 4, end: 7 },
|
29
|
+
{ start: 3, end: 8 },
|
30
|
+
true
|
31
|
+
).should.equal("middle");
|
32
|
+
getAnnotationRangeType(
|
33
|
+
{ start: 4, end: 7 },
|
34
|
+
{ start: 3, end: 8 },
|
35
|
+
false
|
36
|
+
).should.equal("middle");
|
37
|
+
getAnnotationRangeType(
|
38
|
+
{ start: 4, end: 7 },
|
39
|
+
{ start: 3, end: 1 },
|
40
|
+
true
|
41
|
+
).should.equal("middle");
|
42
|
+
getAnnotationRangeType(
|
43
|
+
{ start: 4, end: 7 },
|
44
|
+
{ start: 3, end: 2 },
|
45
|
+
false
|
46
|
+
).should.equal("middle");
|
47
|
+
getAnnotationRangeType(
|
48
|
+
{ start: 4, end: 7 },
|
49
|
+
{ start: 4, end: 1 },
|
50
|
+
true
|
51
|
+
).should.equal("start");
|
52
|
+
getAnnotationRangeType(
|
53
|
+
{ start: 4, end: 7 },
|
54
|
+
{ start: 9, end: 7 },
|
55
|
+
false
|
56
|
+
).should.equal("start");
|
57
|
+
});
|
58
|
+
});
|
@@ -1,15 +1,15 @@
|
|
1
|
-
import normalizePositionByRangeLength from
|
2
|
-
import getRangeLength from
|
1
|
+
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
2
|
+
import getRangeLength from "./getRangeLength";
|
3
3
|
|
4
4
|
export default function getEachPositionInRangeAsArray(range, rangeMax) {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
5
|
+
const output = [];
|
6
|
+
const length = getRangeLength(range, rangeMax);
|
7
|
+
if (!(length > 0)) {
|
8
|
+
return output;
|
9
|
+
}
|
10
|
+
for (let i = range.start; i < length + range.start; i++) {
|
11
|
+
const position = normalizePositionByRangeLength(i, rangeMax);
|
12
|
+
output.push(position);
|
13
|
+
}
|
14
|
+
return output;
|
15
|
+
}
|
@@ -1,9 +1,13 @@
|
|
1
|
-
import getEachPositionInRangeAsArray from
|
2
|
-
import {expect} from
|
1
|
+
import getEachPositionInRangeAsArray from "./getEachPositionInRangeAsArray";
|
2
|
+
import { expect } from "chai";
|
3
3
|
|
4
|
-
describe(
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
describe("getEachPositionInRangeAsArray", function () {
|
5
|
+
it("should correctly determine whether a position is within a range", function () {
|
6
|
+
expect(
|
7
|
+
getEachPositionInRangeAsArray({ start: 1, end: 10 }, 30)
|
8
|
+
).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
9
|
+
expect(
|
10
|
+
getEachPositionInRangeAsArray({ start: 10, end: 5 }, 13)
|
11
|
+
).to.deep.equal([10, 11, 12, 0, 1, 2, 3, 4, 5]);
|
12
|
+
});
|
13
|
+
});
|
@@ -1,9 +1,17 @@
|
|
1
|
-
import getRangeLength from
|
2
|
-
import getOverlapsOfPotentiallyCircularRanges from
|
1
|
+
import getRangeLength from "./getRangeLength";
|
2
|
+
import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCircularRanges";
|
3
3
|
|
4
|
-
export default function getLengthOfOverlappingRegionsBetweenTwoRanges(
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
export default function getLengthOfOverlappingRegionsBetweenTwoRanges(
|
5
|
+
rangeA,
|
6
|
+
rangeB,
|
7
|
+
maxLength
|
8
|
+
) {
|
9
|
+
const overlaps = getOverlapsOfPotentiallyCircularRanges(
|
10
|
+
rangeA,
|
11
|
+
rangeB,
|
12
|
+
maxLength
|
13
|
+
);
|
14
|
+
return overlaps.reduce(function (counter, overlap) {
|
15
|
+
return counter + getRangeLength(overlap, maxLength);
|
16
|
+
}, 0);
|
17
|
+
}
|
@@ -1,24 +1,32 @@
|
|
1
|
-
import assert from
|
2
|
-
import getLengthOfOverlappingRegionsBetweenTwoRanges from
|
3
|
-
describe(
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
import assert from "assert";
|
2
|
+
import getLengthOfOverlappingRegionsBetweenTwoRanges from "./getLengthOfOverlappingRegionsBetweenTwoRanges";
|
3
|
+
describe("getLengthOfOverlappingRegionsBetweenTwoRanges", function () {
|
4
|
+
it("should get the length of the overlaps in a simple case", function () {
|
5
|
+
const length = getLengthOfOverlappingRegionsBetweenTwoRanges(
|
6
|
+
{
|
7
|
+
start: 4,
|
8
|
+
end: 8
|
9
|
+
},
|
10
|
+
{
|
11
|
+
start: 5,
|
12
|
+
end: 10
|
13
|
+
},
|
14
|
+
20
|
15
|
+
);
|
16
|
+
assert.equal(length, 4);
|
17
|
+
});
|
18
|
+
it("should get the length of the overlaps", function () {
|
19
|
+
const length = getLengthOfOverlappingRegionsBetweenTwoRanges(
|
20
|
+
{
|
21
|
+
start: 4,
|
22
|
+
end: 8
|
23
|
+
},
|
24
|
+
{
|
25
|
+
start: 7,
|
26
|
+
end: 5
|
27
|
+
},
|
28
|
+
20
|
29
|
+
);
|
30
|
+
assert.equal(length, 4);
|
31
|
+
});
|
32
|
+
});
|
package/src/getMiddleOfRange.js
CHANGED
@@ -10,35 +10,27 @@
|
|
10
10
|
import assert from "assert";
|
11
11
|
|
12
12
|
import getMiddleOfRange from "./getMiddleOfRange";
|
13
|
-
describe("getMiddleOfRange", function() {
|
14
|
-
it("should return the correct length for ranges that cross the origin", function() {
|
13
|
+
describe("getMiddleOfRange", function () {
|
14
|
+
it("should return the correct length for ranges that cross the origin", function () {
|
15
15
|
const midpoint = getMiddleOfRange({ start: 9, end: 0 }, 10);
|
16
|
-
console.log(`midpoint:`,midpoint)
|
17
16
|
assert(midpoint === 0);
|
18
|
-
|
19
17
|
});
|
20
|
-
it("should return the correct midpoint for ranges that do not cross the origin", function() {
|
18
|
+
it("should return the correct midpoint for ranges that do not cross the origin", function () {
|
21
19
|
const midpoint = getMiddleOfRange({ start: 4, end: 6 }, 10);
|
22
|
-
console.log(`midpoint:`,midpoint)
|
23
20
|
assert(midpoint === 5);
|
24
|
-
|
25
21
|
});
|
26
|
-
it("should return the correct midpoint for ranges that overlapSelf", function() {
|
22
|
+
it("should return the correct midpoint for ranges that overlapSelf", function () {
|
27
23
|
const midpoint = getMiddleOfRange(
|
28
24
|
{ start: 4, end: 9, overlapsSelf: true },
|
29
25
|
10
|
30
26
|
);
|
31
|
-
console.log(`midpoint:`,midpoint)
|
32
27
|
assert(midpoint === 7);
|
33
|
-
|
34
28
|
});
|
35
|
-
it("should return the correct midpoint for ranges that overlapSelf and origin", function() {
|
29
|
+
it("should return the correct midpoint for ranges that overlapSelf and origin", function () {
|
36
30
|
const midpoint = getMiddleOfRange(
|
37
31
|
{ start: 9, end: 1, overlapsSelf: true },
|
38
32
|
10
|
39
33
|
);
|
40
|
-
console.log(`midpoint:`,midpoint)
|
41
34
|
assert(midpoint === 0);
|
42
|
-
|
43
35
|
});
|
44
36
|
});
|
@@ -1,35 +1,35 @@
|
|
1
1
|
export default function getOverlapOfNonCircularRanges(rangeA, rangeB) {
|
2
|
-
|
3
|
-
|
2
|
+
if (rangeA.start < rangeB.start) {
|
3
|
+
if (rangeA.end < rangeB.start) {
|
4
4
|
//no overlap
|
5
|
-
} else {
|
6
|
-
if (rangeA.end < rangeB.end) {
|
7
|
-
return {
|
8
|
-
start: rangeB.start,
|
9
|
-
end: rangeA.end
|
10
|
-
};
|
11
|
-
} else {
|
12
|
-
return {
|
13
|
-
start: rangeB.start,
|
14
|
-
end: rangeB.end
|
15
|
-
};
|
16
|
-
}
|
17
|
-
}
|
18
5
|
} else {
|
19
|
-
|
6
|
+
if (rangeA.end < rangeB.end) {
|
7
|
+
return {
|
8
|
+
start: rangeB.start,
|
9
|
+
end: rangeA.end
|
10
|
+
};
|
11
|
+
} else {
|
12
|
+
return {
|
13
|
+
start: rangeB.start,
|
14
|
+
end: rangeB.end
|
15
|
+
};
|
16
|
+
}
|
17
|
+
}
|
18
|
+
} else {
|
19
|
+
if (rangeA.start > rangeB.end) {
|
20
20
|
//no overlap
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
21
|
+
} else {
|
22
|
+
if (rangeA.end < rangeB.end) {
|
23
|
+
return {
|
24
|
+
start: rangeA.start,
|
25
|
+
end: rangeA.end
|
26
|
+
};
|
27
|
+
} else {
|
28
|
+
return {
|
29
|
+
start: rangeA.start,
|
30
|
+
end: rangeB.end
|
31
|
+
};
|
32
|
+
}
|
34
33
|
}
|
35
|
-
}
|
34
|
+
}
|
35
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {flatMap} from "lodash";
|
1
|
+
import { flatMap } from "lodash-es";
|
2
2
|
import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
|
3
3
|
import getOverlapOfNonCircularRanges from "./getOverlapOfNonCircularRanges";
|
4
4
|
|
@@ -20,8 +20,8 @@ export default function getOverlapsOfPotentiallyCircularRanges(
|
|
20
20
|
|
21
21
|
let overlaps = [];
|
22
22
|
|
23
|
-
normalizedRangeA.forEach(function(nonCircularRangeA
|
24
|
-
normalizedRangeB.forEach(function(nonCircularRangeB
|
23
|
+
normalizedRangeA.forEach(function (nonCircularRangeA) {
|
24
|
+
normalizedRangeB.forEach(function (nonCircularRangeB) {
|
25
25
|
const overlap = getOverlapOfNonCircularRanges(
|
26
26
|
nonCircularRangeA,
|
27
27
|
nonCircularRangeB
|
@@ -39,7 +39,7 @@ export default function getOverlapsOfPotentiallyCircularRanges(
|
|
39
39
|
) {
|
40
40
|
//we have 2 circular ranges that will have gotten split on the origin, so we'll manually mend those pieces back together
|
41
41
|
const joinedOverlap = {};
|
42
|
-
overlaps = flatMap(overlaps,
|
42
|
+
overlaps = flatMap(overlaps, o => {
|
43
43
|
if (o.start === 0) {
|
44
44
|
joinedOverlap.end = o.end;
|
45
45
|
return [];
|
@@ -51,4 +51,4 @@ export default function getOverlapsOfPotentiallyCircularRanges(
|
|
51
51
|
overlaps.push(joinedOverlap);
|
52
52
|
}
|
53
53
|
return overlaps;
|
54
|
-
}
|
54
|
+
}
|
@@ -2,8 +2,8 @@ import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCi
|
|
2
2
|
|
3
3
|
import assert from "assert";
|
4
4
|
|
5
|
-
describe("getOverlapsOfPotentiallyCircularRanges", function() {
|
6
|
-
it("doesnt return an overlap for non overlapping ranges", function() {
|
5
|
+
describe("getOverlapsOfPotentiallyCircularRanges", function () {
|
6
|
+
it("doesnt return an overlap for non overlapping ranges", function () {
|
7
7
|
assert.deepEqual(
|
8
8
|
getOverlapsOfPotentiallyCircularRanges(
|
9
9
|
{
|
@@ -19,7 +19,7 @@ describe("getOverlapsOfPotentiallyCircularRanges", function() {
|
|
19
19
|
[]
|
20
20
|
);
|
21
21
|
});
|
22
|
-
it("does return overlaps for overlapping ranges", function() {
|
22
|
+
it("does return overlaps for overlapping ranges", function () {
|
23
23
|
assert.deepEqual(
|
24
24
|
getOverlapsOfPotentiallyCircularRanges(
|
25
25
|
{
|
@@ -155,26 +155,6 @@ describe("getOverlapsOfPotentiallyCircularRanges", function() {
|
|
155
155
|
}
|
156
156
|
]
|
157
157
|
);
|
158
|
-
console.log(
|
159
|
-
`getOverlapsOfPotentiallyCircularRanges({
|
160
|
-
start: 5,
|
161
|
-
end: 3
|
162
|
-
}, {
|
163
|
-
start: 5,
|
164
|
-
end: 3
|
165
|
-
}, 10):`,
|
166
|
-
getOverlapsOfPotentiallyCircularRanges(
|
167
|
-
{
|
168
|
-
start: 5,
|
169
|
-
end: 3
|
170
|
-
},
|
171
|
-
{
|
172
|
-
start: 5,
|
173
|
-
end: 3
|
174
|
-
},
|
175
|
-
10
|
176
|
-
)
|
177
|
-
);
|
178
158
|
assert.deepEqual(
|
179
159
|
getOverlapsOfPotentiallyCircularRanges(
|
180
160
|
{
|
@@ -1,7 +1,12 @@
|
|
1
|
-
export default function getPositionFromAngle(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
export default function getPositionFromAngle(
|
2
|
+
angle,
|
3
|
+
rangeMax,
|
4
|
+
isInBetweenPositions
|
5
|
+
) {
|
6
|
+
//percent through sequence * rangeMax
|
7
|
+
const unroundedPostion = (angle / Math.PI / 2) * rangeMax;
|
8
|
+
//return either the nearest position, or the nearest "inBetween" postion
|
9
|
+
return isInBetweenPositions
|
10
|
+
? Math.round(unroundedPostion)
|
11
|
+
: Math.floor(unroundedPostion);
|
12
|
+
}
|
package/src/getRangeAngles.js
CHANGED
@@ -13,7 +13,7 @@ export default function getRangeAngles(range, rangeMax) {
|
|
13
13
|
centerAngle: startAngle + totalAngle / 2,
|
14
14
|
locationAngles:
|
15
15
|
range.locations &&
|
16
|
-
range.locations.map(
|
16
|
+
range.locations.map(location => {
|
17
17
|
return getRangeAngles(location, rangeMax);
|
18
18
|
})
|
19
19
|
};
|
@@ -9,24 +9,24 @@
|
|
9
9
|
import getRangeAngles from "./getRangeAngles";
|
10
10
|
|
11
11
|
import assert from "assert";
|
12
|
-
describe("getRangeAngles", function() {
|
12
|
+
describe("getRangeAngles", function () {
|
13
13
|
//tnrtodo set this up
|
14
14
|
|
15
|
-
it("should return the correct angles for ranges that have joined locations", function() {
|
15
|
+
it("should return the correct angles for ranges that have joined locations", function () {
|
16
16
|
const angles = getRangeAngles(
|
17
17
|
{
|
18
18
|
start: 1,
|
19
19
|
end: 6,
|
20
20
|
locations: [
|
21
21
|
{ start: 1, end: 2 },
|
22
|
-
{ start: 3, end: 6 }
|
23
|
-
]
|
22
|
+
{ start: 3, end: 6 }
|
23
|
+
]
|
24
24
|
},
|
25
25
|
10
|
26
26
|
);
|
27
27
|
// console.log('angles: ' + JSON.stringify(angles,null,4));
|
28
28
|
const anglesInRadians = {};
|
29
|
-
Object.keys(angles).forEach(function(key) {
|
29
|
+
Object.keys(angles).forEach(function (key) {
|
30
30
|
anglesInRadians[key] = (angles[key] * 360) / Math.PI / 2;
|
31
31
|
});
|
32
32
|
|
@@ -37,7 +37,7 @@ describe("getRangeAngles", function() {
|
|
37
37
|
angles.locationAngles &&
|
38
38
|
angles.locationAngles.forEach((angles, i) => {
|
39
39
|
const anglesInRadians = {};
|
40
|
-
Object.keys(angles).forEach(function(key) {
|
40
|
+
Object.keys(angles).forEach(function (key) {
|
41
41
|
anglesInRadians[key] = (angles[key] * 360) / Math.PI / 2;
|
42
42
|
});
|
43
43
|
// console.log('anglesInRadians:',anglesInRadians)
|
@@ -47,13 +47,12 @@ describe("getRangeAngles", function() {
|
|
47
47
|
assert((anglesInRadians.endAngle === i) === 0 ? 108 : 252);
|
48
48
|
assert((anglesInRadians.totalAngle === i) === 0 ? 72 : 144);
|
49
49
|
});
|
50
|
-
|
51
50
|
});
|
52
|
-
it("should return the correct angles for ranges that cross the origin", function() {
|
51
|
+
it("should return the correct angles for ranges that cross the origin", function () {
|
53
52
|
const angles = getRangeAngles({ start: 9, end: 0 }, 10);
|
54
53
|
// console.log('angles: ' + JSON.stringify(angles,null,4));
|
55
54
|
const anglesInRadians = {};
|
56
|
-
Object.keys(angles).forEach(function(key) {
|
55
|
+
Object.keys(angles).forEach(function (key) {
|
57
56
|
anglesInRadians[key] = (angles[key] * 360) / Math.PI / 2;
|
58
57
|
});
|
59
58
|
assert(anglesInRadians.startAngle === 324);
|
@@ -61,11 +60,11 @@ describe("getRangeAngles", function() {
|
|
61
60
|
assert(anglesInRadians.totalAngle === 72);
|
62
61
|
// console.log('anglesInRadians: ' + JSON.stringify(anglesInRadians,null,4));
|
63
62
|
});
|
64
|
-
it("should return the correct angles for ranges that do not cross the origin", function() {
|
63
|
+
it("should return the correct angles for ranges that do not cross the origin", function () {
|
65
64
|
const angles = getRangeAngles({ start: 1, end: 2, overlapsSelf: true }, 10);
|
66
65
|
// console.log('angles: ' + JSON.stringify(angles,null,4));
|
67
66
|
const anglesInRadians = {};
|
68
|
-
Object.keys(angles).forEach(function(key) {
|
67
|
+
Object.keys(angles).forEach(function (key) {
|
69
68
|
anglesInRadians[key] = (angles[key] * 360) / Math.PI / 2;
|
70
69
|
});
|
71
70
|
// console.log('anglesInRadians: ' + JSON.stringify(anglesInRadians,null,4));
|
@@ -10,20 +10,20 @@
|
|
10
10
|
import assert from "assert";
|
11
11
|
|
12
12
|
import getRangeLength from "./getRangeLength";
|
13
|
-
describe("getRangeLength", function() {
|
14
|
-
it("should return the correct length for ranges that cross the origin", function() {
|
13
|
+
describe("getRangeLength", function () {
|
14
|
+
it("should return the correct length for ranges that cross the origin", function () {
|
15
15
|
const length = getRangeLength({ start: 9, end: 0 }, 10);
|
16
16
|
assert(length === 2);
|
17
17
|
});
|
18
|
-
it("should return the correct length for ranges that do not cross the origin", function() {
|
18
|
+
it("should return the correct length for ranges that do not cross the origin", function () {
|
19
19
|
const length = getRangeLength({ start: 4, end: 6 }, 10);
|
20
20
|
assert(length === 3);
|
21
21
|
});
|
22
|
-
it("should return the correct length for ranges that overlapSelf", function() {
|
22
|
+
it("should return the correct length for ranges that overlapSelf", function () {
|
23
23
|
const length = getRangeLength({ start: 4, end: 6, overlapsSelf: true }, 10);
|
24
24
|
assert(length === 13);
|
25
25
|
});
|
26
|
-
it("should return the correct length for ranges that overlapSelf and origin", function() {
|
26
|
+
it("should return the correct length for ranges that overlapSelf and origin", function () {
|
27
27
|
const length = getRangeLength({ start: 9, end: 1, overlapsSelf: true }, 10);
|
28
28
|
assert(length === 13);
|
29
29
|
});
|
@@ -1,28 +1,37 @@
|
|
1
1
|
export default function getRangesBetweenTwoRanges(range1, range2) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
// {
|
3
|
+
// start: 85,
|
4
|
+
// end: 92
|
5
|
+
// }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
// {
|
8
|
+
// start: 130,
|
9
|
+
// end: 189
|
10
|
+
// }
|
11
11
|
|
12
|
-
|
12
|
+
// start1 - end2
|
13
13
|
|
14
|
-
|
14
|
+
// start2 - end1
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
const newRanges = [];
|
17
|
+
if (
|
18
|
+
!(
|
19
|
+
range1.start > -1 &&
|
20
|
+
range1.end > -1 &&
|
21
|
+
range2.start > -1 &&
|
22
|
+
range2.end > -1
|
23
|
+
)
|
24
|
+
) {
|
25
|
+
return newRanges;
|
26
|
+
}
|
27
|
+
return [
|
28
|
+
{
|
29
|
+
start: range1.start,
|
30
|
+
end: range2.end
|
31
|
+
},
|
32
|
+
{
|
33
|
+
start: range2.start,
|
34
|
+
end: range1.end
|
19
35
|
}
|
20
|
-
|
21
|
-
|
22
|
-
end: range2.end,
|
23
|
-
},{
|
24
|
-
start: range2.start,
|
25
|
-
end: range1.end,
|
26
|
-
}]
|
27
|
-
};
|
28
|
-
|
36
|
+
];
|
37
|
+
}
|