Debian Codegraph @

gcc/testsuite/gm2/projects/pim/run/pass/random/Geometry.mod

raw
1 (* Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
2 Free Software Foundation, Inc. *)
3 (* This file is part of Chisel.
4
5 Chisel is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 3, or (at your option) any later
8 version.
9
10 Chisel is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with gm2; see the file COPYING. If not, write to the Free Software
17 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
18
19 IMPLEMENTATION MODULE Geometry ;
20
21
22 FROM Assertion IMPORT Assert ;
23
24
25 (*
26 IsSubLine - returns true if the range i1..i2 or j1..j2 are ranges
27 of each other.
28 *)
29
30 PROCEDURE IsSubLine (i1, i2, j1, j2: CARDINAL) : BOOLEAN ;
31 BEGIN
32 RETURN( ((i1<=j1) AND (i2>=j2)) OR ((j1<=i1) AND (j2>=i2)) )
33 END IsSubLine ;
34
35
36 (*
37 IsIntersectingRange - returns true if the ranges i1..i2 j1..j2
38 overlap.
39 *)
40
41 PROCEDURE IsIntersectingRange (i1, i2, j1, j2: CARDINAL) : BOOLEAN ;
42 BEGIN
43 (* Easier to prove NOT outside limits!! *)
44 RETURN( NOT ((i1>j2) OR (i2<j1)) )
45 END IsIntersectingRange ;
46
47
48 (*
49 IntersectionLength - returns the intersection length
50 of the overlapping ranges i1..i2 j1..j2.
51 *)
52
53 PROCEDURE IntersectionLength (i1, i2, j1, j2: CARDINAL) : CARDINAL ;
54 BEGIN
55 IF IsSubRange(i1, i2, j1)
56 THEN
57 RETURN( Abs(j1, Min(i2, j2)) )
58 ELSIF IsSubRange(i1, i2, j2)
59 THEN
60 RETURN( Abs(Max(i1, j1), j2) )
61 ELSE
62 RETURN( 0 )
63 END
64 END IntersectionLength ;
65
66
67 (*
68 IsPointOnLine - returns true if point x, y is on line (x1, y1) , (x2, y2)
69 *)
70
71 PROCEDURE IsPointOnLine (x, y: CARDINAL; x1, y1, x2, y2: CARDINAL) : BOOLEAN ;
72 BEGIN
73 IF (x1=x2) AND (x=x1)
74 THEN
75 RETURN( IsSubRange(y1, y2, y) )
76 ELSIF (y1=y2) AND (y=y1)
77 THEN
78 RETURN( IsSubRange(x1, x2, x) )
79 ELSE
80 RETURN( FALSE )
81 END
82 END IsPointOnLine ;
83
84
85 (*
86 IsSubRange - returns true if i lies inbetween High and Low.
87 *)
88
89 PROCEDURE IsSubRange (Low, High, i: CARDINAL) : BOOLEAN ;
90 BEGIN
91 Assert(High>=Low) ;
92 RETURN( (i>=Low) AND (i<=High) )
93 END IsSubRange ;
94
95
96 (*
97 Max - returns the largest cardinal number from i and j.
98 *)
99
100 PROCEDURE Max (i, j: CARDINAL) : CARDINAL ;
101 BEGIN
102 IF i>j
103 THEN
104 RETURN( i )
105 ELSE
106 RETURN( j )
107 END
108 END Max ;
109
110
111 (*
112 Min - returns the smallest cardinal number from i and j.
113 *)
114
115 PROCEDURE Min (i, j: CARDINAL) : CARDINAL ;
116 BEGIN
117 IF i<j
118 THEN
119 RETURN( i )
120 ELSE
121 RETURN( j )
122 END
123 END Min ;
124
125
126 (*
127 Abs - returns the difference between i and j.
128 *)
129
130 PROCEDURE Abs (i, j: CARDINAL) : CARDINAL ;
131 BEGIN
132 IF i>j
133 THEN
134 RETURN( i-j )
135 ELSE
136 RETURN( j-i )
137 END
138 END Abs ;
139
140
141 (*
142 Swap - swaps two cardinal numbers i and j.
143 *)
144
145 PROCEDURE Swap (VAR i, j: CARDINAL) ;
146 VAR
147 t: CARDINAL ;
148 BEGIN
149 t := i ;
150 i := j ;
151 j := t
152 END Swap ;
153
154
155 END Geometry.