def Colinear(A, B, C):
    line = instantiators['line'](A, C)
    eq = Equals(
        LengthOf(line),
        distance_between_points(line.a, B) +
        distance_between_points(line.b, B))
    return eq
Esempio n. 2
0
def _get_circle_dict(diagram_parse):
    """
    A dictionary of dictionaries, where key of the top dictionary is center point.
    The bottom dictionary contains radii (if multiple circles exist with the same center).

    :param diagram_parse:
    :return:
    """
    # FIXME : this needs to be changed
    eps = CIRCLE_EPS
    assert isinstance(diagram_parse, CoreParse)
    circle_dict = {}


    for point_key, point in diagram_parse.intersection_points.iteritems():
        d = {}
        radius_key = 0
        for circle in diagram_parse.primitive_parse.circles.values():
            if distance_between_points(point, circle.center) <= eps:
                points = {}
                for key in diagram_parse.intersection_points:
                    point = diagram_parse.intersection_points[key]
                    if distance_between_circle_and_point(circle, point) <= eps:
                        points[key] = point
                d[radius_key] = {'instance': circle, 'points': points}
                radius_key += 1
        if len(d) > 0:
            circle_dict[point_key] = d
    return circle_dict
Esempio n. 3
0
def label_distance_to_line(label_point, line, is_length):
    """
    minimum distance among:
    end points, mid point.

    :param point:
    :param line:
    :return:
    """
    mp = midpoint(line.a, line.b)
    distance = distance_between_points(label_point, mp)
    if is_length:
        return distance

    l = 1.0/line_length(line)  # To favor longer line if matching near the points
    return min(distance,
               distance_between_points(label_point, line.a) + l,
               distance_between_points(label_point, line.b) + l)
def Isosceles(triangle):
    sides = [
        distance_between_points(triangle[index - 1], point)
        for index, point in enumerate(triangle)
    ]
    combs = itertools.combinations(sides, 2)

    out = reduce(operator.__or__, (Equals(a, b) for a, b in combs), False)
    return out
Esempio n. 5
0
def label_distance_to_line(label_point, line, is_length):
    """
    minimum distance among:
    end points, mid point.

    :param point:
    :param line:
    :return:
    """
    mp = midpoint(line.a, line.b)
    distance = distance_between_points(label_point, mp)
    if is_length:
        return distance

    l = 1.0 / line_length(
        line)  # To favor longer line if matching near the points
    return min(distance,
               distance_between_points(label_point, line.a) + l,
               distance_between_points(label_point, line.b) + l)
def IsCenterOf(point, twod):
    name = twod.__class__.__name__
    if name == 'circle':
        return Equals(point[0], twod.center[0]) & Equals(
            point[1], twod.center[1])
    elif issubtype(name, 'polygon'):
        distances = [distance_between_points(point, each) for each in twod]
        reg = IsRegular(twod)
        out = reduce(operator.__and__,
                     (Equals(distances[index - 1], distance)
                      for index, distance in enumerate(distances)), True)
        return reg & out
    else:
        raise Exception()
Esempio n. 7
0
def _get_circles(primitive_parse, intersection_points):
    """
    A dictionary of dictionaries, where key of the top dictionary is center point.
    The bottom dictionary contains radii (if multiple circles exist with the same center).

    :param core_parse:
    :return:
    """
    eps = params.CIRCLE_EPS
    circle_dict = {}
    for point_key, point in intersection_points.iteritems():
        d = {}
        radius_key = 0
        for circle in primitive_parse.circles.values():
            if distance_between_points(point, circle.center) <= eps:
                d[radius_key] = circle
                radius_key += 1
        if len(d) > 0:
            circle_dict[point_key] = d
    return circle_dict
