Created
November 8, 2014 19:18
-
-
Save fryguybob/93e71378d5868338f2d1 to your computer and use it in GitHub Desktop.
Tests for `arcDCCW` and `arcDCW`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Diagrams.Coordinates | |
import Diagrams.BoundingBox | |
-- import Diagrams.Backend.Postscript.CmdLine | |
-- import Diagrams.Backend.SVG.CmdLine | |
import Diagrams.Backend.Rasterific.CmdLine | |
import Diagrams.Backend.CmdLine | |
import Data.Default.Class | |
import Data.List | |
import Data.List.Split | |
-- > [1,2,3,4,5,6,...] | |
-- | |
-- Wrap after 'n' elements into a new row. | |
-- | |
-- > [ [1,2,3] | |
-- > , [4,5,6] | |
-- > , ... | |
-- > ] | |
type DB b = D (V b) (N b) | |
tableOf :: Int -> [Diagram B] -> Diagram B | |
tableOf = tableOf' def | |
tableOf' :: CatOpts (N B) -> Int -> [Diagram B] -> Diagram B | |
tableOf' opts n ds = vcat' opts | |
(map (hcat' opts) [[sized w h d | (w,d) <- zip widths row] | (h,row) <- zip heights rows]) | |
where | |
rows = chunksOf n ds | |
cols = transpose rows | |
heights = map (abs . (^._y) . boxExtents . boundingBox) rows | |
widths = map (abs . (^._x) . boxExtents . boundingBox) cols | |
sized ((/2)->w) ((/2)->h) = centerXY . withEnvelope (fromPoints [(-w) ^& (-h), (w ^& h)]) . centerXY | |
half = (/2) | |
tests :: V2 (N B) -> [(String,Diagram B)] | |
tests start | |
= [ (name, pad 1.1 . centerXY $ tableOf' (with & sep.~0.1) 4 (generate test)) | |
| (test,name) <- [ (diaCCW, "DCCW") | |
, (diaCW, "DCW") | |
] | |
] | |
where | |
vectors u v = arrowBetween 0 (0 .+^ u) # lc red | |
<> arrowBetween 0 (0 .+^ v) # lc green | |
diaCCW u v = arcDCCW (direction u) (direction v) # strokeLocTrail <> vectors u v | |
diaCW u v = arcDCW (direction u) (direction v) # strokeLocTrail <> vectors u v | |
generate test = | |
[ withEnvelope (circle 1 :: DB B) $ test start (f start) | |
| f <- map (rotate . (@@ turn) . (/16) . fromIntegral) [0..15] | |
] | |
-- main = mainWith (tests unitX) | |
-- Rasterific | |
main = gifMain [(bg white . snd . last $ tests (f unitX), 4) | |
| f <- map (rotate . (@@ turn) . (/32) . fromIntegral) [0..31] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment