0022717: Exception during sewing
[occt.git] / src / ShapeBuild / ShapeBuild_Vertex.cxx
CommitLineData
7fd59977 1// rln 22.03.99: syntax correction in CombineVertex
2//szv#4 S4163
3#include <ShapeBuild_Vertex.ixx>
4#include <BRep_Tool.hxx>
5#include <Precision.hxx>
6#include <BRep_Builder.hxx>
7
8//=======================================================================
9//function : CombineVertex
10//purpose :
11//=======================================================================
12
13TopoDS_Vertex ShapeBuild_Vertex::CombineVertex (const TopoDS_Vertex& V1,
14 const TopoDS_Vertex& V2,
15 const Standard_Real tolFactor) const
16{
17 return CombineVertex ( BRep_Tool::Pnt ( V1 ), BRep_Tool::Pnt ( V2 ),
18 BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ),
19 tolFactor );
20}
21
22//=======================================================================
23//function : CombineVertex
24//purpose :
25//=======================================================================
26
27TopoDS_Vertex ShapeBuild_Vertex::CombineVertex (const gp_Pnt& pnt1,
28 const gp_Pnt& pnt2,
29 const Standard_Real tol1,
30 const Standard_Real tol2,
31 const Standard_Real tolFactor) const
32{
33 gp_Pnt pos;
34 Standard_Real tol;
35
36 gp_Vec v = pnt2.XYZ() - pnt1.XYZ();
37 Standard_Real dist = v.Magnitude();
38
39 //#47 rln 09.12.98 S4054 PRO14323 entity 2844
40 if ( dist + tol2 <= tol1 ) {
41 pos = pnt1;
42 tol = tol1;
43 }
44 else if ( dist + tol1 <= tol2 ) {
45 pos = pnt2;
46 tol = tol2;
47 }
48 else {
49 tol = 0.5 * ( dist + tol1 + tol2 );
50 Standard_Real s = ( dist > 0. )? ( tol2 - tol1 ) / dist : 0.; //szv#4:S4163:12Mar99 anti-exception
51 pos = 0.5 * ( ( 1 - s ) * pnt1.XYZ() + ( 1 + s ) * pnt2.XYZ() );
52 }
53
54 TopoDS_Vertex V;
55 BRep_Builder B;
56 B.MakeVertex ( V, pos, tolFactor * tol );
57 return V;
58}
59