From 08cd2f6bb195fffafa0e9273aeffef4d854bd5fd Mon Sep 17 00:00:00 2001 From: abk Date: Fri, 5 Oct 2012 13:55:16 +0400 Subject: [PATCH] 0023404: Create SquareConfusion function in Precision package for speed and convenience SquareConfusion function was created in FoundationClasses module -> TKMath toolkit -> Precision package. The function returns square of Precision::Confusion(). SquareConfusion function was corrected in FoundationClasses module -> TKMath toolkit -> Precision package. Squares of Precision::Confusion() were replaced by Precision::SquareConfusion(). --- src/AIS/AIS.cxx | 2 +- src/BRepFeat/BRepFeat_MakeRevolutionForm.cxx | 4 ++-- src/BRepLib/BRepLib_MakeEdge.cxx | 2 +- src/BRepMesh/BRepMesh_FastDiscretFace.cxx | 2 +- src/BRepOffset/BRepOffset_Tool.cxx | 4 ++-- src/ChFi3d/ChFi3d_Builder_C1.cxx | 4 ++-- src/Draft/Draft_Modification_1.cxx | 2 +- src/DsgPrs/DsgPrs.cxx | 6 +++--- src/DsgPrs/DsgPrs_EqualDistancePresentation.cxx | 2 +- src/Extrema/Extrema_ExtPElC.cxx | 2 +- src/Extrema/Extrema_ExtPRevS.cxx | 4 ++-- src/GeomliteTest/GeomliteTest_SurfaceCommands.cxx | 2 +- src/LocOpe/LocOpe_SplitDrafts.cxx | 4 ++-- src/NIS/NIS_Surface.cxx | 2 +- src/Poly/Poly.cxx | 2 +- src/Precision/Precision.cdl | 5 +++++ src/Precision/Precision.lxx | 10 ++++++++++ src/ShapeAnalysis/ShapeAnalysis_Curve.cxx | 2 +- src/ShapeAnalysis/ShapeAnalysis_WireOrder.cxx | 2 +- src/ShapeFix/ShapeFix_Wireframe.cxx | 4 ++-- src/StdPrs/StdPrs_ShadedShape.cxx | 2 +- src/Voxel/Voxel_Writer.cxx | 2 +- src/VrmlData/VrmlData_IndexedFaceSet.cxx | 2 +- src/VrmlData/VrmlData_ShapeConvert.cxx | 2 +- 24 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/AIS/AIS.cxx b/src/AIS/AIS.cxx index 3668c2a988..6aec31c0eb 100755 --- a/src/AIS/AIS.cxx +++ b/src/AIS/AIS.cxx @@ -80,7 +80,7 @@ #include #include -const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion(); +const Standard_Real SquareTolerance = Precision::SquareConfusion(); //======================================================================= //function : Nearest diff --git a/src/BRepFeat/BRepFeat_MakeRevolutionForm.cxx b/src/BRepFeat/BRepFeat_MakeRevolutionForm.cxx index 766044fe26..a5e9347135 100755 --- a/src/BRepFeat/BRepFeat_MakeRevolutionForm.cxx +++ b/src/BRepFeat/BRepFeat_MakeRevolutionForm.cxx @@ -453,12 +453,12 @@ void BRepFeat_MakeRevolutionForm::Init(const TopoDS_Shape& Sbase, if(Sliding && !PtOnFirstEdge) { BRepExtrema_ExtCF ext1(TopoDS::Edge(ee1.Shape()), FirstFace); - if(ext1.NbExt() < 1 || ext1.SquareDistance(1) > Precision::Confusion() * Precision::Confusion()) + if(ext1.NbExt() < 1 || ext1.SquareDistance(1) > Precision::SquareConfusion()) Sliding = Standard_False; } if(Sliding && !PtOnLastEdge) { BRepExtrema_ExtCF ext2(ee2, LastFace); // ExtCF : curves and surfaces - if(ext2.NbExt() < 1 || ext2.SquareDistance(1) > Precision::Confusion() * Precision::Confusion()) + if(ext2.NbExt() < 1 || ext2.SquareDistance(1) > Precision::SquareConfusion()) Sliding = Standard_False; } if(Sliding && PtOnFirstEdge) { diff --git a/src/BRepLib/BRepLib_MakeEdge.cxx b/src/BRepLib/BRepLib_MakeEdge.cxx index d1a58b02f7..9e90393b66 100755 --- a/src/BRepLib/BRepLib_MakeEdge.cxx +++ b/src/BRepLib/BRepLib_MakeEdge.cxx @@ -152,7 +152,7 @@ static Standard_Boolean Project(const Handle(Geom2d_Curve)& C, if (index != 0) { Extrema_POnCurv POC = extrema.Point(index); - if (P.SquareDistance(POC.Value()) <= Precision::Confusion() * Precision::Confusion()) { + if (P.SquareDistance(POC.Value()) <= Precision::SquareConfusion()) { p = POC.Parameter(); return Standard_True; } diff --git a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx index 825b9b5e2a..943e278a9e 100755 --- a/src/BRepMesh/BRepMesh_FastDiscretFace.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscretFace.cxx @@ -946,7 +946,7 @@ void BRepMesh_FastDiscretFace::InternalVertices(const Handle(BRepAdaptor_HSurfac Standard_Real u, v, dist; // precision for compare square distances - double dPreci = Precision::Confusion()*Precision::Confusion(); + double dPreci = Precision::SquareConfusion(); // Insert V parameters by deflection criterion Standard_Integer i,j; diff --git a/src/BRepOffset/BRepOffset_Tool.cxx b/src/BRepOffset/BRepOffset_Tool.cxx index 5cb8043a7d..eda43498d1 100755 --- a/src/BRepOffset/BRepOffset_Tool.cxx +++ b/src/BRepOffset/BRepOffset_Tool.cxx @@ -2408,7 +2408,7 @@ void BRepOffset_Tool::Inter2d (const TopoDS_Face& F, IndexMin = ind; } } - if (Dist2Min <= Precision::Confusion() * Precision::Confusion()) + if (Dist2Min <= Precision::SquareConfusion()) { YaSol = Standard_True; P2d = P1[i1]; @@ -2435,7 +2435,7 @@ void BRepOffset_Tool::Inter2d (const TopoDS_Face& F, IndexMin = ind; } } - if (Dist2Min <= Precision::Confusion() * Precision::Confusion()) + if (Dist2Min <= Precision::SquareConfusion()) { YaSol = Standard_True; P2d = P2[i2]; diff --git a/src/ChFi3d/ChFi3d_Builder_C1.cxx b/src/ChFi3d/ChFi3d_Builder_C1.cxx index 399355ec65..ce7f2f91d0 100755 --- a/src/ChFi3d/ChFi3d_Builder_C1.cxx +++ b/src/ChFi3d/ChFi3d_Builder_C1.cxx @@ -910,7 +910,7 @@ void ChFi3d_Builder::PerformOneCorner(const Standard_Integer Index, distmin2 = extCC.SquareDistance(i); imin = i; } - if (distmin2 <= Precision::Confusion() * Precision::Confusion()) + if (distmin2 <= Precision::SquareConfusion()) { Extrema_POnCurv ponc1,ponc2; extCC.Points( imin, ponc1, ponc2 ); @@ -4101,7 +4101,7 @@ void ChFi3d_Builder::IntersectMoreCorner(const Standard_Integer Index) dist2min = extCC.SquareDistance(i); imin = i; } - if (dist2min <= Precision::Confusion() * Precision::Confusion()) + if (dist2min <= Precision::SquareConfusion()) { Extrema_POnCurv ponc1,ponc2; extCC.Points( imin, ponc1, ponc2 ); diff --git a/src/Draft/Draft_Modification_1.cxx b/src/Draft/Draft_Modification_1.cxx index e573ff1fe6..a2ca0bff83 100755 --- a/src/Draft/Draft_Modification_1.cxx +++ b/src/Draft/Draft_Modification_1.cxx @@ -968,7 +968,7 @@ void Draft_Modification::Perform () Dist2Min = myExtPC.SquareDistance(1); locpmin = myExtPC.Point(1).Parameter(); } - if(myExtPC.NbExt() == 2 && Dist2Min > Precision::Confusion() * Precision::Confusion()) { + if(myExtPC.NbExt() == 2 && Dist2Min > Precision::SquareConfusion()) { //to avoid incorrectly choosing the image //of the first vertex of the initial edge Standard_Real d1_2 = myExtPC.SquareDistance(1); diff --git a/src/DsgPrs/DsgPrs.cxx b/src/DsgPrs/DsgPrs.cxx index 029dece34e..52bcf6c357 100755 --- a/src/DsgPrs/DsgPrs.cxx +++ b/src/DsgPrs/DsgPrs.cxx @@ -322,7 +322,7 @@ void DsgPrs::ComputePlanarFacesLengthPresentation( const Standard_Real FirstArro EndOfArrow1 = ElCLib::Value( ElCLib::Parameter( FirstLin, OffsetPoint ), FirstLin ); EndOfArrow2 = ElCLib::Value( ElCLib::Parameter( SecondLin, OffsetPoint ), SecondLin ); - if (EndOfArrow1.SquareDistance( EndOfArrow2 ) > Precision::Confusion()*Precision::Confusion()) // not null length + if (EndOfArrow1.SquareDistance( EndOfArrow2 ) > Precision::SquareConfusion()) // not null length { gp_Dir LengthDir( gp_Vec( EndOfArrow1, EndOfArrow2 ) ); if ((FirstArrowLength + SecondArrowLength)*(FirstArrowLength + SecondArrowLength) < @@ -359,7 +359,7 @@ void DsgPrs::ComputeCurvilinearFacesLengthPresentation( const Standard_Real Firs GeomAPI_ProjectPointOnCurve ProjectorOnCurve; Quantity_Parameter U1, V1, U2, V2; Standard_Real LastU, LastV; - Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion(); + Standard_Real SquareTolerance = Precision::SquareConfusion(); ProjectorOnSurface.Init( AttachmentPoint1, SecondSurf ); Standard_Integer Index(1); @@ -391,7 +391,7 @@ void DsgPrs::ComputeCurvilinearFacesLengthPresentation( const Standard_Real Firs else DirOfArrow1 = DirAttach; - if (EndOfArrow2.SquareDistance( AttachmentPoint2 ) > Precision::Confusion()*Precision::Confusion()) + if (EndOfArrow2.SquareDistance( AttachmentPoint2 ) > Precision::SquareConfusion()) { VCurve = SecondSurf->VIso( V1 ); ProjectorOnCurve.Init( EndOfArrow2, VCurve ); diff --git a/src/DsgPrs/DsgPrs_EqualDistancePresentation.cxx b/src/DsgPrs/DsgPrs_EqualDistancePresentation.cxx index f6ed6deb6a..f0d77232ed 100755 --- a/src/DsgPrs/DsgPrs_EqualDistancePresentation.cxx +++ b/src/DsgPrs/DsgPrs_EqualDistancePresentation.cxx @@ -94,7 +94,7 @@ void DsgPrs_EqualDistancePresentation::Add( const Handle( Prs3d_Presentation )& { gp_Vec Vec1( Middle, Point1 ); - if (Vec1.SquareMagnitude() > Precision::Confusion()*Precision::Confusion()) + if (Vec1.SquareMagnitude() > Precision::SquareConfusion()) { Standard_Real Angle = gp_Vec( Middle, Point1 ).Angle( gp_Vec( Middle, Point3 ) ); gp_Pnt MidPnt = Point1.Rotated( Plane->Pln().Axis(), Angle*0.5 ); diff --git a/src/Extrema/Extrema_ExtPElC.cxx b/src/Extrema/Extrema_ExtPElC.cxx index 968606939b..a3e9c6441b 100755 --- a/src/Extrema/Extrema_ExtPElC.cxx +++ b/src/Extrema/Extrema_ExtPElC.cxx @@ -401,7 +401,7 @@ Method: Cu = ElCLib::Value(Us,C); DejaEnr = Standard_False; for (NoExt = 0; NoExt < myNbExt; NoExt++) { - if (TbExt[NoExt].SquareDistance(Cu) < Precision::Confusion() * Precision::Confusion()) { + if (TbExt[NoExt].SquareDistance(Cu) < Precision::SquareConfusion()) { DejaEnr = Standard_True; break; } diff --git a/src/Extrema/Extrema_ExtPRevS.cxx b/src/Extrema/Extrema_ExtPRevS.cxx index 90bcdef1a7..a4fab0f5cb 100755 --- a/src/Extrema/Extrema_ExtPRevS.cxx +++ b/src/Extrema/Extrema_ExtPRevS.cxx @@ -88,11 +88,11 @@ static Standard_Boolean HasSingularity(const Adaptor3d_SurfaceOfRevolution& S) P = C->Value(C->FirstParameter()); - if(L.SquareDistance(P) < Precision::Confusion() * Precision::Confusion()) return Standard_True; + if(L.SquareDistance(P) < Precision::SquareConfusion()) return Standard_True; P = C->Value(C->LastParameter()); - if(L.SquareDistance(P) < Precision::Confusion() * Precision::Confusion()) return Standard_True; + if(L.SquareDistance(P) < Precision::SquareConfusion()) return Standard_True; return Standard_False; } diff --git a/src/GeomliteTest/GeomliteTest_SurfaceCommands.cxx b/src/GeomliteTest/GeomliteTest_SurfaceCommands.cxx index 680226be34..566ae9e3bd 100755 --- a/src/GeomliteTest/GeomliteTest_SurfaceCommands.cxx +++ b/src/GeomliteTest/GeomliteTest_SurfaceCommands.cxx @@ -1433,7 +1433,7 @@ static Standard_Integer compBsplSur (Draw_Interpretor& , Standard_Integer n, con gp_Pnt aP1 = GBs1->Value(aU,aV); gp_Pnt aP2 = GBs2->Value(aU,aV); Standard_Real aDist = aP1.SquareDistance(aP2); - if(aDist > Precision::Confusion() * Precision::Confusion()) + if(aDist > Precision::SquareConfusion()) { nbErr++; Standard_Real aD = sqrt(aDist); diff --git a/src/LocOpe/LocOpe_SplitDrafts.cxx b/src/LocOpe/LocOpe_SplitDrafts.cxx index 51e1b0764b..a3758818d9 100755 --- a/src/LocOpe/LocOpe_SplitDrafts.cxx +++ b/src/LocOpe/LocOpe_SplitDrafts.cxx @@ -1638,7 +1638,7 @@ static TopoDS_Edge NewEdge(const TopoDS_Edge& edg, } } - if (Dist2Min <= Precision::Confusion() * Precision::Confusion()) { + if (Dist2Min <= Precision::SquareConfusion()) { prmf = thepmin; myExtPC.Perform(pvl); if (myExtPC.IsDone()) { @@ -1656,7 +1656,7 @@ static TopoDS_Edge NewEdge(const TopoDS_Edge& edg, } } - if (Dist2Min <= Precision::Confusion() * Precision::Confusion()) { + if (Dist2Min <= Precision::SquareConfusion()) { prml = thepmin; break; } diff --git a/src/NIS/NIS_Surface.cxx b/src/NIS/NIS_Surface.cxx index c51e3ba370..54513de7c3 100755 --- a/src/NIS/NIS_Surface.cxx +++ b/src/NIS/NIS_Surface.cxx @@ -223,7 +223,7 @@ void NIS_Surface::Init (const TopoDS_Shape& theShape, myNEdges = 0; // The second loop: copy all nodes and triangles face-by-face - const Standard_Real eps2 = Precision::Confusion()*Precision::Confusion(); + const Standard_Real eps2 = Precision::SquareConfusion(); Standard_Integer nNodes (0), nTriangles (0); for (fexp.ReInit(); fexp.More(); fexp.Next()) { diff --git a/src/Poly/Poly.cxx b/src/Poly/Poly.cxx index 050d1163f2..b1e1179185 100755 --- a/src/Poly/Poly.cxx +++ b/src/Poly/Poly.cxx @@ -459,7 +459,7 @@ void Poly::ComputeNormals(const Handle(Poly_Triangulation)& Tri) Standard_Real aCoord[3]; Standard_Integer iNode[3] = {0, 0, 0}; Standard_Integer iN, iTri; - const Standard_Real eps2 = Precision::Confusion()*Precision::Confusion(); + const Standard_Real eps2 = Precision::SquareConfusion(); for (iTri = 1; iTri <= arrTri.Length(); iTri++) { // Get the nodes of the current triangle diff --git a/src/Precision/Precision.cdl b/src/Precision/Precision.cdl index 14c76d9304..47c21ffef8 100755 --- a/src/Precision/Precision.cdl +++ b/src/Precision/Precision.cdl @@ -164,6 +164,11 @@ is -- becomes easily measurable, but only within a restricted -- space which contains some small objects of the complete scene. + SquareConfusion returns Real from Standard; + ---Purpose: + -- Returns square of Confusion. + -- Created for speed and convenience. + Intersection returns Real from Standard; ---Purpose:Returns the precision value in real space, frequently -- used by intersection algorithms to decide that a solution is reached. diff --git a/src/Precision/Precision.lxx b/src/Precision/Precision.lxx index 8df3e3f101..18ce197343 100755 --- a/src/Precision/Precision.lxx +++ b/src/Precision/Precision.lxx @@ -52,6 +52,16 @@ inline Standard_Real Precision::Confusion() } +//======================================================================= +//function : SquareConfusion +//purpose : +//======================================================================= +inline Standard_Real Precision::SquareConfusion() +{ + return Confusion() * Confusion(); +} + + //======================================================================= //function : Intersection //purpose : diff --git a/src/ShapeAnalysis/ShapeAnalysis_Curve.cxx b/src/ShapeAnalysis/ShapeAnalysis_Curve.cxx index 36cf841c77..ac8f8eb1fd 100755 --- a/src/ShapeAnalysis/ShapeAnalysis_Curve.cxx +++ b/src/ShapeAnalysis/ShapeAnalysis_Curve.cxx @@ -980,7 +980,7 @@ Standard_Boolean ShapeAnalysis_Curve::IsPlanar (const TColgp_Array1OfPnt& pnts, return Standard_True; } gp_XYZ aVecMul = N1^Normal; - return aVecMul.SquareModulus() < Precision::Confusion()*Precision::Confusion(); + return aVecMul.SquareModulus() < Precision::SquareConfusion(); } if (curve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { diff --git a/src/ShapeAnalysis/ShapeAnalysis_WireOrder.cxx b/src/ShapeAnalysis/ShapeAnalysis_WireOrder.cxx index d07ec19324..352319b86e 100755 --- a/src/ShapeAnalysis/ShapeAnalysis_WireOrder.cxx +++ b/src/ShapeAnalysis/ShapeAnalysis_WireOrder.cxx @@ -228,7 +228,7 @@ void ShapeAnalysis_WireOrder::Perform(const Standard_Boolean /*closed*/) fins(i) = myXYZ->Value(2*i); } - Standard_Real tol2 = Precision::Confusion()*Precision::Confusion(); + Standard_Real tol2 = Precision::SquareConfusion(); idone(1) = Standard_True; gp_Pnt wireFirst = debs(1); gp_Pnt wireLast = fins(1); diff --git a/src/ShapeFix/ShapeFix_Wireframe.cxx b/src/ShapeFix/ShapeFix_Wireframe.cxx index 18023db7d7..c6592cc2a1 100755 --- a/src/ShapeFix/ShapeFix_Wireframe.cxx +++ b/src/ShapeFix/ShapeFix_Wireframe.cxx @@ -698,7 +698,7 @@ Standard_Boolean ShapeFix_Wireframe::MergeSmallEdges(TopTools_MapOfShape& theSma C2->D1(first2,P,Vec2); if ( edge1.Orientation() == TopAbs_REVERSED ) Vec1.Reverse(); if ( edge2.Orientation() == TopAbs_REVERSED ) Vec2.Reverse(); - Standard_Real tol2 = Precision::Confusion() * Precision::Confusion(); + Standard_Real tol2 = Precision::SquareConfusion(); if ( Vec1.SquareMagnitude() < tol2 || Vec2.SquareMagnitude() < tol2 ) Ang1 = M_PI/2.; else Ang1 = Abs(Vec1.Angle(Vec2)); @@ -1138,7 +1138,7 @@ Standard_Boolean ShapeFix_Wireframe::MergeSmallEdges(TopTools_MapOfShape& theSma C2->D1(first2,P,Vec2); if ( edge1.Orientation() == TopAbs_REVERSED ) Vec1.Reverse(); if ( edge2.Orientation() == TopAbs_REVERSED ) Vec2.Reverse(); - Standard_Real tol2 = Precision::Confusion() * Precision::Confusion(); + Standard_Real tol2 = Precision::SquareConfusion(); if ( Vec1.SquareMagnitude() < tol2 || Vec2.SquareMagnitude() < tol2 ) Ang1 = M_PI/2.; else Ang1 = Abs(Vec1.Angle(Vec2)); diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index 806ec2c488..2dd01514c4 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -89,7 +89,7 @@ namespace Standard_Real aUmin (0.0), aUmax (0.0), aVmin (0.0), aVmax (0.0), dUmax (0.0), dVmax (0.0); // precision for compare square distances - const double aPreci = Precision::Confusion() * Precision::Confusion(); + const double aPreci = Precision::SquareConfusion(); if (!theDrawer->ShadingAspectGlobal()) { diff --git a/src/Voxel/Voxel_Writer.cxx b/src/Voxel/Voxel_Writer.cxx index 061f2ae2c5..571b86a4c1 100755 --- a/src/Voxel/Voxel_Writer.cxx +++ b/src/Voxel/Voxel_Writer.cxx @@ -418,7 +418,7 @@ Standard_Boolean Voxel_Writer::WriteFloatBinaryVoxels(const TCollection_Extended if (nb_slices) { Standard_Integer i1 = 0, i2 = 0; - Standard_Real small = Precision::Confusion() * Precision::Confusion(); + Standard_Real small = Precision::SquareConfusion(); for (i1 = 0; i1 < nb_slices; i1++) { if (((Standard_ShortReal**)ds->myData)[i1]) diff --git a/src/VrmlData/VrmlData_IndexedFaceSet.cxx b/src/VrmlData/VrmlData_IndexedFaceSet.cxx index 27332eb871..a040a2b425 100755 --- a/src/VrmlData/VrmlData_IndexedFaceSet.cxx +++ b/src/VrmlData/VrmlData_IndexedFaceSet.cxx @@ -102,7 +102,7 @@ const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape () arrNodes[arrIndice[2]] - arrNodes[arrIndice[0]] }; if ((aVec[0] ^ aVec[1]).SquareModulus() > - Precision::Confusion()*Precision::Confusion()) + Precision::SquareConfusion()) ++nTri; else { const_cast (arrIndice[0]) = -1; diff --git a/src/VrmlData/VrmlData_ShapeConvert.cxx b/src/VrmlData/VrmlData_ShapeConvert.cxx index c523c431bc..410d393b9c 100755 --- a/src/VrmlData/VrmlData_ShapeConvert.cxx +++ b/src/VrmlData/VrmlData_ShapeConvert.cxx @@ -414,7 +414,7 @@ Handle_VrmlData_Geometry VrmlData_ShapeConvert::triToIndexedFaceSet Poly_Connect PC(theTri); // Create the Normals node (if UV- values are available) TopLoc_Location aLoc; - const Standard_Real aConf2 = Precision::Confusion()*Precision::Confusion(); + const Standard_Real aConf2 = Precision::SquareConfusion(); const Handle(Geom_Surface) aSurface = BRep_Tool::Surface (theFace, aLoc); if (theTri->HasUVNodes() && aSurface.IsNull() == Standard_False) { if (aSurface->IsCNu(1) && aSurface->IsCNv(1))