lose/utils/algorithms/distances.py
def octagonal_distance(x, y):
    """Calculates the distance between x and y using the octagonal
    formula.

    This is a very fast and fairly accurate approximation of the
    euclidean distance formula.
    See: http://www.flipcode.com/archives/Fast_Approximate_Distance_Functions.shtml

    Args:
        x (point): a point in space
        y (point): a point in space

    Returns:
        int:  the distance calculated between point x and point y
    """
    distance = 0
    diffs = [abs((xval or 0) - (yval or 0)) for xval, yval in lzip(x, y)]
    if len(diffs) != 2:
        raise TypeError('This distance is only valid in 2D')
    diff_min = min(diffs)
    diff_max = max(diffs)
    approximation = diff_max * 1007 + diff_min * 441
    correction = diff_max * 40 if diff_max < (diff_min << 4) else 0
    corrected_approximation = approximation - correction
    distance = (corrected_approximation + 512) >> 10
    return distance
Calculates the distance between x and y using the octagonal
    formula.

    This is a very fast and fairly accurate approximation of the
    euclidean distance formula.
    See: http://www.flipcode.com/archives/Fast_Approximate_Distance_Functions.shtml

    Args:
        x (point): a point in space
        y (point): a point in space

    Returns:
        int:  the distance calculated between point x and point y
    
Calculates the distance between x and y using the octagonal
formula.

This is a very fast and fairly accurate approximation of the
euclidean distance formula.
Calculates the distance between x and y using the octagonal formula . This is a very fast and fairly accurate approximation of the euclidean distance formula .
def octagonal_distance(x, y):
    distance = 0
    diffs = [abs((xval or 0) - (yval or 0)) for xval, yval in lzip(x, y)]
    if len(diffs) != 2:
        raise TypeError('This distance is only valid in 2D')
    diff_min = min(diffs)
    diff_max = max(diffs)
    approximation = diff_max * 1007 + diff_min * 441
    correction = diff_max * 40 if diff_max < (diff_min << 4) else 0
    corrected_approximation = approximation - correction
    distance = (corrected_approximation + 512) >> 10
    return distance
def octagonal_distance ( x , y ) : distance = 0 diffs = [ abs ( ( xval or 0 ) - ( yval or 0 ) ) for xval , yval in lzip ( x , y ) ] if len ( diffs ) != 2 : raise TypeError ( 'This distance is only valid in 2D' ) diff_min = min ( diffs ) diff_max = max ( diffs ) approximation = diff_max * 1007 + diff_min * 441 correction = diff_max * 40 if diff_max < ( diff_min << 4 ) else 0 corrected_approximation = approximation - correction distance = ( corrected_approximation + 512 ) >> 10 return distance
Calculates the distance between x and y using the octagonal
formula.
Calculates the distance between x and y using the octagonal formula .
"""Calculates the distance between x and y using the octagonal
    formula.

    This is a very fast and fairly accurate approximation of the
    euclidean distance formula.
    See: http://www.flipcode.com/archives/Fast_Approximate_Distance_Functions.shtml

    Args:
        x (point): a point in space
        y (point): a point in space

    Returns:
        int:  the distance calculated between point x and point y
    """
the distance calculated between point x and point y
the distance calculated between point x and point y
int
x
a point in space
a point in space
y
a point in space
a point in space