@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.
Files changed (163) hide show
  1. package/adjustRangeToDeletionOfAnotherRange.d.ts +1 -2
  2. package/adjustRangeToDeletionOfAnotherRange.test.d.ts +1 -0
  3. package/adjustRangeToInsert.d.ts +1 -2
  4. package/adjustRangeToInsert.test.d.ts +1 -0
  5. package/adjustRangeToRotation.d.ts +1 -2
  6. package/adjustRangeToRotation.test.d.ts +1 -0
  7. package/checkIfNonCircularRangesOverlap.d.ts +1 -2
  8. package/checkIfNonCircularRangesOverlap.test.d.ts +1 -0
  9. package/checkIfPotentiallyCircularRangesOverlap.d.ts +1 -2
  10. package/checkIfPotentiallyCircularRangesOverlap.test.d.ts +1 -0
  11. package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.d.ts +1 -2
  12. package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.d.ts +1 -0
  13. package/convertRangeIndices.d.ts +1 -10
  14. package/convertRangeIndices.test.d.ts +1 -0
  15. package/convertRangeTo0Based.d.ts +1 -5
  16. package/convertRangeTo1Based.d.ts +1 -5
  17. package/doesRangeSpanEntireSequence.d.ts +1 -2
  18. package/doesRangeSpanOrigin.d.ts +1 -2
  19. package/expandOrContractCircularRangeToPosition.d.ts +2 -3
  20. package/expandOrContractNonCircularRangeToPosition.d.ts +2 -3
  21. package/expandOrContractRangeByLength.d.ts +1 -5
  22. package/expandOrContractRangeByLength.test.d.ts +1 -0
  23. package/expandOrContractRangeToPosition.d.ts +2 -3
  24. package/flipContainedRange.d.ts +1 -5
  25. package/flipContainedRange.test.d.ts +1 -0
  26. package/generateRandomRange.d.ts +3 -3
  27. package/generateRandomRange.test.d.ts +1 -0
  28. package/getAnnotationRangeType.d.ts +1 -2
  29. package/getAnnotationRangeType.test.d.ts +1 -0
  30. package/getEachPositionInRangeAsArray.d.ts +1 -2
  31. package/getEachPositionInRangeAsArray.test.d.ts +1 -0
  32. package/getLengthOfOverlappingRegionsBetweenTwoRanges.d.ts +1 -2
  33. package/getLengthOfOverlappingRegionsBetweenTwoRanges.test.d.ts +1 -0
  34. package/getMiddleOfRange.d.ts +1 -2
  35. package/getMiddleOfRange.test.d.ts +1 -0
  36. package/getOverlapOfNonCircularRanges.d.ts +4 -5
  37. package/getOverlapsOfPotentiallyCircularRanges.d.ts +1 -2
  38. package/getOverlapsOfPotentiallyCircularRanges.test.d.ts +1 -0
  39. package/getPositionFromAngle.d.ts +1 -1
  40. package/getRangeAngles.d.ts +7 -3
  41. package/getRangeAngles.test.d.ts +1 -0
  42. package/getRangeLength.d.ts +1 -5
  43. package/getRangeLength.test.d.ts +1 -0
  44. package/getRangesBetweenTwoRanges.d.ts +1 -2
  45. package/getSequenceWithinRange.d.ts +1 -3
  46. package/getSequenceWithinRange.test.d.ts +1 -0
  47. package/getShortestDistanceBetweenTwoPositions.d.ts +1 -1
  48. package/getShortestDistanceBetweenTwoPositions.test.d.ts +1 -0
  49. package/getYOffsetForPotentiallyCircularRange.d.ts +1 -2
  50. package/getYOffsetsForPotentiallyCircularRanges.d.ts +2 -3
  51. package/getYOffsetsForPotentiallyCircularRanges.test.d.ts +1 -0
  52. package/getZeroedRangeOverlaps.d.ts +1 -2
  53. package/getZeroedRangeOverlaps.test.d.ts +1 -0
  54. package/index.cjs +45 -58
  55. package/index.d.ts +0 -1
  56. package/index.js +45 -58
  57. package/index.test.d.ts +1 -0
  58. package/index.umd.cjs +45 -58
  59. package/invertRange.d.ts +1 -5
  60. package/invertRange.test.d.ts +1 -0
  61. package/isPositionCloserToRangeStartThanRangeEnd.d.ts +1 -2
  62. package/isPositionCloserToRangeStartThanRangeEnd.test.d.ts +1 -0
  63. package/isPositionWithinRange.d.ts +2 -3
  64. package/isRangeOrPositionWithinRange.d.ts +1 -2
  65. package/isRangeOrPositionWithinRange.test.d.ts +1 -0
  66. package/isRangeWithinRange.d.ts +1 -2
  67. package/loopEachPositionInRange.d.ts +1 -2
  68. package/modulatePositionByRange.d.ts +1 -2
  69. package/modulatePositionByRange.test.d.ts +1 -0
  70. package/modulateRangeBySequenceLength.d.ts +1 -8
  71. package/modulateRangeBySequenceLength.test.d.ts +1 -0
  72. package/normalizePositionByRangeLength.d.ts +1 -1
  73. package/normalizePositionByRangeLength.test.d.ts +1 -0
  74. package/normalizePositionByRangeLength1Based.d.ts +1 -1
  75. package/normalizePositionByRangeLength1Based.test.d.ts +1 -0
  76. package/normalizeRange.d.ts +1 -5
  77. package/normalizeRange.test.d.ts +1 -0
  78. package/package.json +2 -10
  79. package/provideInclusiveOptions.d.ts +1 -6
  80. package/reversePositionInRange.d.ts +1 -1
  81. package/splitRangeIntoTwoPartsIfItIsCircular.d.ts +3 -4
  82. package/splitRangeIntoTwoPartsIfItIsCircular.test.d.ts +1 -0
  83. package/src/{adjustRangeToDeletionOfAnotherRange.ts → adjustRangeToDeletionOfAnotherRange.js} +7 -4
  84. package/src/{adjustRangeToInsert.ts → adjustRangeToInsert.js} +4 -4
  85. package/src/adjustRangeToRotation.js +23 -0
  86. package/src/{checkIfNonCircularRangesOverlap.ts → checkIfNonCircularRangesOverlap.js} +4 -5
  87. package/src/{checkIfPotentiallyCircularRangesOverlap.ts → checkIfPotentiallyCircularRangesOverlap.js} +4 -4
  88. package/src/{collapseOverlapsGeneratedFromRangeComparisonIfPossible.ts → collapseOverlapsGeneratedFromRangeComparisonIfPossible.js} +4 -7
  89. package/src/{convertRangeIndices.ts → convertRangeIndices.js} +3 -11
  90. package/src/{convertRangeTo0Based.ts → convertRangeTo0Based.js} +1 -2
  91. package/src/{convertRangeTo1Based.ts → convertRangeTo1Based.js} +1 -2
  92. package/src/doesRangeSpanEntireSequence.js +7 -0
  93. package/src/doesRangeSpanOrigin.js +3 -0
  94. package/src/{expandOrContractCircularRangeToPosition.ts → expandOrContractCircularRangeToPosition.js} +3 -5
  95. package/src/{expandOrContractNonCircularRangeToPosition.ts → expandOrContractNonCircularRangeToPosition.js} +2 -4
  96. package/src/{expandOrContractRangeByLength.ts → expandOrContractRangeByLength.js} +4 -5
  97. package/src/{expandOrContractRangeToPosition.ts → expandOrContractRangeToPosition.js} +8 -6
  98. package/src/{flipContainedRange.ts → flipContainedRange.js} +8 -18
  99. package/src/{generateRandomRange.ts → generateRandomRange.js} +2 -6
  100. package/src/{getAnnotationRangeType.ts → getAnnotationRangeType.js} +3 -5
  101. package/src/{getEachPositionInRangeAsArray.ts → getEachPositionInRangeAsArray.js} +2 -6
  102. package/src/{getLengthOfOverlappingRegionsBetweenTwoRanges.ts → getLengthOfOverlappingRegionsBetweenTwoRanges.js} +3 -4
  103. package/src/{getMiddleOfRange.ts → getMiddleOfRange.js} +1 -2
  104. package/src/{getOverlapOfNonCircularRanges.ts → getOverlapOfNonCircularRanges.js} +1 -7
  105. package/src/{getOverlapsOfPotentiallyCircularRanges.ts → getOverlapsOfPotentiallyCircularRanges.js} +7 -13
  106. package/src/{getPositionFromAngle.ts → getPositionFromAngle.js} +3 -3
  107. package/src/{getRangeAngles.ts → getRangeAngles.js} +3 -8
  108. package/src/{getRangeLength.ts → getRangeLength.js} +1 -4
  109. package/src/{getRangesBetweenTwoRanges.ts → getRangesBetweenTwoRanges.js} +2 -7
  110. package/src/getSequenceWithinRange.js +17 -0
  111. package/src/{getShortestDistanceBetweenTwoPositions.ts → getShortestDistanceBetweenTwoPositions.js} +3 -3
  112. package/src/{getYOffsetForPotentiallyCircularRange.ts → getYOffsetForPotentiallyCircularRange.js} +4 -5
  113. package/src/{getYOffsetsForPotentiallyCircularRanges.ts → getYOffsetsForPotentiallyCircularRanges.js} +4 -5
  114. package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -0
  115. package/src/{getZeroedRangeOverlaps.ts → getZeroedRangeOverlaps.js} +3 -4
  116. package/src/{getZeroedRangeOverlaps.test.ts → getZeroedRangeOverlaps.test.js} +15 -5
  117. package/src/{index.ts → index.js} +0 -1
  118. package/src/{index.test.ts → index.test.js} +3 -11
  119. package/src/invertRange.js +21 -0
  120. package/src/{isPositionCloserToRangeStartThanRangeEnd.ts → isPositionCloserToRangeStartThanRangeEnd.js} +3 -5
  121. package/src/{isPositionWithinRange.ts → isPositionWithinRange.js} +5 -14
  122. package/src/{isRangeOrPositionWithinRange.ts → isRangeOrPositionWithinRange.js} +6 -11
  123. package/src/{isRangeWithinRange.ts → isRangeWithinRange.js} +3 -5
  124. package/src/loopEachPositionInRange.js +5 -0
  125. package/src/{modulatePositionByRange.ts → modulatePositionByRange.js} +1 -6
  126. package/src/{modulateRangeBySequenceLength.ts → modulateRangeBySequenceLength.js} +1 -3
  127. package/src/{normalizePositionByRangeLength.ts → normalizePositionByRangeLength.js} +7 -7
  128. package/src/{normalizePositionByRangeLength1Based.ts → normalizePositionByRangeLength1Based.js} +2 -3
  129. package/src/{normalizeRange.ts → normalizeRange.js} +1 -2
  130. package/src/provideInclusiveOptions.js +39 -0
  131. package/src/{reversePositionInRange.ts → reversePositionInRange.js} +4 -4
  132. package/src/{splitRangeIntoTwoPartsIfItIsCircular.ts → splitRangeIntoTwoPartsIfItIsCircular.js} +4 -5
  133. package/src/{translateRange.ts → translateRange.js} +3 -5
  134. package/src/{trimAnnStartEndToFitSeqLength.ts → trimAnnStartEndToFitSeqLength.js} +2 -2
  135. package/src/{trimNonCicularRangeByAnotherNonCircularRange.ts → trimNonCicularRangeByAnotherNonCircularRange.js} +4 -6
  136. package/src/{trimNumberToFitWithin0ToAnotherNumber.ts → trimNumberToFitWithin0ToAnotherNumber.js} +4 -3
  137. package/src/{trimRangeByAnotherRange.ts → trimRangeByAnotherRange.js} +9 -9
  138. package/src/{zeroSubrangeByContainerRange.ts → zeroSubrangeByContainerRange.js} +8 -10
  139. package/translateRange.d.ts +1 -5
  140. package/translateRange.test.d.ts +1 -0
  141. package/trimAnnStartEndToFitSeqLength.d.ts +1 -1
  142. package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
  143. package/trimNonCicularRangeByAnotherNonCircularRange.d.ts +4 -2
  144. package/trimNumberToFitWithin0ToAnotherNumber.d.ts +1 -1
  145. package/trimRangeByAnotherRange.d.ts +1 -2
  146. package/trimRangeByAnotherRange.test.d.ts +1 -0
  147. package/zeroSubrangeByContainerRange.d.ts +1 -2
  148. package/zeroSubrangeByContainerRange.test.d.ts +1 -0
  149. package/RangeAngles.d.ts +0 -7
  150. package/src/RangeAngles.ts +0 -9
  151. package/src/adjustRangeToRotation.ts +0 -22
  152. package/src/doesRangeSpanEntireSequence.ts +0 -12
  153. package/src/doesRangeSpanOrigin.ts +0 -5
  154. package/src/getSequenceWithinRange.ts +0 -33
  155. package/src/getYOffsetsForPotentiallyCircularRanges.test.ts +0 -17
  156. package/src/invertRange.ts +0 -25
  157. package/src/loopEachPositionInRange.ts +0 -11
  158. package/src/provideInclusiveOptions.ts +0 -79
  159. package/src/types.ts +0 -12
  160. package/types.d.ts +0 -12
  161. /package/src/{getRangeLength.test.ts → getRangeLength.test.js} +0 -0
  162. /package/src/{getSequenceWithinRange.test.ts → getSequenceWithinRange.test.js} +0 -0
  163. /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: Range,
