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
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.
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.
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.
22 #include <Intf_TangentZone.ixx>
24 #define DEBUG_TANGENTZONE 0
25 //=======================================================================
26 //function : Intf_TangentZone
27 //purpose : Constructor of an empty tangent zone.
28 //=======================================================================
30 Intf_TangentZone::Intf_TangentZone ()
32 ParamOnFirstMin = ParamOnSecondMin = RealLast();
33 ParamOnFirstMax = ParamOnSecondMax = RealFirst();
37 //=======================================================================
38 //function : Intf_TangentZone
40 //=======================================================================
42 Intf_TangentZone::Intf_TangentZone (const Intf_TangentZone& Other)
45 ParamOnFirstMin = Other.ParamOnFirstMin;
46 ParamOnFirstMax = Other.ParamOnFirstMax;
47 ParamOnSecondMin = Other.ParamOnSecondMin;
48 ParamOnSecondMax = Other.ParamOnSecondMax;
50 //=======================================================================
52 //purpose : Append the section point to the tangent zone.
53 //=======================================================================
55 void Intf_TangentZone::Append (const Intf_SectionPoint& Pi)
58 if(ParamOnFirstMin > Pi.ParamOnFirst()) ParamOnFirstMin = Pi.ParamOnFirst();
59 if(ParamOnSecondMin > Pi.ParamOnSecond()) ParamOnSecondMin = Pi.ParamOnSecond();
61 if(ParamOnFirstMax < Pi.ParamOnFirst()) ParamOnFirstMax = Pi.ParamOnFirst();
62 if(ParamOnSecondMax < Pi.ParamOnSecond()) ParamOnSecondMax = Pi.ParamOnSecond();
66 //=======================================================================
68 //purpose : Merge the TangentZone to the tangent zone.
69 //=======================================================================
71 void Intf_TangentZone::Append (const Intf_TangentZone& Tzi)
73 Standard_Integer Tzi_NumberOfPoints = Tzi.NumberOfPoints();
74 for (Standard_Integer ipi=1; ipi<=Tzi_NumberOfPoints; ipi++) {
75 PolygonInsert(Tzi.GetPoint(ipi));
80 //=======================================================================
82 //purpose : Insert the section point at his place in the tangent zone.
83 //=======================================================================
85 //Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& Pi)
86 Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& )
89 cout<<" Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& Pi) ???? "<<endl;
91 Standard_Boolean Inserted=Standard_False;
93 Standard_Integer lpon=0;
95 if (Result.Length()<1) {
97 Inserted=Standard_True;
99 else if (Result.Length()==1) {
100 if (Pi.IsOnSameEdge(Result(1))) {
102 Inserted=Standard_True;
106 Standard_Integer lp1, lp2;
107 Standard_Integer nbptz=NumberOfPoints();
108 for (lp1=1; lp1<=nbptz; lp1++) {
110 if (Pi.IsOnSameEdge(Result(lp1))) {
112 if (Pi.IsOnSameEdge(Result(lp2))) {
113 InsertAfter(lp1, Pi);
114 Inserted=Standard_True;
120 if (!Inserted && lpon>0) {
121 InsertAfter(lpon, Pi);
122 Inserted=Standard_True;
128 //=======================================================================
129 //function : PolygonInsert
130 //purpose : Insert the point at his place in the polygonal tangent zone.
131 //=======================================================================
133 void Intf_TangentZone::PolygonInsert (const Intf_SectionPoint& Pi)
135 // Standard_Boolean Inserted=Standard_False;
136 Standard_Integer nbpTz=NumberOfPoints();
137 // Standard_Integer lpi;
142 if(Pi.ParamOnFirst() >= ParamOnFirstMax) {
145 else if(Pi.ParamOnFirst() >= ParamOnFirstMin) {
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;
159 else if (PiParamOnFirst==Resultlpi.ParamOnFirst()) {
160 if (PiParamOnSecond==Resultlpi.ParamOnSecond()) {
161 Inserted=Standard_True;
170 Append(Pi); //-- On met les points sans les classer
171 //-- si on veut on pourra les reclasser
172 //-- ensuite avec un TRI.
176 //=======================================================================
177 //function : InsertAfter
179 //=======================================================================
181 void Intf_TangentZone::InsertAfter(const Standard_Integer Index,
182 const Intf_SectionPoint& Pi)
184 Result.InsertAfter(Index, Pi);
185 if(ParamOnFirstMin > Pi.ParamOnFirst()) ParamOnFirstMin = Pi.ParamOnFirst();
186 if(ParamOnSecondMin > Pi.ParamOnSecond()) ParamOnSecondMin = Pi.ParamOnSecond();
188 if(ParamOnFirstMax < Pi.ParamOnFirst()) ParamOnFirstMax = Pi.ParamOnFirst();
189 if(ParamOnSecondMax < Pi.ParamOnSecond()) ParamOnSecondMax = Pi.ParamOnSecond();
192 //=======================================================================
193 //function : InsertBefore
195 //=======================================================================
197 void Intf_TangentZone::InsertBefore(const Standard_Integer Index,
198 const Intf_SectionPoint& Pi)
200 Result.InsertBefore(Index, Pi);
201 if(ParamOnFirstMin > Pi.ParamOnFirst()) ParamOnFirstMin = Pi.ParamOnFirst();
202 if(ParamOnSecondMin > Pi.ParamOnSecond()) ParamOnSecondMin = Pi.ParamOnSecond();
204 if(ParamOnFirstMax < Pi.ParamOnFirst()) ParamOnFirstMax = Pi.ParamOnFirst();
205 if(ParamOnSecondMax < Pi.ParamOnSecond()) ParamOnSecondMax = Pi.ParamOnSecond();
209 //=======================================================================
210 //function : GetPoint
211 //purpose : Return the section point of range index in the tangent zone.
212 //=======================================================================
214 const Intf_SectionPoint& Intf_TangentZone::GetPoint
215 (const Standard_Integer Index) const
217 return Result(Index);
222 //=======================================================================
224 //purpose : Compare two tangent zone.
225 //=======================================================================
227 Standard_Boolean Intf_TangentZone::IsEqual
228 (const Intf_TangentZone& Other) const
230 if (Result.Length() != Other.Result.Length())
231 return Standard_False;
233 for (i = 1; i <= Result.Length(); i++) {
234 if (!Result(i).IsEqual(Other.Result(i)))
235 return Standard_False;
237 return Standard_True;
241 //=======================================================================
242 //function : Contains
244 //=======================================================================
246 Standard_Boolean Intf_TangentZone::Contains
247 (const Intf_SectionPoint& ThePI) const
250 for (i = 1; i <= Result.Length(); i++)
251 if (ThePI.IsEqual(Result(i)))
252 return Standard_True;
253 return Standard_False;
255 //=======================================================================
256 //function : InfoFirst
258 //=======================================================================
260 void Intf_TangentZone::InfoFirst(Standard_Integer& segMin,
261 Standard_Real& paraMin,
262 Standard_Integer& segMax,
263 Standard_Real& paraMax) const
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;
273 //=======================================================================
274 //function : InfoSecond
276 //=======================================================================
278 void Intf_TangentZone::InfoSecond(Standard_Integer& segMin,
279 Standard_Real& paraMin,
280 Standard_Integer& segMax,
281 Standard_Real& paraMax) const
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;
291 //=======================================================================
292 //function : RangeContains
294 //=======================================================================
296 Standard_Boolean Intf_TangentZone::RangeContains
297 (const Intf_SectionPoint& ThePI) const
299 Standard_Real a, b, 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;
309 //=======================================================================
310 //function : HasCommonRange
312 //=======================================================================
314 Standard_Boolean Intf_TangentZone::HasCommonRange
315 (const Intf_TangentZone& Other) const
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);
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;
331 //=======================================================================
333 //purpose : Dump the TangentZone.
334 //=======================================================================
336 void Intf_TangentZone::Dump (const Standard_Integer
340 #if DEBUG_TANGENTZONE
341 for (Standard_Integer id=0; id<Indent; id++) cout << " ";
343 cout<<" ParamOnFirstMin Max : "<<ParamOnFirstMin<<" "<<ParamOnFirstMax<<endl;
344 cout<<" ParamOnSecondMin Max : "<<ParamOnSecondMin<<" "<<ParamOnSecondMax<<endl;
345 for (Standard_Integer p=1; p<=Result.Length(); p++) {
346 Result(p).Dump(Indent+2);