def _get_pixels_near_line(pixels, line, eps):
    """
    This can be replaced with shorter, more inefficient code.
    Written to boost up the speed.
    :param pixels:
    :param line:
    :param eps:
    :return:
    """
    #return set(pixel for pixel in pixels if distance_between_line_and_point(line, pixel) <= eps)

    p = midpoint(line.a, line.b)
    u = line_unit_vector(line)
    n = line_normal_vector(line)
    half_length = line_length(line) / 2.0
    eps_squared = eps**2

    near_pixels = set()
    for point in pixels:
        vector = point.x - p.x, point.y - p.y
        perpendicular_distance = abs(np.dot(vector, n))
        if perpendicular_distance > eps:
            continue
        parallel_distance = abs(np.dot(vector, u))
        if parallel_distance <= half_length:
            near_pixels.add(point)
        else:
            if distance_between_points_squared(point, line.a) <= eps_squared or \
                    distance_between_points_squared(point, line.b) <= eps_squared:
                near_pixels.add(point)
    return near_pixels
Пример #2
0
def _get_pixels_near_line(pixels, line, eps):
    """
    This can be replaced with shorter, more inefficient code.
    Written to boost up the speed.
    :param pixels:
    :param line:
    :param eps:
    :return:
    """
    #return set(pixel for pixel in pixels if distance_between_line_and_point(line, pixel) <= eps)

    p = midpoint(line.a, line.b)
    u = line_unit_vector(line)
    n = line_normal_vector(line)
    half_length = line_length(line)/2.0
    eps_squared = eps**2

    near_pixels = set()
    for point in pixels:
        vector = point.x - p.x, point.y - p.y
        perpendicular_distance = abs(np.dot(vector, n))
        if perpendicular_distance > eps:
            continue
        parallel_distance = abs(np.dot(vector, u))
        if parallel_distance <= half_length:
            near_pixels.add(point)
        else:
            if distance_between_points_squared(point, line.a) <= eps_squared or \
                    distance_between_points_squared(point, line.b) <= eps_squared:
                near_pixels.add(point)
    return near_pixels
def SquaredLengthOf(line):
    return distance_between_points_squared(*line)
def _get_pixels_near_point(pixels, point, eps):
    return set(pixel for pixel in pixels
               if distance_between_points_squared(pixel, point) <= eps**2)
Пример #5
0
def _get_pixels_near_point(pixels, point, eps):
    return set(pixel for pixel in pixels if distance_between_points_squared(pixel, point) <= eps**2)