(triangles, fringe, grid, skeleton, placed_objects)
return None
Starting from an object in the existing structure on the grid,
        adds an edge to which a triangle from ``triangles`` could be
        welded.  If this method has found a way to do so, it returns
        the object it has just added.

        This method should be applied when ``_weld_triangle`` cannot
        find weldings any more.
Starting from an object in the existing structure on the grid,
        adds an edge to which a triangle from ``triangles`` could be
        welded.  If this method has found a way to do so, it returns
        the object it has just added.
Starting from an object in the existing structure on the grid adds an edge to which a triangle from triangles could be welded . If this method has found a way to do so it returns the object it has just added .
def _grow_pseudopod(triangles, fringe, grid, skeleton, placed_objects):
        """
        Starting from an object in the existing structure on the grid,
        adds an edge to which a triangle from ``triangles`` could be
        welded.  If this method has found a way to do so, it returns
        the object it has just added.

        This method should be applied when ``_weld_triangle`` cannot
        find weldings any more.
        """
        for i in xrange(grid.height):
            for j in xrange(grid.width):
                obj = grid[i, j]
                if not obj:
                    continue

                # Here we need to choose a triangle which has only
                # ``obj`` in common with the existing structure.  The
                # situations when this is not possible should be
                # handled elsewhere.

                def good_triangle(tri):
                    objs = DiagramGrid._triangle_objects(tri)
                    return obj in objs and \
                        placed_objects & (objs - set([obj])) == set()

                tris = [tri for tri in triangles if good_triangle(tri)]
                if not tris:
                    # This object is not interesting.
                    continue

                # Pick the "simplest" of the triangles which could be
                # attached.  Remember that the list of triangles is
                # sorted according to their "simplicity" (see
                # _compute_triangle_min_sizes for the metric).
                #
                # Note that ``tris`` are sequentially built from
                # ``triangles``, so we don't have to worry about hash
                # randomisation.
                tri = tris[0]

                # We have found a triangle which could be attached to
                # the existing structure by a vertex.

                candidates = sorted([e for e in tri if skeleton[e]],
                                    key=lambda e: FiniteSet(e).sort_key())
                edges = [e for e in candidates if obj in e]

                # Note that a meaningful edge (i.e., and edge that is
                # associated with a morphism) containing ``obj``
                # always exists.  That's because all triangles are
                # guaranteed to have at least two meaningful edges.
                # See _drop_redundant_triangles.

                # Get the object at the other end of the edge.
                edge = edges[0]
                other_obj = tuple(edge - frozenset([obj]))[0]

                # Now check for free directions.  When checking for
                # free directions, prefer the horizontal and vertical
                # directions.
                neighbours = [(i - 1, j), (i, j + 1), (i + 1, j), (i, j - 1),
                              (i - 1, j - 1), (i - 1, j + 1), (i + 1, j - 1), (i + 1, j + 1)]

                for pt in neighbours:
                    if DiagramGrid._empty_point(pt, grid):
                        # We have a found a place to grow the
                        # pseudopod into.
                        offset = DiagramGrid._put_object(
                            pt, other_obj, grid, fringe)

                        i += offset[0]
                        j += offset[1]
                        pt = (pt[0] + offset[0], pt[1] + offset[1])
                        fringe.append(((i, j), pt))

                        return other_obj

        # This diagram is actually cooler that I can handle.  Fail cowardly.
        return None
def _grow_pseudopod ( triangles , fringe , grid , skeleton , placed_objects ) : for i in xrange ( grid . height ) : for j in xrange ( grid . width ) : obj = grid [ i , j ] if not obj : continue # Here we need to choose a triangle which has only # ``obj`` in common with the existing structure.  The # situations when this is not possible should be # handled elsewhere. def good_triangle ( tri ) : objs = DiagramGrid . _triangle_objects ( tri ) return obj in objs and placed_objects & ( objs - set ( [ obj ] ) ) == set ( ) tris = [ tri for tri in triangles if good_triangle ( tri ) ] if not tris : # This object is not interesting. continue # Pick the "simplest" of the triangles which could be # attached.  Remember that the list of triangles is # sorted according to their "simplicity" (see # _compute_triangle_min_sizes for the metric). # # Note that ``tris`` are sequentially built from # ``triangles``, so we don't have to worry about hash # randomisation. tri = tris [ 0 ] # We have found a triangle which could be attached to # the existing structure by a vertex. candidates = sorted ( [ e for e in tri if skeleton [ e ] ] , key = lambda e : FiniteSet ( e ) . sort_key ( ) ) edges = [ e for e in candidates if obj in e ] # Note that a meaningful edge (i.e., and edge that is # associated with a morphism) containing ``obj`` # always exists.  That's because all triangles are # guaranteed to have at least two meaningful edges. # See _drop_redundant_triangles. # Get the object at the other end of the edge. edge = edges [ 0 ] other_obj = tuple ( edge - frozenset ( [ obj ] ) ) [ 0 ] # Now check for free directions.  When checking for # free directions, prefer the horizontal and vertical # directions. neighbours = [ ( i - 1 , j ) , ( i , j + 1 ) , ( i + 1 , j ) , ( i , j - 1 ) , ( i - 1 , j - 1 ) , ( i - 1 , j + 1 ) , ( i + 1 , j - 1 ) , ( i + 1 , j + 1 ) ] for pt in neighbours : if DiagramGrid . _empty_point ( pt , grid ) : # We have a found a place to grow the # pseudopod into. offset = DiagramGrid . _put_object ( pt , other_obj , grid , fringe ) i += offset [ 0 ] j += offset [ 1 ] pt = ( pt [ 0 ] + offset [ 0 ] , pt [ 1 ] + offset [ 1 ] ) fringe . append ( ( ( i , j ) , pt ) ) return other_obj # This diagram is actually cooler that I can handle.  Fail cowardly. return None