1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

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().
This commit is contained in:
abk 2012-10-05 13:55:16 +04:00
parent 852a895cda
commit 08cd2f6bb1
24 changed files with 45 additions and 30 deletions

View File

@ -80,7 +80,7 @@
#include <gp_Vec.hxx>
#include <gp_XYZ.hxx>
const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
const Standard_Real SquareTolerance = Precision::SquareConfusion();
//=======================================================================
//function : Nearest

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;

View File

@ -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];

View File

@ -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 );

View File

@ -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);

View File

@ -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 );

View File

@ -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 );

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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())
{

View File

@ -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

View File

@ -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.

View File

@ -52,6 +52,16 @@ inline Standard_Real Precision::Confusion()
}
//=======================================================================
//function : SquareConfusion
//purpose :
//=======================================================================
inline Standard_Real Precision::SquareConfusion()
{
return Confusion() * Confusion();
}
//=======================================================================
//function : Intersection
//purpose :

View File

@ -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))) {

View File

@ -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);

View File

@ -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));

View File

@ -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())
{

View File

@ -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])

View File

@ -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<Standard_Integer&> (arrIndice[0]) = -1;

View File

@ -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))