0033022: Coding - get rid of unused headers [ShapeBuild to STEPControl]
[occt.git] / src / ShapeBuild / ShapeBuild_Vertex.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 //    rln 22.03.99: syntax correction in CombineVertex
15 //szv#4 S4163
16
17 #include <BRep_Builder.hxx>
18 #include <BRep_Tool.hxx>
19 #include <gp_Pnt.hxx>
20 #include <ShapeBuild_Vertex.hxx>
21 #include <TopoDS_Vertex.hxx>
22
23 //=======================================================================
24 //function : CombineVertex
25 //purpose  : 
26 //=======================================================================
27 TopoDS_Vertex ShapeBuild_Vertex::CombineVertex (const TopoDS_Vertex& V1,
28                                                 const TopoDS_Vertex& V2,
29                                                 const Standard_Real tolFactor) const
30 {
31   return CombineVertex ( BRep_Tool::Pnt ( V1 ), BRep_Tool::Pnt ( V2 ), 
32                          BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ), 
33                          tolFactor );
34 }
35
36 //=======================================================================
37 //function : CombineVertex
38 //purpose  : 
39 //=======================================================================
40
41 TopoDS_Vertex ShapeBuild_Vertex::CombineVertex (const gp_Pnt& pnt1, 
42                                                 const gp_Pnt& pnt2,
43                                                 const Standard_Real tol1, 
44                                                 const Standard_Real tol2,
45                                                 const Standard_Real tolFactor) const
46 {
47   gp_Pnt pos;
48   Standard_Real tol;
49   
50   gp_Vec v = pnt2.XYZ() - pnt1.XYZ();
51   Standard_Real dist = v.Magnitude();
52
53   //#47 rln 09.12.98 S4054 PRO14323 entity 2844
54   if ( dist + tol2 <= tol1 ) {
55     pos = pnt1;
56     tol = tol1;
57   }
58   else if ( dist + tol1 <= tol2 ) {
59     pos = pnt2;
60     tol = tol2;
61   }
62   else {
63     tol = 0.5 * ( dist + tol1 + tol2 );
64     Standard_Real s = ( dist > 0. )? ( tol2 - tol1 ) / dist : 0.; //szv#4:S4163:12Mar99 anti-exception
65     pos = 0.5 * ( ( 1 - s ) * pnt1.XYZ() + ( 1 + s ) * pnt2.XYZ() );
66   }
67   
68   TopoDS_Vertex V;
69   BRep_Builder B;
70   B.MakeVertex ( V, pos, tolFactor * tol );
71   return V;
72 }
73