[project @ 1997-03-14 08:02:40 by simonpj]
[nofib.git] / real / hidden / Hide.hs
1 module Hide(hiddenline) where
2 import Numbers
3 import Vectors
4 import EdgePlate
5 import Geometric
6 import Comparing
7 import Memo
8 import Postscript
9 import Array -- 1.3
10 import ArrBase -- 1.3
11
12 -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13 -- section 5: Hiding
14
15 -- The following function does the entire job...
16 hiddenline :: Vector -> Input -> Output
17 hiddenline v corners
18 = (draw . scale factor base . hideObj . makeObject) rotated
19 where rotated = v `rot` corners
20 (base,factor) = getExtremes (concat rotated)
21
22 -- `hide' calculates the leftovers of plate bottom as compared to plates tops
23 hide :: Array (Triangle Int) Bool -> Object -> Plate -> [Edge]
24 hide memory obj bottom@(Plt _ ls) =
25 foldr cmp ls tops
26 where tops = [top| top <- obj, lazyAbove memory top bottom]
27
28 -- `hideObj' hides edgeparts in an object, with view direction vec[0,0,1]
29 hideObj :: Object -> [Edge]
30 hideObj obj = concat [hide (mkmemo above obj) obj plt| plt <- obj]
31
32
33 getExtremes :: [Vector] -> (Vector,Number)
34 getExtremes vs =
35 (vec [minimum xs, minimum ys, 0], factor)
36 where
37 factor = ((400 / ((maximum xs-minimum xs) `max` 1)) `min`
38 (640 / ((maximum ys-minimum ys) `max` 1)))
39 xs = map x vs
40 ys = map y vs