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 : Intersect
58 //=======================================================================
60 void Intrv_Intervals::Intersect (const Intrv_Interval& Tool)
62 Intrv_Intervals Inter(Tool);
66 //=======================================================================
67 //function : Intersect
69 //=======================================================================
71 void Intrv_Intervals::Intersect (const Intrv_Intervals& Tool)
73 Intrv_Intervals XUni(*this);
79 //=======================================================================
82 //=======================================================================
84 void Intrv_Intervals::Subtract (const Intrv_Interval& Tool)
86 Standard_Integer index = 1;
88 while (index <= myInter.Length()) {
90 switch (Tool.Position (myInter(index))) {
93 index = myInter.Length(); // sortir
96 case Intrv_JustBefore :
97 myInter(index).CutAtStart
98 (Tool.End (),Tool.TolEnd ()); // modifier le debut
99 index = myInter.Length(); // sortir
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
109 case Intrv_JustEnclosingAtEnd :
110 case Intrv_Enclosing :
112 case Intrv_JustEnclosingAtStart :
113 myInter.Remove(index); // detruire et
114 index--; // continuer
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
126 case Intrv_JustOverlappingAtEnd :
127 case Intrv_OverlappingAtEnd :
128 myInter(index).SetEnd
129 (Tool.Start(),Tool.TolStart()); // garder le debut
132 case Intrv_JustAfter :
133 myInter(index).CutAtEnd
134 (Tool.Start(),Tool.TolStart()); // modifier la fin
145 //=======================================================================
146 //function : Subtract
148 //=======================================================================
150 void Intrv_Intervals::Subtract (const Intrv_Intervals& Tool)
152 Standard_Integer index;
153 for (index = 1; index <= Tool.myInter.Length(); index++)
154 Subtract (Tool.myInter(index));
157 //=======================================================================
160 //=======================================================================
162 void Intrv_Intervals::Unite (const Intrv_Interval& Tool)
164 Standard_Boolean Inserted = Standard_False;
165 Intrv_Interval Tins(Tool);
166 Standard_Integer index = 1;
168 while (index <= myInter.Length()) {
170 switch (Tins.Position (myInter(index))) {
173 Inserted = Standard_True;
174 myInter.InsertBefore(index,Tins); // inserer avant et
175 index = myInter.Length(); // sortir
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
187 Tins.FuseAtStart(myInter(index).Start(),
188 myInter(index).TolStart()); // modifier le debut
190 case Intrv_JustEnclosingAtEnd :
191 Tins.FuseAtEnd (myInter(index).End (),
192 myInter(index).TolEnd ()); // modifier la fin
194 case Intrv_Enclosing :
195 myInter.Remove(index); // detruire et
196 index--; // continuer
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
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
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
223 Inserted = Standard_True;
224 index = myInter.Length(); // sortir
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
241 if ( !Inserted ) myInter.Append (Tins);
244 //=======================================================================
247 //=======================================================================
249 void Intrv_Intervals::Unite (const Intrv_Intervals& Tool)
251 Standard_Integer index;
252 for (index = 1; index<=Tool.myInter.Length(); index++)
253 Unite (Tool.myInter(index));
256 //=======================================================================
259 //=======================================================================
261 void Intrv_Intervals::XUnite (const Intrv_Interval& Tool)
263 Intrv_Intervals Inter(Tool);
267 //=======================================================================
270 //=======================================================================
272 void Intrv_Intervals::XUnite (const Intrv_Intervals& Tool)
274 Intrv_Intervals Sub2(Tool);
275 Sub2.Subtract(*this);