Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/eXene/graph-util/box.sml
ViewVC logotype

Annotation of /sml/trunk/src/eXene/graph-util/box.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (view) (download)

1 : monnier 2 (* box.sml
2 :     *
3 :     * COPYRIGHT (c) 1994 by AT&T Bell Laboratories
4 :     *
5 :     * Code for simple box data structure.
6 :     *
7 :     * A box is essentially a rectangle stored as the upper left point
8 :     * and lower right bounding point. Note that the lower right point
9 :     * is not actually part of the rectangle. Explicitly,
10 :     * RECT{x,y,wid,ht} corresponds to the box
11 :     * BOX{x1=x,y1=y,x2=x+wid,y2=y+ht}. For certain computations (e.g.,
12 :     * constructing regions), this representation is more useful.
13 :     *
14 :     *)
15 :    
16 :     structure Box =
17 :     struct
18 :    
19 :     datatype box = BOX of {x1 : int, y1 : int, x2 : int, y2 : int}
20 :    
21 :     val zeroBox = BOX{x1 = 0, y1 = 0, x2 = 0, y2 = 0}
22 :    
23 :     fun miny(BOX{y1,...}) = y1
24 :    
25 :     (* inBox:
26 :     * returns true if point is in box
27 :     *)
28 :     fun inBox(BOX{x1,y1,x2,y2},Geometry.PT{x,y}) =
29 :     x2 > x andalso x >= x1 andalso y2 > y andalso y >= y1
30 :    
31 :     (* inside:
32 :     * returns true if first box is contained in second
33 :     *)
34 :     fun inside(BOX{x1,y1,x2,y2},BOX{x1=x1',y1=y1',x2=x2',y2=y2'}) =
35 :     x1' <= x1 andalso y1' <= y1 andalso x2' >= x2 andalso y2' >= y2
36 :    
37 :     (* overlap:
38 :     * returns true if boxes overlap
39 :     *)
40 :     fun overlap(BOX{x1,y1,x2,y2},BOX{x1=x1',y1=y1',x2=x2',y2=y2'}) =
41 :     x2 > x1' andalso x1 < x2' andalso y2 > y1' andalso y1 < y2'
42 :    
43 :     (* boundBox:
44 :     * returns bounding box of two boxes
45 :     *)
46 :     fun boundBox(BOX{x1,y1,x2,y2},BOX{x1=x1',y1=y1',x2=x2',y2=y2'}) = BOX{
47 :     x1 = Int.min(x1,x1'),
48 :     x2 = Int.max(x2,x2'),
49 :     y1 = Int.min(y1,y1'),
50 :     y2 = Int.max(y2,y2')
51 :     }
52 :    
53 :     (* offsetBox:
54 :     * translate box by given vector
55 :     *)
56 :     fun offsetBox (Geometry.PT{x,y}) (BOX{x1,y1,x2,y2}) =
57 :     BOX{x1 = x1+x, x2 = x2+x, y1 = y1+y, y2 = y2+y}
58 :    
59 :     (* xOffsetBox:
60 :     * horizontally translate box
61 :     *)
62 :     fun xOffsetBox x (BOX{x1,y1,x2,y2}) = BOX{x1 = x1+x, x2 = x2+x, y1 = y1, y2 = y2}
63 :    
64 :     (* yOffsetBox:
65 :     * vertically translate box
66 :     *)
67 :     fun yOffsetBox y (BOX{x1,y1,x2,y2}) = BOX{x1 = x1, x2 = x2, y1 = y1+y, y2 = y2+y}
68 :    
69 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0