diff options
author | William Carroll <wpcarro@gmail.com> | 2020-08-05T23·15+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-08-05T23·15+0100 |
commit | e14fff7d4b04c37155acf046b7b3f350cf6ad3b6 (patch) | |
tree | 501e9483218ee20559075e2243e474b56fcd77fe /scratch | |
parent | d45685e2459df4c73702a854309646ae1e146eec (diff) |
Support Transforms.optimize
Partially optimize inputs and document rules for further optimizations we can make.
Diffstat (limited to 'scratch')
-rw-r--r-- | scratch/brilliant/Spec.hs | 7 | ||||
-rw-r--r-- | scratch/brilliant/Transforms.hs | 12 |
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 |