0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / ShapeBuild / ShapeBuild_Vertex.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14// rln 22.03.99: syntax correction in CombineVertex
15//szv#4 S4163
42cf5bc1 16
17#include <BRep_Builder.hxx>
7fd59977 18#include <BRep_Tool.hxx>
42cf5bc1 19#include <gp_Pnt.hxx>
7fd59977 20#include <Precision.hxx>
42cf5bc1 21#include <ShapeBuild_Vertex.hxx>
22#include <TopoDS_Vertex.hxx>
7fd59977 23
24//=======================================================================
25//function : CombineVertex
26//purpose :
27//=======================================================================
7fd59977 28TopoDS_Vertex ShapeBuild_Vertex::CombineVertex (const TopoDS_Vertex& V1,
29 const TopoDS_Vertex& V2,
30 const Standard_Real tolFactor) const
31{
32 return CombineVertex ( BRep_Tool::Pnt ( V1 ), BRep_Tool::Pnt ( V2 ),
33 BRep_Tool::Tolerance ( V1 ), BRep_Tool::Tolerance ( V2 ),
34 tolFactor );
35}
36
37//=======================================================================
38//function : CombineVertex
39//purpose :
40//=======================================================================
41
42TopoDS_Vertex ShapeBuild_Vertex::CombineVertex (const gp_Pnt& pnt1,
43 const gp_Pnt& pnt2,
44 const Standard_Real tol1,
45 const Standard_Real tol2,
46 const Standard_Real tolFactor) const
47{
48 gp_Pnt pos;
49 Standard_Real tol;
50
51 gp_Vec v = pnt2.XYZ() - pnt1.XYZ();
52 Standard_Real dist = v.Magnitude();
53
54 //#47 rln 09.12.98 S4054 PRO14323 entity 2844
55 if ( dist + tol2 <= tol1 ) {
56 pos = pnt1;
57 tol = tol1;
58 }
59 else if ( dist + tol1 <= tol2 ) {
60 pos = pnt2;
61 tol = tol2;
62 }
63 else {
64 tol = 0.5 * ( dist + tol1 + tol2 );
65 Standard_Real s = ( dist > 0. )? ( tol2 - tol1 ) / dist : 0.; //szv#4:S4163:12Mar99 anti-exception
66 pos = 0.5 * ( ( 1 - s ) * pnt1.XYZ() + ( 1 + s ) * pnt2.XYZ() );
67 }
68
69 TopoDS_Vertex V;
70 BRep_Builder B;
71 B.MakeVertex ( V, pos, tolFactor * tol );
72 return V;
73}
74