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 |
20 | #include <Intrv_Intervals.ixx> |
21 | |
22 | // **---------**** Other |
23 | // ***-----* IsBefore |
24 | // ***------------* IsJustBefore |
25 | // ***-----------------* IsOverlappingAtStart |
26 | // ***------------------------* IsJustEnclosingAtEnd |
27 | // ***-----------------------------------* IsEnclosing |
28 | // ***----* IsJustOverlappingAtStart |
29 | // ***-----------* IsSimilar |
30 | // ***----------------------* IsJustEnclosingAtStart |
31 | // ***-* IsInside |
32 | // ***------* IsJustOverlappingAtEnd |
33 | // ***-----------------* IsOverlappingAtEnd |
34 | // ***--------* IsJustAfter |
35 | // ***---* IsAfter |
36 | |
37 | //======================================================================= |
38 | //function : Intrv_Intervals |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | Intrv_Intervals::Intrv_Intervals () |
43 | {} |
44 | |
45 | //======================================================================= |
46 | //function : Intrv_Intervals |
47 | //purpose : |
48 | //======================================================================= |
49 | |
50 | Intrv_Intervals::Intrv_Intervals (const Intrv_Interval& Int) |
51 | { myInter.Append(Int); } |
52 | |
53 | //======================================================================= |
54 | //function : Intrv_Intervals |
55 | //purpose : |
56 | //======================================================================= |
57 | |
58 | Intrv_Intervals::Intrv_Intervals (const Intrv_Intervals& Int) |
59 | { myInter = Int.myInter; } |
60 | |
61 | //======================================================================= |
62 | //function : Intersect |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | void Intrv_Intervals::Intersect (const Intrv_Interval& Tool) |
67 | { |
68 | Intrv_Intervals Inter(Tool); |
69 | Intersect(Inter); |
70 | } |
71 | |
72 | //======================================================================= |
73 | //function : Intersect |
74 | //purpose : |
75 | //======================================================================= |
76 | |
77 | void Intrv_Intervals::Intersect (const Intrv_Intervals& Tool) |
78 | { |
79 | Intrv_Intervals XUni(*this); |
80 | XUni.XUnite(Tool); |
81 | Unite(Tool); |
82 | Subtract(XUni); |
83 | } |
84 | |
85 | //======================================================================= |
86 | //function : Subtract |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | void Intrv_Intervals::Subtract (const Intrv_Interval& Tool) |
91 | { |
92 | Standard_Integer index = 1; |
93 | |
94 | while (index <= myInter.Length()) { |
95 | |
96 | switch (Tool.Position (myInter(index))) { |
97 | |
98 | case Intrv_Before : |
99 | index = myInter.Length(); // sortir |
100 | break; |
101 | |
102 | case Intrv_JustBefore : |
103 | myInter(index).CutAtStart |
104 | (Tool.End (),Tool.TolEnd ()); // modifier le debut |
105 | index = myInter.Length(); // sortir |
106 | break; |
107 | |
108 | case Intrv_OverlappingAtStart : |
109 | case Intrv_JustOverlappingAtStart : |
110 | myInter(index).SetStart |
111 | (Tool.End (),Tool.TolEnd ()); // garder la fin |
112 | index = myInter.Length(); // sortir |
113 | break; |
114 | |
115 | case Intrv_JustEnclosingAtEnd : |
116 | case Intrv_Enclosing : |
117 | case Intrv_Similar : |
118 | case Intrv_JustEnclosingAtStart : |
119 | myInter.Remove(index); // detruire et |
120 | index--; // continuer |
121 | break; |
122 | |
123 | case Intrv_Inside : |
124 | myInter.InsertAfter(index,myInter(index)); |
125 | myInter(index ).SetEnd |
126 | (Tool.Start(),Tool.TolStart()); // garder le debut |
127 | myInter(index+1).SetStart |
128 | (Tool.End (),Tool.TolEnd ()); // garder la fin |
129 | index = myInter.Length(); // sortir |
130 | break; |
131 | |
132 | case Intrv_JustOverlappingAtEnd : |
133 | case Intrv_OverlappingAtEnd : |
134 | myInter(index).SetEnd |
135 | (Tool.Start(),Tool.TolStart()); // garder le debut |
136 | break; // continuer |
137 | |
138 | case Intrv_JustAfter : |
139 | myInter(index).CutAtEnd |
140 | (Tool.Start(),Tool.TolStart()); // modifier la fin |
141 | break; // continuer |
142 | |
143 | case Intrv_After : |
144 | break; // continuer |
145 | |
146 | } |
147 | index++; |
148 | } |
149 | } |
150 | |
151 | //======================================================================= |
152 | //function : Subtract |
153 | //purpose : |
154 | //======================================================================= |
155 | |
156 | void Intrv_Intervals::Subtract (const Intrv_Intervals& Tool) |
157 | { |
158 | Standard_Integer index; |
159 | for (index = 1; index <= Tool.myInter.Length(); index++) |
160 | Subtract (Tool.myInter(index)); |
161 | } |
162 | |
163 | //======================================================================= |
164 | //function : Unite |
165 | //purpose : |
166 | //======================================================================= |
167 | |
168 | void Intrv_Intervals::Unite (const Intrv_Interval& Tool) |
169 | { |
170 | Standard_Boolean Inserted = Standard_False; |
171 | Intrv_Interval Tins(Tool); |
172 | Standard_Integer index = 1; |
173 | |
174 | while (index <= myInter.Length()) { |
175 | |
176 | switch (Tins.Position (myInter(index))) { |
177 | |
178 | case Intrv_Before : |
179 | Inserted = Standard_True; |
180 | myInter.InsertBefore(index,Tins); // inserer avant et |
181 | index = myInter.Length(); // sortir |
182 | break; |
183 | |
184 | case Intrv_JustBefore : |
185 | case Intrv_OverlappingAtStart : |
186 | Inserted = Standard_True; |
187 | myInter(index).SetStart |
188 | (Tins.Start(),Tins.TolStart()); // changer le debut |
189 | index = myInter.Length(); // sortir |
190 | break; |
191 | |
192 | case Intrv_Similar : |
193 | Tins.FuseAtStart(myInter(index).Start(), |
194 | myInter(index).TolStart()); // modifier le debut |
195 | case Intrv_JustEnclosingAtEnd : |
196 | Tins.FuseAtEnd (myInter(index).End (), |
197 | myInter(index).TolEnd ()); // modifier la fin |
198 | case Intrv_Enclosing : |
199 | myInter.Remove(index); // detruire et |
200 | index--; // continuer |
201 | break; |
202 | |
203 | case Intrv_JustOverlappingAtEnd : |
204 | Tins.SetStart (myInter(index).Start(), |
205 | myInter(index).TolStart()); // changer le debut |
206 | Tins.FuseAtEnd (myInter(index).End (), |
207 | myInter(index).TolEnd ()); // modifier la fin |
208 | myInter.Remove(index); // detruire et |
209 | index--; // continuer |
210 | break; |
211 | |
212 | case Intrv_JustOverlappingAtStart : |
213 | Inserted = Standard_True; |
214 | myInter(index).FuseAtStart |
215 | (Tins.Start(),Tins.TolStart()); // modifier le debut |
216 | index = myInter.Length(); // sortir |
217 | break; |
218 | |
219 | case Intrv_JustEnclosingAtStart : |
220 | Tins.FuseAtStart(myInter(index).Start(), |
221 | myInter(index).TolStart()); // modifier le debut |
222 | myInter.Remove(index); // detruire et |
223 | index--; // continuer |
224 | break; |
225 | |
226 | case Intrv_Inside : |
227 | Inserted = Standard_True; |
228 | index = myInter.Length(); // sortir |
229 | break; |
230 | |
231 | case Intrv_OverlappingAtEnd : |
232 | case Intrv_JustAfter : |
233 | Tins.SetStart(myInter(index).Start(), |
234 | myInter(index).TolStart()); // changer le debut |
235 | myInter.Remove(index); // detruire et |
236 | index--; // continuer |
237 | break; |
238 | |
239 | case Intrv_After : |
240 | break; // continuer |
241 | |
242 | } |
243 | index++; |
244 | } |
245 | if ( !Inserted ) myInter.Append (Tins); |
246 | } |
247 | |
248 | //======================================================================= |
249 | //function : Unite |
250 | //purpose : |
251 | //======================================================================= |
252 | |
253 | void Intrv_Intervals::Unite (const Intrv_Intervals& Tool) |
254 | { |
255 | Standard_Integer index; |
256 | for (index = 1; index<=Tool.myInter.Length(); index++) |
257 | Unite (Tool.myInter(index)); |
258 | } |
259 | |
260 | //======================================================================= |
261 | //function : XUnite |
262 | //purpose : |
263 | //======================================================================= |
264 | |
265 | void Intrv_Intervals::XUnite (const Intrv_Interval& Tool) |
266 | { |
267 | Intrv_Intervals Inter(Tool); |
268 | XUnite(Inter); |
269 | } |
270 | |
271 | //======================================================================= |
272 | //function : XUnite |
273 | //purpose : |
274 | //======================================================================= |
275 | |
276 | void Intrv_Intervals::XUnite (const Intrv_Intervals& Tool) |
277 | { |
278 | Intrv_Intervals Sub2(Tool); |
279 | Sub2.Subtract(*this); |
280 | Subtract(Tool); |
281 | Unite(Sub2); |
282 | } |
283 | |