import { ComputedShapeParams } from "./oncoprintshape" ; import { RGBAColor } from "./oncoprintruleset" ; export type Omit < T , K extends keyof T > = Pick < T , Exclude < keyof T , K > > ; export function cloneShallow < T extends Object > ( obj ) { const ret = { } ; for ( const key of ( Object . keys ( obj ) as ( keyof T ) [ ] ) ) { ret [ key ] = obj [ key ] ; } return ret as T ; } export function extendArray ( target , source ) { for ( let i = 0 ; i < source . length ; i ++ ) { target . push ( source [ i ] ) ; } } export function doesCellIntersectPixel ( cellHitzone , pixelX ) { const lower = cellHitzone [ 0 ] , upper = cellHitzone [ 1 ] ; if ( upper < pixelX ) { return false ; } else if ( lower < pixelX + 1 ) { return true ; } else { return false ; } } export function ifndef < T > ( x , val ) { return ( typeof x === "undefined" ? val : x ) ; } export function shallowExtend < T extends Object , S extends Object > ( target , source ) { const ret = { } ; for ( const key of Object . keys ( target ) as ( keyof T & S ) [ ] ) { ret [ key ] = target [ key as keyof T ] as any ; } for ( const key of Object . keys ( source ) as ( keyof T & S ) [ ] ) { ret [ key ] = source [ key as keyof S ] as any ; } return ret as T & S ; } export function objectValues < T extends Object > ( obj ) { return Object . keys ( obj ) . map ( function ( key ) { return obj [ key ] ; } ) ; } export function arrayFindIndex < T > ( arr , predicate , start_index ? ) { start_index = start_index || 0 ; for ( let i = start_index ; i < arr . length ; i ++ ) { if ( predicate ( arr [ i ] ) ) { return i ; } } return - 1 ; } export function sgndiff ( a , b ) { if ( a < b ) { return - 1 ; } else if ( a > b ) { return 1 ; } else { return 0 ; } } export function clamp ( x , lower , upper ) { return Math . max ( lower , Math . min ( upper , x ) ) ; } export function z_comparator ( shapeA , shapeB ) { const zA = shapeA . z ; const zB = shapeB . z ; if ( zA < zB ) { return - 1 ; } else if ( zA > zB ) { return 1 ; } else { return 0 ; } } export function fastParseInt10 ( x , substringStart ? , substringEnd ? ) { substringStart = substringStart || 0 ; substringEnd = substringEnd || x . length ; let ret = 0 ; for ( let i = substringStart ; i < substringEnd ; i ++ ) { ret *= 10 ; ret += x . charCodeAt ( i ) - 48 ; } return ret ; } export function fastParseInt16 ( x ) { let ret = 0 ; let nextCharCode ; for ( let i = 0 ; i < x . length ; i ++ ) { ret *= 16 ; nextCharCode = x . charCodeAt ( i ) ; if ( nextCharCode > 96 ) { ret += nextCharCode - 87 ; } else if ( nextCharCode > 64 ) { ret += nextCharCode - 55 ; } else { ret += nextCharCode - 48 ; } } return ret ; } export function rgbString ( color ) { return `rgb(${ color [ 0 ] },${ color [ 1 ] },${ color [ 2 ] })` ; }