38e94636fec01f69638cb793ac256ed03bb1fcbd
[occt.git] / src / Intf / Intf_TangentZone.cxx
1 // Created on: 1991-06-24
2 // Created by: Didier PIFFAULT
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <Intf_TangentZone.ixx>
23
24 #define  DEBUG_TANGENTZONE 0 
25 //=======================================================================
26 //function : Intf_TangentZone
27 //purpose  : Constructor of an empty tangent zone.
28 //=======================================================================
29
30 Intf_TangentZone::Intf_TangentZone       ()
31 {
32   ParamOnFirstMin   = ParamOnSecondMin  = RealLast();
33   ParamOnFirstMax   = ParamOnSecondMax  = RealFirst();
34 }
35
36
37 //=======================================================================
38 //function : Intf_TangentZone
39 //purpose  : Copy
40 //=======================================================================
41
42 Intf_TangentZone::Intf_TangentZone (const Intf_TangentZone& Other)
43 {
44   Result=Other.Result;
45   ParamOnFirstMin   = Other.ParamOnFirstMin;
46   ParamOnFirstMax   = Other.ParamOnFirstMax;
47   ParamOnSecondMin  = Other.ParamOnSecondMin;
48   ParamOnSecondMax  = Other.ParamOnSecondMax;
49 }
50 //=======================================================================
51 //function : Append
52 //purpose  : Append the section point to the tangent zone.
53 //=======================================================================
54
55 void Intf_TangentZone::Append            (const Intf_SectionPoint& Pi)
56 {
57   Result.Append(Pi);
58   if(ParamOnFirstMin  > Pi.ParamOnFirst())   ParamOnFirstMin  = Pi.ParamOnFirst();
59   if(ParamOnSecondMin > Pi.ParamOnSecond())  ParamOnSecondMin = Pi.ParamOnSecond();
60
61   if(ParamOnFirstMax  < Pi.ParamOnFirst())   ParamOnFirstMax  = Pi.ParamOnFirst();
62   if(ParamOnSecondMax < Pi.ParamOnSecond())  ParamOnSecondMax = Pi.ParamOnSecond();
63 }
64
65
66 //=======================================================================
67 //function : Append
68 //purpose  : Merge the TangentZone to the tangent zone.
69 //=======================================================================
70
71 void Intf_TangentZone::Append            (const Intf_TangentZone& Tzi)
72 {
73   Standard_Integer Tzi_NumberOfPoints = Tzi.NumberOfPoints();
74   for (Standard_Integer ipi=1; ipi<=Tzi_NumberOfPoints; ipi++) {
75     PolygonInsert(Tzi.GetPoint(ipi));
76   }
77 }
78
79
80 //=======================================================================
81 //function : Insert
82 //purpose  : Insert the section point at his place in the tangent zone.
83 //=======================================================================
84
85 //Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& Pi)
86 Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& )
87 {
88 #if DEBUG_TANGENTZONE
89   cout<<" Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& Pi) ???? "<<endl;
90 #endif
91   Standard_Boolean Inserted=Standard_False;
92 /*
93   Standard_Integer lpon=0;
94
95   if (Result.Length()<1) {
96     Append(Pi);
97     Inserted=Standard_True;
98   }
99   else if (Result.Length()==1) {
100     if (Pi.IsOnSameEdge(Result(1))) {
101       InsertAfter(1, Pi);
102       Inserted=Standard_True;
103     }
104   }
105   else {
106     Standard_Integer lp1, lp2;
107     Standard_Integer nbptz=NumberOfPoints();
108     for (lp1=1; lp1<=nbptz; lp1++) {
109       lp2=(lp1%nbptz)+1;
110       if (Pi.IsOnSameEdge(Result(lp1))) {
111         lpon=lp1;
112         if (Pi.IsOnSameEdge(Result(lp2))) {
113           InsertAfter(lp1, Pi);
114           Inserted=Standard_True;
115           break;
116         }
117       }
118     }
119   }
120   if (!Inserted && lpon>0) {
121     InsertAfter(lpon, Pi);
122     Inserted=Standard_True;
123   }
124 */
125   return Inserted;
126 }
127
128 //=======================================================================
129 //function : PolygonInsert
130 //purpose  : Insert the point at his place in the polygonal tangent zone.
131 //=======================================================================
132
133 void Intf_TangentZone::PolygonInsert (const Intf_SectionPoint& Pi)
134 {
135 //  Standard_Boolean  Inserted=Standard_False;
136   Standard_Integer nbpTz=NumberOfPoints();
137 //  Standard_Integer lpi;
138   if(nbpTz==0) { 
139     Append(Pi);
140     return;
141   }
142   if(Pi.ParamOnFirst() >= ParamOnFirstMax) { 
143     Append(Pi);
144   }
145   else if(Pi.ParamOnFirst() >= ParamOnFirstMin) { 
146     InsertBefore(1,Pi);
147   }
148   else {
149 /*----- Trop Long lbr le 13 mai 97  
150     Standard_Real PiParamOnFirst  = Pi.ParamOnFirst();
151     Standard_Real PiParamOnSecond = Pi.ParamOnSecond();
152     for (lpi=1; lpi<=nbpTz; lpi++) {
153       const Intf_SectionPoint& Resultlpi = Result(lpi);
154       if (PiParamOnFirst<Resultlpi.ParamOnFirst()) {
155         InsertBefore(lpi, Pi);
156         Inserted=Standard_True;
157         break;
158       }
159       else if (PiParamOnFirst==Resultlpi.ParamOnFirst()) {
160         if (PiParamOnSecond==Resultlpi.ParamOnSecond()) {
161           Inserted=Standard_True;
162           break;
163         }
164       }
165     }
166     if (!Inserted) {
167       Append(Pi);
168     }
169 ------ */
170     Append(Pi); //-- On met les points sans les classer 
171                 //-- si on veut on pourra les reclasser 
172                 //-- ensuite avec un TRI. 
173   }
174 }
175
176 //=======================================================================
177 //function : InsertAfter
178 //purpose  : 
179 //=======================================================================
180
181 void  Intf_TangentZone::InsertAfter(const Standard_Integer Index,
182                                     const Intf_SectionPoint& Pi)
183 {
184   Result.InsertAfter(Index, Pi);
185   if(ParamOnFirstMin  > Pi.ParamOnFirst())   ParamOnFirstMin  = Pi.ParamOnFirst();
186   if(ParamOnSecondMin > Pi.ParamOnSecond())  ParamOnSecondMin = Pi.ParamOnSecond();
187
188   if(ParamOnFirstMax  < Pi.ParamOnFirst())   ParamOnFirstMax  = Pi.ParamOnFirst();
189   if(ParamOnSecondMax < Pi.ParamOnSecond())  ParamOnSecondMax = Pi.ParamOnSecond();
190 }
191
192 //=======================================================================
193 //function : InsertBefore
194 //purpose  : 
195 //=======================================================================
196
197 void  Intf_TangentZone::InsertBefore(const Standard_Integer Index,
198                                      const Intf_SectionPoint& Pi)
199 {
200   Result.InsertBefore(Index, Pi);
201   if(ParamOnFirstMin  > Pi.ParamOnFirst())   ParamOnFirstMin  = Pi.ParamOnFirst();
202   if(ParamOnSecondMin > Pi.ParamOnSecond())  ParamOnSecondMin = Pi.ParamOnSecond();
203   
204   if(ParamOnFirstMax  < Pi.ParamOnFirst())   ParamOnFirstMax  = Pi.ParamOnFirst();
205   if(ParamOnSecondMax < Pi.ParamOnSecond())  ParamOnSecondMax = Pi.ParamOnSecond();
206 }
207
208
209 //=======================================================================
210 //function : GetPoint
211 //purpose  : Return the section point of range index in the tangent zone.
212 //=======================================================================
213
214 const Intf_SectionPoint& Intf_TangentZone::GetPoint 
215   (const Standard_Integer Index) const
216 {
217   return Result(Index);
218 }
219
220
221
222 //=======================================================================
223 //function : IsEqual
224 //purpose  : Compare two tangent zone.
225 //=======================================================================
226
227 Standard_Boolean Intf_TangentZone::IsEqual
228   (const Intf_TangentZone& Other) const
229 {
230   if (Result.Length() != Other.Result.Length())
231     return Standard_False;
232   Standard_Integer i;
233   for (i = 1; i <= Result.Length(); i++) {
234     if (!Result(i).IsEqual(Other.Result(i)))
235       return Standard_False;
236   }
237   return Standard_True;
238 }
239
240
241 //=======================================================================
242 //function : Contains
243 //purpose  : 
244 //=======================================================================
245
246 Standard_Boolean Intf_TangentZone::Contains
247  (const Intf_SectionPoint& ThePI) const
248 {
249   Standard_Integer i;
250   for (i = 1; i <= Result.Length(); i++)
251     if (ThePI.IsEqual(Result(i)))
252       return Standard_True;
253   return Standard_False;
254 }
255 //=======================================================================
256 //function : InfoFirst
257 //purpose  : 
258 //=======================================================================
259
260 void Intf_TangentZone::InfoFirst(Standard_Integer& segMin,
261                                  Standard_Real& paraMin, 
262                                  Standard_Integer& segMax,
263                                  Standard_Real& paraMax) const
264 {
265   ParamOnFirst(paraMin, paraMax);
266   segMin  = (Standard_Integer)(IntegerPart(paraMin));
267   paraMin = paraMin-(Standard_Real)segMin;
268   segMax  = (Standard_Integer)(IntegerPart(paraMax));
269   paraMax = paraMax-(Standard_Real)segMax;
270 }
271
272
273 //=======================================================================
274 //function : InfoSecond
275 //purpose  : 
276 //=======================================================================
277
278 void Intf_TangentZone::InfoSecond(Standard_Integer& segMin,
279                                   Standard_Real& paraMin, 
280                                   Standard_Integer& segMax,
281                                   Standard_Real& paraMax) const
282 {
283   ParamOnSecond(paraMin, paraMax);
284   segMin  = (Standard_Integer)(IntegerPart(paraMin));
285   paraMin = paraMin-(Standard_Real)segMin;
286   segMax  = (Standard_Integer)(IntegerPart(paraMax));
287   paraMax = paraMax-(Standard_Real)segMax;
288 }
289
290
291 //=======================================================================
292 //function : RangeContains
293 //purpose  : 
294 //=======================================================================
295
296 Standard_Boolean Intf_TangentZone::RangeContains
297  (const Intf_SectionPoint& ThePI) const
298 {
299   Standard_Real a, b, c, d;
300   ParamOnFirst(a, b);
301   ParamOnSecond(c, d);
302   if (a<=ThePI.ParamOnFirst() && ThePI.ParamOnFirst()<=b &&
303       c<=ThePI.ParamOnSecond()&& ThePI.ParamOnSecond()<=d )
304     return Standard_True;
305   return Standard_False;
306 }
307
308
309 //=======================================================================
310 //function : HasCommonRange
311 //purpose  : 
312 //=======================================================================
313
314 Standard_Boolean Intf_TangentZone::HasCommonRange
315  (const Intf_TangentZone& Other) const
316 {
317   Standard_Real a1,b1,c1,d1;
318   Standard_Real a2,b2,c2,d2;
319   ParamOnFirst(a1, b1);
320   ParamOnSecond(a2, b2);
321   Other.ParamOnFirst(c1, d1);
322   Other.ParamOnSecond(c2, d2);
323
324   if ((c1<=a1 && a1<=d1 || c1<=b1 && b1<=d1 || a1<=c1 && c1<=b1) &&
325       (c2<=a2 && a2<=d2 || c2<=b2 && b2<=d2 || a2<=c2 && c2<=b2))
326     return Standard_True;
327   return Standard_False;
328 }
329
330
331 //=======================================================================
332 //function : Dump
333 //purpose  : Dump the TangentZone.
334 //=======================================================================
335
336 void Intf_TangentZone::Dump (const Standard_Integer /*Indent*/) const
337 {
338 #if DEBUG_TANGENTZONE
339   for (Standard_Integer id=0; id<Indent; id++) cout << " ";
340   cout << "TZ \n" ;
341   cout<<"  ParamOnFirstMin Max    : "<<ParamOnFirstMin<<" "<<ParamOnFirstMax<<endl;
342   cout<<"  ParamOnSecondMin Max   : "<<ParamOnSecondMin<<" "<<ParamOnSecondMax<<endl;
343   for (Standard_Integer p=1; p<=Result.Length(); p++) {
344     Result(p).Dump(Indent+2);
345   }
346 #endif
347 }