1 module GeomNum 2 3 4 5 6 (GeomNumb(..),Numb,Rationals,grid,rnd2 7 ) 8 9 where 10 11 import Params (renderLeft,renderTop,renderHeight,windowWidth) 12 import Rationals (Rationals(..),rndNR) 13 14 15 16 17 18 19 type Numb = Rationals 20 21 class (Fractional a) => GeomNumb a where 22 23 24 25 26 27 28 29 30 31 rnd :: a->Int 32 zerO,positive,negative :: a->Bool 33 ratio :: a -> a -> (a,a) 34 xCoordInRange :: a->Bool 35 yCoordInRange :: a->Bool 36 37 38 instance GeomNumb Rationals where 39 40 rnd = rndNR 41 zerO a = (a==0) 42 positive a = signum a > 0 43 negative a = signum a < 0 44 ratio 0 y = if (positive y) then (0,1) else (0,-1) 45 ratio x 0 = if (positive x) then (1,0) else (-1,0) 46 ratio x y = (signum x*(n:%%1),signum y*(d:%%1)) 47 where (n:%%d)= abs x/abs y 48 xCoordInRange x = (fromIntegral renderLeft) <= x && x <= (fromIntegral windowWidth) 49 yCoordInRange x = (fromIntegral renderTop) <= x && x <= (fromIntegral renderHeight) 50 51 rnd2 :: Numb -> Numb 52 rnd2 a = rnd a :%% 1 53 54 grid :: Numb -> Numb 55 grid (x:%%1) = (div (x+5) 10 * 10) :%% 1