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
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
20 #include <Intrv_Intervals.ixx>
22 // **---------**** Other
24 // ***------------* IsJustBefore
25 // ***-----------------* IsOverlappingAtStart
26 // ***------------------------* IsJustEnclosingAtEnd
27 // ***-----------------------------------* IsEnclosing
28 // ***----* IsJustOverlappingAtStart
29 // ***-----------* IsSimilar
30 // ***----------------------* IsJustEnclosingAtStart
32 // ***------* IsJustOverlappingAtEnd
33 // ***-----------------* IsOverlappingAtEnd
34 // ***--------* IsJustAfter
37 //=======================================================================
38 //function : Intrv_Intervals
40 //=======================================================================
42 Intrv_Intervals::Intrv_Intervals ()
45 //=======================================================================
46 //function : Intrv_Intervals
48 //=======================================================================
50 Intrv_Intervals::Intrv_Intervals (const Intrv_Interval& Int)
51 { myInter.Append(Int); }
53 //=======================================================================
54 //function : Intrv_Intervals
56 //=======================================================================
58 Intrv_Intervals::Intrv_Intervals (const Intrv_Intervals& Int)
59 { myInter = Int.myInter; }
61 //=======================================================================
62 //function : Intersect
64 //=======================================================================
66 void Intrv_Intervals::Intersect (const Intrv_Interval& Tool)
68 Intrv_Intervals Inter(Tool);
72 //=======================================================================
73 //function : Intersect
75 //=======================================================================
77 void Intrv_Intervals::Intersect (const Intrv_Intervals& Tool)
79 Intrv_Intervals XUni(*this);
85 //=======================================================================
88 //=======================================================================
90 void Intrv_Intervals::Subtract (const Intrv_Interval& Tool)
92 Standard_Integer index = 1;
94 while (index <= myInter.Length()) {
96 switch (Tool.Position (myInter(index))) {
99 index = myInter.Length(); // sortir
102 case Intrv_JustBefore :
103 myInter(index).CutAtStart
104 (Tool.End (),Tool.TolEnd ()); // modifier le debut
105 index = myInter.Length(); // sortir
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
115 case Intrv_JustEnclosingAtEnd :
116 case Intrv_Enclosing :
118 case Intrv_JustEnclosingAtStart :
119 myInter.Remove(index); // detruire et
120 index--; // continuer
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
132 case Intrv_JustOverlappingAtEnd :
133 case Intrv_OverlappingAtEnd :
134 myInter(index).SetEnd
135 (Tool.Start(),Tool.TolStart()); // garder le debut
138 case Intrv_JustAfter :
139 myInter(index).CutAtEnd
140 (Tool.Start(),Tool.TolStart()); // modifier la fin
151 //=======================================================================
152 //function : Subtract
154 //=======================================================================
156 void Intrv_Intervals::Subtract (const Intrv_Intervals& Tool)
158 Standard_Integer index;
159 for (index = 1; index <= Tool.myInter.Length(); index++)
160 Subtract (Tool.myInter(index));
163 //=======================================================================
166 //=======================================================================
168 void Intrv_Intervals::Unite (const Intrv_Interval& Tool)
170 Standard_Boolean Inserted = Standard_False;
171 Intrv_Interval Tins(Tool);
172 Standard_Integer index = 1;
174 while (index <= myInter.Length()) {
176 switch (Tins.Position (myInter(index))) {
179 Inserted = Standard_True;
180 myInter.InsertBefore(index,Tins); // inserer avant et
181 index = myInter.Length(); // sortir
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
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
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
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
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
227 Inserted = Standard_True;
228 index = myInter.Length(); // sortir
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
245 if ( !Inserted ) myInter.Append (Tins);
248 //=======================================================================
251 //=======================================================================
253 void Intrv_Intervals::Unite (const Intrv_Intervals& Tool)
255 Standard_Integer index;
256 for (index = 1; index<=Tool.myInter.Length(); index++)
257 Unite (Tool.myInter(index));
260 //=======================================================================
263 //=======================================================================
265 void Intrv_Intervals::XUnite (const Intrv_Interval& Tool)
267 Intrv_Intervals Inter(Tool);
271 //=======================================================================
274 //=======================================================================
276 void Intrv_Intervals::XUnite (const Intrv_Intervals& Tool)
278 Intrv_Intervals Sub2(Tool);
279 Sub2.Subtract(*this);