about summary refs log tree commit diff
path: root/scratch
diff options
context:
space:
mode:
Diffstat (limited to 'scratch')
-rw-r--r--scratch/brilliant/Spec.hs7
-rw-r--r--scratch/brilliant/Transforms.hs12
2 files changed, 19 insertions, 0 deletions
diff --git a/scratch/brilliant/Spec.hs b/scratch/brilliant/Spec.hs
index d5ad6234ddc0..f2450bdd9a5c 100644
--- a/scratch/brilliant/Spec.hs
+++ b/scratch/brilliant/Spec.hs
@@ -71,3 +71,10 @@ main = hspec $ do
                    , Utils.rotate (-3) ['A','S','D','F','G','H','J','K','L',';']
                    , Utils.rotate (-3) ['Z','X','C','V','B','N','M',',','.','/']
                    ]
+
+  describe "Transforms.optimize" $ do
+    it "removes superfluous horizontal transformations" $ do
+      Transforms.optimize [HorizontalFlip, HorizontalFlip] == []
+
+    it "removes superfluous vertical transformations" $ do
+      Transforms.optimize [VerticalFlip, VerticalFlip] == []
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