def scourUnitlessLength(length, renderer_workaround=False, is_control_point=False):  # length is of a numeric type
    """
    Scours the numeric part of a length only. Does not accept units.

    This is faster than scourLength on elements guaranteed not to
    contain units.
    """
    if not isinstance(length, Decimal):
        length = getcontext().create_decimal(str(length))
    initial_length = length

    # reduce numeric precision
    # plus() corresponds to the unary prefix plus operator and applies context precision and rounding
    if is_control_point:
        length = scouringContextC.plus(length)
    else:
        length = scouringContext.plus(length)

    # remove trailing zeroes as we do not care for significance
    intLength = length.to_integral_value()
    if length == intLength:
        length = Decimal(intLength)
    else:
        length = length.normalize()

    # Gather the non-scientific notation version of the coordinate.
    # Re-quantize from the initial value to prevent unnecessary loss of precision
    # (e.g. 123.4 should become 123, not 120 or even 100)
    nonsci = '{0:f}'.format(length)
    nonsci = '{0:f}'.format(initial_length.quantize(Decimal(nonsci)))
    if not renderer_workaround:
        if len(nonsci) > 2 and nonsci[:2] == '0.':
            nonsci = nonsci[1:]  # remove the 0, leave the dot
        elif len(nonsci) > 3 and nonsci[:3] == '-0.':
            nonsci = '-' + nonsci[2:]  # remove the 0, leave the minus and dot
    return_value = nonsci

    # Gather the scientific notation version of the coordinate which
    # can only be shorter if the length of the number is at least 4 characters (e.g. 1000 = 1e3).
    if len(nonsci) > 3:
        # We have to implement this ourselves since both 'normalize()' and 'to_sci_string()'
        # don't handle negative exponents in a reasonable way (e.g. 0.000001 remains unchanged)
        exponent = length.adjusted()  # how far do we have to shift the dot?
        length = length.scaleb(-exponent).normalize()  # shift the dot and remove potential trailing zeroes

        sci = six.text_type(length) + 'e' + six.text_type(exponent)

        if len(sci) < len(nonsci):
            return_value = sci

    return return_value
def scourUnitlessLength ( length , renderer_workaround = False , is_control_point = False ) : if not isinstance ( length , Decimal ) : length = getcontext ( ) . create_decimal ( str ( length ) ) initial_length = length if is_control_point : length = scouringContextC . plus ( length ) else : length = scouringContext . plus ( length ) intLength = length . to_integral_value ( ) if length == intLength : length = Decimal ( intLength ) else : length = length . normalize ( ) nonsci = '{0:f}' . format ( length ) nonsci = '{0:f}' . format ( initial_length . quantize ( Decimal ( nonsci ) ) ) if not renderer_workaround : if len ( nonsci ) > 2 and nonsci [ : 2 ] == '0.' : nonsci = nonsci [ 1 : ] elif len ( nonsci ) > 3 and nonsci [ : 3 ] == '-0.' : nonsci = '-' + nonsci [ 2 : ] return_value = nonsci if len ( nonsci ) > 3 : exponent = length . adjusted ( ) length = length . scaleb ( - exponent ) . normalize ( ) sci = six . text_type ( length ) + 'e' + six . text_type ( exponent ) if len ( sci ) < len ( nonsci ) : return_value = sci return return_value
Scours the numeric part of a length only. Does not accept units.

    This is faster than scourLength on elements guaranteed not to
    contain units.