- moved updating matrices test case into unit test

This commit is contained in:
wrobell 2007-07-26 19:23:55 +00:00
parent b42862026d
commit 6b58085fb8
2 changed files with 20 additions and 18 deletions

View File

@ -462,26 +462,10 @@ class Canvas(object):
def update_matrices(self, items):
"""
Update the matrix of the items scheduled to be updated
their children.
Recalculate matrices of the items. Items' children matrices are
recalculated, too.
Return items, which matrices were recalculated.
>>> c = Canvas()
>>> from gaphas import item
>>> i = item.Item()
>>> ii = item.Item()
>>> i.matrix = (1.0, 0.0, 0.0, 1.0, 5.0, 0.0)
>>> c.add(i)
>>> ii.matrix = (1.0, 0.0, 0.0, 1.0, 0.0, 8.0)
>>> c.add(ii, i)
>>> c.update_matrices()
>>> c.get_matrix_i2c(i)
cairo.Matrix(1, 0, 0, 1, 5, 0)
>>> c.get_matrix_i2c(ii)
cairo.Matrix(1, 0, 0, 1, 5, 8)
>>> len(c._dirty_items)
0
"""
changed = set()
for item in items:

View File

@ -4,6 +4,24 @@ from gaphas.canvas import Canvas
from gaphas.examples import Box
from gaphas.item import Line, Handle
from gaphas.constraint import BalanceConstraint, EqualsConstraint
import cairo
class MatricesTestCase(unittest.TestCase):
def test_update_matrices(self):
"""Test updating of matrices"""
c = Canvas()
i = Box()
ii = Box()
c.add(i)
c.add(ii, i)
i.matrix = (1.0, 0.0, 0.0, 1.0, 5.0, 0.0)
ii.matrix = (1.0, 0.0, 0.0, 1.0, 0.0, 8.0)
updated = c.update_matrices([i])
self.assertEquals(i._matrix_i2c, cairo.Matrix(1, 0, 0, 1, 5, 0))
self.assertEquals(ii._matrix_i2c, cairo.Matrix(1, 0, 0, 1, 5, 8))
# fixme: what about multiple constraints for a handle?
# what about 1d projection?