b311480e |
1 | // Created on: 1991-12-13 |
2 | // Created by: Christophe MARION |
3 | // Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | #ifndef No_Exception |
18 | #define No_Exception |
19 | #endif |
42cf5bc1 |
20 | |
21 | |
22 | #include <Intrv_Interval.hxx> |
23 | #include <Intrv_Intervals.hxx> |
24 | #include <Standard_OutOfRange.hxx> |
7fd59977 |
25 | |
26 | // **---------**** Other |
27 | // ***-----* IsBefore |
28 | // ***------------* IsJustBefore |
29 | // ***-----------------* IsOverlappingAtStart |
30 | // ***------------------------* IsJustEnclosingAtEnd |
31 | // ***-----------------------------------* IsEnclosing |
32 | // ***----* IsJustOverlappingAtStart |
33 | // ***-----------* IsSimilar |
34 | // ***----------------------* IsJustEnclosingAtStart |
35 | // ***-* IsInside |
36 | // ***------* IsJustOverlappingAtEnd |
37 | // ***-----------------* IsOverlappingAtEnd |
38 | // ***--------* IsJustAfter |
39 | // ***---* IsAfter |
7fd59977 |
40 | //======================================================================= |
41 | //function : Intrv_Intervals |
42 | //purpose : |
43 | //======================================================================= |
7fd59977 |
44 | Intrv_Intervals::Intrv_Intervals () |
45 | {} |
46 | |
47 | //======================================================================= |
48 | //function : Intrv_Intervals |
49 | //purpose : |
50 | //======================================================================= |
51 | |
52 | Intrv_Intervals::Intrv_Intervals (const Intrv_Interval& Int) |
53 | { myInter.Append(Int); } |
54 | |
7fd59977 |
55 | //======================================================================= |
56 | //function : Intersect |
57 | //purpose : |
58 | //======================================================================= |
59 | |
60 | void Intrv_Intervals::Intersect (const Intrv_Interval& Tool) |
61 | { |
62 | Intrv_Intervals Inter(Tool); |
63 | Intersect(Inter); |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : Intersect |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | void Intrv_Intervals::Intersect (const Intrv_Intervals& Tool) |
72 | { |
73 | Intrv_Intervals XUni(*this); |
74 | XUni.XUnite(Tool); |
75 | Unite(Tool); |
76 | Subtract(XUni); |
77 | } |
78 | |
79 | //======================================================================= |
80 | //function : Subtract |
81 | //purpose : |
82 | //======================================================================= |
83 | |
84 | void Intrv_Intervals::Subtract (const Intrv_Interval& Tool) |
85 | { |
86 | Standard_Integer index = 1; |
87 | |
88 | while (index <= myInter.Length()) { |
89 | |
90 | switch (Tool.Position (myInter(index))) { |
91 | |
92 | case Intrv_Before : |
93 | index = myInter.Length(); // sortir |
94 | break; |
95 | |
96 | case Intrv_JustBefore : |
97 | myInter(index).CutAtStart |
98 | (Tool.End (),Tool.TolEnd ()); // modifier le debut |
99 | index = myInter.Length(); // sortir |
100 | break; |
101 | |
102 | case Intrv_OverlappingAtStart : |
103 | case Intrv_JustOverlappingAtStart : |
104 | myInter(index).SetStart |
105 | (Tool.End (),Tool.TolEnd ()); // garder la fin |
106 | index = myInter.Length(); // sortir |
107 | break; |
108 | |
109 | case Intrv_JustEnclosingAtEnd : |
110 | case Intrv_Enclosing : |
111 | case Intrv_Similar : |
112 | case Intrv_JustEnclosingAtStart : |
113 | myInter.Remove(index); // detruire et |
114 | index--; // continuer |
115 | break; |
116 | |
117 | case Intrv_Inside : |
118 | myInter.InsertAfter(index,myInter(index)); |
119 | myInter(index ).SetEnd |
120 | (Tool.Start(),Tool.TolStart()); // garder le debut |
121 | myInter(index+1).SetStart |
122 | (Tool.End (),Tool.TolEnd ()); // garder la fin |
123 | index = myInter.Length(); // sortir |
124 | break; |
125 | |
126 | case Intrv_JustOverlappingAtEnd : |
127 | case Intrv_OverlappingAtEnd : |
128 | myInter(index).SetEnd |
129 | (Tool.Start(),Tool.TolStart()); // garder le debut |
130 | break; // continuer |
131 | |
132 | case Intrv_JustAfter : |
133 | myInter(index).CutAtEnd |
134 | (Tool.Start(),Tool.TolStart()); // modifier la fin |
135 | break; // continuer |
136 | |
137 | case Intrv_After : |
138 | break; // continuer |
139 | |
140 | } |
141 | index++; |
142 | } |
143 | } |
144 | |
145 | //======================================================================= |
146 | //function : Subtract |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | void Intrv_Intervals::Subtract (const Intrv_Intervals& Tool) |
151 | { |
152 | Standard_Integer index; |
153 | for (index = 1; index <= Tool.myInter.Length(); index++) |
154 | Subtract (Tool.myInter(index)); |
155 | } |
156 | |
157 | //======================================================================= |
158 | //function : Unite |
159 | //purpose : |
160 | //======================================================================= |
161 | |
162 | void Intrv_Intervals::Unite (const Intrv_Interval& Tool) |
163 | { |
164 | Standard_Boolean Inserted = Standard_False; |
165 | Intrv_Interval Tins(Tool); |
166 | Standard_Integer index = 1; |
167 | |
168 | while (index <= myInter.Length()) { |
169 | |
170 | switch (Tins.Position (myInter(index))) { |
171 | |
172 | case Intrv_Before : |
173 | Inserted = Standard_True; |
174 | myInter.InsertBefore(index,Tins); // inserer avant et |
175 | index = myInter.Length(); // sortir |
176 | break; |
177 | |
178 | case Intrv_JustBefore : |
179 | case Intrv_OverlappingAtStart : |
180 | Inserted = Standard_True; |
181 | myInter(index).SetStart |
182 | (Tins.Start(),Tins.TolStart()); // changer le debut |
183 | index = myInter.Length(); // sortir |
184 | break; |
185 | |
186 | case Intrv_Similar : |
187 | Tins.FuseAtStart(myInter(index).Start(), |
188 | myInter(index).TolStart()); // modifier le debut |
b1811c1d |
189 | Standard_FALLTHROUGH |
7fd59977 |
190 | case Intrv_JustEnclosingAtEnd : |
191 | Tins.FuseAtEnd (myInter(index).End (), |
192 | myInter(index).TolEnd ()); // modifier la fin |
b1811c1d |
193 | Standard_FALLTHROUGH |
7fd59977 |
194 | case Intrv_Enclosing : |
195 | myInter.Remove(index); // detruire et |
196 | index--; // continuer |
197 | break; |
198 | |
199 | case Intrv_JustOverlappingAtEnd : |
200 | Tins.SetStart (myInter(index).Start(), |
201 | myInter(index).TolStart()); // changer le debut |
202 | Tins.FuseAtEnd (myInter(index).End (), |
203 | myInter(index).TolEnd ()); // modifier la fin |
204 | myInter.Remove(index); // detruire et |
205 | index--; // continuer |
206 | break; |
207 | |
208 | case Intrv_JustOverlappingAtStart : |
209 | Inserted = Standard_True; |
210 | myInter(index).FuseAtStart |
211 | (Tins.Start(),Tins.TolStart()); // modifier le debut |
212 | index = myInter.Length(); // sortir |
213 | break; |
214 | |
215 | case Intrv_JustEnclosingAtStart : |
216 | Tins.FuseAtStart(myInter(index).Start(), |
217 | myInter(index).TolStart()); // modifier le debut |
218 | myInter.Remove(index); // detruire et |
219 | index--; // continuer |
220 | break; |
221 | |
222 | case Intrv_Inside : |
223 | Inserted = Standard_True; |
224 | index = myInter.Length(); // sortir |
225 | break; |
226 | |
227 | case Intrv_OverlappingAtEnd : |
228 | case Intrv_JustAfter : |
229 | Tins.SetStart(myInter(index).Start(), |
230 | myInter(index).TolStart()); // changer le debut |
231 | myInter.Remove(index); // detruire et |
232 | index--; // continuer |
233 | break; |
234 | |
235 | case Intrv_After : |
236 | break; // continuer |
237 | |
238 | } |
239 | index++; |
240 | } |
241 | if ( !Inserted ) myInter.Append (Tins); |
242 | } |
243 | |
244 | //======================================================================= |
245 | //function : Unite |
246 | //purpose : |
247 | //======================================================================= |
248 | |
249 | void Intrv_Intervals::Unite (const Intrv_Intervals& Tool) |
250 | { |
251 | Standard_Integer index; |
252 | for (index = 1; index<=Tool.myInter.Length(); index++) |
253 | Unite (Tool.myInter(index)); |
254 | } |
255 | |
256 | //======================================================================= |
257 | //function : XUnite |
258 | //purpose : |
259 | //======================================================================= |
260 | |
261 | void Intrv_Intervals::XUnite (const Intrv_Interval& Tool) |
262 | { |
263 | Intrv_Intervals Inter(Tool); |
264 | XUnite(Inter); |
265 | } |
266 | |
267 | //======================================================================= |
268 | //function : XUnite |
269 | //purpose : |
270 | //======================================================================= |
271 | |
272 | void Intrv_Intervals::XUnite (const Intrv_Intervals& Tool) |
273 | { |
274 | Intrv_Intervals Sub2(Tool); |
275 | Sub2.Subtract(*this); |
276 | Subtract(Tool); |
277 | Unite(Sub2); |
278 | } |
279 | |