@teselagen/range-utils 0.3.7 → 0.3.8
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.js +233 -85
- package/index.mjs +233 -85
- package/index.umd.js +233 -85
- package/package.json +1 -2
- 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 +51 -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/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/src/index.js
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
export { default as adjustRangeToDeletionOfAnotherRange } from
|
2
|
-
export { default as adjustRangeToInsert } from
|
3
|
-
export { default as checkIfNonCircularRangesOverlap } from
|
4
|
-
export { default as checkIfPotentiallyCircularRangesOverlap } from
|
5
|
-
export { default as collapseOverlapsGeneratedFromRangeComparisonIfPossible } from
|
6
|
-
export { default as convertRangeIndices } from
|
7
|
-
export { default as convertRangeTo0Based } from
|
8
|
-
export { default as convertRangeTo1Based } from
|
9
|
-
export { default as doesRangeSpanEntireSequence } from
|
10
|
-
export { default as isRangeOrPositionWithinRange } from
|
11
|
-
export { default as doesRangeSpanOrigin } from
|
12
|
-
export { default as expandOrContractCircularRangeToPosition } from
|
13
|
-
export { default as expandOrContractNonCircularRangeToPosition } from
|
14
|
-
export { default as expandOrContractRangeByLength } from
|
15
|
-
export { default as expandOrContractRangeToPosition } from
|
16
|
-
export { default as flipContainedRange } from
|
17
|
-
export { default as generateRandomRange } from
|
18
|
-
export { default as getAnnotationRangeType } from
|
19
|
-
export { default as getEachPositionInRangeAsArray } from
|
20
|
-
export { default as getLengthOfOverlappingRegionsBetweenTwoRanges } from
|
21
|
-
export { default as getOverlapOfNonCircularRanges } from
|
22
|
-
export { default as getOverlapsOfPotentiallyCircularRanges } from
|
23
|
-
export { default as getPositionFromAngle } from
|
24
|
-
export { default as getRangeAngles } from
|
25
|
-
export { default as getRangeLength } from
|
26
|
-
export { default as getMiddleOfRange } from
|
27
|
-
export { default as getRangesBetweenTwoRanges } from
|
28
|
-
export { default as getSequenceWithinRange } from
|
29
|
-
export { default as getShortestDistanceBetweenTwoPositions } from
|
30
|
-
export { default as getYOffsetForPotentiallyCircularRange } from
|
31
|
-
export { default as getYOffsetsForPotentiallyCircularRanges } from
|
32
|
-
export { default as invertRange } from
|
33
|
-
export { default as isPositionCloserToRangeStartThanRangeEnd } from
|
34
|
-
export { default as isPositionWithinRange } from
|
35
|
-
export { default as isRangeWithinRange } from
|
36
|
-
export { default as loopEachPositionInRange } from
|
37
|
-
export { default as modulatePositionByRange } from
|
38
|
-
export { default as modulateRangeBySequenceLength } from
|
39
|
-
export { default as normalizePositionByRangeLength } from
|
40
|
-
export { default as normalizePositionByRangeLength1Based } from
|
41
|
-
export { default as normalizeRange } from
|
42
|
-
export { default as provideInclusiveOptions } from
|
43
|
-
export { default as reversePositionInRange } from
|
44
|
-
export { default as splitRangeIntoTwoPartsIfItIsCircular } from
|
45
|
-
export { default as translateRange } from
|
46
|
-
export { default as trimNonCicularRangeByAnotherNonCircularRange } from
|
47
|
-
export { default as trimNumberToFitWithin0ToAnotherNumber } from
|
48
|
-
export { default as trimRangeByAnotherRange } from
|
49
|
-
export { default as zeroSubrangeByContainerRange } from
|
50
|
-
export { default as adjustRangeToRotation } from
|
51
|
-
export { default as getZeroedRangeOverlaps } from
|
1
|
+
export { default as adjustRangeToDeletionOfAnotherRange } from "./adjustRangeToDeletionOfAnotherRange";
|
2
|
+
export { default as adjustRangeToInsert } from "./adjustRangeToInsert";
|
3
|
+
export { default as checkIfNonCircularRangesOverlap } from "./checkIfNonCircularRangesOverlap";
|
4
|
+
export { default as checkIfPotentiallyCircularRangesOverlap } from "./checkIfPotentiallyCircularRangesOverlap";
|
5
|
+
export { default as collapseOverlapsGeneratedFromRangeComparisonIfPossible } from "./collapseOverlapsGeneratedFromRangeComparisonIfPossible";
|
6
|
+
export { default as convertRangeIndices } from "./convertRangeIndices";
|
7
|
+
export { default as convertRangeTo0Based } from "./convertRangeTo0Based";
|
8
|
+
export { default as convertRangeTo1Based } from "./convertRangeTo1Based";
|
9
|
+
export { default as doesRangeSpanEntireSequence } from "./doesRangeSpanEntireSequence";
|
10
|
+
export { default as isRangeOrPositionWithinRange } from "./isRangeOrPositionWithinRange";
|
11
|
+
export { default as doesRangeSpanOrigin } from "./doesRangeSpanOrigin";
|
12
|
+
export { default as expandOrContractCircularRangeToPosition } from "./expandOrContractCircularRangeToPosition";
|
13
|
+
export { default as expandOrContractNonCircularRangeToPosition } from "./expandOrContractNonCircularRangeToPosition";
|
14
|
+
export { default as expandOrContractRangeByLength } from "./expandOrContractRangeByLength";
|
15
|
+
export { default as expandOrContractRangeToPosition } from "./expandOrContractRangeToPosition";
|
16
|
+
export { default as flipContainedRange } from "./flipContainedRange";
|
17
|
+
export { default as generateRandomRange } from "./generateRandomRange";
|
18
|
+
export { default as getAnnotationRangeType } from "./getAnnotationRangeType";
|
19
|
+
export { default as getEachPositionInRangeAsArray } from "./getEachPositionInRangeAsArray";
|
20
|
+
export { default as getLengthOfOverlappingRegionsBetweenTwoRanges } from "./getLengthOfOverlappingRegionsBetweenTwoRanges";
|
21
|
+
export { default as getOverlapOfNonCircularRanges } from "./getOverlapOfNonCircularRanges";
|
22
|
+
export { default as getOverlapsOfPotentiallyCircularRanges } from "./getOverlapsOfPotentiallyCircularRanges";
|
23
|
+
export { default as getPositionFromAngle } from "./getPositionFromAngle";
|
24
|
+
export { default as getRangeAngles } from "./getRangeAngles";
|
25
|
+
export { default as getRangeLength } from "./getRangeLength";
|
26
|
+
export { default as getMiddleOfRange } from "./getMiddleOfRange";
|
27
|
+
export { default as getRangesBetweenTwoRanges } from "./getRangesBetweenTwoRanges";
|
28
|
+
export { default as getSequenceWithinRange } from "./getSequenceWithinRange";
|
29
|
+
export { default as getShortestDistanceBetweenTwoPositions } from "./getShortestDistanceBetweenTwoPositions";
|
30
|
+
export { default as getYOffsetForPotentiallyCircularRange } from "./getYOffsetForPotentiallyCircularRange";
|
31
|
+
export { default as getYOffsetsForPotentiallyCircularRanges } from "./getYOffsetsForPotentiallyCircularRanges";
|
32
|
+
export { default as invertRange } from "./invertRange";
|
33
|
+
export { default as isPositionCloserToRangeStartThanRangeEnd } from "./isPositionCloserToRangeStartThanRangeEnd";
|
34
|
+
export { default as isPositionWithinRange } from "./isPositionWithinRange";
|
35
|
+
export { default as isRangeWithinRange } from "./isRangeWithinRange";
|
36
|
+
export { default as loopEachPositionInRange } from "./loopEachPositionInRange";
|
37
|
+
export { default as modulatePositionByRange } from "./modulatePositionByRange";
|
38
|
+
export { default as modulateRangeBySequenceLength } from "./modulateRangeBySequenceLength";
|
39
|
+
export { default as normalizePositionByRangeLength } from "./normalizePositionByRangeLength";
|
40
|
+
export { default as normalizePositionByRangeLength1Based } from "./normalizePositionByRangeLength1Based";
|
41
|
+
export { default as normalizeRange } from "./normalizeRange";
|
42
|
+
export { default as provideInclusiveOptions } from "./provideInclusiveOptions";
|
43
|
+
export { default as reversePositionInRange } from "./reversePositionInRange";
|
44
|
+
export { default as splitRangeIntoTwoPartsIfItIsCircular } from "./splitRangeIntoTwoPartsIfItIsCircular";
|
45
|
+
export { default as translateRange } from "./translateRange";
|
46
|
+
export { default as trimNonCicularRangeByAnotherNonCircularRange } from "./trimNonCicularRangeByAnotherNonCircularRange";
|
47
|
+
export { default as trimNumberToFitWithin0ToAnotherNumber } from "./trimNumberToFitWithin0ToAnotherNumber";
|
48
|
+
export { default as trimRangeByAnotherRange } from "./trimRangeByAnotherRange";
|
49
|
+
export { default as zeroSubrangeByContainerRange } from "./zeroSubrangeByContainerRange";
|
50
|
+
export { default as adjustRangeToRotation } from "./adjustRangeToRotation";
|
51
|
+
export { default as getZeroedRangeOverlaps } from "./getZeroedRangeOverlaps";
|
package/src/index.test.js
CHANGED
@@ -3,15 +3,11 @@ import fs from "fs";
|
|
3
3
|
|
4
4
|
describe("index.js", () => {
|
5
5
|
it(`should export all functions defined`, () => {
|
6
|
-
return new Promise(
|
7
|
-
|
6
|
+
return new Promise(resolve => {
|
8
7
|
fs.readdir(__dirname, (err, files) => {
|
9
8
|
let passes = true;
|
10
9
|
files.forEach(file => {
|
11
|
-
if (
|
12
|
-
file.indexOf(".test.js") > -1 ||
|
13
|
-
file.indexOf("index.js") > -1
|
14
|
-
) {
|
10
|
+
if (file.indexOf(".test.js") > -1 || file.indexOf("index.js") > -1) {
|
15
11
|
return;
|
16
12
|
}
|
17
13
|
const funcOrObj = src[file.replace(".js", "")];
|
@@ -24,10 +20,12 @@ describe("index.js", () => {
|
|
24
20
|
}
|
25
21
|
});
|
26
22
|
if (!passes) {
|
27
|
-
throw new Error(
|
23
|
+
throw new Error(
|
24
|
+
"Please make sure to export (or ignore) each file! Update index.js to export the file"
|
25
|
+
);
|
28
26
|
}
|
29
27
|
resolve();
|
30
28
|
});
|
31
|
-
})
|
29
|
+
});
|
32
30
|
});
|
33
31
|
});
|
package/src/invertRange.test.js
CHANGED
@@ -1,96 +1,106 @@
|
|
1
|
-
|
2
|
-
import
|
3
|
-
import chai from 'chai';
|
1
|
+
import invertRange from "./invertRange";
|
2
|
+
import chai from "chai";
|
4
3
|
chai.should();
|
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
|
-
|
60
|
-
|
61
|
-
|
4
|
+
describe("invertRange", function () {
|
5
|
+
it("should invert a non-circular range", function () {
|
6
|
+
const invertedRange = invertRange({ start: 2, end: 2 }, 10);
|
7
|
+
invertedRange.start.should.equal(3);
|
8
|
+
invertedRange.end.should.equal(1);
|
9
|
+
});
|
10
|
+
it("should invert a non-circular range", function () {
|
11
|
+
const invertedRange = invertRange({ start: 0, end: 2 }, 10);
|
12
|
+
invertedRange.start.should.equal(3);
|
13
|
+
invertedRange.end.should.equal(9);
|
14
|
+
});
|
15
|
+
it("should invert a non-circular range", function () {
|
16
|
+
const invertedRange = invertRange({ start: 0, end: 9 }, 10);
|
17
|
+
invertedRange.start.should.equal(0);
|
18
|
+
invertedRange.end.should.equal(9);
|
19
|
+
});
|
20
|
+
it("should invert a non-circular range", function () {
|
21
|
+
const invertedRange = invertRange({ start: 4, end: 9 }, 10);
|
22
|
+
invertedRange.start.should.equal(0);
|
23
|
+
invertedRange.end.should.equal(3);
|
24
|
+
});
|
25
|
+
it("should invert a circular range", function () {
|
26
|
+
const invertedRange = invertRange({ start: 3, end: 1 }, 10);
|
27
|
+
invertedRange.start.should.equal(2);
|
28
|
+
invertedRange.end.should.equal(2);
|
29
|
+
});
|
30
|
+
it("should invert a circular range", function () {
|
31
|
+
const invertedRange = invertRange({ start: 9, end: 1 }, 10);
|
32
|
+
invertedRange.start.should.equal(2);
|
33
|
+
invertedRange.end.should.equal(8);
|
34
|
+
});
|
35
|
+
it("should invert a circular range", function () {
|
36
|
+
const invertedRange = invertRange({ start: 3, end: 0 }, 10);
|
37
|
+
invertedRange.start.should.equal(1);
|
38
|
+
invertedRange.end.should.equal(2);
|
39
|
+
});
|
40
|
+
it("should handle inverting a whole range by returning the original range", function () {
|
41
|
+
const invertedRange = invertRange({ start: 4, end: 3 }, 10);
|
42
|
+
invertedRange.start.should.equal(4);
|
43
|
+
invertedRange.end.should.equal(3);
|
44
|
+
});
|
45
|
+
it("should handle inverting a caret position", function () {
|
46
|
+
const invertedRange = invertRange(1, 10);
|
47
|
+
invertedRange.start.should.equal(1);
|
48
|
+
invertedRange.end.should.equal(0);
|
49
|
+
});
|
50
|
+
it("should handle inverting a caret position", function () {
|
51
|
+
const invertedRange = invertRange(0, 10);
|
52
|
+
invertedRange.start.should.equal(0);
|
53
|
+
invertedRange.end.should.equal(9);
|
54
|
+
});
|
55
|
+
//tnrtodo: maybe one day we'll want to handle the "entire range" case in a special way, but for now we'll just return the original range
|
56
|
+
// it('should handle inverting a whole range by setting the start and end to -1', function () {
|
57
|
+
// var invertedRange = invertRange({start: 4, end:3}, 10);
|
58
|
+
// invertedRange.start.should.equal(-1)
|
59
|
+
// invertedRange.end.should.equal(-1)
|
60
|
+
// });
|
62
61
|
});
|
63
|
-
describe(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
62
|
+
describe("invertRange should handle options inclusive1BasedEnd or inclusive1BasedStart", function () {
|
63
|
+
it("should handle inverting a whole range by returning the original range", function () {
|
64
|
+
const options = { inclusive1BasedEnd: true };
|
65
|
+
const invertedRange = invertRange({ start: 2, end: 2 }, 10, options);
|
66
|
+
invertedRange.start.should.equal(2);
|
67
|
+
invertedRange.end.should.equal(2);
|
68
|
+
});
|
69
|
+
it("should invert a non-circular range", function () {
|
70
|
+
const options = { inclusive1BasedEnd: true };
|
71
|
+
const invertedRange = invertRange({ start: 0, end: 2 }, 10, options);
|
72
|
+
invertedRange.start.should.equal(2);
|
73
|
+
invertedRange.end.should.equal(10);
|
74
|
+
});
|
75
|
+
it("should invert non-circular range 1", function () {
|
76
|
+
const invertedRange = invertRange({ start: 0, end: 9 }, 10, {
|
77
|
+
inclusive1BasedEnd: true
|
78
|
+
});
|
79
|
+
invertedRange.start.should.equal(9);
|
80
|
+
invertedRange.end.should.equal(10);
|
81
|
+
});
|
82
|
+
it("should invert a non-circular range 2", function () {
|
83
|
+
const invertedRange = invertRange({ start: 1, end: 9 }, 10, {
|
84
|
+
inclusive1BasedEnd: true,
|
85
|
+
inclusive1BasedStart: true
|
86
|
+
});
|
87
|
+
invertedRange.start.should.equal(10);
|
88
|
+
invertedRange.end.should.equal(10);
|
89
|
+
});
|
90
|
+
it("should invert a non-circular range 3", function () {
|
91
|
+
const invertedRange = invertRange({ start: 3, end: 6 }, 10, {
|
92
|
+
inclusive1BasedEnd: true,
|
93
|
+
inclusive1BasedStart: true
|
94
|
+
});
|
95
|
+
invertedRange.start.should.equal(7);
|
96
|
+
invertedRange.end.should.equal(2);
|
97
|
+
});
|
98
|
+
it("should invert a circular range 4", function () {
|
99
|
+
const invertedRange = invertRange({ start: 6, end: 3 }, 10, {
|
100
|
+
inclusive1BasedEnd: true,
|
101
|
+
inclusive1BasedStart: true
|
102
|
+
});
|
103
|
+
invertedRange.start.should.equal(4);
|
104
|
+
invertedRange.end.should.equal(5);
|
105
|
+
});
|
96
106
|
});
|
@@ -1,8 +1,20 @@
|
|
1
1
|
//function to calculate whether a position is closer to the range start than the range end
|
2
|
-
import getShortestDistanceBetweenTwoPositions from
|
2
|
+
import getShortestDistanceBetweenTwoPositions from "./getShortestDistanceBetweenTwoPositions";
|
3
3
|
|
4
|
-
export default function isPositionCloserToRangeStartThanRangeEnd(
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
export default function isPositionCloserToRangeStartThanRangeEnd(
|
5
|
+
position,
|
6
|
+
range,
|
7
|
+
maxLength
|
8
|
+
) {
|
9
|
+
const distanceFromStart = getShortestDistanceBetweenTwoPositions(
|
10
|
+
range.start,
|
11
|
+
position,
|
12
|
+
maxLength
|
13
|
+
);
|
14
|
+
const distanceFromEnd = getShortestDistanceBetweenTwoPositions(
|
15
|
+
range.end,
|
16
|
+
position,
|
17
|
+
maxLength
|
18
|
+
);
|
19
|
+
return distanceFromStart <= distanceFromEnd;
|
20
|
+
}
|
@@ -1,17 +1,37 @@
|
|
1
|
-
import isPositionCloserToRangeStartThanRangeEnd from
|
2
|
-
import {expect} from
|
1
|
+
import isPositionCloserToRangeStartThanRangeEnd from "./isPositionCloserToRangeStartThanRangeEnd";
|
2
|
+
import { expect } from "chai";
|
3
3
|
|
4
|
-
describe(
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
4
|
+
describe("isPositionCloserToRangeStartThanRangeEnd", function () {
|
5
|
+
it("should correctly determine whether a position is closer to the start of a range than the end", function () {
|
6
|
+
expect(
|
7
|
+
isPositionCloserToRangeStartThanRangeEnd(0, { start: 1, end: 10 }, 100)
|
8
|
+
).to.equal(true);
|
9
|
+
expect(
|
10
|
+
isPositionCloserToRangeStartThanRangeEnd(1, { start: 0, end: 10 }, 100)
|
11
|
+
).to.equal(true);
|
12
|
+
expect(
|
13
|
+
isPositionCloserToRangeStartThanRangeEnd(11, { start: 1, end: 10 }, 100)
|
14
|
+
).to.equal(false);
|
15
|
+
expect(
|
16
|
+
isPositionCloserToRangeStartThanRangeEnd(0, { start: 0, end: 10 }, 100)
|
17
|
+
).to.equal(true);
|
18
|
+
expect(
|
19
|
+
isPositionCloserToRangeStartThanRangeEnd(10, { start: 0, end: 10 }, 100)
|
20
|
+
).to.equal(false);
|
21
|
+
expect(
|
22
|
+
isPositionCloserToRangeStartThanRangeEnd(10, { start: 10, end: 5 }, 100)
|
23
|
+
).to.equal(true);
|
24
|
+
expect(
|
25
|
+
isPositionCloserToRangeStartThanRangeEnd(11, { start: 10, end: 5 }, 100)
|
26
|
+
).to.equal(true);
|
27
|
+
expect(
|
28
|
+
isPositionCloserToRangeStartThanRangeEnd(4, { start: 10, end: 5 }, 100)
|
29
|
+
).to.equal(false);
|
30
|
+
expect(
|
31
|
+
isPositionCloserToRangeStartThanRangeEnd(5, { start: 10, end: 5 }, 100)
|
32
|
+
).to.equal(false);
|
33
|
+
expect(
|
34
|
+
isPositionCloserToRangeStartThanRangeEnd(6, { start: 10, end: 5 }, 100)
|
35
|
+
).to.equal(false);
|
36
|
+
});
|
37
|
+
});
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
|
2
2
|
/**
|
3
|
-
*
|
3
|
+
*
|
4
4
|
* @param {*} position //assumed to be a 0 based "caretPosition"
|
5
5
|
* @param {*} range //0 based inclusive range
|
6
|
-
* @param {*} sequenceLength
|
7
|
-
* @param {*} includeEdges - (default false) whether or not to say
|
6
|
+
* @param {*} sequenceLength
|
7
|
+
* @param {*} includeEdges - (default false) whether or not to say
|
8
8
|
*/
|
9
9
|
function isPositionWithinRange(
|
10
10
|
position,
|
@@ -14,7 +14,7 @@ function isPositionWithinRange(
|
|
14
14
|
includeEndEdge
|
15
15
|
) {
|
16
16
|
const ranges = splitRangeIntoTwoPartsIfItIsCircular(range, sequenceLength);
|
17
|
-
const positionFits = ranges.some(function(range) {
|
17
|
+
const positionFits = ranges.some(function (range) {
|
18
18
|
if (includeStartEdge ? position < range.start : position <= range.start) {
|
19
19
|
return false;
|
20
20
|
} else {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {isObject} from "lodash";
|
1
|
+
import { isObject } from "lodash";
|
2
2
|
import isRangeWithinRange from "./isRangeWithinRange";
|
3
3
|
import isPositionWithinRange from "./isPositionWithinRange";
|
4
4
|
|
@@ -9,21 +9,27 @@ export default function isRangeOrPositionWithinRange(
|
|
9
9
|
includeStartEdge,
|
10
10
|
includeEndEdge
|
11
11
|
) {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
if (
|
13
|
+
rangeOrPositionToCheck === undefined ||
|
14
|
+
rangeOrPositionToCheck === null ||
|
15
|
+
containingRange === undefined ||
|
16
|
+
containingRange === null
|
17
|
+
) {
|
18
|
+
return false;
|
16
19
|
}
|
17
|
-
if (isObject(rangeOrPositionToCheck))
|
18
|
-
return isRangeWithinRange(
|
20
|
+
if (isObject(rangeOrPositionToCheck)) {
|
21
|
+
return isRangeWithinRange(
|
22
|
+
rangeOrPositionToCheck,
|
19
23
|
containingRange,
|
20
|
-
maxLength
|
24
|
+
maxLength
|
25
|
+
);
|
21
26
|
} else {
|
22
|
-
return isPositionWithinRange(
|
27
|
+
return isPositionWithinRange(
|
28
|
+
rangeOrPositionToCheck,
|
23
29
|
containingRange,
|
24
30
|
maxLength,
|
25
31
|
includeStartEdge,
|
26
|
-
includeEndEdge
|
32
|
+
includeEndEdge
|
33
|
+
);
|
27
34
|
}
|
28
|
-
|
29
|
-
};
|
35
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import isRangeOrPositionWithinRange from "./isRangeOrPositionWithinRange";
|
2
|
-
import {expect} from "chai";
|
2
|
+
import { expect } from "chai";
|
3
3
|
|
4
|
-
describe("isRangeOrPositionWithinRange", function() {
|
5
|
-
it("should correctly determine whether a position is within a range", function() {
|
4
|
+
describe("isRangeOrPositionWithinRange", function () {
|
5
|
+
it("should correctly determine whether a position is within a range", function () {
|
6
6
|
expect(isRangeOrPositionWithinRange(1, { start: 1, end: 1 })).to.equal(
|
7
7
|
false
|
8
8
|
);
|
@@ -38,7 +38,7 @@ describe("isRangeOrPositionWithinRange", function() {
|
|
38
38
|
);
|
39
39
|
});
|
40
40
|
|
41
|
-
it("should correctly determine whether a position is within a range when includeStartEdge/includeEndEdge is set to true", function() {
|
41
|
+
it("should correctly determine whether a position is within a range when includeStartEdge/includeEndEdge is set to true", function () {
|
42
42
|
expect(
|
43
43
|
isRangeOrPositionWithinRange(1, { start: 1, end: 1 }, 11, true, true)
|
44
44
|
).to.equal(true);
|
@@ -47,7 +47,7 @@ describe("isRangeOrPositionWithinRange", function() {
|
|
47
47
|
).to.equal(true);
|
48
48
|
});
|
49
49
|
|
50
|
-
it("should work for angle values w/ long decimal places", function() {
|
50
|
+
it("should work for angle values w/ long decimal places", function () {
|
51
51
|
expect(
|
52
52
|
isRangeOrPositionWithinRange(
|
53
53
|
{ start: 5.669848916850995, end: 5.815135586893387 },
|
@@ -56,7 +56,7 @@ describe("isRangeOrPositionWithinRange", function() {
|
|
56
56
|
)
|
57
57
|
).to.equal(true);
|
58
58
|
});
|
59
|
-
it("should correctly determine whether a position is within a range", function() {
|
59
|
+
it("should correctly determine whether a position is within a range", function () {
|
60
60
|
expect(
|
61
61
|
isRangeOrPositionWithinRange(null, { start: 1, end: 10 }, 100)
|
62
62
|
).to.equal(false);
|
@@ -6,12 +6,11 @@ export default function isRangeWithinRange(
|
|
6
6
|
containingRange,
|
7
7
|
maxLength
|
8
8
|
) {
|
9
|
-
|
10
9
|
const ranges = trimRangeByAnotherRange(
|
11
10
|
rangeToCheck,
|
12
11
|
containingRange,
|
13
12
|
maxLength
|
14
13
|
);
|
15
|
-
if (ranges === null) return false
|
14
|
+
if (ranges === null) return false;
|
16
15
|
return !ranges;
|
17
|
-
}
|
16
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import getEachPositionInRangeAsArray from
|
1
|
+
import getEachPositionInRangeAsArray from "./getEachPositionInRangeAsArray";
|
2
2
|
|
3
3
|
export default function loopEachPositionInRange(range, rangeMax, func) {
|
4
|
-
|
5
|
-
}
|
4
|
+
getEachPositionInRangeAsArray(range, rangeMax).map(func);
|
5
|
+
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
//this function takes a position that might not fit in a given range and puts it into that range
|
2
2
|
export default function modulatePositionByRange(position, range) {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
3
|
+
let returnVal = position;
|
4
|
+
if (position < range.start) {
|
5
|
+
returnVal = range.end - (range.start - (position + 1));
|
6
|
+
} else if (position > range.end) {
|
7
|
+
returnVal = range.start + (position - range.end - 1);
|
8
|
+
}
|
9
|
+
return returnVal;
|
10
|
+
}
|
@@ -1,12 +1,11 @@
|
|
1
|
-
import modulatePositionByRange from
|
2
|
-
import {expect} from
|
1
|
+
import modulatePositionByRange from "./modulatePositionByRange";
|
2
|
+
import { expect } from "chai";
|
3
3
|
|
4
|
-
describe(
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
})
|
4
|
+
describe("modulatePositionByRange", function () {
|
5
|
+
it("should modulate positions by their min and max", function () {
|
6
|
+
expect(modulatePositionByRange(0, { start: 1, end: 10 })).to.equal(10);
|
7
|
+
expect(modulatePositionByRange(11, { start: 1, end: 10 })).to.equal(1);
|
8
|
+
expect(modulatePositionByRange(0, { start: 0, end: 10 })).to.equal(0);
|
9
|
+
expect(modulatePositionByRange(10, { start: 0, end: 10 })).to.equal(10);
|
10
|
+
});
|
11
|
+
});
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import normalizePositionByRangeLength from
|
2
|
-
import provideInclusiveOptions from
|
3
|
-
import {assign} from "lodash";
|
1
|
+
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
2
|
+
import provideInclusiveOptions from "./provideInclusiveOptions";
|
3
|
+
import { assign } from "lodash";
|
4
4
|
export default provideInclusiveOptions(modulateRangeBySequenceLength);
|
5
5
|
|
6
6
|
function modulateRangeBySequenceLength(range, seqLen) {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
return assign(range, {
|
8
|
+
start: normalizePositionByRangeLength(range.start, seqLen),
|
9
|
+
end: normalizePositionByRangeLength(range.end, seqLen)
|
10
|
+
});
|
11
11
|
}
|