Ejemplo n.º 1
0
def interpret_range(S):
    if type(S) is tuple:
        return tuple(sorted(S))
    else:
        if ":" in S:
            a, b, *_ = S.split(":")
            return tuple(sorted((interpret_float(a), interpret_float(b))))
        else:
            a = interpret_float(S)
            return a, a + 1
Ejemplo n.º 2
0
def interpret_range(S):
    if type(S) is tuple:
        return tuple(sorted(S))
    else:
        if ':' in S:
            a, b, *_ = S.split(':')
            return tuple(sorted((interpret_float(a), interpret_float(b))))
        else:
            a = interpret_float(S)
            return a, a + 1
Ejemplo n.º 3
0
def pack_binomial(value):
    value = "".join(c for c in value if c in set("1234567890.-+K"))
    K = 0
    C = 0
    sgn = 1
    for k, g in ((k, "".join(g)) for k, g in groupby(value, key=lambda v: True if v in ("+", "-") else False)):
        if k:
            if g.count("-") % 2:
                sgn = -1
            else:
                sgn = 1
        else:
            if "K" in g:
                if g[0] == "K":
                    coefficient = 1
                else:
                    coefficient = interpret_int(g[: g.find("K")])
                K += coefficient * sgn
            else:
                constant = interpret_float(g)
                C += constant * sgn

    if K < 0:
        SIGN = -1
        K = abs(K)
    else:
        SIGN = 1

    return C, SIGN, K
Ejemplo n.º 4
0
def interpret_rgba(C):
    RGBA = [0, 0, 0, 1]
    if type(C) is tuple:
        for pos, value in enumerate(C[:4]):
            RGBA[pos] = value
    else:
        C = C.lower()
        hx = "0123456789abcdef"
        numeric = "0123456789., "
        flo = "0123456789."
        i = "0123456789"
        # rgba
        if all(c in numeric for c in C):
            for pos, channel in enumerate(C.split(",")[:4]):
                RGBA[pos] = interpret_float(channel)
        # hex
        else:
            colorstring = "".join(c for c in C if c in hx)
            if len(colorstring) > 4:
                colorstring = colorstring + "000000ff"[len(colorstring) :]
                bytes = 2
            else:
                colorstring = colorstring + "000f"[len(colorstring) :]
                bytes = 1
            for pos in range(4):
                RGBA[pos] = int(colorstring[pos * bytes : pos * bytes + bytes], 16) / (16 ** bytes - 1)
    return tuple(RGBA)
Ejemplo n.º 5
0
def pack_binomial(value):
    value = ''.join(c for c in value if c in set('1234567890.-+K'))
    K = 0
    C = 0
    sgn = 1
    for k, g in ((k, ''.join(g)) for k, g in groupby(
            value, key=lambda v: True if v in ('+', '-') else False)):
        if k:
            if g.count('-') % 2:
                sgn = -1
            else:
                sgn = 1
        else:
            if 'K' in g:
                if g[0] == 'K':
                    coefficient = 1
                else:
                    coefficient = interpret_int(g[:g.find('K')])
                K += coefficient * sgn
            else:
                constant = interpret_float(g)
                C += constant * sgn

    if K < 0:
        SIGN = -1
        K = abs(K)
    else:
        SIGN = 1

    return C, SIGN, K
Ejemplo n.º 6
0
def interpret_rgba(C):
    RGBA = [0, 0, 0, 1]
    if type(C) is tuple:
        for pos, value in enumerate(C[:4]):
            RGBA[pos] = value
    else:
        C = C.lower()
        hx = '0123456789abcdef'
        numeric = '0123456789., '
        flo = '0123456789.'
        i = '0123456789'
        # rgba
        if all(c in numeric for c in C):
            for pos, channel in enumerate(C.split(',')[:4]):
                RGBA[pos] = interpret_float(channel)
        # hex
        else:
            colorstring = ''.join(c for c in C if c in hx)
            if len(colorstring) > 4:
                colorstring = colorstring + '000000ff'[len(colorstring):]
                bytes = 2
            else:
                colorstring = colorstring + '000f'[len(colorstring):]
                bytes = 1
            for pos in range(4):
                RGBA[pos] = int(colorstring[pos * bytes:pos * bytes + bytes],
                                16) / (16**bytes - 1)
    return tuple(RGBA)
