import o from 'ospec' ; interface LatLon { lat : number ; lon : number ; } interface Point { x : number ; y : number ; } interface Bounds { x : number ; y : number ; width : number ; height : number ; } /** Prefix a message if the prefix exists */ function prefix ( base , prefixText ? ) { if ( prefixText ) return `${ prefixText }:${ base }` ; return base ; } param numA param numB param text param variance function approxEqual ( numA , numB , text , variance = 0.001 ) { if ( numA == null ) { o ( numA ) . notEquals ( undefined ) ( `${ text } should be approx equal to ${ numB }` ) ; return ; } const diff = Math . abs ( numA - numB ) ; o ( diff <= variance ) . equals ( true ) ( `${ text } (${ numA } vs ${ numB }) should be less than ${ variance }` ) ; } function approxBounds ( boundsA , boundsB , message ? , variance ? ) { approxEqual ( boundsA ?. width , boundsB . width , prefix ( 'width' , message ) , variance ) ; approxEqual ( boundsA ?. height , boundsB . height , prefix ( 'height' , message ) , variance ) ; approxEqual ( boundsA ?. y , boundsB . y , prefix ( 'top' , message ) , variance ) ; approxEqual ( boundsA ?. x , boundsB . x , prefix ( 'left' , message ) , variance ) ; } function approxLatLon ( latLonA , latLonB , message ? , variance = 0.0001 ) { approxEqual ( latLonA ?. lat , latLonB . lat , prefix ( 'lat' , message ) , variance ) ; approxEqual ( latLonA ?. lon , latLonB . lon , prefix ( 'lon' , message ) , variance ) ; } function approxPoint ( pA , pB , message ? , variance ? ) { approxEqual ( pA ?. x , pB . x , prefix ( 'x' , message ) , variance ) ; approxEqual ( pA ?. y , pB . y , prefix ( 'y' , message ) , variance ) ; } export const Approx = { point : approxPoint , latLon : approxLatLon , equal : approxEqual , bounds : approxBounds } ;