From 33440f5dd49e6474a6d78a34a82e9df6460d4bd7 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 27 Jul 2014 03:17:38 +0200 Subject: [PATCH] Fold vector/rotation/list expressions into constants. --- lslopt/lsloptimizer.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lslopt/lsloptimizer.py b/lslopt/lsloptimizer.py index c379d26..0ec5345 100644 --- a/lslopt/lsloptimizer.py +++ b/lslopt/lsloptimizer.py @@ -157,9 +157,18 @@ class optimizer(object): return if code0 in ('VECTOR', 'ROTATION', 'LIST'): + isconst = True for x in code[:1:-1]: self.FoldTree(x) - # TODO: Fold into constant if possible. + if x[0] != CONSTANT: + isconst = False + if isconst: + value = [x[2] for x in code[2:]] + if code0 == 'VECTOR': + value = lslfuncs.Vector([lslfuncs.ff(x) for x in value]) + elif code0 == 'ROTATION': + value = lslfuncs.Quaternion([lslfuncs.ff(x) for x in value]) + code[:] = [CONSTANT, code[1], value] return if code0 == 'FIELD':