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 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
22 #include <Intrv_Interval.hxx>
23 #include <Intrv_Intervals.hxx>
24 #include <Standard_OutOfRange.hxx>
26 // **---------**** Other
28 // ***------------* IsJustBefore
29 // ***-----------------* IsOverlappingAtStart
30 // ***------------------------* IsJustEnclosingAtEnd
31 // ***-----------------------------------* IsEnclosing
32 // ***----* IsJustOverlappingAtStart
33 // ***-----------* IsSimilar
34 // ***----------------------* IsJustEnclosingAtStart
36 // ***------* IsJustOverlappingAtEnd
37 // ***-----------------* IsOverlappingAtEnd
38 // ***--------* IsJustAfter
40 //=======================================================================
41 //function : Intrv_Intervals
43 //=======================================================================
44 Intrv_Intervals::Intrv_Intervals ()
47 //=======================================================================
48 //function : Intrv_Intervals
50 //=======================================================================
52 Intrv_Intervals::Intrv_Intervals (const Intrv_Interval& Int)
53 { myInter.Append(Int); }
55 //=======================================================================
56 //function : Intrv_Intervals
58 //=======================================================================
60 Intrv_Intervals::Intrv_Intervals (const Intrv_Intervals& Int)
61 { myInter = Int.myInter; }
63 //=======================================================================
64 //function : Intersect
66 //=======================================================================
68 void Intrv_Intervals::Intersect (const Intrv_Interval& Tool)
70 Intrv_Intervals Inter(Tool);
74 //=======================================================================
75 //function : Intersect
77 //=======================================================================
79 void Intrv_Intervals::Intersect (const Intrv_Intervals& Tool)
81 Intrv_Intervals XUni(*this);
87 //=======================================================================
90 //=======================================================================
92 void Intrv_Intervals::Subtract (const Intrv_Interval& Tool)
94 Standard_Integer index = 1;
96 while (index <= myInter.Length()) {
98 switch (Tool.Position (myInter(index))) {
101 index = myInter.Length(); // sortir
104 case Intrv_JustBefore :
105 myInter(index).CutAtStart
106 (Tool.End (),Tool.TolEnd ()); // modifier le debut
107 index = myInter.Length(); // sortir
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
117 case Intrv_JustEnclosingAtEnd :
118 case Intrv_Enclosing :
120 case Intrv_JustEnclosingAtStart :
121 myInter.Remove(index); // detruire et
122 index--; // continuer
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
134 case Intrv_JustOverlappingAtEnd :
135 case Intrv_OverlappingAtEnd :
136 myInter(index).SetEnd
137 (Tool.Start(),Tool.TolStart()); // garder le debut
140 case Intrv_JustAfter :
141 myInter(index).CutAtEnd
142 (Tool.Start(),Tool.TolStart()); // modifier la fin
153 //=======================================================================
154 //function : Subtract
156 //=======================================================================
158 void Intrv_Intervals::Subtract (const Intrv_Intervals& Tool)
160 Standard_Integer index;
161 for (index = 1; index <= Tool.myInter.Length(); index++)
162 Subtract (Tool.myInter(index));
165 //=======================================================================
168 //=======================================================================
170 void Intrv_Intervals::Unite (const Intrv_Interval& Tool)
172 Standard_Boolean Inserted = Standard_False;
173 Intrv_Interval Tins(Tool);
174 Standard_Integer index = 1;
176 while (index <= myInter.Length()) {
178 switch (Tins.Position (myInter(index))) {
181 Inserted = Standard_True;
182 myInter.InsertBefore(index,Tins); // inserer avant et
183 index = myInter.Length(); // sortir
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
195 Tins.FuseAtStart(myInter(index).Start(),
196 myInter(index).TolStart()); // modifier le debut
198 case Intrv_JustEnclosingAtEnd :
199 Tins.FuseAtEnd (myInter(index).End (),
200 myInter(index).TolEnd ()); // modifier la fin
202 case Intrv_Enclosing :
203 myInter.Remove(index); // detruire et
204 index--; // continuer
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
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
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
231 Inserted = Standard_True;
232 index = myInter.Length(); // sortir
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
249 if ( !Inserted ) myInter.Append (Tins);
252 //=======================================================================
255 //=======================================================================
257 void Intrv_Intervals::Unite (const Intrv_Intervals& Tool)
259 Standard_Integer index;
260 for (index = 1; index<=Tool.myInter.Length(); index++)
261 Unite (Tool.myInter(index));
264 //=======================================================================
267 //=======================================================================
269 void Intrv_Intervals::XUnite (const Intrv_Interval& Tool)
271 Intrv_Intervals Inter(Tool);
275 //=======================================================================
278 //=======================================================================
280 void Intrv_Intervals::XUnite (const Intrv_Intervals& Tool)
282 Intrv_Intervals Sub2(Tool);
283 Sub2.Subtract(*this);