summaryrefslogtreecommitdiff
path: root/host/simu/utils
diff options
context:
space:
mode:
authorNicolas Schodet2011-04-28 22:08:31 +0200
committerNicolas Schodet2011-04-28 22:08:31 +0200
commitb0ef2ecc8467319f27fd5de45c0bc9906013147b (patch)
tree7575cf51a08b5ef92513e51ce00ecb827c1e1cf8 /host/simu/utils
parenta62e936645808b33558168bd2225c96ad388740c (diff)
host/simu: add transformation matrix push/pop
Diffstat (limited to 'host/simu/utils')
-rw-r--r--host/simu/utils/trans_matrix.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/host/simu/utils/trans_matrix.py b/host/simu/utils/trans_matrix.py
index 99ffe707..12bc7b35 100644
--- a/host/simu/utils/trans_matrix.py
+++ b/host/simu/utils/trans_matrix.py
@@ -47,6 +47,7 @@ class TransMatrix:
self.matrix = m
else:
self.matrix = self.IDENTITY
+ self.stack = [ ]
def identity (self):
"""Set to identity.
@@ -163,6 +164,25 @@ class TransMatrix:
vl = sqrt (v[0] ** 2 + v[1] ** 2)
return vl
+ def push (self):
+ """Save the current value to be poped later.
+
+ >>> a = TransMatrix ()
+ >>> a.translate ((2, 3)); a
+ ((1, 0), (0, 1), (2, 3))
+ >>> a.push ()
+ >>> a.scale (2); a
+ ((2, 0), (0, 2), (4, 6))
+ >>> a.pop ()
+ >>> a
+ ((1, 0), (0, 1), (2, 3))
+ """
+ self.stack.append (self.matrix)
+
+ def pop (self):
+ """Restore saved value, see push."""
+ self.matrix = self.stack.pop ()
+
def __repr__ (self):
return self.matrix.__repr__ ()