1 module Geometric (Geom(..)) where
    2 import Numbers
    3 import Vectors
    4 import EdgePlate
    5 import Rotate
    6 
    7 class Geom a where
    8         (|||) :: a -> a -> Bool                     -- two entities are parrallel ?
    9         vertical :: a -> Bool
   10         rot :: Vector -> a -> a                     -- rotation
   11         proj :: a -> a                      -- projection
   12         scale :: Number -> Vector -> a -> a    -- scale the entity and
   13                                  -- put it in the first quadrant
   14 
   15 
   16 instance Geom a => Geom [a] where
   17         rot viewdir = map (rot viewdir)
   18         proj = map proj
   19         scale f b = map (scale f b)
   20 
   21 instance Geom Vector where
   22         v ||| w = v*w == 0
   23         vertical v = v ||| vec [0,0,1]
   24         rot = rotate
   25         proj v = vec [x(v),y(v),0]
   26         scale factor base v = factor `mulv` (v - base)
   27 
   28 instance Geom Edge where
   29         l ||| k        = h(l) ||| h(k)
   30         vertical l = vertical (h(l))
   31         v `rot` l = edgeT (v `rot` s(l)) (v `rot` t(l))
   32         proj l = edgeT (proj(s(l))) (proj(t(l)))
   33         scale f b l = edgeT (scale f b (s(l))) (scale f b (t(l)))
   34 
   35 instance Geom Plate where
   36         plt1 ||| plt2 = n(plt1) ||| n(plt2)
   37         vertical plt = z( n(plt) ) == 0
   38         v `rot` (Plt n ls)  = Plt n [v `rot` l| l<-ls]
   39         proj (Plt n ls) = Plt n [proj l| l<-ls]