import math


def objListUtility_indexToPos( p, featLen, numBins ):
    """ Utility function for the MafBlock instance version of 
    libMafGffPlot.objListToBinnedWiggle()
    Takes in a single index position in a [1, featLen] range and then provides the
    appropriate position in an array of length numBins. Maps an integer to the space
    [0, numBins].
    """ 
    # map point p from [1, featLen] to [0, featLen - 1]
    z  = float( p - 1.0 )
    # scale z to [0, featLen)
    z /= featLen
    # map  to [0, numBins)
    z *= float( numBins )
    # return the index in a length numBins array
    return math.floor( z )