7fd59977 |
1 | #include <BndLib.ixx> // BUG BUG BUG pas .hxx |
2 | |
3 | #include <ElCLib.hxx> |
4 | #include <gp_XYZ.hxx> |
5 | #include <gp_XY.hxx> |
6 | #include <gp_Pnt.hxx> |
7 | #include <gp_Pnt2d.hxx> |
8 | #include <BndLib_Compute.hxx> |
9 | #include <Precision.hxx> |
10 | #include <Standard_Failure.hxx> |
11 | |
12 | |
13 | static void OpenMin(const gp_Dir& V,Bnd_Box& B) { |
14 | gp_Dir OX(1.,0.,0.); |
15 | gp_Dir OY(0.,1.,0.); |
16 | gp_Dir OZ(0.,0.,1.); |
17 | if (V.IsParallel(OX,Precision::Angular())) |
18 | B.OpenXmin(); |
19 | else if (V.IsParallel(OY,Precision::Angular())) |
20 | B.OpenYmin(); |
21 | else if (V.IsParallel(OZ,Precision::Angular())) |
22 | B.OpenZmin(); |
23 | else { |
24 | B.OpenXmin();B.OpenYmin();B.OpenZmin(); |
25 | } |
26 | } |
27 | |
28 | static void OpenMax(const gp_Dir& V,Bnd_Box& B) { |
29 | gp_Dir OX(1.,0.,0.); |
30 | gp_Dir OY(0.,1.,0.); |
31 | gp_Dir OZ(0.,0.,1.); |
32 | if (V.IsParallel(OX,Precision::Angular())) |
33 | B.OpenXmax(); |
34 | else if (V.IsParallel(OY,Precision::Angular())) |
35 | B.OpenYmax(); |
36 | else if (V.IsParallel(OZ,Precision::Angular())) |
37 | B.OpenZmax(); |
38 | else { |
39 | B.OpenXmax();B.OpenYmax();B.OpenZmax(); |
40 | } |
41 | } |
42 | |
43 | static void OpenMinMax(const gp_Dir& V,Bnd_Box& B) { |
44 | gp_Dir OX(1.,0.,0.); |
45 | gp_Dir OY(0.,1.,0.); |
46 | gp_Dir OZ(0.,0.,1.); |
47 | if (V.IsParallel(OX,Precision::Angular())) { |
48 | B.OpenXmax();B.OpenXmin(); |
49 | } |
50 | else if (V.IsParallel(OY,Precision::Angular())) { |
51 | B.OpenYmax();B.OpenYmin(); |
52 | } |
53 | else if (V.IsParallel(OZ,Precision::Angular())) { |
54 | B.OpenZmax();B.OpenZmin(); |
55 | } |
56 | else { |
57 | B.OpenXmin();B.OpenYmin();B.OpenZmin(); |
58 | B.OpenXmax();B.OpenYmax();B.OpenZmax(); |
59 | } |
60 | } |
61 | |
62 | static void OpenMin(const gp_Dir2d& V,Bnd_Box2d& B) { |
63 | gp_Dir2d OX(1.,0.); |
64 | gp_Dir2d OY(0.,1.); |
65 | if (V.IsParallel(OX,Precision::Angular())) |
66 | B.OpenXmin(); |
67 | else if (V.IsParallel(OY,Precision::Angular())) |
68 | B.OpenYmin(); |
69 | else { |
70 | B.OpenXmin();B.OpenYmin(); |
71 | } |
72 | } |
73 | |
74 | static void OpenMax(const gp_Dir2d& V,Bnd_Box2d& B) { |
75 | gp_Dir2d OX(1.,0.); |
76 | gp_Dir2d OY(0.,1.); |
77 | if (V.IsParallel(OX,Precision::Angular())) |
78 | B.OpenXmax(); |
79 | else if (V.IsParallel(OY,Precision::Angular())) |
80 | B.OpenYmax(); |
81 | else { |
82 | B.OpenXmax();B.OpenYmax(); |
83 | } |
84 | } |
85 | |
86 | static void OpenMinMax(const gp_Dir2d& V,Bnd_Box2d& B) { |
87 | gp_Dir2d OX(1.,0.); |
88 | gp_Dir2d OY(0.,1.); |
89 | if (V.IsParallel(OX,Precision::Angular())) { |
90 | B.OpenXmax();B.OpenXmin(); |
91 | } |
92 | else if (V.IsParallel(OY,Precision::Angular())) { |
93 | B.OpenYmax();B.OpenYmin(); |
94 | } |
95 | else { |
96 | B.OpenXmin();B.OpenYmin(); |
97 | B.OpenXmax();B.OpenYmax(); |
98 | } |
99 | } |
100 | |
101 | |
102 | void BndLib::Add( const gp_Lin& L,const Standard_Real P1, |
103 | const Standard_Real P2, |
104 | const Standard_Real Tol, Bnd_Box& B) { |
105 | |
106 | if (Precision::IsNegativeInfinite(P1)) { |
107 | if (Precision::IsNegativeInfinite(P2)) { |
108 | Standard_Failure::Raise("BndLib::bad parameter"); |
109 | } |
110 | else if (Precision::IsPositiveInfinite(P2)) { |
111 | OpenMinMax(L.Direction(),B); |
112 | B.Add(ElCLib::Value(0.,L)); |
113 | } |
114 | else { |
115 | OpenMin(L.Direction(),B); |
116 | B.Add(ElCLib::Value(P2,L)); |
117 | } |
118 | } |
119 | else if (Precision::IsPositiveInfinite(P1)) { |
120 | if (Precision::IsNegativeInfinite(P2)) { |
121 | OpenMinMax(L.Direction(),B); |
122 | B.Add(ElCLib::Value(0.,L)); |
123 | } |
124 | else if (Precision::IsPositiveInfinite(P2)) { |
125 | Standard_Failure::Raise("BndLib::bad parameter"); |
126 | } |
127 | else { |
128 | OpenMax(L.Direction(),B); |
129 | B.Add(ElCLib::Value(P2,L)); |
130 | } |
131 | } |
132 | else { |
133 | B.Add(ElCLib::Value(P1,L)); |
134 | if (Precision::IsNegativeInfinite(P2)) { |
135 | OpenMin(L.Direction(),B); |
136 | } |
137 | else if (Precision::IsPositiveInfinite(P2)){ |
138 | OpenMax(L.Direction(),B); |
139 | } |
140 | else { |
141 | B.Add(ElCLib::Value(P2,L)); |
142 | } |
143 | } |
144 | B.Enlarge(Tol); |
145 | } |
146 | |
147 | void BndLib::Add( const gp_Lin2d& L,const Standard_Real P1, |
148 | const Standard_Real P2, |
149 | const Standard_Real Tol, Bnd_Box2d& B) { |
150 | |
151 | if (Precision::IsNegativeInfinite(P1)) { |
152 | if (Precision::IsNegativeInfinite(P2)) { |
153 | Standard_Failure::Raise("BndLib::bad parameter"); |
154 | } |
155 | else if (Precision::IsPositiveInfinite(P2)) { |
156 | OpenMinMax(L.Direction(),B); |
157 | B.Add(ElCLib::Value(0.,L)); |
158 | } |
159 | else { |
160 | OpenMin(L.Direction(),B); |
161 | B.Add(ElCLib::Value(P2,L)); |
162 | } |
163 | } |
164 | else if (Precision::IsPositiveInfinite(P1)) { |
165 | if (Precision::IsNegativeInfinite(P2)) { |
166 | OpenMinMax(L.Direction(),B); |
167 | B.Add(ElCLib::Value(0.,L)); |
168 | } |
169 | else if (Precision::IsPositiveInfinite(P2)) { |
170 | Standard_Failure::Raise("BndLib::bad parameter"); |
171 | } |
172 | else { |
173 | OpenMax(L.Direction(),B); |
174 | B.Add(ElCLib::Value(P2,L)); |
175 | } |
176 | } |
177 | else { |
178 | B.Add(ElCLib::Value(P1,L)); |
179 | if (Precision::IsNegativeInfinite(P2)) { |
180 | OpenMin(L.Direction(),B); |
181 | } |
182 | else if (Precision::IsPositiveInfinite(P2)){ |
183 | OpenMax(L.Direction(),B); |
184 | } |
185 | else { |
186 | B.Add(ElCLib::Value(P2,L)); |
187 | } |
188 | } |
189 | B.Enlarge(Tol); |
190 | } |
191 | |
192 | void BndLib::Add( const gp_Circ& C,const Standard_Real Tol, Bnd_Box& B) { |
193 | |
194 | Standard_Real R = C.Radius(); |
195 | gp_XYZ O = C.Location().XYZ(); |
196 | gp_XYZ Xd = C.XAxis().Direction().XYZ(); |
197 | gp_XYZ Yd = C.YAxis().Direction().XYZ(); |
198 | B.Add(gp_Pnt(O -R*Xd -R*Yd)); |
199 | B.Add(gp_Pnt(O -R*Xd +R*Yd)); |
200 | B.Add(gp_Pnt(O +R*Xd -R*Yd)); |
201 | B.Add(gp_Pnt(O +R*Xd +R*Yd)); |
202 | B.Enlarge(Tol); |
203 | } |
204 | |
205 | void BndLib::Add( const gp_Circ& C,const Standard_Real P1, |
206 | const Standard_Real P2, |
207 | const Standard_Real Tol, Bnd_Box& B) { |
208 | |
209 | Compute(P1,P2,C.Radius(),C.Radius(),C.XAxis().Direction().XYZ(), |
210 | C.YAxis().Direction().XYZ(),C.Location().XYZ(),B); |
211 | B.Enlarge(Tol); |
212 | } |
213 | |
214 | void BndLib::Add( const gp_Circ2d& C,const Standard_Real Tol, Bnd_Box2d& B) { |
215 | |
216 | Standard_Real R = C.Radius(); |
217 | gp_XY O = C.Location().XY(); |
218 | gp_XY Xd = C.XAxis().Direction().XY(); |
219 | gp_XY Yd = C.YAxis().Direction().XY(); |
220 | B.Add(gp_Pnt2d(O -R*Xd -R*Yd)); |
221 | B.Add(gp_Pnt2d(O -R*Xd +R*Yd)); |
222 | B.Add(gp_Pnt2d(O +R*Xd -R*Yd)); |
223 | B.Add(gp_Pnt2d(O +R*Xd +R*Yd)); |
224 | B.Enlarge(Tol); |
225 | } |
226 | |
227 | void BndLib::Add(const gp_Circ2d& C,const Standard_Real P1, |
228 | const Standard_Real P2, |
229 | const Standard_Real Tol, Bnd_Box2d& B) { |
230 | |
231 | Compute(P1,P2,C.Radius(),C.Radius(),C.XAxis().Direction().XY(), |
232 | C.YAxis().Direction().XY(),C.Location().XY(),B); |
233 | B.Enlarge(Tol); |
234 | } |
235 | |
236 | void BndLib::Add( const gp_Elips& C,const Standard_Real Tol, Bnd_Box& B) { |
237 | |
238 | Standard_Real Ra = C.MajorRadius(); |
239 | Standard_Real Rb = C.MinorRadius(); |
240 | gp_XYZ Xd = C.XAxis().Direction().XYZ(); |
241 | gp_XYZ Yd = C.YAxis().Direction().XYZ(); |
242 | gp_XYZ O = C.Location().XYZ(); |
243 | B.Add(gp_Pnt(O +Ra*Xd +Rb*Yd)); |
244 | B.Add(gp_Pnt(O -Ra*Xd +Rb*Yd)); |
245 | B.Add(gp_Pnt(O -Ra*Xd -Rb*Yd)); |
246 | B.Add(gp_Pnt(O +Ra*Xd -Rb*Yd)); |
247 | B.Enlarge(Tol); |
248 | } |
249 | |
250 | void BndLib::Add( const gp_Elips& C,const Standard_Real P1, |
251 | const Standard_Real P2, |
252 | const Standard_Real Tol, Bnd_Box& B) { |
253 | |
254 | Compute(P1,P2,C.MajorRadius(),C.MinorRadius(),C.XAxis().Direction().XYZ(), |
255 | C.YAxis().Direction().XYZ(),C.Location().XYZ(),B); |
256 | B.Enlarge(Tol); |
257 | } |
258 | |
259 | void BndLib::Add( const gp_Elips2d& C,const Standard_Real Tol, Bnd_Box2d& B) { |
260 | |
261 | Standard_Real Ra= C.MajorRadius(); |
262 | Standard_Real Rb= C.MinorRadius(); |
263 | gp_XY Xd = C.XAxis().Direction().XY(); |
264 | gp_XY Yd = C.YAxis().Direction().XY(); |
265 | gp_XY O = C.Location().XY(); |
266 | B.Add(gp_Pnt2d(O +Ra*Xd +Rb*Yd)); |
267 | B.Add(gp_Pnt2d(O -Ra*Xd +Rb*Yd)); |
268 | B.Add(gp_Pnt2d(O -Ra*Xd -Rb*Yd)); |
269 | B.Add(gp_Pnt2d(O +Ra*Xd -Rb*Yd)); |
270 | B.Enlarge(Tol); |
271 | } |
272 | |
273 | void BndLib::Add( const gp_Elips2d& C,const Standard_Real P1, |
274 | const Standard_Real P2, |
275 | const Standard_Real Tol, Bnd_Box2d& B) { |
276 | |
277 | Compute(P1,P2,C.MajorRadius(),C.MinorRadius(), |
278 | C.XAxis().Direction().XY(), |
279 | C.YAxis().Direction().XY(),C.Location().XY(),B); |
280 | B.Enlarge(Tol); |
281 | } |
282 | |
283 | void BndLib::Add( const gp_Parab& P,const Standard_Real P1, |
284 | const Standard_Real P2, |
285 | const Standard_Real Tol, Bnd_Box& B) { |
286 | |
287 | if (Precision::IsNegativeInfinite(P1)) { |
288 | if (Precision::IsNegativeInfinite(P2)) { |
289 | Standard_Failure::Raise("BndLib::bad parameter"); |
290 | } |
291 | else if (Precision::IsPositiveInfinite(P2)) { |
292 | B.OpenXmax();B.OpenYmax();B.OpenZmax(); |
293 | } |
294 | else { |
295 | B.Add(ElCLib::Value(P2,P)); |
296 | } |
297 | B.OpenXmin();B.OpenYmin();B.OpenZmin(); |
298 | } |
299 | else if (Precision::IsPositiveInfinite(P1)) { |
300 | if (Precision::IsNegativeInfinite(P2)) { |
301 | B.OpenXmin();B.OpenYmin();B.OpenZmin(); |
302 | } |
303 | else if (Precision::IsPositiveInfinite(P2)) { |
304 | Standard_Failure::Raise("BndLib::bad parameter"); |
305 | } |
306 | else { |
307 | B.Add(ElCLib::Value(P2,P)); |
308 | } |
309 | B.OpenXmax();B.OpenYmax();B.OpenZmax(); |
310 | } |
311 | else { |
312 | B.Add(ElCLib::Value(P1,P)); |
313 | if (Precision::IsNegativeInfinite(P2)) { |
314 | B.OpenXmin();B.OpenYmin();B.OpenZmin(); |
315 | } |
316 | else if (Precision::IsPositiveInfinite(P2)){ |
317 | B.OpenXmax();B.OpenYmax();B.OpenZmax(); |
318 | } |
319 | else { |
320 | B.Add(ElCLib::Value(P2,P)); |
321 | if (P1*P2<0) B.Add(ElCLib::Value(0.,P)); |
322 | } |
323 | } |
324 | B.Enlarge(Tol); |
325 | } |
326 | |
327 | void BndLib::Add( const gp_Parab2d& P,const Standard_Real P1, |
328 | const Standard_Real P2, |
329 | const Standard_Real Tol, Bnd_Box2d& B) { |
330 | |
331 | if (Precision::IsNegativeInfinite(P1)) { |
332 | if (Precision::IsNegativeInfinite(P2)) { |
333 | Standard_Failure::Raise("BndLib::bad parameter"); |
334 | } |
335 | else if (Precision::IsPositiveInfinite(P2)) { |
336 | B.OpenXmax();B.OpenYmax(); |
337 | } |
338 | else { |
339 | B.Add(ElCLib::Value(P2,P)); |
340 | } |
341 | B.OpenXmin();B.OpenYmin(); |
342 | } |
343 | else if (Precision::IsPositiveInfinite(P1)) { |
344 | if (Precision::IsNegativeInfinite(P2)) { |
345 | B.OpenXmin();B.OpenYmin(); |
346 | } |
347 | else if (Precision::IsPositiveInfinite(P2)) { |
348 | Standard_Failure::Raise("BndLib::bad parameter"); |
349 | } |
350 | else { |
351 | B.Add(ElCLib::Value(P2,P)); |
352 | } |
353 | B.OpenXmax();B.OpenYmax(); |
354 | } |
355 | else { |
356 | B.Add(ElCLib::Value(P1,P)); |
357 | if (Precision::IsNegativeInfinite(P2)) { |
358 | B.OpenXmin();B.OpenYmin(); |
359 | } |
360 | else if (Precision::IsPositiveInfinite(P2)){ |
361 | B.OpenXmax();B.OpenYmax(); |
362 | } |
363 | else { |
364 | B.Add(ElCLib::Value(P2,P)); |
365 | if (P1*P2<0) B.Add(ElCLib::Value(0.,P)); |
366 | } |
367 | } |
368 | B.Enlarge(Tol); |
369 | } |
370 | |
371 | void BndLib::Add( const gp_Hypr& H,const Standard_Real P1, |
372 | const Standard_Real P2, |
373 | const Standard_Real Tol, Bnd_Box& B) { |
374 | |
375 | if (Precision::IsNegativeInfinite(P1)) { |
376 | if (Precision::IsNegativeInfinite(P2)) { |
377 | Standard_Failure::Raise("BndLib::bad parameter"); |
378 | } |
379 | else if (Precision::IsPositiveInfinite(P2)) { |
380 | B.OpenXmax();B.OpenYmax();B.OpenZmax(); |
381 | } |
382 | else { |
383 | B.Add(ElCLib::Value(P2,H)); |
384 | } |
385 | B.OpenXmin();B.OpenYmin();B.OpenZmin(); |
386 | } |
387 | else if (Precision::IsPositiveInfinite(P1)) { |
388 | if (Precision::IsNegativeInfinite(P2)) { |
389 | B.OpenXmin();B.OpenYmin();B.OpenZmin(); |
390 | } |
391 | else if (Precision::IsPositiveInfinite(P2)) { |
392 | Standard_Failure::Raise("BndLib::bad parameter"); |
393 | } |
394 | else { |
395 | B.Add(ElCLib::Value(P2,H)); |
396 | } |
397 | B.OpenXmax();B.OpenYmax();B.OpenZmax(); |
398 | } |
399 | else { |
400 | B.Add(ElCLib::Value(P1,H)); |
401 | if (Precision::IsNegativeInfinite(P2)) { |
402 | B.OpenXmin();B.OpenYmin();B.OpenZmin(); |
403 | } |
404 | else if (Precision::IsPositiveInfinite(P2)){ |
405 | B.OpenXmax();B.OpenYmax();B.OpenZmax(); |
406 | } |
407 | else { |
408 | B.Add(ElCLib::Value(P2,H)); |
409 | if (P1*P2<0) B.Add(ElCLib::Value(0.,H)); |
410 | } |
411 | } |
412 | B.Enlarge(Tol); |
413 | } |
414 | |
415 | void BndLib::Add(const gp_Hypr2d& H,const Standard_Real P1, |
416 | const Standard_Real P2, |
417 | const Standard_Real Tol, Bnd_Box2d& B) { |
418 | |
419 | if (Precision::IsNegativeInfinite(P1)) { |
420 | if (Precision::IsNegativeInfinite(P2)) { |
421 | Standard_Failure::Raise("BndLib::bad parameter"); |
422 | } |
423 | else if (Precision::IsPositiveInfinite(P2)) { |
424 | B.OpenXmax();B.OpenYmax(); |
425 | } |
426 | else { |
427 | B.Add(ElCLib::Value(P2,H)); |
428 | } |
429 | B.OpenXmin();B.OpenYmin(); |
430 | } |
431 | else if (Precision::IsPositiveInfinite(P1)) { |
432 | if (Precision::IsNegativeInfinite(P2)) { |
433 | B.OpenXmin();B.OpenYmin(); |
434 | } |
435 | else if (Precision::IsPositiveInfinite(P2)) { |
436 | Standard_Failure::Raise("BndLib::bad parameter"); |
437 | } |
438 | else { |
439 | B.Add(ElCLib::Value(P2,H)); |
440 | } |
441 | B.OpenXmax();B.OpenYmax(); |
442 | } |
443 | else { |
444 | B.Add(ElCLib::Value(P1,H)); |
445 | if (Precision::IsNegativeInfinite(P2)) { |
446 | B.OpenXmin();B.OpenYmin(); |
447 | } |
448 | else if (Precision::IsPositiveInfinite(P2)){ |
449 | B.OpenXmax();B.OpenYmax(); |
450 | } |
451 | else { |
452 | B.Add(ElCLib::Value(P2,H)); |
453 | if (P1*P2<0) B.Add(ElCLib::Value(0.,H)); |
454 | } |
455 | } |
456 | B.Enlarge(Tol); |
457 | } |
458 | |
459 | void BndLib::Add( const gp_Cylinder& S,const Standard_Real UMin, |
460 | const Standard_Real UMax,const Standard_Real VMin, |
461 | const Standard_Real VMax,const Standard_Real Tol, Bnd_Box& B) { |
462 | |
463 | if (Precision::IsNegativeInfinite(VMin)) { |
464 | if (Precision::IsNegativeInfinite(VMax)) { |
465 | Standard_Failure::Raise("BndLib::bad parameter"); |
466 | } |
467 | else if (Precision::IsPositiveInfinite(VMax)) { |
468 | OpenMinMax(S.Axis().Direction(),B); |
469 | } |
470 | else { |
471 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
472 | S.XAxis().Direction().XYZ(), |
473 | S.YAxis().Direction().XYZ(), |
474 | S.Location().XYZ() + VMax*S.Axis().Direction().XYZ(),B); |
475 | OpenMin(S.Axis().Direction(),B); |
476 | } |
477 | } |
478 | else if (Precision::IsPositiveInfinite(VMin)) { |
479 | if (Precision::IsNegativeInfinite(VMax)) { |
480 | OpenMinMax(S.Axis().Direction(),B); |
481 | } |
482 | else if (Precision::IsPositiveInfinite(VMax)) { |
483 | Standard_Failure::Raise("BndLib::bad parameter"); |
484 | } |
485 | else { |
486 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
487 | S.XAxis().Direction().XYZ(), |
488 | S.YAxis().Direction().XYZ(), |
489 | S.Location().XYZ() + VMax*S.Axis().Direction().XYZ(),B); |
490 | OpenMax(S.Axis().Direction(),B); |
491 | } |
492 | |
493 | } |
494 | else { |
495 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
496 | S.XAxis().Direction().XYZ(), |
497 | S.YAxis().Direction().XYZ(), |
498 | S.Location().XYZ() + VMin*S.Axis().Direction().XYZ(),B); |
499 | if (Precision::IsNegativeInfinite(VMax)) { |
500 | OpenMin(S.Axis().Direction(),B); |
501 | } |
502 | else if (Precision::IsPositiveInfinite(VMax)) { |
503 | OpenMax(S.Axis().Direction(),B); |
504 | } |
505 | else { |
506 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
507 | S.XAxis().Direction().XYZ(), |
508 | S.YAxis().Direction().XYZ(), |
509 | S.Location().XYZ() + VMax*S.Axis().Direction().XYZ(),B); |
510 | } |
511 | } |
512 | |
513 | B.Enlarge(Tol); |
514 | |
515 | } |
516 | |
517 | void BndLib::Add( const gp_Cylinder& S,const Standard_Real VMin, |
518 | const Standard_Real VMax,const Standard_Real Tol, Bnd_Box& B) { |
519 | |
520 | BndLib::Add(S,0.,2.*PI,VMin,VMax,Tol,B); |
521 | } |
522 | |
523 | void BndLib::Add(const gp_Cone& S,const Standard_Real UMin, |
524 | const Standard_Real UMax,const Standard_Real VMin, |
525 | const Standard_Real VMax,const Standard_Real Tol, Bnd_Box& B) { |
526 | |
527 | Standard_Real R = S.RefRadius(); |
528 | Standard_Real A = S.SemiAngle(); |
529 | if (Precision::IsNegativeInfinite(VMin)) { |
530 | if (Precision::IsNegativeInfinite(VMax)) { |
531 | Standard_Failure::Raise("BndLib::bad parameter"); |
532 | } |
533 | else if (Precision::IsPositiveInfinite(VMax)) { |
534 | gp_Dir D(Cos(A)*S.Axis().Direction()); |
535 | OpenMinMax(D,B); |
536 | } |
537 | else { |
538 | Compute(UMin,UMax,R+VMax*Sin(A),R+VMax*Sin(A), |
539 | S.XAxis().Direction().XYZ(), |
540 | S.YAxis().Direction().XYZ(), |
541 | S.Location().XYZ() + |
542 | VMax*Cos(A)*S.Axis().Direction().XYZ(),B); |
543 | gp_Dir D(Cos(A)*S.Axis().Direction()); |
544 | OpenMin(D,B); |
545 | } |
546 | |
547 | } |
548 | else if (Precision::IsPositiveInfinite(VMin)) { |
549 | if (Precision::IsNegativeInfinite(VMax)) { |
550 | gp_Dir D(Cos(A)*S.Axis().Direction()); |
551 | OpenMinMax(D,B); |
552 | } |
553 | else if (Precision::IsPositiveInfinite(VMax)) { |
554 | Standard_Failure::Raise("BndLib::bad parameter"); |
555 | } |
556 | else { |
557 | Compute(UMin,UMax,R+VMax*Sin(A),R+VMax*Sin(A), |
558 | S.XAxis().Direction().XYZ(), |
559 | S.YAxis().Direction().XYZ(), |
560 | S.Location().XYZ() + |
561 | VMax*Cos(A)*S.Axis().Direction().XYZ(),B); |
562 | gp_Dir D(Cos(A)*S.Axis().Direction()); |
563 | OpenMax(D,B); |
564 | } |
565 | |
566 | } |
567 | else { |
568 | Compute(UMin,UMax,R+VMin*Sin(A),R+VMin*Sin(A), |
569 | S.XAxis().Direction().XYZ(), |
570 | S.YAxis().Direction().XYZ(), |
571 | S.Location().XYZ() + |
572 | VMin*Cos(A)*S.Axis().Direction().XYZ(),B); |
573 | if (Precision::IsNegativeInfinite(VMax)) { |
574 | gp_Dir D(Cos(A)*S.Axis().Direction()); |
575 | OpenMin(D,B); |
576 | } |
577 | else if (Precision::IsPositiveInfinite(VMax)) { |
578 | gp_Dir D(Cos(A)*S.Axis().Direction()); |
579 | OpenMax(D,B); |
580 | } |
581 | else { |
582 | Compute(UMin,UMax,R+VMax*Sin(A),R+VMax*Sin(A), |
583 | S.XAxis().Direction().XYZ(), |
584 | S.YAxis().Direction().XYZ(), |
585 | S.Location().XYZ() + |
586 | VMax*Cos(A)*S.Axis().Direction().XYZ(),B); |
587 | } |
588 | } |
589 | |
590 | |
591 | B.Enlarge(Tol); |
592 | } |
593 | |
594 | void BndLib::Add( const gp_Cone& S,const Standard_Real VMin, |
595 | const Standard_Real VMax,const Standard_Real Tol, Bnd_Box& B) { |
596 | |
597 | BndLib::Add(S,0.,2.*PI,VMin,VMax,Tol,B); |
598 | } |
599 | |
600 | void BndLib::Add(const gp_Sphere& S,const Standard_Real UMin, |
601 | const Standard_Real UMax,const Standard_Real VMin, |
602 | const Standard_Real VMax,const Standard_Real Tol, Bnd_Box& B) { |
0d969553 |
603 | |
7fd59977 |
604 | #if 0 |
605 | Standard_Real Fi1; |
606 | Standard_Real Fi2; |
607 | if (VMax<VMin) { |
608 | Fi1 = VMax; |
609 | Fi2 = VMin; |
610 | } |
611 | else { |
612 | Fi1 = VMin; |
613 | Fi2 = VMax; |
614 | } |
615 | |
616 | if (-Fi1>Precision::Angular()) { |
617 | if (-Fi2>Precision::Angular()) { |
618 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
619 | S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(), |
620 | S.Location().XYZ(),B); |
621 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
622 | S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(), |
623 | S.Location().XYZ()- S.Radius()*S.Position().Axis().Direction().XYZ(),B); |
624 | } |
625 | else { |
626 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
627 | S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(), |
628 | S.Location().XYZ()+ S.Radius()*S.Position().Axis().Direction().XYZ(),B); |
629 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
630 | S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(), |
631 | S.Location().XYZ()- S.Radius()*S.Position().Axis().Direction().XYZ(),B); |
632 | } |
633 | } |
634 | else { |
635 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
636 | S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(), |
637 | S.Location().XYZ(),B); |
638 | Compute(UMin,UMax,S.Radius(),S.Radius(), |
639 | S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(), |
640 | S.Location().XYZ() +S.Radius()*S.Position().Axis().Direction().XYZ(),B); |
641 | } |
642 | B.Enlarge(Tol); |
643 | #else |
644 | Standard_Real u,v,du,dv; |
645 | Standard_Integer iu,iv; |
646 | du = (UMax-UMin)/10; |
647 | dv = (VMax-VMin)/10; |
648 | Standard_Real COSV[11]; |
649 | Standard_Real SINV[11]; |
650 | for(iv=0,v=VMin;iv<=10;iv++) { |
651 | COSV[iv]=cos(v); |
652 | SINV[iv]=sin(v); |
653 | v+=dv; |
654 | } |
655 | for(u=UMin,iu=0; iu<=10 ; iu++) { |
656 | Standard_Real Radiuscosu=S.Radius()*cos(u); |
657 | Standard_Real Radiussinu=S.Radius()*sin(u); |
658 | for(v=VMin,iv=0; iv<=10 ; iv++) { |
659 | Standard_Real sinv=SINV[iv]; |
660 | Standard_Real cosv=COSV[iv]; |
661 | gp_XYZ M; |
662 | M.SetLinearForm (cosv*Radiuscosu, S.Position().XDirection().XYZ(), |
663 | cosv*Radiussinu, S.Position().YDirection().XYZ(), |
664 | S.Radius()*sinv, S.Position().Direction().XYZ() , |
665 | S.Position().Location().XYZ() ); |
666 | //-- static int t=0; |
667 | //-- cout<<"point p"<<++t<<" "<<M.X()<<" "<<M.Y()<<" "<<M.Z()<<endl; |
668 | B.Add(gp_Pnt(M)); |
669 | v+=dv; |
670 | } |
671 | u+=du; |
672 | } |
673 | |
674 | Standard_Real Maxduv = Max(du,dv)*0.5; |
675 | Standard_Real Fleche = S.Radius() * (1 - cos(Maxduv)); |
676 | B.Enlarge(Fleche); |
677 | B.Enlarge(10*Tol); |
678 | #endif |
679 | } |
680 | |
681 | void BndLib::Add( const gp_Sphere& S,const Standard_Real Tol, Bnd_Box& B) { |
682 | |
683 | Standard_Real R = S.Radius(); |
684 | gp_XYZ O = S.Location().XYZ(); |
685 | gp_XYZ Xd = S.XAxis().Direction().XYZ(); |
686 | gp_XYZ Yd = S.YAxis().Direction().XYZ(); |
687 | gp_XYZ Zd = S.Position().Axis().Direction().XYZ(); |
688 | B.Add(gp_Pnt(O -R*Xd -R*Yd+ R*Zd)); |
689 | B.Add(gp_Pnt(O -R*Xd +R*Yd+ R*Zd)); |
690 | B.Add(gp_Pnt(O +R*Xd -R*Yd+ R*Zd)); |
691 | B.Add(gp_Pnt(O +R*Xd +R*Yd+ R*Zd)); |
692 | B.Add(gp_Pnt(O +R*Xd -R*Yd- R*Zd)); |
693 | B.Add(gp_Pnt(O -R*Xd -R*Yd- R*Zd)); |
694 | B.Add(gp_Pnt(O +R*Xd +R*Yd- R*Zd)); |
695 | B.Add(gp_Pnt(O -R*Xd +R*Yd- R*Zd)); |
696 | B.Enlarge(Tol); |
697 | } |
698 | |
699 | void BndLib::Add(const gp_Torus& S,const Standard_Real UMin, |
700 | const Standard_Real UMax,const Standard_Real VMin, |
701 | const Standard_Real VMax,const Standard_Real Tol, Bnd_Box& B) { |
702 | |
703 | Standard_Integer Fi1; |
704 | Standard_Integer Fi2; |
705 | if (VMax<VMin) { |
706 | Fi1 = (Standard_Integer )( VMax/(PI/4.)); |
707 | Fi2 = (Standard_Integer )( VMin/(PI/4.)); |
708 | } |
709 | else { |
710 | Fi1 = (Standard_Integer )( VMin/(PI/4.)); |
711 | Fi2 = (Standard_Integer )( VMax/(PI/4.)); |
712 | } |
713 | Fi2++; |
714 | |
715 | Standard_Real Ra = S.MajorRadius(); |
716 | Standard_Real Ri = S.MinorRadius(); |
717 | |
718 | if (Fi2<Fi1) return; |
719 | |
720 | #define SC 0.71 |
721 | #define addP0 (Compute(UMin,UMax,Ra+Ri,Ra+Ri,S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(),S.Location().XYZ(),B)) |
722 | #define addP1 (Compute(UMin,UMax,Ra+Ri*SC,Ra+Ri*SC,S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(),S.Location().XYZ()+(Ri*SC)*S.Axis().Direction().XYZ(),B)) |
723 | #define addP2 (Compute(UMin,UMax,Ra,Ra,S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(),S.Location().XYZ()+Ri*S.Axis().Direction().XYZ(),B)) |
724 | #define addP3 (Compute(UMin,UMax,Ra-Ri*SC,Ra-Ri*SC,S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(),S.Location().XYZ()+(Ri*SC)*S.Axis().Direction().XYZ(),B)) |
725 | #define addP4 (Compute(UMin,UMax,Ra-Ri,Ra-Ri,S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(),S.Location().XYZ(),B)) |
726 | #define addP5 (Compute(UMin,UMax,Ra-Ri*SC,Ra-Ri*SC,S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(),S.Location().XYZ()-(Ri*SC)*S.Axis().Direction().XYZ(),B)) |
727 | #define addP6 (Compute(UMin,UMax,Ra,Ra,S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(),S.Location().XYZ()-Ri*S.Axis().Direction().XYZ(),B)) |
728 | #define addP7 (Compute(UMin,UMax,Ra+Ri*SC,Ra+Ri*SC,S.XAxis().Direction().XYZ(),S.YAxis().Direction().XYZ(),S.Location().XYZ()-(Ri*SC)*S.Axis().Direction().XYZ(),B)) |
729 | |
730 | switch (Fi1) { |
731 | case 0 : |
732 | { |
733 | addP0; |
734 | if (Fi2 <= 0) break; |
735 | } |
736 | case 1 : |
737 | { |
738 | addP1; |
739 | if (Fi2 <= 1) break; |
740 | } |
741 | case 2 : |
742 | { |
743 | addP2; |
744 | if (Fi2 <= 2) break; |
745 | } |
746 | case 3 : |
747 | { |
748 | addP3; |
749 | if (Fi2 <= 3) break; |
750 | } |
751 | case 4 : |
752 | { |
753 | addP4; |
754 | if (Fi2 <= 4) break; |
755 | } |
756 | case 5 : |
757 | { |
758 | addP5; |
759 | if (Fi2 <= 5) break; |
760 | } |
761 | case 6 : |
762 | { |
763 | addP6; |
764 | if (Fi2 <= 6) break; |
765 | } |
766 | case 7 : |
767 | { |
768 | addP7; |
769 | if (Fi2 <= 7) break; |
770 | } |
771 | case 8 : |
772 | default : |
773 | { |
774 | addP0; |
775 | switch (Fi2) { |
776 | case 15 : |
777 | addP7; |
778 | case 14 : |
779 | addP6; |
780 | case 13 : |
781 | addP5; |
782 | case 12 : |
783 | addP4; |
784 | case 11 : |
785 | addP3; |
786 | case 10 : |
787 | addP2; |
788 | case 9 : |
789 | addP1; |
790 | case 8 : |
791 | break; |
792 | } |
793 | } |
794 | } |
795 | B.Enlarge(Tol); |
796 | } |
797 | |
798 | |
799 | void BndLib::Add( const gp_Torus& S,const Standard_Real Tol, Bnd_Box& B) { |
800 | |
801 | Standard_Real RMa = S.MajorRadius(); |
802 | Standard_Real Rmi = S.MinorRadius(); |
803 | gp_XYZ O = S.Location().XYZ(); |
804 | gp_XYZ Xd = S.XAxis().Direction().XYZ(); |
805 | gp_XYZ Yd = S.YAxis().Direction().XYZ(); |
806 | gp_XYZ Zd = S.Axis().Direction().XYZ(); |
807 | B.Add(gp_Pnt(O -(RMa+Rmi)*Xd -(RMa+Rmi)*Yd+ Rmi*Zd)); |
808 | B.Add(gp_Pnt(O -(RMa+Rmi)*Xd -(RMa+Rmi)*Yd- Rmi*Zd)); |
809 | B.Add(gp_Pnt(O +(RMa+Rmi)*Xd -(RMa+Rmi)*Yd+ Rmi*Zd)); |
810 | B.Add(gp_Pnt(O +(RMa+Rmi)*Xd -(RMa+Rmi)*Yd- Rmi*Zd)); |
811 | B.Add(gp_Pnt(O -(RMa+Rmi)*Xd +(RMa+Rmi)*Yd+ Rmi*Zd)); |
812 | B.Add(gp_Pnt(O -(RMa+Rmi)*Xd +(RMa+Rmi)*Yd- Rmi*Zd)); |
813 | B.Add(gp_Pnt(O +(RMa+Rmi)*Xd +(RMa+Rmi)*Yd+ Rmi*Zd)); |
814 | B.Add(gp_Pnt(O +(RMa+Rmi)*Xd +(RMa+Rmi)*Yd- Rmi*Zd)); |
815 | B.Enlarge(Tol); |
816 | } |
817 | |
818 | |
819 | |