Ejemplo n.º 7
0
def pack_binomial(value):
    value = ''.join(c for c in value if c in set('1234567890.-+K'))
    K = 0
    C = 0
    sgn = 1
    for k, g in ( (k, ''.join(g)) for k, g in groupby(value, key=lambda v: True if v in ('+', '-') else False) ):
        if k:
            if g.count('-') % 2:
                sgn = -1
            else:
                sgn = 1
        else:
            if 'K' in g:
                if g[0] == 'K':
                    coefficient = 1
                else:
                    coefficient = interpret_int(g[:g.find('K')])
                K += coefficient*sgn
            else:
                constant = interpret_float(g)
                C += constant*sgn
    
    if K < 0:
        SIGN = -1
        K = abs(K)
    else:
        SIGN = 1

    return C, SIGN, K
Ejemplo n.º 8
0
def interpret_haylor(value):  # X X X X X : (X, X, X, X, X)
    if type(value) is tuple:
        return value
    else:
        if "," in value:
            print("1 dimensional values take only one coordinate")
            return ()
        L = (interpret_float(val, fail=None) for val in value.split())
        return tuple(v for v in L if v is not None)
Ejemplo n.º 9
0
def interpret_haylor(value):  # X X X X X : (X, X, X, X, X)
    if type(value) is tuple:
        return value
    else:
        if ',' in value:
            print('1 dimensional values take only one coordinate')
            return ()
        L = (interpret_float(val, fail=None) for val in value.split())
        return tuple(v for v in L if v is not None)
Ejemplo n.º 10
0
def interpret_open_range(S):
    if type(S) is tuple:
        return tuple(sorted(S))
    else:
        if ":" in S:
            a, b, *_ = S.split(":")
        else:
            a = S
            b = ""

        if a:
            i = interpret_float(a)
        else:
            i = None
        if b:
            j = interpret_float(b)
        else:
            j = None
        return i, j
Ejemplo n.º 11
0
def interpret_open_range(S):
    if type(S) is tuple:
        return tuple(sorted(S))
    else:
        if ':' in S:
            a, b, *_ = S.split(':')
        else:
            a = S
            b = ''

        if a:
            i = interpret_float(a)
        else:
            i = None
        if b:
            j = interpret_float(b)
        else:
            j = None
        return i, j
Ejemplo n.º 12
0
 def __init__(self, string):
     if type(string) is self.__class__:
         self._stops, self._colors = string.get_stops_colors()
     else:
         stops = [stop for stop in (stop.split(':') for stop in string.split('|')) if len(stop) > 1]
         if stops:
             self._stops, self._colors = zip( * sorted((interpret_float(stop[0]), interpret_rgba(stop[1])) for stop in stops) )
         else:
             self._stops  = 0,
             self._colors = interpret_rgba(string),
Ejemplo n.º 13
0
 def __init__(self, string):
     if type(string) is self.__class__:
         self._stops, self._colors = string.get_stops_colors()
     else:
         stops = [
             stop
             for stop in (stop.split(':') for stop in string.split('|'))
             if len(stop) > 1
         ]
         if stops:
             self._stops, self._colors = zip(*sorted(
                 (interpret_float(stop[0]), interpret_rgba(stop[1]))
                 for stop in stops))
         else:
             self._stops = 0,
             self._colors = interpret_rgba(string),
Ejemplo n.º 14
0
def interpret_float_tuple(value):
    L = (interpret_float(val, fail=None) for val in value.split(","))
    return tuple(v for v in L if v is not None)
Ejemplo n.º 15
0
def interpret_float_tuple(value):
    L = (interpret_float(val, fail=None) for val in value.split(','))
    return tuple(v for v in L if v is not None)