1 // Created on: 1991-06-24
2 // Created by: Didier PIFFAULT
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Intf_SectionPoint.hxx>
19 #include <Intf_TangentZone.hxx>
20 #include <Standard_OutOfRange.hxx>
21
22 #define DEBUG_TANGENTZONE 0
23 //=======================================================================
24 //function : Intf_TangentZone
25 //purpose : Constructor of an empty tangent zone.
26 //=======================================================================
27
Intf_TangentZone()28 Intf_TangentZone::Intf_TangentZone ()
29 {
30 ParamOnFirstMin = ParamOnSecondMin = RealLast();
31 ParamOnFirstMax = ParamOnSecondMax = RealFirst();
32 }
33
34 //=======================================================================
35 //function : Append
36 //purpose : Append the section point to the tangent zone.
37 //=======================================================================
38
Append(const Intf_SectionPoint & Pi)39 void Intf_TangentZone::Append (const Intf_SectionPoint& Pi)
40 {
41 Result.Append(Pi);
42 if(ParamOnFirstMin > Pi.ParamOnFirst()) ParamOnFirstMin = Pi.ParamOnFirst();
43 if(ParamOnSecondMin > Pi.ParamOnSecond()) ParamOnSecondMin = Pi.ParamOnSecond();
44
45 if(ParamOnFirstMax < Pi.ParamOnFirst()) ParamOnFirstMax = Pi.ParamOnFirst();
46 if(ParamOnSecondMax < Pi.ParamOnSecond()) ParamOnSecondMax = Pi.ParamOnSecond();
47 }
48
49
50 //=======================================================================
51 //function : Append
52 //purpose : Merge the TangentZone to the tangent zone.
53 //=======================================================================
54
Append(const Intf_TangentZone & Tzi)55 void Intf_TangentZone::Append (const Intf_TangentZone& Tzi)
56 {
57 Standard_Integer Tzi_NumberOfPoints = Tzi.NumberOfPoints();
58 for (Standard_Integer ipi=1; ipi<=Tzi_NumberOfPoints; ipi++) {
59 PolygonInsert(Tzi.GetPoint(ipi));
60 }
61 }
62
63
64 //=======================================================================
65 //function : Insert
66 //purpose : Insert the section point at his place in the tangent zone.
67 //=======================================================================
68
69 //Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& Pi)
Insert(const Intf_SectionPoint &)70 Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& )
71 {
72 #if DEBUG_TANGENTZONE
73 std::cout<<" Standard_Boolean Intf_TangentZone::Insert (const Intf_SectionPoint& Pi) ???? "<<std::endl;
74 #endif
75 Standard_Boolean Inserted=Standard_False;
76 /*
77 Standard_Integer lpon=0;
78
79 if (Result.Length()<1) {
80 Append(Pi);
81 Inserted=Standard_True;
82 }
83 else if (Result.Length()==1) {
84 if (Pi.IsOnSameEdge(Result(1))) {
85 InsertAfter(1, Pi);
86 Inserted=Standard_True;
87 }
88 }
89 else {
90 Standard_Integer lp1, lp2;
91 Standard_Integer nbptz=NumberOfPoints();
92 for (lp1=1; lp1<=nbptz; lp1++) {
93 lp2=(lp1%nbptz)+1;
94 if (Pi.IsOnSameEdge(Result(lp1))) {
95 lpon=lp1;
96 if (Pi.IsOnSameEdge(Result(lp2))) {
97 InsertAfter(lp1, Pi);
98 Inserted=Standard_True;
99 break;
100 }
101 }
102 }
103 }
104 if (!Inserted && lpon>0) {
105 InsertAfter(lpon, Pi);
106 Inserted=Standard_True;
107 }
108 */
109 return Inserted;
110 }
111
112 //=======================================================================
113 //function : PolygonInsert
114 //purpose : Insert the point at his place in the polygonal tangent zone.
115 //=======================================================================
116
PolygonInsert(const Intf_SectionPoint & Pi)117 void Intf_TangentZone::PolygonInsert (const Intf_SectionPoint& Pi)
118 {
119 // Standard_Boolean Inserted=Standard_False;
120 Standard_Integer nbpTz=NumberOfPoints();
121 // Standard_Integer lpi;
122 if(nbpTz==0) {
123 Append(Pi);
124 return;
125 }
126 if(Pi.ParamOnFirst() >= ParamOnFirstMax) {
127 Append(Pi);
128 }
129 else if(Pi.ParamOnFirst() >= ParamOnFirstMin) {
130 InsertBefore(1,Pi);
131 }
132 else {
133 /*----- Trop Long lbr le 13 mai 97
134 Standard_Real PiParamOnFirst = Pi.ParamOnFirst();
135 Standard_Real PiParamOnSecond = Pi.ParamOnSecond();
136 for (lpi=1; lpi<=nbpTz; lpi++) {
137 const Intf_SectionPoint& Resultlpi = Result(lpi);
138 if (PiParamOnFirst<Resultlpi.ParamOnFirst()) {
139 InsertBefore(lpi, Pi);
140 Inserted=Standard_True;
141 break;
142 }
143 else if (PiParamOnFirst==Resultlpi.ParamOnFirst()) {
144 if (PiParamOnSecond==Resultlpi.ParamOnSecond()) {
145 Inserted=Standard_True;
146 break;
147 }
148 }
149 }
150 if (!Inserted) {
151 Append(Pi);
152 }
153 ------ */
154 Append(Pi); //-- On met les points sans les classer
155 //-- si on veut on pourra les reclasser
156 //-- ensuite avec un TRI.
157 }
158 }
159
160 //=======================================================================
161 //function : InsertAfter
162 //purpose :
163 //=======================================================================
164
InsertAfter(const Standard_Integer Index,const Intf_SectionPoint & Pi)165 void Intf_TangentZone::InsertAfter(const Standard_Integer Index,
166 const Intf_SectionPoint& Pi)
167 {
168 Result.InsertAfter(Index, Pi);
169 if(ParamOnFirstMin > Pi.ParamOnFirst()) ParamOnFirstMin = Pi.ParamOnFirst();
170 if(ParamOnSecondMin > Pi.ParamOnSecond()) ParamOnSecondMin = Pi.ParamOnSecond();
171
172 if(ParamOnFirstMax < Pi.ParamOnFirst()) ParamOnFirstMax = Pi.ParamOnFirst();
173 if(ParamOnSecondMax < Pi.ParamOnSecond()) ParamOnSecondMax = Pi.ParamOnSecond();
174 }
175
176 //=======================================================================
177 //function : InsertBefore
178 //purpose :
179 //=======================================================================
180
InsertBefore(const Standard_Integer Index,const Intf_SectionPoint & Pi)181 void Intf_TangentZone::InsertBefore(const Standard_Integer Index,
182 const Intf_SectionPoint& Pi)
183 {
184 Result.InsertBefore(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 //=======================================================================
194 //function : GetPoint
195 //purpose : Return the section point of range index in the tangent zone.
196 //=======================================================================
197
GetPoint(const Standard_Integer Index) const198 const Intf_SectionPoint& Intf_TangentZone::GetPoint
199 (const Standard_Integer Index) const
200 {
201 return Result(Index);
202 }
203
204
205
206 //=======================================================================
207 //function : IsEqual
208 //purpose : Compare two tangent zone.
209 //=======================================================================
210
IsEqual(const Intf_TangentZone & Other) const211 Standard_Boolean Intf_TangentZone::IsEqual
212 (const Intf_TangentZone& Other) const
213 {
214 if (Result.Length() != Other.Result.Length())
215 return Standard_False;
216 Standard_Integer i;
217 for (i = 1; i <= Result.Length(); i++) {
218 if (!Result(i).IsEqual(Other.Result(i)))
219 return Standard_False;
220 }
221 return Standard_True;
222 }
223
224
225 //=======================================================================
226 //function : Contains
227 //purpose :
228 //=======================================================================
229
Contains(const Intf_SectionPoint & ThePI) const230 Standard_Boolean Intf_TangentZone::Contains
231 (const Intf_SectionPoint& ThePI) const
232 {
233 Standard_Integer i;
234 for (i = 1; i <= Result.Length(); i++)
235 if (ThePI.IsEqual(Result(i)))
236 return Standard_True;
237 return Standard_False;
238 }
239 //=======================================================================
240 //function : InfoFirst
241 //purpose :
242 //=======================================================================
243
InfoFirst(Standard_Integer & segMin,Standard_Real & paraMin,Standard_Integer & segMax,Standard_Real & paraMax) const244 void Intf_TangentZone::InfoFirst(Standard_Integer& segMin,
245 Standard_Real& paraMin,
246 Standard_Integer& segMax,
247 Standard_Real& paraMax) const
248 {
249 ParamOnFirst(paraMin, paraMax);
250 segMin = (Standard_Integer)(IntegerPart(paraMin));
251 paraMin = paraMin-(Standard_Real)segMin;
252 segMax = (Standard_Integer)(IntegerPart(paraMax));
253 paraMax = paraMax-(Standard_Real)segMax;
254 }
255
256
257 //=======================================================================
258 //function : InfoSecond
259 //purpose :
260 //=======================================================================
261
InfoSecond(Standard_Integer & segMin,Standard_Real & paraMin,Standard_Integer & segMax,Standard_Real & paraMax) const262 void Intf_TangentZone::InfoSecond(Standard_Integer& segMin,
263 Standard_Real& paraMin,
264 Standard_Integer& segMax,
265 Standard_Real& paraMax) const
266 {
267 ParamOnSecond(paraMin, paraMax);
268 segMin = (Standard_Integer)(IntegerPart(paraMin));
269 paraMin = paraMin-(Standard_Real)segMin;
270 segMax = (Standard_Integer)(IntegerPart(paraMax));
271 paraMax = paraMax-(Standard_Real)segMax;
272 }
273
274
275 //=======================================================================
276 //function : RangeContains
277 //purpose :
278 //=======================================================================
279
RangeContains(const Intf_SectionPoint & ThePI) const280 Standard_Boolean Intf_TangentZone::RangeContains
281 (const Intf_SectionPoint& ThePI) const
282 {
283 Standard_Real a, b, c, d;
284 ParamOnFirst(a, b);
285 ParamOnSecond(c, d);
286 if (a<=ThePI.ParamOnFirst() && ThePI.ParamOnFirst()<=b &&
287 c<=ThePI.ParamOnSecond()&& ThePI.ParamOnSecond()<=d )
288 return Standard_True;
289 return Standard_False;
290 }
291
292
293 //=======================================================================
294 //function : HasCommonRange
295 //purpose :
296 //=======================================================================
297
HasCommonRange(const Intf_TangentZone & Other) const298 Standard_Boolean Intf_TangentZone::HasCommonRange
299 (const Intf_TangentZone& Other) const
300 {
301 Standard_Real a1,b1,c1,d1;
302 Standard_Real a2,b2,c2,d2;
303 ParamOnFirst(a1, b1);
304 ParamOnSecond(a2, b2);
305 Other.ParamOnFirst(c1, d1);
306 Other.ParamOnSecond(c2, d2);
307
308 if (((c1<=a1 && a1<=d1) || (c1<=b1 && b1<=d1) || (a1<=c1 && c1<=b1)) &&
309 ((c2<=a2 && a2<=d2) || (c2<=b2 && b2<=d2) || (a2<=c2 && c2<=b2)))
310 return Standard_True;
311 return Standard_False;
312 }
313
314
315 //=======================================================================
316 //function : Dump
317 //purpose : Dump the TangentZone.
318 //=======================================================================
319
Dump(const Standard_Integer) const320 void Intf_TangentZone::Dump (const Standard_Integer /*Indent*/) const
321 {
322 #if DEBUG_TANGENTZONE
323 for (Standard_Integer id=0; id<Indent; id++) std::cout << " ";
324 std::cout << "TZ \n" ;
325 std::cout<<" ParamOnFirstMin Max : "<<ParamOnFirstMin<<" "<<ParamOnFirstMax<<std::endl;
326 std::cout<<" ParamOnSecondMin Max : "<<ParamOnSecondMin<<" "<<ParamOnSecondMax<<std::endl;
327 for (Standard_Integer p=1; p<=Result.Length(); p++) {
328 Result(p).Dump(Indent+2);
329 }
330 #endif
331 }
332