From 198753532d118634eb931610cdcdc9c2ca68ee33 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 26 Sep 2013 20:13:17 +0400 Subject: [PATCH] 0023863: Wrong distance value between circle and cylinder The verification of intersection of a circle and a cylinder was added to the calculation of extrema Test cases for issue CR23863 --- src/Extrema/Extrema_ExtElCS.cxx | 78 +++++++++++++++++++++------------ tests/bugs/moddata_3/bug23863 | 38 ++++++++++++++++ 2 files changed, 89 insertions(+), 27 deletions(-) create mode 100755 tests/bugs/moddata_3/bug23863 diff --git a/src/Extrema/Extrema_ExtElCS.cxx b/src/Extrema/Extrema_ExtElCS.cxx index e3acae68fa..de862227a7 100755 --- a/src/Extrema/Extrema_ExtElCS.cxx +++ b/src/Extrema/Extrema_ExtElCS.cxx @@ -314,48 +314,72 @@ void Extrema_ExtElCS::Perform(const gp_Circ& C, Standard_Real aTolConf = Precision::Confusion(); Standard_Real aCylRad = S.Radius(); + // Check whether two objects have intersection points + IntAna_Quadric aCylQuad(S); + IntAna_IntConicQuad aCircCylInter(C, aCylQuad); + Standard_Integer aNbInter = aCircCylInter.NbPoints(); + if (!aCircCylInter.IsDone()) + aNbInter = 0; + // Compute the extremas. - myNbExt = 2*aNbExt; + myNbExt = 2*aNbExt + aNbInter; mySqDist = new TColStd_HArray1OfReal(1, myNbExt); myPoint1 = new Extrema_HArray1OfPOnCurv(1, myNbExt); myPoint2 = new Extrema_HArray1OfPOnSurf(1, myNbExt); for (i = 1; i <= aNbExt; i++) { - Extrema_POnCurv aPOnAxis; - Extrema_POnCurv aPOnCirc; - Standard_Real aSqDist = anExtC.SquareDistance(i); - Standard_Real aDist = sqrt (aSqDist); + Extrema_POnCurv aPOnAxis; + Extrema_POnCurv aPOnCirc; + Standard_Real aSqDist = anExtC.SquareDistance(i); + Standard_Real aDist = sqrt (aSqDist); - anExtC.Points(i, aPOnAxis, aPOnCirc); + anExtC.Points(i, aPOnAxis, aPOnCirc); - if (aSqDist <= (aTolConf * aTolConf) || aCenter.IsEqual(aPOnAxis.Value(), aTolConf)) { - myNbExt -= 2; - continue; - } + if (aSqDist <= (aTolConf * aTolConf)) { + myNbExt -= 2; + continue; + } - gp_Dir aDir(aPOnAxis.Value().XYZ(). - Subtracted(aPOnCirc.Value().XYZ())); - Standard_Real aShift[2] = { aDist + aCylRad, aDist - aCylRad }; - Standard_Integer j; + gp_Dir aDir(aPOnAxis.Value().XYZ().Subtracted(aPOnCirc.Value().XYZ())); + Standard_Real aShift[2] = { aDist + aCylRad, aDist - aCylRad }; + Standard_Integer j; - for (j = 0; j < 2; j++) { - gp_Vec aVec(aDir); - gp_Pnt aPntOnCyl; + for (j = 0; j < 2; j++) { + gp_Vec aVec(aDir); + gp_Pnt aPntOnCyl; - aVec.Multiply(aShift[j]); - aPntOnCyl = aPOnCirc.Value().Translated(aVec); + aVec.Multiply(aShift[j]); + aPntOnCyl = aPOnCirc.Value().Translated(aVec); - Standard_Real aU; - Standard_Real aV; + Standard_Real aU; + Standard_Real aV; - ElSLib::Parameters(S, aPntOnCyl, aU, aV); + ElSLib::Parameters(S, aPntOnCyl, aU, aV); - Extrema_POnSurf aPOnSurf(aU, aV, aPntOnCyl); + Extrema_POnSurf aPOnSurf(aU, aV, aPntOnCyl); - myPoint1->SetValue(aCurI, aPOnCirc); - myPoint2->SetValue(aCurI, aPOnSurf); - mySqDist->SetValue(aCurI++, aShift[j] * aShift[j]); - } + myPoint1->SetValue(aCurI, aPOnCirc); + myPoint2->SetValue(aCurI, aPOnSurf); + mySqDist->SetValue(aCurI++, aShift[j] * aShift[j]); + } + } + + // Adding intersection points to the list of extremas + for (i=1; i<=aNbInter; i++) + { + Standard_Real aU; + Standard_Real aV; + + gp_Pnt aInterPnt = aCircCylInter.Point(i); + + aU = ElCLib::Parameter(C, aInterPnt); + Extrema_POnCurv aPOnCirc(aU, aInterPnt); + + ElSLib::Parameters(S, aInterPnt, aU, aV); + Extrema_POnSurf aPOnCyl(aU, aV, aInterPnt); + myPoint1->SetValue(aCurI, aPOnCirc); + myPoint2->SetValue(aCurI, aPOnCyl); + mySqDist->SetValue(aCurI++, 0.0); } } diff --git a/tests/bugs/moddata_3/bug23863 b/tests/bugs/moddata_3/bug23863 new file mode 100755 index 0000000000..6abaafbbf8 --- /dev/null +++ b/tests/bugs/moddata_3/bug23863 @@ -0,0 +1,38 @@ +puts "================" +puts "OCC23863" +puts "================" +puts "" +####################################################################### +# Wrong distance value between circle and cylinder +####################################################################### + +pcylinder b1 10 10 +explode b1 f +copy b1_1 b1 +circle b2 0 10 10 1 0 0 5 +mkedge b2 b2 + +distmini d b1 b2 + +regexp {([-0-9.+eE]+)$} [dump d_val] full dist +regexp { +Vertex +: +Min +[-0-9.+eE]+ +Max +([-0-9.+eE]+)} [ maxtolerance d ] full toler +set good_dist 0 +if { [expr abs( ${dist} - ${good_dist} )] > ${toler} } { + puts "Faulty : the distanse is ${dist}. It is bad value" +} + +regexp { +Point 3D : +([-0-9.+eE]+), +([-0-9.+eE]+), +([-0-9.+eE]+)} [ dump d ] full x y z +set good_x 0 +set good_y 10 +set good_z 5 +if { [expr abs( ${x} - ${good_x} )] > ${toler} } { + puts "Faulty : the x coordinate of the point is ${x}. It is bad value" +} +if { [expr abs( ${y} - ${good_y} )] > ${toler} } { + puts "Faulty : the y coordinate of the point is ${y}. It is bad value" +} +if { [expr abs( ${z} - ${good_z} )] > ${toler} } { + puts "Faulty : the z coordinate of the point is ${z}. It is bad value" +} + +set 2dviewer 1