1 module Comparing (above,cmp) where
    2 import Numbers
    3 import Vectors
    4 import EdgePlate
    5 import Preds
    6 import Solve
    7 import Geometric
    8 import Cross
    9 import List(nub)--1.3
   10 -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   11 -- section 8: Comparing
   12 
   13 cmp :: Plate -> [Edge] -> [Edge]
   14 cmp p ls = concat [comp l p| l<-ls]
   15 
   16 comp :: Edge -> Plate -> [Edge]
   17 comp l p@(Plt _ ks) =
   18         if          inS &&     inT     then []
   19         else if crosses==[]       then [l]
   20         else if     inS && not inT     then [edgeT w (t l)]
   21         else if not inS &&     inT     then [edgeT (s l) v]
   22                                         else [edgeT (s l) v, edgeT w (t l)]
   23         where
   24         inS    = s(l) `into` p
   25         inT    = t(l) `into` p
   26         crosses        = nub [p| k<-ks, (p,q)<-cross l k]
   27         cr1    = head crosses
   28         cr2    = last crosses
   29         (v,w)  = if len(s(l)-cr1) <= len(s(l)-cr2)
   30                   then (cr1,cr2)
   31                   else (cr2,cr1)
   32 
   33 
   34 -- ls `above` ks means that the edges of ks have to be inspected
   35 -- individually, and hidden where lying inside ls.
   36 -- Be careful not to call 'alt ls' when ls is vertical
   37 above :: Plate -> Plate -> Bool
   38 ls `above` ks =
   39         if vertical ls
   40         then if vertical ks
   41              then or [z(p) > z(q)| p<-olk, q<-okl]
   42              else or [  z(p)   > alt ks p| p<-olk]
   43         else if vertical ks
   44              then or [alt ls q >   z(q)  | q<-okl]
   45              else or [alt ls p > alt ks p| p<-ovl]
   46         where olk = overlap ls ks
   47               okl = overlap ks ls
   48               ovl = nub ([proj p|p<-olk]++[proj p|p<-okl])