From c88ec8e43960514d27a6368d864a68e07eb18e50 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 6 May 2011 16:37:52 -0400 Subject: [PATCH] Add the counter-clockwise rotations (with respect to the x-axis) to the Cardinal module. --- src/Cardinal.hs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Cardinal.hs b/src/Cardinal.hs index f62896f..c6f7e8f 100644 --- a/src/Cardinal.hs +++ b/src/Cardinal.hs @@ -1,6 +1,8 @@ module Cardinal where +import Prelude hiding (LT) + data Cardinal = F | B | L @@ -48,3 +50,42 @@ instance Fractional Cardinal where x / y = Quotient x y recip x = Quotient (Scalar 1) x fromRational x = Scalar (fromRational x) + +-- | Rotate a cardinal direction counter-clockwise about the x-axis. +ccwx :: Cardinal -> Cardinal +ccwx F = F +ccwx B = B +ccwx L = T +ccwx R = D +ccwx D = L +ccwx T = R +ccwx FL = FT +ccwx FR = FD +ccwx FD = FL +ccwx FT = FR +ccwx BL = BT +ccwx BR = BD +ccwx BD = BL +ccwx BT = BR +ccwx LD = LT +ccwx LT = RT +ccwx RD = LD +ccwx RT = RD +ccwx FLD = FLT +ccwx FLT = FRT +ccwx FRD = FLD +ccwx FRT = FRD +ccwx BLD = BLT +ccwx BLT = BRT +ccwx BRD = BLD +ccwx BRT = BRD +ccwx I = I +ccwx (Scalar s) = (Scalar s) +ccwx (Sum c0 c1) = Sum (ccwx c0) (ccwx c1) +ccwx (Difference c0 c1) = Difference (ccwx c0) (ccwx c1) +ccwx (Product c0 c1) = Product (ccwx c0) (ccwx c1) +ccwx (Quotient c0 c1) = Quotient (ccwx c0) (ccwx c1) + +-- | Rotate a cardinal direction clockwise about the x-axis. +cwx :: Cardinal -> Cardinal +cwx = ccwx . ccwx . ccwx -- 2.43.2