about summary refs log tree commit diff
path: root/scratch/brilliant/Transforms.hs
diff options
context:
space:
mode:
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