diff --git a/src/mol-data/int/impl/interval.ts b/src/mol-data/int/impl/interval.ts index 79b9b12730e6e89a4e6f4392533b4d56d08888b7..540b7b38bafb8c096d241948ea96421d58b8d2a0 100644 --- a/src/mol-data/int/impl/interval.ts +++ b/src/mol-data/int/impl/interval.ts @@ -8,7 +8,7 @@ import Tuple from '../tuple' export const Empty = Tuple.Zero; export function ofRange(min: number, max: number) { return max < min ? Tuple.create(min, min) : Tuple.create(min, max + 1); } -export function ofBounds(min: number, max: number) { return max <= min ? Tuple.create(min, min) : Tuple.create(min, max); } +export function ofBounds(start: number, end: number) { return end <= start ? Tuple.create(start, start) : Tuple.create(start, end); } export const is = Tuple.is; export const start = Tuple.fst; diff --git a/src/mol-data/int/impl/segmentation.ts b/src/mol-data/int/impl/segmentation.ts index 7caa3bfb8919e5476fddf430ccc793f8df786fc3..fed6a7fb70a7f6e9854529323651752e5680b124 100644 --- a/src/mol-data/int/impl/segmentation.ts +++ b/src/mol-data/int/impl/segmentation.ts @@ -10,7 +10,14 @@ import Interval from '../interval' import SortedArray from '../sorted-array' import Segs from '../segmentation' -type Segmentation = { segments: SortedArray, segmentMap: Int32Array, count: number } +interface Segmentation { + /** Segments stored as a sorted array */ + segments: SortedArray, + /** Mapping of values to segments */ + segmentMap: Int32Array, + /** Number of segments */ + count: number +} export function create(values: ArrayLike<number>): Segmentation { const segments = SortedArray.ofSortedArray(values); diff --git a/src/mol-data/int/interval.ts b/src/mol-data/int/interval.ts index dc5b0de839c2eb0bbd5fe8d7f0b94a6eb27bf6e2..2b4c6cd17238ffa7f8a06574427f3b29422f3b8c 100644 --- a/src/mol-data/int/interval.ts +++ b/src/mol-data/int/interval.ts @@ -10,34 +10,47 @@ namespace Interval { export const Empty: Interval = Impl.Empty as any; export const ofSingleton: (value: number) => Interval = (v) => Impl.ofRange(v, v) as any; - /** Create interval [min, max] */ + /** Create interval from range [min, max] */ export const ofRange: (min: number, max: number) => Interval = Impl.ofRange as any; - /** Create interval [min, max) */ + /** Create interval from bounds [start, end), i.e. [start, end - 1] */ export const ofBounds: (start: number, end: number) => Interval = Impl.ofBounds as any; export const is: (v: any) => v is Interval = Impl.is as any; + /** Test if a value is within the bounds of the interval */ export const has: (interval: Interval, x: number) => boolean = Impl.has as any; export const indexOf: (interval: Interval, x: number) => number = Impl.indexOf as any; export const getAt: (interval: Interval, i: number) => number = Impl.getAt as any; + /** Start value of the interval, same as min value */ export const start: (interval: Interval) => number = Impl.start as any; + /** End value of the interval, same as max + 1 */ export const end: (interval: Interval) => number = Impl.end as any; + /** Min value of the interval, same as start value */ export const min: (interval: Interval) => number = Impl.min as any; + /** Max value of the interval, same as end - 1 */ export const max: (interval: Interval) => number = Impl.max as any; + /** Number of values in the interval */ export const size: (interval: Interval) => number = Impl.size as any; + /** Hash code describing the interval */ export const hashCode: (interval: Interval) => number = Impl.hashCode as any; + /** Test if two intervals are identical */ export const areEqual: (a: Interval, b: Interval) => boolean = Impl.areEqual as any; + /** Test if two intervals are intersecting, i.e. their bounds overlap */ export const areIntersecting: (a: Interval, b: Interval) => boolean = Impl.areIntersecting as any; + + /** Test if interval b is fully included in interval a */ export const isSubInterval: (a: Interval, b: Interval) => boolean = Impl.isSubInterval as any; export const findPredecessorIndex: (interval: Interval, x: number) => number = Impl.findPredecessorIndex as any; export const findPredecessorIndexInInterval: (interval: Interval, x: number, bounds: Interval) => number = Impl.findPredecessorIndexInInterval as any; export const findRange: (interval: Interval, min: number, max: number) => Interval = Impl.findRange as any; + /** Get a new interval that is the intersection of the two intervals */ export const intersect: (a: Interval, b: Interval) => Interval = Impl.intersect as any; } +/** Interval describing a range [min, max] of values */ interface Interval { '@type': 'int-interval' } export default Interval \ No newline at end of file