Permalink
Browse files

DiagramGrid: Lay down the beginnings of the main construction loop.

This commit enables DiagramGrid to add the first edge to the layout and
introduces the (currently empty) function _weld_triangle, which welds
one triangle to the current fringe.

All triangles which are relevant to the plot are assumed to form a
prefix of the list of triangles.  Whether this is true will be later
revealed by further tests and the details of functionality.
  • Loading branch information...
scolobb committed Jun 22, 2012
1 parent 90ee353 commit 75b080bd39c3dddbdce23137a60b77fd665c22c9
Showing with 20 additions and 0 deletions.
  1. +20 −0 sympy/categories/diagram_drawing.py
@@ -274,6 +274,14 @@ def _other_vertex(triangle, edge):
"""
return (DiagramGrid._triangle_objects(triangle) - FiniteSet(edge)).args[0]
+ @staticmethod
+ def _weld_triangle(triangles, fringe, grid, skeleton):
+ """
+ Welds a triangle to the fringe and returns ``True``, if
+ possible. Otherwise returns ``False``.
+ """
+ pass
+
def __new__(cls, diagram):
premises = DiagramGrid._simplify_morphisms(diagram.premises)
conclusions = DiagramGrid._simplify_morphisms(diagram.conclusions)
@@ -286,3 +294,15 @@ def __new__(cls, diagram):
triangles = DiagramGrid._drop_redundant_triangles(triangles, skeleton)
triangle_sizes = DiagramGrid._compute_triangle_min_sizes(
triangles, skeleton)
+
+ triangles = sorted(triangles, key=lambda triangle: triangle_sizes[triangle])
+
+ grid = _GrowableGrid(2, 1)
+
+ # Place the first edge on the grid.
+ root_edge = [e for e in triangles[0] if skeleton[e]][0]
+ grid[0, 0], grid[0, 1] = root_edge
+ fringe = [((0,0), (0, 1))]
+
+ while DiagramGrid._weld_triangle(triangles, fringe, grid, skeleton):
+ pass

0 comments on commit 75b080b

Please sign in to comment.