1 module Preds(into,onto) where
    2 import Numbers
    3 import Vectors
    4 import EdgePlate
    5 import Geometric
    6 -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    7 -- section 9: Predicates
    8 
    9 -- p `onto` l <=> proj(p) is member of set proj(l)
   10 onto ::  Vector -> Edge -> Bool
   11 p`onto`l | vertical l = proj(p)==proj(s(l))
   12          | otherwise  = v ||| w && 0<=v`inpr`w && v`inpr`w<=w`inpr`w
   13                         where v = proj(p-s(l))
   14                               w = proj(h(l))
   15 -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   16 -- section 9: Predicates
   17 
   18 -- v `into` ls means that proj(v) is inside (including the border of) proj(ls).
   19 into :: Vector -> Plate -> Bool
   20 v`into`p @ (Plt _ ls)
   21         | vertical p  = or  [v`onto`l |l<-ls]
   22         | otherwise   = and [a>=0| a<-zs] || and [a<=0| a<-zs]
   23                         where zs = [z ( (v-s(l)) * h(l) )| l<-ls]