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