File: Direction.hs

package info (click to toggle)
haskell-diagrams-lib 1.4.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,256 kB
  • sloc: haskell: 8,263; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- |

module Diagrams.Test.Direction where


import           Diagrams.Direction
import           Diagrams.Prelude
import           Instances
import           Test.Tasty
import           Test.Tasty.QuickCheck

tests :: TestTree
tests = testGroup "Direction" [
         testProperty "Length does not effect from direction" $
           \(Positive f) (NonZero v) -> fromDirection(dir ((v  :: V2 Double) ^* (f+0.001))) =~ fromDirection(dir v)
         , testProperty "HasTheta subtraction yeilds same result as anglebetween" $
            (anglebetsub)
         , testProperty "anglebetweenDirs is commutative" $
           \a b -> angleBetweenDirs (a :: Direction V2 Double) b =~ angleBetweenDirs b a
         , testProperty "fromdirection does not effect angleBetweenDirs" $
           \a b -> angleBetween (fromDirection (a  :: Direction V2 Double)) (fromDirection b) =~ angleBetweenDirs a b



      ]

if' :: Bool -> a -> a -> a
if' True  x _ = x
if' False _ y = y

anglebetsub :: Direction V2 Double -> Direction V2 Double -> Bool
anglebetsub a b = (if' (abs (a ^.  _theta^.rad  - b ^. _theta^.rad) < pi)
                       (abs ((a ^.  _theta  ^-^ b ^. _theta)^.rad))
                       (2*pi - abs (a ^.  _theta^.rad  - b ^. _theta^.rad) ) =~ angleBetweenDirs a b ^.rad)