@teselagen/range-utils 0.3.20-beta.1 → 0.3.20
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/adjustRangeToDeletionOfAnotherRange.d.ts +1 -2
- package/adjustRangeToDeletionOfAnotherRange.test.d.ts +1 -0
- package/adjustRangeToInsert.d.ts +1 -2
- package/adjustRangeToInsert.test.d.ts +1 -0
- package/adjustRangeToRotation.d.ts +1 -2
- package/adjustRangeToRotation.test.d.ts +1 -0
- package/checkIfNonCircularRangesOverlap.d.ts +1 -2
- package/checkIfNonCircularRangesOverlap.test.d.ts +1 -0
- package/checkIfPotentiallyCircularRangesOverlap.d.ts +1 -2
- package/checkIfPotentiallyCircularRangesOverlap.test.d.ts +1 -0
- package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.d.ts +1 -2
- package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.d.ts +1 -0
- package/convertRangeIndices.d.ts +1 -10
- package/convertRangeIndices.test.d.ts +1 -0
- package/convertRangeTo0Based.d.ts +1 -5
- package/convertRangeTo1Based.d.ts +1 -5
- package/doesRangeSpanEntireSequence.d.ts +1 -2
- package/doesRangeSpanOrigin.d.ts +1 -2
- package/expandOrContractCircularRangeToPosition.d.ts +2 -3
- package/expandOrContractNonCircularRangeToPosition.d.ts +2 -3
- package/expandOrContractRangeByLength.d.ts +1 -5
- package/expandOrContractRangeByLength.test.d.ts +1 -0
- package/expandOrContractRangeToPosition.d.ts +2 -3
- package/flipContainedRange.d.ts +1 -5
- package/flipContainedRange.test.d.ts +1 -0
- package/generateRandomRange.d.ts +3 -3
- package/generateRandomRange.test.d.ts +1 -0
- package/getAnnotationRangeType.d.ts +1 -2
- package/getAnnotationRangeType.test.d.ts +1 -0
- package/getEachPositionInRangeAsArray.d.ts +1 -2
- package/getEachPositionInRangeAsArray.test.d.ts +1 -0
- package/getLengthOfOverlappingRegionsBetweenTwoRanges.d.ts +1 -2
- package/getLengthOfOverlappingRegionsBetweenTwoRanges.test.d.ts +1 -0
- package/getMiddleOfRange.d.ts +1 -2
- package/getMiddleOfRange.test.d.ts +1 -0
- package/getOverlapOfNonCircularRanges.d.ts +4 -5
- package/getOverlapsOfPotentiallyCircularRanges.d.ts +1 -2
- package/getOverlapsOfPotentiallyCircularRanges.test.d.ts +1 -0
- package/getPositionFromAngle.d.ts +1 -1
- package/getRangeAngles.d.ts +7 -3
- package/getRangeAngles.test.d.ts +1 -0
- package/getRangeLength.d.ts +1 -5
- package/getRangeLength.test.d.ts +1 -0
- package/getRangesBetweenTwoRanges.d.ts +1 -2
- package/getSequenceWithinRange.d.ts +1 -3
- package/getSequenceWithinRange.test.d.ts +1 -0
- package/getShortestDistanceBetweenTwoPositions.d.ts +1 -1
- package/getShortestDistanceBetweenTwoPositions.test.d.ts +1 -0
- package/getYOffsetForPotentiallyCircularRange.d.ts +1 -2
- package/getYOffsetsForPotentiallyCircularRanges.d.ts +2 -3
- package/getYOffsetsForPotentiallyCircularRanges.test.d.ts +1 -0
- package/getZeroedRangeOverlaps.d.ts +1 -2
- package/getZeroedRangeOverlaps.test.d.ts +1 -0
- package/index.cjs +45 -58
- package/index.d.ts +0 -1
- package/index.js +45 -58
- package/index.test.d.ts +1 -0
- package/index.umd.cjs +45 -58
- package/invertRange.d.ts +1 -5
- package/invertRange.test.d.ts +1 -0
- package/isPositionCloserToRangeStartThanRangeEnd.d.ts +1 -2
- package/isPositionCloserToRangeStartThanRangeEnd.test.d.ts +1 -0
- package/isPositionWithinRange.d.ts +2 -3
- package/isRangeOrPositionWithinRange.d.ts +1 -2
- package/isRangeOrPositionWithinRange.test.d.ts +1 -0
- package/isRangeWithinRange.d.ts +1 -2
- package/loopEachPositionInRange.d.ts +1 -2
- package/modulatePositionByRange.d.ts +1 -2
- package/modulatePositionByRange.test.d.ts +1 -0
- package/modulateRangeBySequenceLength.d.ts +1 -8
- package/modulateRangeBySequenceLength.test.d.ts +1 -0
- package/normalizePositionByRangeLength.d.ts +1 -1
- package/normalizePositionByRangeLength.test.d.ts +1 -0
- package/normalizePositionByRangeLength1Based.d.ts +1 -1
- package/normalizePositionByRangeLength1Based.test.d.ts +1 -0
- package/normalizeRange.d.ts +1 -5
- package/normalizeRange.test.d.ts +1 -0
- package/package.json +2 -10
- package/provideInclusiveOptions.d.ts +1 -6
- package/reversePositionInRange.d.ts +1 -1
- package/splitRangeIntoTwoPartsIfItIsCircular.d.ts +3 -4
- package/splitRangeIntoTwoPartsIfItIsCircular.test.d.ts +1 -0
- package/src/{adjustRangeToDeletionOfAnotherRange.ts → adjustRangeToDeletionOfAnotherRange.js} +7 -4
- package/src/{adjustRangeToInsert.ts → adjustRangeToInsert.js} +4 -4
- package/src/adjustRangeToRotation.js +23 -0
- package/src/{checkIfNonCircularRangesOverlap.ts → checkIfNonCircularRangesOverlap.js} +4 -5
- package/src/{checkIfPotentiallyCircularRangesOverlap.ts → checkIfPotentiallyCircularRangesOverlap.js} +4 -4
- package/src/{collapseOverlapsGeneratedFromRangeComparisonIfPossible.ts → collapseOverlapsGeneratedFromRangeComparisonIfPossible.js} +4 -7
- package/src/{convertRangeIndices.ts → convertRangeIndices.js} +3 -11
- package/src/{convertRangeTo0Based.ts → convertRangeTo0Based.js} +1 -2
- package/src/{convertRangeTo1Based.ts → convertRangeTo1Based.js} +1 -2
- package/src/doesRangeSpanEntireSequence.js +7 -0
- package/src/doesRangeSpanOrigin.js +3 -0
- package/src/{expandOrContractCircularRangeToPosition.ts → expandOrContractCircularRangeToPosition.js} +3 -5
- package/src/{expandOrContractNonCircularRangeToPosition.ts → expandOrContractNonCircularRangeToPosition.js} +2 -4
- package/src/{expandOrContractRangeByLength.ts → expandOrContractRangeByLength.js} +4 -5
- package/src/{expandOrContractRangeToPosition.ts → expandOrContractRangeToPosition.js} +8 -6
- package/src/{flipContainedRange.ts → flipContainedRange.js} +8 -18
- package/src/{generateRandomRange.ts → generateRandomRange.js} +2 -6
- package/src/{getAnnotationRangeType.ts → getAnnotationRangeType.js} +3 -5
- package/src/{getEachPositionInRangeAsArray.ts → getEachPositionInRangeAsArray.js} +2 -6
- package/src/{getLengthOfOverlappingRegionsBetweenTwoRanges.ts → getLengthOfOverlappingRegionsBetweenTwoRanges.js} +3 -4
- package/src/{getMiddleOfRange.ts → getMiddleOfRange.js} +1 -2
- package/src/{getOverlapOfNonCircularRanges.ts → getOverlapOfNonCircularRanges.js} +1 -7
- package/src/{getOverlapsOfPotentiallyCircularRanges.ts → getOverlapsOfPotentiallyCircularRanges.js} +7 -13
- package/src/{getPositionFromAngle.ts → getPositionFromAngle.js} +3 -3
- package/src/{getRangeAngles.ts → getRangeAngles.js} +3 -8
- package/src/{getRangeLength.ts → getRangeLength.js} +1 -4
- package/src/{getRangesBetweenTwoRanges.ts → getRangesBetweenTwoRanges.js} +2 -7
- package/src/getSequenceWithinRange.js +17 -0
- package/src/{getShortestDistanceBetweenTwoPositions.ts → getShortestDistanceBetweenTwoPositions.js} +3 -3
- package/src/{getYOffsetForPotentiallyCircularRange.ts → getYOffsetForPotentiallyCircularRange.js} +4 -5
- package/src/{getYOffsetsForPotentiallyCircularRanges.ts → getYOffsetsForPotentiallyCircularRanges.js} +4 -5
- package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -0
- package/src/{getZeroedRangeOverlaps.ts → getZeroedRangeOverlaps.js} +3 -4
- package/src/{getZeroedRangeOverlaps.test.ts → getZeroedRangeOverlaps.test.js} +15 -5
- package/src/{index.ts → index.js} +0 -1
- package/src/{index.test.ts → index.test.js} +3 -11
- package/src/invertRange.js +21 -0
- package/src/{isPositionCloserToRangeStartThanRangeEnd.ts → isPositionCloserToRangeStartThanRangeEnd.js} +3 -5
- package/src/{isPositionWithinRange.ts → isPositionWithinRange.js} +5 -14
- package/src/{isRangeOrPositionWithinRange.ts → isRangeOrPositionWithinRange.js} +6 -11
- package/src/{isRangeWithinRange.ts → isRangeWithinRange.js} +3 -5
- package/src/loopEachPositionInRange.js +5 -0
- package/src/{modulatePositionByRange.ts → modulatePositionByRange.js} +1 -6
- package/src/{modulateRangeBySequenceLength.ts → modulateRangeBySequenceLength.js} +1 -3
- package/src/{normalizePositionByRangeLength.ts → normalizePositionByRangeLength.js} +7 -7
- package/src/{normalizePositionByRangeLength1Based.ts → normalizePositionByRangeLength1Based.js} +2 -3
- package/src/{normalizeRange.ts → normalizeRange.js} +1 -2
- package/src/provideInclusiveOptions.js +39 -0
- package/src/{reversePositionInRange.ts → reversePositionInRange.js} +4 -4
- package/src/{splitRangeIntoTwoPartsIfItIsCircular.ts → splitRangeIntoTwoPartsIfItIsCircular.js} +4 -5
- package/src/{translateRange.ts → translateRange.js} +3 -5
- package/src/{trimAnnStartEndToFitSeqLength.ts → trimAnnStartEndToFitSeqLength.js} +2 -2
- package/src/{trimNonCicularRangeByAnotherNonCircularRange.ts → trimNonCicularRangeByAnotherNonCircularRange.js} +4 -6
- package/src/{trimNumberToFitWithin0ToAnotherNumber.ts → trimNumberToFitWithin0ToAnotherNumber.js} +4 -3
- package/src/{trimRangeByAnotherRange.ts → trimRangeByAnotherRange.js} +9 -9
- package/src/{zeroSubrangeByContainerRange.ts → zeroSubrangeByContainerRange.js} +8 -10
- package/translateRange.d.ts +1 -5
- package/translateRange.test.d.ts +1 -0
- package/trimAnnStartEndToFitSeqLength.d.ts +1 -1
- package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
- package/trimNonCicularRangeByAnotherNonCircularRange.d.ts +4 -2
- package/trimNumberToFitWithin0ToAnotherNumber.d.ts +1 -1
- package/trimRangeByAnotherRange.d.ts +1 -2
- package/trimRangeByAnotherRange.test.d.ts +1 -0
- package/zeroSubrangeByContainerRange.d.ts +1 -2
- package/zeroSubrangeByContainerRange.test.d.ts +1 -0
- package/RangeAngles.d.ts +0 -7
- package/src/RangeAngles.ts +0 -9
- package/src/adjustRangeToRotation.ts +0 -22
- package/src/doesRangeSpanEntireSequence.ts +0 -12
- package/src/doesRangeSpanOrigin.ts +0 -5
- package/src/getSequenceWithinRange.ts +0 -33
- package/src/getYOffsetsForPotentiallyCircularRanges.test.ts +0 -17
- package/src/invertRange.ts +0 -25
- package/src/loopEachPositionInRange.ts +0 -11
- package/src/provideInclusiveOptions.ts +0 -79
- package/src/types.ts +0 -12
- package/types.d.ts +0 -12
- /package/src/{getRangeLength.test.ts → getRangeLength.test.js} +0 -0
- /package/src/{getSequenceWithinRange.test.ts → getSequenceWithinRange.test.js} +0 -0
- /package/src/{getShortestDistanceBetweenTwoPositions.test.ts → getShortestDistanceBetweenTwoPositions.test.js} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { assign } from "lodash-es";
|
|
2
|
-
import { Range } from "./types";
|
|
3
2
|
|
|
4
3
|
export default function adjustRangeToInsert(
|
|
5
|
-
rangeToBeAdjusted
|
|
6
|
-
insertStart
|
|
7
|
-
insertLength
|
|
4
|
+
rangeToBeAdjusted,
|
|
5
|
+
insertStart,
|
|
6
|
+
insertLength
|
|
8
7
|
) {
|
|
8
|
+
// ac.throw([ac.range, ac.posInt, ac.posInt], arguments);
|
|
9
9
|
const newRange = assign({}, rangeToBeAdjusted);
|
|
10
10
|
if (rangeToBeAdjusted.start > rangeToBeAdjusted.end) {
|
|
11
11
|
//circular range
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { assign } from "lodash-es";
|
|
2
|
+
|
|
3
|
+
import { identity } from "lodash-es";
|
|
4
|
+
|
|
5
|
+
export default function adjustRangeToRotation(
|
|
6
|
+
rangeToBeAdjusted,
|
|
7
|
+
rotateTo = 0,
|
|
8
|
+
rangeLength
|
|
9
|
+
) {
|
|
10
|
+
// ac.throw([ac.range, ac.posInt, ac.posInt], arguments);
|
|
11
|
+
const mod = rangeLength ? modulo : identity;
|
|
12
|
+
|
|
13
|
+
const newRange = assign({}, rangeToBeAdjusted, {
|
|
14
|
+
start: mod(rangeToBeAdjusted.start - (rotateTo || 0), rangeLength),
|
|
15
|
+
end: mod(rangeToBeAdjusted.end - (rotateTo || 0), rangeLength)
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return newRange;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function modulo(n, m) {
|
|
22
|
+
return ((n % m) + m) % m;
|
|
23
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Range } from "./types";
|
|
2
|
-
|
|
3
1
|
//
|
|
4
|
-
|
|
2
|
+
// ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
|
|
5
3
|
export default function checkIfNonCircularRangesOverlap(
|
|
6
|
-
range
|
|
7
|
-
comparisonRange
|
|
4
|
+
range,
|
|
5
|
+
comparisonRange
|
|
8
6
|
) {
|
|
7
|
+
// ac.throw([ac.range, ac.range], arguments);
|
|
9
8
|
if (range.start < comparisonRange.start) {
|
|
10
9
|
if (range.end < comparisonRange.start) {
|
|
11
10
|
//----llll
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
//
|
|
2
|
-
//
|
|
3
2
|
import checkIfNonCircularRangesOverlap from "./checkIfNonCircularRangesOverlap";
|
|
4
3
|
|
|
5
4
|
import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
|
|
6
|
-
|
|
5
|
+
// ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
|
|
7
6
|
|
|
8
7
|
export default function checkIfPotentiallyCircularRangesOverlap(
|
|
9
|
-
range
|
|
10
|
-
comparisonRange
|
|
8
|
+
range,
|
|
9
|
+
comparisonRange
|
|
11
10
|
) {
|
|
11
|
+
// ac.throw([ac.range, ac.range], arguments);
|
|
12
12
|
//split the potentially circular ranges and compare each part for overlap
|
|
13
13
|
return splitRangeIntoTwoPartsIfItIsCircular(range, Infinity).some(
|
|
14
14
|
function (splitRange) {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { Range } from "./types";
|
|
2
|
-
|
|
3
1
|
//this function is a little confusing, but basically it takes an array of overlaps
|
|
4
2
|
//generated from a range overlaps calculation, and it sews them together if possible
|
|
5
3
|
export default function collapseOverlapsGeneratedFromRangeComparisonIfPossible(
|
|
6
|
-
overlaps
|
|
7
|
-
sequenceLength
|
|
8
|
-
optionalOriginalRange
|
|
9
|
-
)
|
|
4
|
+
overlaps,
|
|
5
|
+
sequenceLength,
|
|
6
|
+
optionalOriginalRange
|
|
7
|
+
) {
|
|
10
8
|
const originalRangeLinear =
|
|
11
9
|
optionalOriginalRange &&
|
|
12
10
|
optionalOriginalRange.start <= optionalOriginalRange.end;
|
|
@@ -77,5 +75,4 @@ export default function collapseOverlapsGeneratedFromRangeComparisonIfPossible(
|
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
|
-
return overlaps;
|
|
81
78
|
}
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { assign } from "lodash-es";
|
|
2
|
-
import { Range } from "./types";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default function convertRangeIndices(
|
|
10
|
-
range: Range,
|
|
11
|
-
inputType: RangeIndicesOptions = {},
|
|
12
|
-
outputType: RangeIndicesOptions = {}
|
|
13
|
-
) {
|
|
3
|
+
export default function convertRangeIndices(range, inputType, outputType) {
|
|
4
|
+
inputType = inputType || {};
|
|
5
|
+
outputType = outputType || {};
|
|
14
6
|
return assign({}, range, {
|
|
15
7
|
start:
|
|
16
8
|
Number(range.start) +
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import convertRangeIndices from "./convertRangeIndices";
|
|
2
|
-
import { Range } from "./types";
|
|
3
2
|
|
|
4
|
-
export default function convertRangeTo0Based(range
|
|
3
|
+
export default function convertRangeTo0Based(range) {
|
|
5
4
|
return convertRangeIndices(range, {
|
|
6
5
|
inclusive1BasedStart: true,
|
|
7
6
|
inclusive1BasedEnd: true
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
2
2
|
import { assign } from "lodash-es";
|
|
3
3
|
|
|
4
|
-
import { Range } from "./types";
|
|
5
|
-
|
|
6
4
|
export default function expandOrContractCircularRangeToPosition(
|
|
7
|
-
range
|
|
8
|
-
position
|
|
9
|
-
maxLength
|
|
5
|
+
range,
|
|
6
|
+
position,
|
|
7
|
+
maxLength
|
|
10
8
|
) {
|
|
11
9
|
// 0 1 2 3 4 5 6 7 8 9
|
|
12
10
|
// r r r r r - - r r r
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { assign } from "lodash-es";
|
|
2
2
|
|
|
3
|
-
import { Range } from "./types";
|
|
4
|
-
|
|
5
3
|
export default function expandOrContractNonCircularRangeToPosition(
|
|
6
|
-
range
|
|
7
|
-
position
|
|
4
|
+
range,
|
|
5
|
+
position
|
|
8
6
|
) {
|
|
9
7
|
const newRange = assign({}, range);
|
|
10
8
|
let endMoved = true;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { clone } from "lodash-es";
|
|
2
|
-
import { Range } from "./types";
|
|
3
2
|
import normalizeRange from "./normalizeRange";
|
|
4
3
|
|
|
5
4
|
export default function expandOrContractRangeByLength(
|
|
6
|
-
range
|
|
7
|
-
shiftBy
|
|
8
|
-
shiftStart
|
|
9
|
-
sequenceLength
|
|
5
|
+
range,
|
|
6
|
+
shiftBy,
|
|
7
|
+
shiftStart,
|
|
8
|
+
sequenceLength
|
|
10
9
|
) {
|
|
11
10
|
const rangeToReturn = clone(range);
|
|
12
11
|
if (shiftStart) {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import expandOrContractCircularRangeToPosition from "./expandOrContractCircularRangeToPosition";
|
|
2
2
|
import expandOrContractNonCircularRangeToPosition from "./expandOrContractNonCircularRangeToPosition";
|
|
3
3
|
|
|
4
|
-
import { Range } from "./types";
|
|
5
|
-
|
|
6
4
|
export default function expandOrContractRangeToPosition(
|
|
7
|
-
range
|
|
8
|
-
position
|
|
9
|
-
maxLength
|
|
5
|
+
range,
|
|
6
|
+
position,
|
|
7
|
+
maxLength
|
|
10
8
|
) {
|
|
11
9
|
if (range.start > range.end) {
|
|
12
10
|
return expandOrContractCircularRangeToPosition(range, position, maxLength);
|
|
13
11
|
} else {
|
|
14
|
-
return expandOrContractNonCircularRangeToPosition(
|
|
12
|
+
return expandOrContractNonCircularRangeToPosition(
|
|
13
|
+
range,
|
|
14
|
+
position,
|
|
15
|
+
maxLength
|
|
16
|
+
);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
@@ -4,12 +4,10 @@ import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCi
|
|
|
4
4
|
import translateRange from "./translateRange";
|
|
5
5
|
import getRangeLength from "./getRangeLength";
|
|
6
6
|
|
|
7
|
-
import { Range } from "./types";
|
|
8
|
-
|
|
9
7
|
export default function flipRelativeRange(
|
|
10
|
-
innerRange
|
|
11
|
-
outerRange
|
|
12
|
-
sequenceLength
|
|
8
|
+
innerRange,
|
|
9
|
+
outerRange,
|
|
10
|
+
sequenceLength
|
|
13
11
|
) {
|
|
14
12
|
const isFullyContained = isRangeWithinRange(
|
|
15
13
|
innerRange,
|
|
@@ -24,11 +22,7 @@ export default function flipRelativeRange(
|
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
function flipNonFullyContainedRange(
|
|
28
|
-
innerRange: Range,
|
|
29
|
-
outerRange: Range,
|
|
30
|
-
sequenceLength: number
|
|
31
|
-
) {
|
|
25
|
+
function flipNonFullyContainedRange(innerRange, outerRange, sequenceLength) {
|
|
32
26
|
const outerFullyContained = isRangeWithinRange(
|
|
33
27
|
outerRange,
|
|
34
28
|
innerRange,
|
|
@@ -103,11 +97,7 @@ function flipNonFullyContainedRange(
|
|
|
103
97
|
return flippedInnerRange;
|
|
104
98
|
}
|
|
105
99
|
|
|
106
|
-
function flipFullyContainedRange(
|
|
107
|
-
innerRange: Range,
|
|
108
|
-
outerRange: Range,
|
|
109
|
-
sequenceLength: number
|
|
110
|
-
) {
|
|
100
|
+
function flipFullyContainedRange(innerRange, outerRange, sequenceLength) {
|
|
111
101
|
//translate both ranges by offset such that outer range start = 0
|
|
112
102
|
const translateBy = -outerRange.start;
|
|
113
103
|
const translatedOuterRange = translateRange(
|
|
@@ -138,9 +128,9 @@ function flipFullyContainedRange(
|
|
|
138
128
|
}
|
|
139
129
|
|
|
140
130
|
function flipNonOriginSpanningContainedRange(
|
|
141
|
-
innerRange
|
|
142
|
-
outerRange
|
|
143
|
-
sequenceLength
|
|
131
|
+
innerRange,
|
|
132
|
+
outerRange,
|
|
133
|
+
sequenceLength
|
|
144
134
|
) {
|
|
145
135
|
//non origin spanning, fully contained inner
|
|
146
136
|
const offsetFromStart = innerRange.start - outerRange.start;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
2
2
|
|
|
3
|
-
export default function generateRandomRange(
|
|
4
|
-
minStart: number,
|
|
5
|
-
maxEnd: number,
|
|
6
|
-
maxLength: number
|
|
7
|
-
) {
|
|
3
|
+
export default function generateRandomRange(minStart, maxEnd, maxLength) {
|
|
8
4
|
const start = getRandomInt(minStart, maxEnd);
|
|
9
5
|
let end;
|
|
10
6
|
if (maxLength) {
|
|
@@ -21,6 +17,6 @@ export default function generateRandomRange(
|
|
|
21
17
|
};
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
function getRandomInt(min
|
|
20
|
+
function getRandomInt(min, max) {
|
|
25
21
|
return Math.floor(Math.random() * (max - min)) + min;
|
|
26
22
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Range } from "./types";
|
|
2
|
-
|
|
3
1
|
//function that returns the annotation range type
|
|
4
2
|
export default function getAnnotationRangeType(
|
|
5
|
-
annotationRange
|
|
6
|
-
enclosingRangeType
|
|
7
|
-
forward
|
|
3
|
+
annotationRange,
|
|
4
|
+
enclosingRangeType,
|
|
5
|
+
forward
|
|
8
6
|
) {
|
|
9
7
|
if (annotationRange.start === enclosingRangeType.start) {
|
|
10
8
|
if (annotationRange.end === enclosingRangeType.end) {
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
2
2
|
import getRangeLength from "./getRangeLength";
|
|
3
|
-
import { Range } from "./types";
|
|
4
3
|
|
|
5
|
-
export default function getEachPositionInRangeAsArray(
|
|
6
|
-
|
|
7
|
-
rangeMax: number
|
|
8
|
-
) {
|
|
9
|
-
const output: number[] = [];
|
|
4
|
+
export default function getEachPositionInRangeAsArray(range, rangeMax) {
|
|
5
|
+
const output = [];
|
|
10
6
|
const length = getRangeLength(range, rangeMax);
|
|
11
7
|
if (!(length > 0)) {
|
|
12
8
|
return output;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import getRangeLength from "./getRangeLength";
|
|
2
2
|
import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCircularRanges";
|
|
3
|
-
import { Range } from "./types";
|
|
4
3
|
|
|
5
4
|
export default function getLengthOfOverlappingRegionsBetweenTwoRanges(
|
|
6
|
-
rangeA
|
|
7
|
-
rangeB
|
|
8
|
-
maxLength
|
|
5
|
+
rangeA,
|
|
6
|
+
rangeB,
|
|
7
|
+
maxLength
|
|
9
8
|
) {
|
|
10
9
|
const overlaps = getOverlapsOfPotentiallyCircularRanges(
|
|
11
10
|
rangeA,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import getRangeLength from "./getRangeLength";
|
|
2
2
|
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
3
|
-
import { Range } from "./types";
|
|
4
3
|
|
|
5
|
-
export default function getMiddleOfRange(range
|
|
4
|
+
export default function getMiddleOfRange(range, rangeMax) {
|
|
6
5
|
const len = getRangeLength({ start: range.start, end: range.end }, rangeMax);
|
|
7
6
|
return normalizePositionByRangeLength(
|
|
8
7
|
range.start + Math.floor(len / 2),
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default function getOverlapOfNonCircularRanges(
|
|
4
|
-
rangeA: Range,
|
|
5
|
-
rangeB: Range
|
|
6
|
-
) {
|
|
1
|
+
export default function getOverlapOfNonCircularRanges(rangeA, rangeB) {
|
|
7
2
|
if (rangeA.start < rangeB.start) {
|
|
8
3
|
if (rangeA.end < rangeB.start) {
|
|
9
4
|
//no overlap
|
|
@@ -37,5 +32,4 @@ export default function getOverlapOfNonCircularRanges(
|
|
|
37
32
|
}
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
|
-
return null;
|
|
41
35
|
}
|
package/src/{getOverlapsOfPotentiallyCircularRanges.ts → getOverlapsOfPotentiallyCircularRanges.js}
RENAMED
|
@@ -2,15 +2,12 @@ import { flatMap } from "lodash-es";
|
|
|
2
2
|
import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
|
|
3
3
|
import getOverlapOfNonCircularRanges from "./getOverlapOfNonCircularRanges";
|
|
4
4
|
|
|
5
|
-
//returns an array of the overlaps between two potentially circular ranges
|
|
6
|
-
import { Range } from "./types";
|
|
7
|
-
|
|
8
5
|
//returns an array of the overlaps between two potentially circular ranges
|
|
9
6
|
export default function getOverlapsOfPotentiallyCircularRanges(
|
|
10
|
-
rangeA
|
|
11
|
-
rangeB
|
|
12
|
-
maxRangeLength
|
|
13
|
-
joinIfPossible
|
|
7
|
+
rangeA,
|
|
8
|
+
rangeB,
|
|
9
|
+
maxRangeLength,
|
|
10
|
+
joinIfPossible //by default this fn only returns **non-circular** overlaps, if true it will try to join overlaps split on the origin
|
|
14
11
|
) {
|
|
15
12
|
const normalizedRangeA = splitRangeIntoTwoPartsIfItIsCircular(
|
|
16
13
|
rangeA,
|
|
@@ -21,7 +18,7 @@ export default function getOverlapsOfPotentiallyCircularRanges(
|
|
|
21
18
|
maxRangeLength
|
|
22
19
|
);
|
|
23
20
|
|
|
24
|
-
let overlaps
|
|
21
|
+
let overlaps = [];
|
|
25
22
|
|
|
26
23
|
normalizedRangeA.forEach(function (nonCircularRangeA) {
|
|
27
24
|
normalizedRangeB.forEach(function (nonCircularRangeB) {
|
|
@@ -41,7 +38,7 @@ export default function getOverlapsOfPotentiallyCircularRanges(
|
|
|
41
38
|
maxRangeLength
|
|
42
39
|
) {
|
|
43
40
|
//we have 2 circular ranges that will have gotten split on the origin, so we'll manually mend those pieces back together
|
|
44
|
-
const joinedOverlap
|
|
41
|
+
const joinedOverlap = {};
|
|
45
42
|
overlaps = flatMap(overlaps, o => {
|
|
46
43
|
if (o.start === 0) {
|
|
47
44
|
joinedOverlap.end = o.end;
|
|
@@ -50,11 +47,8 @@ export default function getOverlapsOfPotentiallyCircularRanges(
|
|
|
50
47
|
joinedOverlap.start = o.start;
|
|
51
48
|
return [];
|
|
52
49
|
}
|
|
53
|
-
return [o];
|
|
54
50
|
});
|
|
55
|
-
|
|
56
|
-
overlaps.push(joinedOverlap as Range);
|
|
57
|
-
}
|
|
51
|
+
overlaps.push(joinedOverlap);
|
|
58
52
|
}
|
|
59
53
|
return overlaps;
|
|
60
54
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default function getPositionFromAngle(
|
|
2
|
-
angle
|
|
3
|
-
rangeMax
|
|
4
|
-
isInBetweenPositions
|
|
2
|
+
angle,
|
|
3
|
+
rangeMax,
|
|
4
|
+
isInBetweenPositions
|
|
5
5
|
) {
|
|
6
6
|
//percent through sequence * rangeMax
|
|
7
7
|
const unroundedPostion = (angle / Math.PI / 2) * rangeMax;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import getRangeLength from "./getRangeLength";
|
|
2
|
-
import { Range } from "./types";
|
|
3
|
-
import { RangeAngles } from "./RangeAngles";
|
|
4
2
|
|
|
5
|
-
export default function getRangeAngles(
|
|
6
|
-
range: Range,
|
|
7
|
-
rangeMax: number
|
|
8
|
-
): RangeAngles {
|
|
3
|
+
export default function getRangeAngles(range, rangeMax) {
|
|
9
4
|
const { startAngle, totalAngle, endAngle } = getStartEndAndTotalAngle(
|
|
10
5
|
range,
|
|
11
6
|
rangeMax
|
|
@@ -18,13 +13,13 @@ export default function getRangeAngles(
|
|
|
18
13
|
centerAngle: startAngle + totalAngle / 2,
|
|
19
14
|
locationAngles:
|
|
20
15
|
range.locations &&
|
|
21
|
-
range.locations.map(
|
|
16
|
+
range.locations.map(location => {
|
|
22
17
|
return getRangeAngles(location, rangeMax);
|
|
23
18
|
})
|
|
24
19
|
};
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
function getStartEndAndTotalAngle(range
|
|
22
|
+
function getStartEndAndTotalAngle(range, rangeMax) {
|
|
28
23
|
const rangeLength = getRangeLength(
|
|
29
24
|
{ start: range.start, end: range.end },
|
|
30
25
|
rangeMax
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import provideInclusiveOptions from "./provideInclusiveOptions";
|
|
2
|
-
import { Range } from "./types";
|
|
3
|
-
|
|
4
2
|
export default provideInclusiveOptions(getRangeLength);
|
|
5
|
-
|
|
6
|
-
function getRangeLength(range: Range, rangeMax: number) {
|
|
3
|
+
function getRangeLength(range, rangeMax) {
|
|
7
4
|
let toRet;
|
|
8
5
|
if (range.end < range.start) {
|
|
9
6
|
toRet = rangeMax - range.start + range.end + 1;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default function getRangesBetweenTwoRanges(
|
|
4
|
-
range1: Range,
|
|
5
|
-
range2: Range
|
|
6
|
-
) {
|
|
1
|
+
export default function getRangesBetweenTwoRanges(range1, range2) {
|
|
7
2
|
// {
|
|
8
3
|
// start: 85,
|
|
9
4
|
// end: 92
|
|
@@ -18,7 +13,7 @@ export default function getRangesBetweenTwoRanges(
|
|
|
18
13
|
|
|
19
14
|
// start2 - end1
|
|
20
15
|
|
|
21
|
-
const newRanges
|
|
16
|
+
const newRanges = [];
|
|
22
17
|
if (
|
|
23
18
|
!(
|
|
24
19
|
range1.start > -1 &&
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
export default function getSequenceWithinRange(range, sequence) {
|
|
3
|
+
// ac.throw([ac.range, ac.oneOfType([ac.array, ac.string])], arguments);
|
|
4
|
+
if (range.start < 0 || range.end < 0) return "";
|
|
5
|
+
if (range.start > range.end) {
|
|
6
|
+
//circular range
|
|
7
|
+
let subSequence = sequence.slice(range.start, sequence.length);
|
|
8
|
+
if (typeof subSequence === "string") {
|
|
9
|
+
subSequence += sequence.slice(0, range.end + 1);
|
|
10
|
+
} else {
|
|
11
|
+
subSequence = subSequence.concat(sequence.slice(0, range.end + 1));
|
|
12
|
+
}
|
|
13
|
+
return subSequence;
|
|
14
|
+
} else {
|
|
15
|
+
return sequence.slice(range.start, range.end + 1);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/{getYOffsetForPotentiallyCircularRange.ts → getYOffsetForPotentiallyCircularRange.js}
RENAMED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import checkIfPotentiallyCircularRangesOverlap from "./checkIfPotentiallyCircularRangesOverlap";
|
|
2
|
-
import { Range } from "./types";
|
|
3
2
|
|
|
4
3
|
export default function getYOffsetForPotentiallyCircularRange(
|
|
5
|
-
range
|
|
6
|
-
YOffsetLevelsWithRanges
|
|
7
|
-
assignYOffsetToRange
|
|
4
|
+
range,
|
|
5
|
+
YOffsetLevelsWithRanges,
|
|
6
|
+
assignYOffsetToRange
|
|
8
7
|
) {
|
|
9
8
|
//adjust the yOffset of the range being pushed in by checking its range against other range already in the row
|
|
10
|
-
let yOffset =
|
|
9
|
+
let yOffset = [];
|
|
11
10
|
//YOffsetLevelsWithRanges is an array of arrays (array of yOffset levels holding arrays of range)
|
|
12
11
|
//loop through y offset levels starting with the 0 level until an empty one is found and push the range into it. If none are found, add another level.
|
|
13
12
|
const openYOffsetFound = YOffsetLevelsWithRanges.some(
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import getYOffsetForPotentiallyCircularRange from "./getYOffsetForPotentiallyCircularRange";
|
|
2
|
-
import { Range } from "./types";
|
|
3
2
|
|
|
4
3
|
export default function getYOffsetsForPotentiallyCircularRanges(
|
|
5
|
-
ranges
|
|
6
|
-
assignYOffsetToRange
|
|
4
|
+
ranges,
|
|
5
|
+
assignYOffsetToRange
|
|
7
6
|
) {
|
|
8
7
|
//adjust the yOffset of the range being pushed in by checking its range against other ranges already in the row
|
|
9
|
-
const yOffsets
|
|
8
|
+
const yOffsets = [];
|
|
10
9
|
let maxYOffset = 0;
|
|
11
|
-
const yOffsetLevels
|
|
10
|
+
const yOffsetLevels = []; //yOffsetLevels is an array of arrays (array of yOffset levels holding arrays of ranges)
|
|
12
11
|
ranges.forEach(function (range) {
|
|
13
12
|
//loop through y offset levels starting with the 0 level until an empty one is found and push the range into it. If none are found, add another level.
|
|
14
13
|
const yOffset = getYOffsetForPotentiallyCircularRange(
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import getYOffsetsForPotentiallyCircularRanges from "./getYOffsetsForPotentiallyCircularRanges.js";
|
|
3
|
+
describe("getYOffsetsForPotentiallyCircularRanges", function () {
|
|
4
|
+
it("returns correct yOffset for overlapping ranges", function () {
|
|
5
|
+
expect(
|
|
6
|
+
getYOffsetsForPotentiallyCircularRanges([
|
|
7
|
+
{
|
|
8
|
+
start: 5,
|
|
9
|
+
end: 100
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
start: 50,
|
|
13
|
+
end: 50
|
|
14
|
+
}
|
|
15
|
+
])
|
|
16
|
+
).to.deep.equal({ yOffsets: [0, 1], maxYOffset: 1 });
|
|
17
|
+
expect(
|
|
18
|
+
getYOffsetsForPotentiallyCircularRanges([
|
|
19
|
+
{
|
|
20
|
+
start: 5,
|
|
21
|
+
end: 100
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
start: 50,
|
|
25
|
+
end: 50
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
start: 50,
|
|
29
|
+
end: 50
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
start: 150,
|
|
33
|
+
end: 4
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
start: 150,
|
|
37
|
+
end: 150
|
|
38
|
+
}
|
|
39
|
+
])
|
|
40
|
+
).to.deep.equal({ yOffsets: [0, 1, 2, 0, 1], maxYOffset: 2 });
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Range } from "./types";
|
|
2
1
|
import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCircularRanges";
|
|
3
2
|
import collapseOverlapsGeneratedFromRangeComparisonIfPossible from "./collapseOverlapsGeneratedFromRangeComparisonIfPossible";
|
|
4
3
|
import zeroSubrangeByContainerRange from "./zeroSubrangeByContainerRange";
|
|
@@ -6,9 +5,9 @@ import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
|
6
5
|
|
|
7
6
|
//gets the overlapping sections of two ranges and zeroes them to their first point of intersection!
|
|
8
7
|
export default function getZeroedRangeOverlaps(
|
|
9
|
-
annotation
|
|
10
|
-
selection
|
|
11
|
-
sequenceLength
|
|
8
|
+
annotation,
|
|
9
|
+
selection,
|
|
10
|
+
sequenceLength
|
|
12
11
|
) {
|
|
13
12
|
const overlaps = collapseOverlapsGeneratedFromRangeComparisonIfPossible(
|
|
14
13
|
getOverlapsOfPotentiallyCircularRanges(
|