import { JsonExpr } from "./Expr" ; internal export enum InterpolationMode { Discrete , Linear , Cubic , Exponential } internal export interface InterpolatedPropertyDefinition < T > { interpolation ? : "Discrete" | "Linear" | "Cubic" | "Exponential" ; zoomLevels : number [ ] ; values : T [ ] ; exponent ? : number ; } param p internal export function isInterpolatedPropertyDefinition < T > ( p ) { if ( p && p . interpolationMode === undefined && Array . isArray ( p . values ) && p . values . length > 0 && p . values [ 0 ] !== undefined && Array . isArray ( p . zoomLevels ) && p . zoomLevels . length > 0 && p . zoomLevels [ 0 ] !== undefined && p . values . length === p . zoomLevels . length ) { return true ; } return false ; } param property export function interpolatedPropertyDefinitionToJsonExpr ( property ) { if ( property . interpolation === undefined || property . interpolation === "Discrete" ) { const step = [ "step" , [ "zoom" ] , property . values [ 0 ] ] ; for ( let i = 1 ; i < property . zoomLevels . length ; ++ i ) { step . push ( property . zoomLevels [ i ] , property . values [ i ] ) ; } return step ; } const interpolation = [ "interpolate" ] ; switch ( property . interpolation ) { case "Linear" : interpolation . push ( [ "linear" ] ) ; break ; case "Cubic" : interpolation . push ( [ "cubic" ] ) ; break ; case "Exponential" : interpolation . push ( [ "exponential" , property . exponent !== undefined ? property . exponent : 2 ] ) ; break ; default : throw new Error ( `interpolation mode '${ property . interpolation }' is not supported` ) ; } interpolation . push ( [ "zoom" ] ) ; for ( let i = 0 ; i < property . zoomLevels . length ; ++ i ) { interpolation . push ( property . zoomLevels [ i ] , property . values [ i ] ) ; } return interpolation ; }