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_Intervals.hxx>
24 // **---------**** Other
26 // ***------------* IsJustBefore
27 // ***-----------------* IsOverlappingAtStart
28 // ***------------------------* IsJustEnclosingAtEnd
29 // ***-----------------------------------* IsEnclosing
30 // ***----* IsJustOverlappingAtStart
31 // ***-----------* IsSimilar
32 // ***----------------------* IsJustEnclosingAtStart
34 // ***------* IsJustOverlappingAtEnd
35 // ***-----------------* IsOverlappingAtEnd
36 // ***--------* IsJustAfter
38 //=======================================================================
39 //function : Intrv_Intervals
41 //=======================================================================
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 : Intersect
56 //=======================================================================
58 void Intrv_Intervals::Intersect (const Intrv_Interval& Tool)
60 Intrv_Intervals Inter(Tool);
64 //=======================================================================
65 //function : Intersect
67 //=======================================================================
69 void Intrv_Intervals::Intersect (const Intrv_Intervals& Tool)
71 Intrv_Intervals XUni(*this);
77 //=======================================================================
80 //=======================================================================
82 void Intrv_Intervals::Subtract (const Intrv_Interval& Tool)
84 Standard_Integer index = 1;
86 while (index <= myInter.Length()) {
88 switch (Tool.Position (myInter(index))) {
91 index = myInter.Length(); // sortir
94 case Intrv_JustBefore :
95 myInter(index).CutAtStart
96 (Tool.End (),Tool.TolEnd ()); // modifier le debut
97 index = myInter.Length(); // sortir
100 case Intrv_OverlappingAtStart :
101 case Intrv_JustOverlappingAtStart :
102 myInter(index).SetStart
103 (Tool.End (),Tool.TolEnd ()); // garder la fin
104 index = myInter.Length(); // sortir
107 case Intrv_JustEnclosingAtEnd :
108 case Intrv_Enclosing :
110 case Intrv_JustEnclosingAtStart :
111 myInter.Remove(index); // detruire et
112 index--; // continuer
116 myInter.InsertAfter(index,myInter(index));
117 myInter(index ).SetEnd
118 (Tool.Start(),Tool.TolStart()); // garder le debut
119 myInter(index+1).SetStart
120 (Tool.End (),Tool.TolEnd ()); // garder la fin
121 index = myInter.Length(); // sortir
124 case Intrv_JustOverlappingAtEnd :
125 case Intrv_OverlappingAtEnd :
126 myInter(index).SetEnd
127 (Tool.Start(),Tool.TolStart()); // garder le debut
130 case Intrv_JustAfter :
131 myInter(index).CutAtEnd
132 (Tool.Start(),Tool.TolStart()); // modifier la fin
143 //=======================================================================
144 //function : Subtract
146 //=======================================================================
148 void Intrv_Intervals::Subtract (const Intrv_Intervals& Tool)
150 Standard_Integer index;
151 for (index = 1; index <= Tool.myInter.Length(); index++)
152 Subtract (Tool.myInter(index));
155 //=======================================================================
158 //=======================================================================
160 void Intrv_Intervals::Unite (const Intrv_Interval& Tool)
162 Standard_Boolean Inserted = Standard_False;
163 Intrv_Interval Tins(Tool);
164 Standard_Integer index = 1;
166 while (index <= myInter.Length()) {
168 switch (Tins.Position (myInter(index))) {
171 Inserted = Standard_True;
172 myInter.InsertBefore(index,Tins); // inserer avant et
173 index = myInter.Length(); // sortir
176 case Intrv_JustBefore :
177 case Intrv_OverlappingAtStart :
178 Inserted = Standard_True;
179 myInter(index).SetStart
180 (Tins.Start(),Tins.TolStart()); // changer le debut
181 index = myInter.Length(); // sortir
185 Tins.FuseAtStart(myInter(index).Start(),
186 myInter(index).TolStart()); // modifier le debut
188 case Intrv_JustEnclosingAtEnd :
189 Tins.FuseAtEnd (myInter(index).End (),
190 myInter(index).TolEnd ()); // modifier la fin
192 case Intrv_Enclosing :
193 myInter.Remove(index); // detruire et
194 index--; // continuer
197 case Intrv_JustOverlappingAtEnd :
198 Tins.SetStart (myInter(index).Start(),
199 myInter(index).TolStart()); // changer le debut
200 Tins.FuseAtEnd (myInter(index).End (),
201 myInter(index).TolEnd ()); // modifier la fin
202 myInter.Remove(index); // detruire et
203 index--; // continuer
206 case Intrv_JustOverlappingAtStart :
207 Inserted = Standard_True;
208 myInter(index).FuseAtStart
209 (Tins.Start(),Tins.TolStart()); // modifier le debut
210 index = myInter.Length(); // sortir
213 case Intrv_JustEnclosingAtStart :
214 Tins.FuseAtStart(myInter(index).Start(),
215 myInter(index).TolStart()); // modifier le debut
216 myInter.Remove(index); // detruire et
217 index--; // continuer
221 Inserted = Standard_True;
222 index = myInter.Length(); // sortir
225 case Intrv_OverlappingAtEnd :
226 case Intrv_JustAfter :
227 Tins.SetStart(myInter(index).Start(),
228 myInter(index).TolStart()); // changer le debut
229 myInter.Remove(index); // detruire et
230 index--; // continuer
239 if ( !Inserted ) myInter.Append (Tins);
242 //=======================================================================
245 //=======================================================================
247 void Intrv_Intervals::Unite (const Intrv_Intervals& Tool)
249 Standard_Integer index;
250 for (index = 1; index<=Tool.myInter.Length(); index++)
251 Unite (Tool.myInter(index));
254 //=======================================================================
257 //=======================================================================
259 void Intrv_Intervals::XUnite (const Intrv_Interval& Tool)
261 Intrv_Intervals Inter(Tool);
265 //=======================================================================
268 //=======================================================================
270 void Intrv_Intervals::XUnite (const Intrv_Intervals& Tool)
272 Intrv_Intervals Sub2(Tool);
273 Sub2.Subtract(*this);