6
- insertStart: number,
7
- insertLength: number
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: Range,
7
- comparisonRange: Range
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
- import { Range } from "./types";
5
+ // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
7
6
 
8
7
  export default function checkIfPotentiallyCircularRangesOverlap(
9
- range: Range,
10
- comparisonRange: Range
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: Range[],
7
- sequenceLength: number,
8
- optionalOriginalRange?: Range
9
- ): Range[] {
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
- interface RangeIndicesOptions {
5
- inclusive1BasedStart?: boolean;
6
- inclusive1BasedEnd?: boolean;
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: Range) {
3
+ export default function convertRangeTo0Based(range) {
5
4
  return convertRangeIndices(range, {
6
5
  inclusive1BasedStart: true,
7
6
  inclusive1BasedEnd: true
@@ -1,7 +1,6 @@
1
1
  import convertRangeIndices from "./convertRangeIndices";
2
- import { Range } from "./types";
3
2
 
4
- export default function convertRangeTo1Based(range: Range) {
3
+ export default function convertRangeTo1Based(range) {
5
4
  return convertRangeIndices(
6
5
  range,
7
6
  {},
@@ -0,0 +1,7 @@
1
+ import getRangeLength from "./getRangeLength";
2
+
3
+ export default function doesRangeSpanEntireSequence(range, sequenceLength) {
4
+ if (getRangeLength(range) === sequenceLength) {
5
+ return true;
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ export default function doesRangeSpanOrigin(range) {
2
+ return range.start > range.end;
3
+ }
@@ -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: Range,
8
- position: number,
9
- maxLength: number
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: Range,
7
- position: number
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: Range,
7
- shiftBy: number,
8
- shiftStart: boolean,
9
- sequenceLength: number
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: Range,
8
- position: number,
9
- maxLength: number
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(range, position);
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: Range,
11
- outerRange: Range,
12
- sequenceLength: number
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: Range,
142
- outerRange: Range,
143
- sequenceLength: number
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: number, max: number) {
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: Range,
6
- enclosingRangeType: Range,
7
- forward: boolean
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
- range: Range,
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: Range,
7
- rangeB: Range,
8
- maxLength: number
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: Range, rangeMax: number) {
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
- import { Range } from "./types";
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
  }
@@ -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: Range,
11
- rangeB: Range,
12
- maxRangeLength: number,
13
- joinIfPossible = false //by default this fn only returns **non-circular** overlaps, if true it will try to join overlaps split on the origin
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: Range[] = [];
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: Partial<Range> = {};
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
- if (Object.keys(joinedOverlap).length > 0) {
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: number,
3
- rangeMax: number,
4
- isInBetweenPositions?: boolean
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((location: Range) => {
16
+ range.locations.map(location => {
22
17
  return getRangeAngles(location, rangeMax);
23
18
  })
24
19
  };
25
20
  }
26
21
 
27
- function getStartEndAndTotalAngle(range: Range, rangeMax: number) {
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
- import { Range } from "./types";
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: Range[] = [];
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
+ }
@@ -1,7 +1,7 @@
1
1
  export default function getShortestDistanceBetweenTwoPositions(
2
- position1: number,
3
- position2: number,
4
- sequenceLength: number
2
+ position1,
3
+ position2,
4
+ sequenceLength
5
5
  ) {
6
6
  if (position1 < position2) {
7
7
  const position1Holder = position1;
@@ -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: Range,
6
- YOffsetLevelsWithRanges: Range[][],
7
- assignYOffsetToRange: boolean
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 = 0;
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: Range[],
6
- assignYOffsetToRange: boolean
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: number[] = [];
8
+ const yOffsets = [];
10
9
  let maxYOffset = 0;
11
- const yOffsetLevels: Range[][] = []; //yOffsetLevels is an array of arrays (array of yOffset levels holding arrays of ranges)
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: Range,
10
- selection: Range,
11
- sequenceLength: number
8
+ annotation,
9
+ selection,
10
+ sequenceLength
12
11
  ) {
13
12
  const overlaps = collapseOverlapsGeneratedFromRangeComparisonIfPossible(
14
13
  getOverlapsOfPotentiallyCircularRanges(