Esempio n. 1
0
def _get_all_polygons(graph_parse, name, n, is_variable):
    polygons = {}
    frozensets = set()
    line_graph = graph_parse.line_graph
    for keys in itertools.permutations(graph_parse.intersection_points, n):
        if frozenset(keys) in frozensets:
            continue
        if not all(line_graph.has_edge(keys[idx-1], key) for idx, key in enumerate(keys)):
            continue

        angles = []
        for idx, key in enumerate(keys):
            angles.extend(_get_angles(graph_parse, False, keys[idx-2], keys[idx-1], key).values())
        if len(angles) < n:
            continue

        convex = polygon_is_convex(tuple(graph_parse.intersection_points[key] for key in keys))

        if is_variable:
            points = list(graph_parse.core_parse.point_variables[key] for key in keys)
        else:
            points = list(graph_parse.intersection_points[key] for key in keys)
        if not convex:
            points.reverse()
        # polygon = instantiators[name](*points)
        polygon = FormulaNode(signatures[name.capitalize()], points)
        polygon_key = tuple(keys)
        polygons[polygon_key] = polygon
        frozensets.add(frozenset(keys))
    return polygons
Esempio n. 2
0
def _get_polygons(graph_parse, name, is_variable, *args):
    # TODO : include ignore_trivial parameter. This ignores area-0 polygons.
    assert isinstance(graph_parse, GraphParse)
    line_graph = graph_parse.line_graph
    if all(line_graph.has_edge(args[idx-1], arg) for idx, arg in enumerate(args)):
        convex = polygon_is_convex(tuple(graph_parse.intersection_points[key] for key in args))

        if is_variable:
            points = list(graph_parse.core_parse.point_variables[key] for key in args)
        else:
            points = list(graph_parse.intersection_points[key] for key in args)
        if not convex:
            points.reverse()
        polygon = FormulaNode(signatures[name.capitalize()], points)
        polygon_key = tuple(args)
        return {polygon_key: polygon}
    else:
        return {}
def _get_all_polygons(graph_parse, name, n, is_variable):
    polygons = {}
    frozensets = set()
    line_graph = graph_parse.line_graph
    for keys in itertools.permutations(graph_parse.intersection_points, n):
        if frozenset(keys) in frozensets:
            continue
        if not all(
                line_graph.has_edge(keys[idx - 1], key)
                for idx, key in enumerate(keys)):
            continue

        angles = []
        for idx, key in enumerate(keys):
            angles.extend(
                _get_angles(graph_parse, False, keys[idx - 2], keys[idx - 1],
                            key).values())
        if len(angles) < n:
            continue

        convex = polygon_is_convex(
            tuple(graph_parse.intersection_points[key] for key in keys))

        if is_variable:
            points = list(graph_parse.core_parse.point_variables[key]
                          for key in keys)
        else:
            points = list(graph_parse.intersection_points[key] for key in keys)
        if not convex:
            points.reverse()
        polygon = instantiators[name](*points)
        # polygon = FormulaNode(signatures[name.capitalize()], points)
        polygon_key = tuple(keys)
        polygons[polygon_key] = polygon
        frozensets.add(frozenset(keys))
    return polygons