about summary refs log tree commit diff
path: root/scratch/brilliant/Transforms.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-05T23·15+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-05T23·15+0100
commite14fff7d4b04c37155acf046b7b3f350cf6ad3b6 (patch)
tree501e9483218ee20559075e2243e474b56fcd77fe /scratch/brilliant/Transforms.hs
parentd45685e2459df4c73702a854309646ae1e146eec (diff)
Support Transforms.optimize
Partially optimize inputs and document rules for further optimizations we can
make.
Diffstat (limited to 'scratch/brilliant/Transforms.hs')
-rw-r--r--scratch/brilliant/Transforms.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/scratch/brilliant/Transforms.hs b/scratch/brilliant/Transforms.hs
index 810c5f960ae1..d8df8f8372e0 100644
--- a/scratch/brilliant/Transforms.hs
+++ b/scratch/brilliant/Transforms.hs
@@ -33,6 +33,18 @@ command = vertical
         Nothing -> pure $ Shift n
         Just _  -> pure $ Shift (-1 * n)
 
+-- | Attempt to remove redundant transformations.
+-- | Here are some rules that I'd like to support but may not have time for:
+-- | - All even-numbered flips (w/o intermittent shifts) can become zero
+-- | - All odd-numbered flips (w/o intermittent shifts) can become 1
+-- | - All shifts can be be reduce to the absolute value of shifts
+optimize :: [Transform] -> [Transform]
+optimize [] = []
+optimize [x] = [x]
+optimize (VerticalFlip:VerticalFlip:xs) = optimize xs
+optimize (HorizontalFlip:HorizontalFlip:xs) = optimize xs
+optimize xs = xs
+
 fromString :: String -> Maybe [Transform]
 fromString x =
   case readP_to_S (manyTill command eof) x of