Esempio n. 8
0
def _get_circles(primitive_parse, intersection_points):
    """
    A dictionary of dictionaries, where key of the top dictionary is center point.
    The bottom dictionary contains radii (if multiple circles exist with the same center).

    :param core_parse:
    :return:
    """
    eps = params.CIRCLE_EPS
    circle_dict = {}
    for point_key, point in intersection_points.iteritems():
        d = {}
        radius_key = 0
        for circle in primitive_parse.circles.values():
            if distance_between_points(point, circle.center) <= eps:
                d[radius_key] = circle
                radius_key += 1
        if len(d) > 0:
            circle_dict[point_key] = d
    return circle_dict
Esempio n. 9
0
def label_distance_to_angle(label_point, angle):
    """
    If outside of the convex area, then distance is very high.
    :param point:
    :param angle:
    :return:
    """
    caa = cartesian_angle(angle.b, angle.a)
    cam = cartesian_angle(angle.b, label_point)
    cac = cartesian_angle(angle.b, angle.c)
    dm = signed_distance_between_cartesian_angles(cam, caa)
    dc = signed_distance_between_cartesian_angles(cac, caa)
    cav = caa + dc/2.0
    if cav > 2*np.pi:
        cav -= 2*np.pi
    cad = min(signed_distance_between_cartesian_angles(cam, cav), signed_distance_between_cartesian_angles(cav, cam))
    dist = distance_between_points(label_point, angle.b)
    if dc > dm:
        return dist*(1+cad+dc)
    else:
        return 100*dist  # effectively infinite
Esempio n. 10
0
def label_distance_to_angle(label_point, angle):
    """
    If outside of the convex area, then distance is very high.
    :param point:
    :param angle:
    :return:
    """
    caa = cartesian_angle(angle.b, angle.a)
    cam = cartesian_angle(angle.b, label_point)
    cac = cartesian_angle(angle.b, angle.c)
    dm = signed_distance_between_cartesian_angles(cam, caa)
    dc = signed_distance_between_cartesian_angles(cac, caa)
    cav = caa + dc / 2.0
    if cav > 2 * np.pi:
        cav -= 2 * np.pi
    cad = min(signed_distance_between_cartesian_angles(cam, cav),
              signed_distance_between_cartesian_angles(cav, cam))
    dist = distance_between_points(label_point, angle.b)
    if dc > dm:
        return dist * (1 + cad + dc)
    else:
        return 100 * dist  # effectively infinite
Esempio n. 11
0
def _get_radius(center, points):
    return max(distance_between_points(center, point) for point in points)
Esempio n. 12
0
def label_distance_to_arc(label_point, arc):
    return distance_between_points(label_point, arc_midpoint(arc))
def PointLiesOnCircle(point, circle):
    d = distance_between_points(point, circle.center)
    return Equals(d, circle.radius)
Esempio n. 14
0
def PointLiesOnLine(point, line):
    return Colinear(line.a, point, line.b) + Equals(
        LengthOf(line),
        distance_between_points(line.a, point) +
        distance_between_points(line.b, point))
Esempio n. 15
0
def _distance_to_closest_point(point, points):
    return min(distance_between_points(point, p) for p in points)
Esempio n. 16
0
def label_distance_to_point(label_point, point):
    return distance_between_points(label_point, point)
Esempio n. 17
0
def label_distance_to_point(label_point, point):
    return distance_between_points(label_point, point)
Esempio n. 18
0
def label_distance_to_arc(label_point, arc):
    return distance_between_points(label_point, arc_midpoint(arc))
Esempio n. 19
0
def PointLiesOnLine(point, line):
    return Colinear(line.a, point, line.b) + Equals(LengthOf(line), distance_between_points(line.a, point) + distance_between_points(line.b, point))
def IsRectLengthOf(number, quad):
    l1 = distance_between_points(quad[0], quad[1])
    l2 = distance_between_points(quad[1], quad[2])
    return Equals(l1, number) | Equals(l2, number)
Esempio n. 21
0
def _get_radius(center, points):
    return max(distance_between_points(center, point) for point in points)
Esempio n. 22
0
def _distance_to_closest_point(point, points):
    return min(distance_between_points(point, p) for p in points)
Esempio n. 23
0
def PointLiesOnCircle(point, circle):
    d = distance_between_points(point, circle.center)
    return Equals(d, circle.radius)