7fd59977 |
1 | // File: Bisector_Bisec.cxx |
2 | // Created: Mon Jul 4 10:05:48 1994 |
3 | // Author: Yves FRICAUD |
4 | // <yfr@phobox> |
5 | |
6 | #include <Bisector_Bisec.ixx> |
7 | #include <Bisector.hxx> |
8 | #include <Geom2d_Circle.hxx> |
9 | #include <Geom2d_Line.hxx> |
10 | #include <Geom2d_Point.hxx> |
11 | #include <Geom2d_CartesianPoint.hxx> |
12 | #include <Geom2d_TrimmedCurve.hxx> |
13 | #include <gp.hxx> |
14 | #include <gp_Pnt2d.hxx> |
15 | #include <gp_Vec2d.hxx> |
16 | #include <StdFail_NotDone.hxx> |
17 | #include <Standard_NotImplemented.hxx> |
18 | #include <Precision.hxx> |
19 | #include <Bisector_Curve.hxx> |
20 | #include <Bisector_BisecAna.hxx> |
21 | #include <Bisector_BisecPC.hxx> |
22 | #include <Bisector_BisecCC.hxx> |
23 | |
24 | /* |
25 | #include <DrawTrSurf.hxx> |
26 | static char tname[100]; |
27 | static Standard_CString name = tname ; |
28 | static Standard_Integer nbb = 0; |
29 | */ |
30 | |
31 | #ifdef DEB |
32 | static Standard_Boolean PointIsOnCurve(const Handle(Geom2d_Curve)& C, |
33 | const gp_Pnt2d& P, |
34 | Standard_Real& U); |
35 | #endif |
36 | static Standard_Boolean IsMaxRC (const Handle(Geom2d_Curve)& C, |
37 | Standard_Real U, |
38 | Standard_Real& R); |
39 | |
40 | static void ReplaceByLineIfIsToSmall (Handle(Geom2d_Curve)& Bis, |
41 | Standard_Real& UFirst, |
42 | Standard_Real& ULast); |
43 | //============================================================================= |
44 | //function : Constructeur vide |
45 | //============================================================================= |
46 | Bisector_Bisec::Bisector_Bisec() |
47 | { |
48 | } |
49 | |
50 | //=========================================================================== |
51 | // calcul de la bissectrice entre deux courbes issue d un point. |
52 | // |
53 | // afirstcurve : \ courbes entre lesquelles on veut calculer la |
54 | // asecondcurve : / bissectrice. |
55 | // apoint : point par lequel doit passer la bissectrice. |
56 | // afirstvector : \ vecteurs pour determiner le secteur dans lequel |
57 | // asecondvector : / la bissectrice doit se trouver. |
58 | // adirection : indique le cote de la bissectrice a conserver. |
59 | // tolerance : seuil a partir duquel les bisectrices sont degenerees |
60 | //=========================================================================== |
61 | |
62 | void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , |
63 | const Handle(Geom2d_Curve)& asecondcurve , |
64 | const gp_Pnt2d& apoint , |
65 | const gp_Vec2d& afirstvector , |
66 | const gp_Vec2d& asecondvector , |
67 | const Standard_Real adirection , |
68 | const Standard_Real tolerance , |
69 | const Standard_Boolean oncurve ) |
70 | { |
71 | Handle(Standard_Type) Type1 = afirstcurve ->DynamicType(); |
72 | Handle(Standard_Type) Type2 = asecondcurve->DynamicType(); |
73 | Handle(Bisector_Curve) Bis; |
74 | Standard_Real UFirst,ULast; |
75 | |
76 | if (Type1 == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
77 | Type1 = Handle(Geom2d_TrimmedCurve)::DownCast(afirstcurve) |
78 | ->BasisCurve()->DynamicType(); |
79 | } |
80 | if (Type2 == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
81 | Type2 = Handle(Geom2d_TrimmedCurve)::DownCast(asecondcurve) |
82 | ->BasisCurve()->DynamicType(); |
83 | } |
84 | |
85 | if ( (Type1 == STANDARD_TYPE(Geom2d_Circle) || Type1 == STANDARD_TYPE(Geom2d_Line)) && |
86 | (Type2 == STANDARD_TYPE(Geom2d_Circle) || Type2 == STANDARD_TYPE(Geom2d_Line)) ) { |
87 | //------------------------------------------------------------------ |
88 | // Bissectrice analytique. |
89 | //------------------------------------------------------------------ |
90 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna(); |
91 | BisAna->Perform(afirstcurve , |
92 | asecondcurve , |
93 | apoint , |
94 | afirstvector , |
95 | asecondvector , |
96 | adirection , |
97 | tolerance , |
98 | oncurve ); |
99 | UFirst = BisAna->ParameterOfStartPoint(); |
100 | ULast = BisAna->ParameterOfEndPoint(); |
101 | Bis = BisAna; |
102 | } |
103 | else { |
104 | Standard_Boolean IsLine = Standard_False; |
105 | |
106 | if (oncurve) { |
107 | gp_Dir2d Fd(afirstvector); |
108 | gp_Dir2d Sd(asecondvector); |
109 | //if (Fd.Dot(Sd) < Precision::Angular() - 1.) { |
110 | //if (Fd.Dot(Sd) < 10*Precision::Angular() - 1.) //patch |
111 | if (Fd.Dot(Sd) < Sqrt(2.*Precision::Angular()) - 1.) |
112 | IsLine = Standard_True; |
113 | } |
114 | if (IsLine) { |
115 | //------------------------------------------------------------------ |
116 | // Demi-Droite. |
117 | //------------------------------------------------------------------ |
118 | gp_Dir2d N ( - adirection*afirstvector.Y(), adirection*afirstvector.X()); |
119 | Handle (Geom2d_CartesianPoint) PG = new Geom2d_CartesianPoint(apoint); |
120 | Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); |
121 | Handle (Geom2d_TrimmedCurve) |
122 | BisL = new Geom2d_TrimmedCurve (L,0,Precision::Infinite()); |
123 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
124 | BisAna->Init(BisL); |
125 | UFirst = BisAna->ParameterOfStartPoint(); |
126 | ULast = BisAna->ParameterOfEndPoint(); |
127 | Bis = BisAna; |
128 | } |
129 | else { |
130 | //------------------------------------------------------------------- |
131 | // Bissectrice algo |
132 | //------------------------------------------------------------------- |
133 | Handle(Bisector_BisecCC) BisCC = new Bisector_BisecCC(); |
134 | BisCC -> Perform(asecondcurve, |
135 | afirstcurve , |
136 | adirection , |
137 | adirection , |
138 | apoint); |
139 | |
140 | if (BisCC -> IsEmpty()) { |
141 | // la bissectrice est vide apoint se projette a la fin de la courbe |
142 | // guide . Construction d une fausse bissectrice. |
143 | // modified by NIZHNY-EAP Mon Feb 21 12:00:13 2000 ___BEGIN___ |
144 | gp_Dir2d dir1(afirstvector), dir2(asecondvector); |
145 | Standard_Real |
146 | Nx = - dir1.X() - dir2.X(), |
147 | Ny = - dir1.Y() - dir2.Y(); |
148 | if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { |
149 | Nx = - afirstvector.Y(); |
150 | Ny = afirstvector.X(); |
151 | } |
152 | //gp_Dir2d N ( - adirection*afirstvector.Y(), adirection*afirstvector.X()); |
153 | gp_Dir2d N ( adirection*Nx, adirection*Ny); |
154 | // modified by NIZHNY-EAP Mon Feb 21 12:00:19 2000 ___END___ |
155 | |
156 | Handle (Geom2d_CartesianPoint) PG = new Geom2d_CartesianPoint(apoint); |
157 | Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); |
158 | Handle (Geom2d_TrimmedCurve) |
159 | BisL = new Geom2d_TrimmedCurve (L,0,Precision::Infinite()); |
160 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
161 | BisAna->Init(BisL); |
162 | UFirst = BisAna->ParameterOfStartPoint(); |
163 | ULast = BisAna->ParameterOfEndPoint(); |
164 | Bis = BisAna; |
165 | } |
166 | else { |
167 | UFirst = BisCC->FirstParameter(); |
168 | ULast = BisCC->LastParameter (); |
169 | Bis = BisCC; |
170 | ReplaceByLineIfIsToSmall(Bis,UFirst,ULast); |
171 | } |
172 | } |
173 | } |
174 | thebisector = new Geom2d_TrimmedCurve(Bis,UFirst,ULast); |
175 | |
176 | /* |
177 | sprintf( name, "c1_%d", ++nbb ); |
178 | DrawTrSurf::Set( name, afirstcurve ); |
179 | sprintf( name, "c2_%d", nbb ); |
180 | DrawTrSurf::Set( name, asecondcurve ); |
181 | sprintf( name, "p%d", nbb ); |
182 | DrawTrSurf::Set( name, apoint ); |
183 | sprintf( name, "b%d", nbb ); |
184 | DrawTrSurf::Set( name, thebisector ); |
185 | */ |
186 | } |
187 | |
188 | //=========================================================================== |
189 | // calcul de la bissectrice entre une courbe et un point issue d un point. |
190 | // |
191 | // afirstcurve : \ courbe et point entre lesquelles on veut calculer la |
192 | // asecondpoint : / bissectrice. |
193 | // apoint : point par lequel doit passer la bissectrice. |
194 | // afirstvector : \ vecteurs pour determiner le secteur dans lequel |
195 | // asecondvector : / la bissectrice doit se trouver. |
196 | // adirection : indique le cote de la bissectrice a conserver. |
197 | // tolerance : seuil a partir duquel les bisectrices sont degenerees |
198 | //=========================================================================== |
199 | |
200 | void Bisector_Bisec::Perform(const Handle(Geom2d_Curve)& afirstcurve , |
201 | const Handle(Geom2d_Point)& asecondpoint , |
202 | const gp_Pnt2d& apoint , |
203 | const gp_Vec2d& afirstvector , |
204 | const gp_Vec2d& asecondvector, |
205 | const Standard_Real adirection , |
206 | const Standard_Real tolerance , |
207 | const Standard_Boolean oncurve ) |
208 | { |
209 | //gp_Pnt2d SecondPnt = asecondpoint->Pnt2d(); |
210 | |
211 | Handle(Bisector_Curve) Bis; |
212 | Handle(Standard_Type) Type1 = afirstcurve ->DynamicType(); |
213 | Standard_Real UFirst,ULast; |
214 | |
215 | if (Type1 == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
216 | Type1 = Handle(Geom2d_TrimmedCurve)::DownCast(afirstcurve) |
217 | ->BasisCurve()->DynamicType(); |
218 | } |
219 | |
220 | if ( Type1 == STANDARD_TYPE(Geom2d_Circle) || Type1 == STANDARD_TYPE(Geom2d_Line)) { |
221 | //------------------------------------------------------------------ |
222 | // Bissectrice analytique. |
223 | //------------------------------------------------------------------ |
224 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna(); |
225 | BisAna -> Perform (afirstcurve , |
226 | asecondpoint , |
227 | apoint , |
228 | afirstvector , |
229 | asecondvector , |
230 | adirection , |
231 | tolerance , |
232 | oncurve ); |
233 | UFirst = BisAna->ParameterOfStartPoint(); |
234 | ULast = BisAna->ParameterOfEndPoint(); |
235 | Bis = BisAna; |
236 | } |
237 | else { |
238 | Standard_Boolean IsLine = Standard_False; |
239 | Standard_Real RC = Precision::Infinite(); |
240 | |
241 | if (oncurve) { |
242 | if (Bisector::IsConvex(afirstcurve,adirection) || |
243 | IsMaxRC(afirstcurve,afirstcurve->LastParameter(),RC)) { |
244 | IsLine = Standard_True; |
245 | } |
246 | } |
247 | if (IsLine) { |
248 | //------------------------------------------------------------------ |
249 | // Demi-Droite. |
250 | //------------------------------------------------------------------ |
251 | gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); |
252 | Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); |
253 | Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve(L,0,RC); |
254 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
255 | BisAna->Init(BisL); |
256 | UFirst = BisAna->ParameterOfStartPoint(); |
257 | ULast = BisAna->ParameterOfEndPoint(); |
258 | Bis = BisAna; |
259 | } |
260 | else { |
261 | //------------------------------------------------------------------- |
262 | // Bissectrice algo |
263 | //------------------------------------------------------------------- |
264 | Handle(Bisector_BisecPC) BisPC = new Bisector_BisecPC(); |
265 | Handle(Geom2d_Curve) afirstcurvereverse = afirstcurve->Reversed(); |
266 | |
267 | BisPC -> Perform(afirstcurvereverse , |
268 | asecondpoint->Pnt2d(), |
269 | - adirection ); |
270 | // Modified by Sergey KHROMOV - Thu Feb 21 16:49:54 2002 Begin |
271 | if (BisPC -> IsEmpty()) { |
272 | gp_Dir2d dir1(afirstvector), dir2(asecondvector); |
273 | Standard_Real |
274 | Nx = - dir1.X() - dir2.X(), |
275 | Ny = - dir1.Y() - dir2.Y(); |
276 | if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { |
277 | Nx = - afirstvector.Y(); |
278 | Ny = afirstvector.X(); |
279 | } |
280 | // gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); |
281 | gp_Dir2d N ( adirection*Nx, adirection*Ny); |
282 | Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); |
283 | Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve(L,0,RC); |
284 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
285 | BisAna->Init(BisL); |
286 | UFirst = BisAna->ParameterOfStartPoint(); |
287 | ULast = BisAna->ParameterOfEndPoint(); |
288 | Bis = BisAna; |
289 | } else { |
290 | // Modified by Sergey KHROMOV - Wed Mar 6 17:01:08 2002 End |
291 | UFirst = BisPC->Parameter(apoint); |
292 | ULast = BisPC->LastParameter(); |
293 | if(UFirst >= ULast) |
294 | { |
295 | //Standard_Real t = .9; |
296 | //UFirst = (1. - t) * BisPC->FirstParameter() + t * ULast; |
297 | //Extrapolate by line |
298 | //gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); |
299 | gp_Vec2d V( BisPC->Value(BisPC->FirstParameter()), BisPC->Value(ULast) ); |
300 | gp_Dir2d N( V ); |
301 | Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); |
302 | Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve (L,0,RC); |
303 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
304 | BisAna->Init(BisL); |
305 | UFirst = BisAna->ParameterOfStartPoint(); |
306 | ULast = BisAna->ParameterOfEndPoint(); |
307 | Bis = BisAna; |
308 | } |
309 | else |
310 | Bis = BisPC; |
311 | } |
312 | } |
313 | } |
314 | thebisector = new Geom2d_TrimmedCurve(Bis,UFirst,ULast); |
315 | |
316 | /* |
317 | sprintf( name, "c1_%d", ++nbb ); |
318 | DrawTrSurf::Set( name, afirstcurve ); |
319 | sprintf( name, "c2_%d", nbb ); |
320 | DrawTrSurf::Set( name, SecondPnt ); |
321 | sprintf( name, "p%d", nbb ); |
322 | DrawTrSurf::Set( name, apoint ); |
323 | sprintf( name, "b%d", nbb ); |
324 | DrawTrSurf::Set( name, thebisector ); |
325 | */ |
326 | } |
327 | |
328 | //=========================================================================== |
329 | // calcul de la bissectrice entre une courbe et un point issue d un point. |
330 | // |
331 | // afirstpoint : \ point et courbe entre lesquelles on veut calculer la |
332 | // asecondcurve : / bissectrice. |
333 | // apoint : point par lequel doit passer la bissectrice. |
334 | // afirstvector : \ vecteurs pour determiner le secteur dans lequel |
335 | // asecondvector : / la bissectrice doit se trouver. |
336 | // adirection : indique le cote de la bissectrice a conserver. |
337 | // tolerance : seuil a partir duquel les bisectrices sont degenerees |
338 | //=========================================================================== |
339 | |
340 | void Bisector_Bisec::Perform(const Handle(Geom2d_Point)& afirstpoint , |
341 | const Handle(Geom2d_Curve)& asecondcurve , |
342 | const gp_Pnt2d& apoint , |
343 | const gp_Vec2d& afirstvector , |
344 | const gp_Vec2d& asecondvector, |
345 | const Standard_Real adirection , |
346 | const Standard_Real tolerance , |
347 | const Standard_Boolean oncurve ) |
348 | |
349 | { |
350 | //gp_Pnt2d FirstPnt = afirstpoint->Pnt2d(); |
351 | |
352 | Handle(Bisector_Curve) Bis; |
353 | Handle(Standard_Type) Type1 = asecondcurve ->DynamicType(); |
354 | Standard_Real UFirst,ULast; |
355 | |
356 | if (Type1 == STANDARD_TYPE(Geom2d_TrimmedCurve)) { |
357 | Type1 = Handle(Geom2d_TrimmedCurve)::DownCast(asecondcurve) |
358 | ->BasisCurve()->DynamicType(); |
359 | } |
360 | |
361 | if ( Type1 == STANDARD_TYPE(Geom2d_Circle) || Type1 == STANDARD_TYPE(Geom2d_Line)) { |
362 | //------------------------------------------------------------------ |
363 | // Bissectrice analytique. |
364 | //------------------------------------------------------------------ |
365 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna(); |
366 | BisAna -> Perform (afirstpoint , |
367 | asecondcurve , |
368 | apoint , |
369 | afirstvector , |
370 | asecondvector , |
371 | adirection , |
372 | tolerance , |
373 | oncurve ); |
374 | UFirst = BisAna->ParameterOfStartPoint(); |
375 | ULast = BisAna->ParameterOfEndPoint(); |
376 | Bis = BisAna; |
377 | } |
378 | else { |
379 | // Standard_Real UPoint = 0.; |
380 | Standard_Boolean IsLine = Standard_False; |
381 | Standard_Real RC = Precision::Infinite(); |
382 | |
383 | if (oncurve) { |
384 | if (Bisector::IsConvex(asecondcurve, adirection) || |
385 | IsMaxRC(asecondcurve,asecondcurve->FirstParameter(),RC)) { |
386 | IsLine = Standard_True; |
387 | } |
388 | } |
389 | if (IsLine) { |
390 | //------------------------------------------------------------------ |
391 | // Demi-Droite. |
392 | //------------------------------------------------------------------ |
393 | gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); |
394 | Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); |
395 | Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve (L,0,RC); |
396 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
397 | BisAna->Init(BisL); |
398 | UFirst = BisAna->ParameterOfStartPoint(); |
399 | ULast = BisAna->ParameterOfEndPoint(); |
400 | Bis = BisAna; |
401 | } |
402 | else { |
403 | //------------------------------------------------------------------- |
404 | // Bissectrice algo |
405 | //------------------------------------------------------------------- |
406 | Handle(Bisector_BisecPC) BisPC = new Bisector_BisecPC(); |
407 | BisPC -> Perform(asecondcurve , |
408 | afirstpoint->Pnt2d(), |
409 | adirection ); |
410 | // Modified by Sergey KHROMOV - Thu Feb 21 16:49:54 2002 Begin |
411 | if (BisPC -> IsEmpty()) { |
412 | gp_Dir2d dir1(afirstvector), dir2(asecondvector); |
413 | Standard_Real |
414 | Nx = - dir1.X() - dir2.X(), |
415 | Ny = - dir1.Y() - dir2.Y(); |
416 | if (Abs(Nx) <= gp::Resolution() && Abs(Ny) <= gp::Resolution()) { |
417 | Nx = - afirstvector.Y(); |
418 | Ny = afirstvector.X(); |
419 | } |
420 | // gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); |
421 | gp_Dir2d N ( adirection*Nx, adirection*Ny); |
422 | Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); |
423 | Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve(L,0,RC); |
424 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
425 | BisAna->Init(BisL); |
426 | UFirst = BisAna->ParameterOfStartPoint(); |
427 | ULast = BisAna->ParameterOfEndPoint(); |
428 | Bis = BisAna; |
429 | } else { |
430 | // Modified by Sergey KHROMOV - Thu Feb 21 16:49:58 2002 End |
431 | UFirst = BisPC->Parameter(apoint); |
432 | ULast = BisPC->LastParameter(); |
433 | if(UFirst >= ULast) |
434 | { |
435 | //Extrapolate by line |
436 | //gp_Dir2d N ( -adirection*afirstvector.Y(), adirection*afirstvector.X()); |
437 | gp_Vec2d V( BisPC->Value(BisPC->FirstParameter()), BisPC->Value(ULast) ); |
438 | gp_Dir2d N( V ); |
439 | Handle (Geom2d_Line) L = new Geom2d_Line (apoint,N); |
440 | Handle (Geom2d_TrimmedCurve) BisL = new Geom2d_TrimmedCurve (L,0,RC); |
441 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
442 | BisAna->Init(BisL); |
443 | UFirst = BisAna->ParameterOfStartPoint(); |
444 | ULast = BisAna->ParameterOfEndPoint(); |
445 | Bis = BisAna; |
446 | } |
447 | else |
448 | Bis = BisPC; |
449 | } |
450 | } |
451 | } |
452 | thebisector = new Geom2d_TrimmedCurve(Bis,UFirst,ULast); |
453 | |
454 | /* |
455 | sprintf( name, "c1_%d", ++nbb ); |
456 | DrawTrSurf::Set( name, FirstPnt ); |
457 | sprintf( name, "c2_%d", nbb ); |
458 | DrawTrSurf::Set( name, asecondcurve ); |
459 | sprintf( name, "p%d", nbb ); |
460 | DrawTrSurf::Set( name, apoint ); |
461 | sprintf( name, "b%d", nbb ); |
462 | DrawTrSurf::Set( name, thebisector ); |
463 | */ |
464 | } |
465 | |
466 | //=========================================================================== |
467 | // calcul de la bissectrice entre deux points issue d un point. |
468 | // |
469 | // afirstpoint : \ courbes entre lesquelles on veut calculer la |
470 | // asecondpoint : / bissectrice. |
471 | // apoint : point par lequel doit passer la bissectrice. |
472 | // afirstvector : \ vecteurs pour determiner le secteur dans lequel |
473 | // asecondvector : / la bissectrice doit se trouver. |
474 | // adirection : indique le cote de la bissectrice a conserver. |
475 | //=========================================================================== |
476 | |
477 | void Bisector_Bisec::Perform(const Handle(Geom2d_Point)& afirstpoint , |
478 | const Handle(Geom2d_Point)& asecondpoint , |
479 | const gp_Pnt2d& apoint , |
480 | const gp_Vec2d& afirstvector , |
481 | const gp_Vec2d& asecondvector, |
482 | const Standard_Real adirection , |
483 | const Standard_Real tolerance , |
484 | const Standard_Boolean oncurve ) |
485 | { |
486 | Handle(Bisector_BisecAna) Bis = new Bisector_BisecAna(); |
487 | |
488 | Bis -> Perform (afirstpoint , |
489 | asecondpoint , |
490 | apoint , |
491 | afirstvector , |
492 | asecondvector , |
493 | adirection , |
494 | tolerance , |
495 | oncurve ); |
496 | thebisector = new Geom2d_TrimmedCurve(Bis, |
497 | Bis->ParameterOfStartPoint(), |
498 | Bis->ParameterOfEndPoint()); |
499 | |
500 | /* |
501 | sprintf( name, "c1_%d", ++nbb ); |
502 | DrawTrSurf::Set( name, afirstpoint->Pnt2d() ); |
503 | sprintf( name, "c2_%d", nbb ); |
504 | DrawTrSurf::Set( name, asecondpoint->Pnt2d() ); |
505 | sprintf( name, "p%d", nbb ); |
506 | DrawTrSurf::Set( name, apoint ); |
507 | sprintf( name, "b%d", nbb ); |
508 | DrawTrSurf::Set( name, thebisector ); |
509 | */ |
510 | } |
511 | |
512 | //============================================================================= |
513 | //function : Value |
514 | //purpose : |
515 | //============================================================================= |
516 | const Handle(Geom2d_TrimmedCurve)& Bisector_Bisec::Value() const |
517 | { |
518 | return thebisector; |
519 | } |
520 | |
521 | //============================================================================= |
522 | //function : ChangeValue |
523 | //purpose : |
524 | //============================================================================= |
525 | const Handle(Geom2d_TrimmedCurve)& Bisector_Bisec::ChangeValue() |
526 | { |
527 | return thebisector; |
528 | } |
529 | |
530 | //============================================================================= |
531 | //function : PointIsOnCurve |
532 | // purpose : |
533 | //============================================================================= |
534 | #ifdef DEB |
535 | static Standard_Boolean PointIsOnCurve(const Handle(Geom2d_Curve)& C, |
536 | const gp_Pnt2d& P, |
537 | Standard_Real& U) |
538 | { |
539 | if (C->Value(C->FirstParameter()).IsEqual(P,Precision::Confusion())) { |
540 | U = C->FirstParameter(); |
541 | return Standard_True; |
542 | } |
543 | if (C->Value(C->LastParameter()).IsEqual(P,Precision::Confusion())) { |
544 | U = C->LastParameter(); |
545 | return Standard_True; |
546 | } |
547 | return Standard_False; |
548 | } |
549 | #endif |
550 | //============================================================================= |
551 | //function : ReplaceByLineIfIsToSmall |
552 | //purpose : Si une bissectrice algorithmique est de taille negligeable elle est |
553 | // remplace par une demi-droite. |
554 | //============================================================================= |
555 | static void ReplaceByLineIfIsToSmall (Handle(Geom2d_Curve)& Bis, |
556 | Standard_Real& UFirst, |
557 | Standard_Real& ULast ) |
558 | |
559 | { |
560 | if (Abs(ULast - UFirst) > 2.*Precision::PConfusion()*10.) return; //patch |
561 | |
562 | gp_Pnt2d PF = Bis->Value(UFirst); |
563 | gp_Pnt2d PL = Bis->Value(ULast); |
564 | |
565 | if (PF.Distance(PL) > Precision::Confusion()*10.) return; |
566 | |
567 | gp_Vec2d T1 = Bis->DN(UFirst,1); |
568 | |
569 | Handle (Geom2d_CartesianPoint) PG = new Geom2d_CartesianPoint(PF); |
570 | Handle (Geom2d_Line) L = new Geom2d_Line (PF,T1); |
571 | Handle (Geom2d_TrimmedCurve) |
572 | BisL = new Geom2d_TrimmedCurve (L,0,Precision::Infinite()); |
573 | Handle(Bisector_BisecAna) BisAna = new Bisector_BisecAna (); |
574 | BisAna->Init(BisL); |
575 | UFirst = BisAna->ParameterOfStartPoint(); |
576 | ULast = BisAna->ParameterOfEndPoint(); |
577 | Bis = BisAna; |
578 | } |
579 | |
580 | //============================================================================= |
581 | //function : IsMaxRC |
582 | //purpose : |
583 | //============================================================================= |
584 | static Standard_Boolean IsMaxRC (const Handle(Geom2d_Curve)& C, |
585 | Standard_Real U, |
586 | Standard_Real& R) |
587 | { |
588 | Standard_Real KF,KL; |
589 | Standard_Real US = C->FirstParameter(); |
590 | Standard_Real UL = C->LastParameter(); |
591 | |
592 | gp_Vec2d D1,D2; |
593 | gp_Pnt2d P; |
594 | Standard_Real Norm2; |
595 | |
596 | C->D2(US,P,D1,D2); |
597 | Norm2 = D1.SquareMagnitude();; |
598 | if (Norm2 < gp::Resolution()) { KF = 0.0;} |
599 | else { KF = Abs(D1^D2)/(Norm2*sqrt(Norm2));} |
600 | |
601 | C->D2(UL,P,D1,D2); |
602 | Norm2 = D1.SquareMagnitude();; |
603 | if (Norm2 < gp::Resolution()) { KL = 0.0;} |
604 | else { KL = Abs(D1^D2)/(Norm2*sqrt(Norm2));} |
605 | |
606 | Standard_Boolean IsMax = Standard_False; |
607 | |
608 | if (U == UL) { |
609 | if (KL < KF) { |
610 | if (KL == 0.0) R = Precision::Infinite(); else R = 1/KL; |
611 | IsMax = Standard_True; |
612 | } |
613 | } |
614 | else { |
615 | if (KF < KL) { |
616 | if (KF == 0.0) R = Precision::Infinite(); else R = 1/KF; |
617 | IsMax = Standard_True; |
618 | } |
619 | } |
620 | return IsMax; |
621 | } |