]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Cardinal.hs
Add the counter-clockwise rotations (with respect to the x-axis) to the Cardinal...
[spline3.git] / src / Cardinal.hs
1 module Cardinal
2 where
3
4 import Prelude hiding (LT)
5
6 data Cardinal = F
7 | B
8 | L
9 | R
10 | D
11 | T
12 | FL
13 | FR
14 | FD
15 | FT
16 | BL
17 | BR
18 | BD
19 | BT
20 | LD
21 | LT
22 | RD
23 | RT
24 | FLD
25 | FLT
26 | FRD
27 | FRT
28 | BLD
29 | BLT
30 | BRD
31 | BRT
32 | I
33 | Scalar Double
34 | Sum Cardinal Cardinal
35 | Difference Cardinal Cardinal
36 | Product Cardinal Cardinal
37 | Quotient Cardinal Cardinal
38 deriving (Show, Eq)
39
40 instance Num Cardinal where
41 x + y = Sum x y
42 x - y = Difference x y
43 x * y = Product x y
44 negate x = Product (Scalar (-1)) x
45 abs x = x
46 signum x = x
47 fromInteger x = Scalar (fromIntegral x)
48
49 instance Fractional Cardinal where
50 x / y = Quotient x y
51 recip x = Quotient (Scalar 1) x
52 fromRational x = Scalar (fromRational x)
53
54 -- | Rotate a cardinal direction counter-clockwise about the x-axis.
55 ccwx :: Cardinal -> Cardinal
56 ccwx F = F
57 ccwx B = B
58 ccwx L = T
59 ccwx R = D
60 ccwx D = L
61 ccwx T = R
62 ccwx FL = FT
63 ccwx FR = FD
64 ccwx FD = FL
65 ccwx FT = FR
66 ccwx BL = BT
67 ccwx BR = BD
68 ccwx BD = BL
69 ccwx BT = BR
70 ccwx LD = LT
71 ccwx LT = RT
72 ccwx RD = LD
73 ccwx RT = RD
74 ccwx FLD = FLT
75 ccwx FLT = FRT
76 ccwx FRD = FLD
77 ccwx FRT = FRD
78 ccwx BLD = BLT
79 ccwx BLT = BRT
80 ccwx BRD = BLD
81 ccwx BRT = BRD
82 ccwx I = I
83 ccwx (Scalar s) = (Scalar s)
84 ccwx (Sum c0 c1) = Sum (ccwx c0) (ccwx c1)
85 ccwx (Difference c0 c1) = Difference (ccwx c0) (ccwx c1)
86 ccwx (Product c0 c1) = Product (ccwx c0) (ccwx c1)
87 ccwx (Quotient c0 c1) = Quotient (ccwx c0) (ccwx c1)
88
89 -- | Rotate a cardinal direction clockwise about the x-axis.
90 cwx :: Cardinal -> Cardinal
91 cwx = ccwx . ccwx . ccwx