0029151: GCC 7.1 warnings "this statement may fall through" [-Wimplicit-fallthrough=]
[occt.git] / src / Intrv / Intrv_Intervals.cxx
1 // Created on: 1991-12-13
2 // Created by: Christophe MARION
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef No_Exception
18 #define No_Exception
19 #endif
20
21
22 #include <Intrv_Interval.hxx>
23 #include <Intrv_Intervals.hxx>
24 #include <Standard_OutOfRange.hxx>
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
40 //=======================================================================
41 //function : Intrv_Intervals
42 //purpose  :
43 //=======================================================================
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
55 //=======================================================================
56 //function : Intrv_Intervals
57 //purpose  :
58 //=======================================================================
59
60 Intrv_Intervals::Intrv_Intervals (const Intrv_Intervals& Int)
61 { myInter = Int.myInter; }
62
63 //=======================================================================
64 //function : Intersect
65 //purpose  :
66 //=======================================================================
67
68 void Intrv_Intervals::Intersect (const Intrv_Interval& Tool)
69 {
70   Intrv_Intervals Inter(Tool);
71   Intersect(Inter);
72 }
73
74 //=======================================================================
75 //function : Intersect
76 //purpose  :
77 //=======================================================================
78
79 void Intrv_Intervals::Intersect (const Intrv_Intervals& Tool)
80 {
81   Intrv_Intervals XUni(*this);
82   XUni.XUnite(Tool);
83   Unite(Tool);
84   Subtract(XUni);
85 }
86
87 //=======================================================================
88 //function : Subtract
89 //purpose  :
90 //=======================================================================
91
92 void Intrv_Intervals::Subtract (const Intrv_Interval& Tool)
93 {
94   Standard_Integer index = 1;
95
96   while (index <= myInter.Length()) {
97
98     switch (Tool.Position (myInter(index))) {
99
100     case Intrv_Before :
101       index = myInter.Length();                       // sortir
102       break;
103
104     case Intrv_JustBefore :
105       myInter(index).CutAtStart
106         (Tool.End  (),Tool.TolEnd  ());               // modifier le debut
107       index = myInter.Length();                       // sortir
108       break;
109
110     case Intrv_OverlappingAtStart :
111     case Intrv_JustOverlappingAtStart :
112       myInter(index).SetStart
113         (Tool.End  (),Tool.TolEnd  ());               // garder la fin
114       index = myInter.Length();                       // sortir
115       break;
116
117     case Intrv_JustEnclosingAtEnd :
118     case Intrv_Enclosing :
119     case Intrv_Similar :
120     case Intrv_JustEnclosingAtStart :
121       myInter.Remove(index);                          // detruire et
122       index--;                                        // continuer
123       break;
124
125     case Intrv_Inside :
126       myInter.InsertAfter(index,myInter(index));
127       myInter(index  ).SetEnd
128         (Tool.Start(),Tool.TolStart());               // garder le debut
129       myInter(index+1).SetStart
130         (Tool.End  (),Tool.TolEnd  ());               // garder la fin
131       index = myInter.Length();                       // sortir
132       break;
133
134     case Intrv_JustOverlappingAtEnd :
135     case Intrv_OverlappingAtEnd :
136       myInter(index).SetEnd
137         (Tool.Start(),Tool.TolStart());               // garder le debut
138       break;                                          // continuer
139
140     case Intrv_JustAfter :
141       myInter(index).CutAtEnd
142         (Tool.Start(),Tool.TolStart());               // modifier la fin
143       break;                                          // continuer
144
145     case Intrv_After :
146       break;                                          // continuer
147
148     }
149     index++;
150   }
151 }
152
153 //=======================================================================
154 //function : Subtract
155 //purpose  :
156 //=======================================================================
157
158 void Intrv_Intervals::Subtract (const Intrv_Intervals& Tool)
159 {
160   Standard_Integer index;
161   for (index = 1; index <= Tool.myInter.Length(); index++)
162     Subtract (Tool.myInter(index));
163 }
164
165 //=======================================================================
166 //function : Unite
167 //purpose  :
168 //=======================================================================
169
170 void Intrv_Intervals::Unite (const Intrv_Interval& Tool)
171 {
172   Standard_Boolean Inserted = Standard_False;
173   Intrv_Interval Tins(Tool);
174   Standard_Integer index = 1;
175
176   while (index <= myInter.Length()) {
177
178     switch (Tins.Position (myInter(index))) {
179         
180     case Intrv_Before :
181       Inserted = Standard_True;
182       myInter.InsertBefore(index,Tins);               // inserer avant et
183       index = myInter.Length();                       // sortir
184       break;
185
186     case Intrv_JustBefore :
187     case Intrv_OverlappingAtStart :
188       Inserted = Standard_True;
189       myInter(index).SetStart
190         (Tins.Start(),Tins.TolStart());               // changer le debut
191       index = myInter.Length();                       // sortir
192       break;
193
194     case Intrv_Similar :
195       Tins.FuseAtStart(myInter(index).Start(),
196                        myInter(index).TolStart());    // modifier le debut
197       Standard_FALLTHROUGH
198     case Intrv_JustEnclosingAtEnd :
199       Tins.FuseAtEnd  (myInter(index).End  (),
200                        myInter(index).TolEnd  ());    // modifier la fin
201       Standard_FALLTHROUGH
202     case Intrv_Enclosing :
203       myInter.Remove(index);                          // detruire et
204       index--;                                        // continuer
205       break;
206
207     case Intrv_JustOverlappingAtEnd :
208       Tins.SetStart   (myInter(index).Start(),
209                        myInter(index).TolStart());    // changer le debut
210       Tins.FuseAtEnd  (myInter(index).End  (),
211                        myInter(index).TolEnd  ());    // modifier la fin
212       myInter.Remove(index);                          // detruire et
213       index--;                                        // continuer
214       break;
215
216     case Intrv_JustOverlappingAtStart :
217       Inserted = Standard_True;
218       myInter(index).FuseAtStart
219         (Tins.Start(),Tins.TolStart());               // modifier le debut
220       index = myInter.Length();                       // sortir
221       break;
222
223     case Intrv_JustEnclosingAtStart :
224       Tins.FuseAtStart(myInter(index).Start(),
225                        myInter(index).TolStart());    // modifier le debut
226       myInter.Remove(index);                          // detruire et
227       index--;                                        // continuer
228       break;
229
230     case Intrv_Inside :
231       Inserted = Standard_True;
232       index = myInter.Length();                       // sortir
233       break;
234
235     case Intrv_OverlappingAtEnd :
236     case Intrv_JustAfter :
237       Tins.SetStart(myInter(index).Start(),
238                     myInter(index).TolStart());       // changer le debut
239       myInter.Remove(index);                          // detruire et
240       index--;                                        // continuer
241       break;
242
243     case Intrv_After :
244       break;                                          // continuer
245
246     }
247     index++;
248   }
249   if ( !Inserted ) myInter.Append (Tins);
250 }
251
252 //=======================================================================
253 //function : Unite
254 //purpose  :
255 //=======================================================================
256
257 void Intrv_Intervals::Unite (const Intrv_Intervals& Tool)
258 {
259   Standard_Integer index;
260   for (index = 1; index<=Tool.myInter.Length(); index++)
261     Unite (Tool.myInter(index));
262 }
263
264 //=======================================================================
265 //function : XUnite
266 //purpose  :
267 //=======================================================================
268
269 void Intrv_Intervals::XUnite (const Intrv_Interval& Tool)
270 {
271   Intrv_Intervals Inter(Tool);
272   XUnite(Inter);
273 }
274
275 //=======================================================================
276 //function : XUnite
277 //purpose  :
278 //=======================================================================
279
280 void Intrv_Intervals::XUnite (const Intrv_Intervals& Tool)
281 {
282   Intrv_Intervals Sub2(Tool);
283   Sub2.Subtract(*this);
284   Subtract(Tool);
285   Unite(Sub2);
286 }
287