From 4db8b2732920013437a6cee2ff142e4935e4ab0b Mon Sep 17 00:00:00 2001 From: ifv Date: Fri, 6 Aug 2021 14:49:14 +0300 Subject: [PATCH] 0026269: Modeling Data - Analytical extrema does not take into account trimmed input data Treatment of trimmed data is added Extrema/Extrema_ExtCC.cxx Test cases added tests/lowalgos/extcc/bug26269_1 tests/lowalgos/extcc/bug26269_2 Test cases are modified according to new behavior of algorithm --- src/Extrema/Extrema_ExtCC.cxx | 102 ++++++++++++++++++++++++++++++- tests/lowalgos/extcc/bug26269_1 | 24 ++++++++ tests/lowalgos/extcc/bug26269_2 | 24 ++++++++ tests/lowalgos/extcc/bug29712_13 | 19 ++++-- tests/lowalgos/extcc/bug29712_21 | 19 ++++-- tests/lowalgos/extcc/bug29712_22 | 21 +++++-- tests/lowalgos/extcc/bug29712_24 | 20 ++++-- tests/lowalgos/extcc/bug29712_25 | 19 ++++-- tests/lowalgos/extcc/bug29712_29 | 20 ++++-- tests/lowalgos/extcc/bug29712_3 | 12 +++- tests/lowalgos/extcc/bug29712_32 | 19 ++++-- tests/lowalgos/extcc/bug29712_37 | 20 ++++-- tests/lowalgos/extcc/bug29712_5 | 11 +++- 13 files changed, 288 insertions(+), 42 deletions(-) create mode 100644 tests/lowalgos/extcc/bug26269_1 create mode 100644 tests/lowalgos/extcc/bug26269_2 diff --git a/src/Extrema/Extrema_ExtCC.cxx b/src/Extrema/Extrema_ExtCC.cxx index fa77b80c79..e200956bbb 100644 --- a/src/Extrema/Extrema_ExtCC.cxx +++ b/src/Extrema/Extrema_ExtCC.cxx @@ -539,7 +539,54 @@ void Extrema_ExtCC::PrepareParallelResult(const Standard_Real theUt11, mypoints.Append(aP2); mySqDist.Append(theSqDist); } - } + else + { + //Case like this: + + // ************** aLin1 + // o + // o + // *********** aLin2 + // + //Take minimal trimmed distance + Standard_Real aDmin, aDists[4] = {mydist11, mydist12, mydist21, mydist22}; + Extrema_POnCurv aP1, aP2; + aDmin = aDists[0]; + Standard_Integer i, imin = 0; + for (i = 1; i < 4; ++i) + { + if (aDmin > aDists[i]) + { + aDmin = aDists[i]; + imin = i; + } + } + if (imin == 0) + { + aP1.SetValues(myInf[0], P1f); + aP2.SetValues(myInf[1], P2f); + } + else if (imin == 1) + { + aP1.SetValues(myInf[0], P1f); + aP2.SetValues(mySup[1], P2l); + } + else if (imin == 2) + { + aP1.SetValues(mySup[0], P1l); + aP2.SetValues(myInf[1], P2f); + } + else + { + aP1.SetValues(mySup[0], P1l); + aP2.SetValues(mySup[1], P2l); + } + ClearSolutions(); + mypoints.Append(aP1); + mypoints.Append(aP2); + mySqDist.Append(aDmin); + } + } } else { @@ -639,7 +686,7 @@ void Extrema_ExtCC::PrepareParallelResult(const Standard_Real theUt11, aMinSqD = Min(aMinSqD, ExtPCir.SquareDistance(anExtID)); } - if (aMinSqD <= aMinSquareDist) + if (aMinSqD <= aMinSquareDist + 10.* Epsilon(1. + aMinSqD)) { ClearSolutions(); mySqDist.Append(aMinSqD); @@ -717,7 +764,58 @@ void Extrema_ExtCC::PrepareParallelResult(const Standard_Real theUt11, } } } + else + { + //Case like this: + // ************** Cir1 + // o + // o + // *********** Cir2 + // + //Take minimal trimmed distance + myIsPar = Standard_False; + Standard_Real aDmin, aDists[4] = { mydist11, mydist12, mydist21, mydist22 }; + Extrema_POnCurv aP1, aP2; + aDmin = aDists[0]; + Standard_Integer k, imin = 0; + for (k = 1; k < 4; ++k) + { + if (aDmin > aDists[k]) + { + aDmin = aDists[k]; + imin = k; + } + } + if (aDmin <= aMinSquareDist + 10.* Epsilon(1. + aDmin)) + { + if (imin == 0) + { + aP1.SetValues(myInf[0], P1f); + aP2.SetValues(myInf[1], P2f); + } + else if (imin == 1) + { + aP1.SetValues(myInf[0], P1f); + aP2.SetValues(mySup[1], P2l); + } + else if (imin == 2) + { + aP1.SetValues(mySup[0], P1l); + aP2.SetValues(myInf[1], P2f); + } + else + { + aP1.SetValues(mySup[0], P1l); + aP2.SetValues(mySup[1], P2l); + } + ClearSolutions(); + mypoints.Append(aP1); + mypoints.Append(aP2); + mySqDist.Append(aDmin); + aMinSquareDist = Min(aMinSquareDist, aDmin); + } + } aProjRng1.Shift(M_PI); } } diff --git a/tests/lowalgos/extcc/bug26269_1 b/tests/lowalgos/extcc/bug26269_1 new file mode 100644 index 0000000000..a07c5f6c81 --- /dev/null +++ b/tests/lowalgos/extcc/bug26269_1 @@ -0,0 +1,24 @@ +puts "========" +puts "0026269: Modeling Data - Analytical extrema does not take into account trimmed input data" +puts "========" +puts "" + +#case 1 +line l1 0 0 0 1 0 0 +line l2 2 2 0 1 0 0 +trim l1 l1 0 1 +trim l2 l2 0 1 + +set res_extrema [extrema l1 l2] + +if { [regexp "Infinite number of extremas" $res_extrema] == 0} { + if {[llength $res_extrema] != 1} { + puts "Error : expected 1 extrema, but found [llength $res_extrema]" + } +} else { + puts "Error : Infinite number of extremas is found" +} + +smallview +X+Y +fit +checkview -screenshot -2d -path ${imagedir}/${test_image}.png \ No newline at end of file diff --git a/tests/lowalgos/extcc/bug26269_2 b/tests/lowalgos/extcc/bug26269_2 new file mode 100644 index 0000000000..0726fd2dca --- /dev/null +++ b/tests/lowalgos/extcc/bug26269_2 @@ -0,0 +1,24 @@ +puts "========" +puts "0026269: Modeling Data - Analytical extrema does not take into account trimmed input data" +puts "========" +puts "" + +#case 2 +circle c1 0 0 0 10 +circle c2 0 0 0 5 +trim c1 c1 0 1 +trim c2 c2 3 4 + +set res_extrema [extrema c1 c2] + +if { [regexp "Infinite number of extremas" $res_extrema] == 0} { + if {[llength $res_extrema] != 1} { + puts "Error : expected 1 extrema, but found [llength $res_extrema]" + } +} else { + puts "Error : Infinite number of extremas is found" +} + +smallview +X+Y +fit +checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/lowalgos/extcc/bug29712_13 b/tests/lowalgos/extcc/bug29712_13 index 36dc300487..3e54f3fd65 100644 --- a/tests/lowalgos/extcc/bug29712_13 +++ b/tests/lowalgos/extcc/bug29712_13 @@ -17,8 +17,19 @@ circle c2 0 0 0 0 0 1 50 trim c1 c1 0 3 trim c2 c2 4 6 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c1 c2] full aDist1 -checkreal Distance $aDist1 $ExpDist 1.0e-7 0.0 +extrema c1 c2 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c2 c1] full aDist2 -checkreal Distance $aDist2 $ExpDist 1.0e-7 0.0 +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} + +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} diff --git a/tests/lowalgos/extcc/bug29712_21 b/tests/lowalgos/extcc/bug29712_21 index f2a1b419fe..569a0687c4 100644 --- a/tests/lowalgos/extcc/bug29712_21 +++ b/tests/lowalgos/extcc/bug29712_21 @@ -17,8 +17,19 @@ circle c2 0 0 0 0 0 1 50 trim c1 c1 0 3 trim c2 c2 -3.2 -1.2 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c1 c2] full aDist1 -checkreal Distance $aDist1 $ExpDist 1.0e-7 0.0 +extrema c1 c2 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c2 c1] full aDist2 -checkreal Distance $aDist2 $ExpDist 1.0e-7 0.0 +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} + +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} \ No newline at end of file diff --git a/tests/lowalgos/extcc/bug29712_22 b/tests/lowalgos/extcc/bug29712_22 index 9287c1f237..b9e5d07333 100644 --- a/tests/lowalgos/extcc/bug29712_22 +++ b/tests/lowalgos/extcc/bug29712_22 @@ -10,15 +10,24 @@ puts "" # However, they are bounded (trimmed) curves # and are shifted relatively to each other. -set ExpDist 150.0 - circle c1 0 0 0 0 0 1 100 circle c2 0 0 0 0 0 1 50 trim c1 c1 0 3 trim c2 c2 -3.1 -1.1 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c1 c2] full aDist1 -checkreal Distance $aDist1 $ExpDist 1.0e-7 0.0 +extrema c1 c2 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} + +renamevar ext_1 e1 +extrema c2 c1 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c2 c1] full aDist2 -checkreal Distance $aDist2 $ExpDist 1.0e-7 0.0 +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} diff --git a/tests/lowalgos/extcc/bug29712_24 b/tests/lowalgos/extcc/bug29712_24 index 280f73a4ed..7c0e22d63f 100644 --- a/tests/lowalgos/extcc/bug29712_24 +++ b/tests/lowalgos/extcc/bug29712_24 @@ -10,15 +10,25 @@ puts "" # However, they are bounded (trimmed) curves # and are shifted relatively to each other. -set ExpDist 150.0 circle c1 0 0 0 0 0 1 100 circle c2 0 0 0 0 0 1 50 trim c1 c1 0 3 trim c2 c2 -9.5 -7.5 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c1 c2] full aDist1 -checkreal Distance $aDist1 $ExpDist 1.0e-7 0.0 +extrema c1 c2 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c2 c1] full aDist2 -checkreal Distance $aDist2 $ExpDist 1.0e-7 0.0 +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} + +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} diff --git a/tests/lowalgos/extcc/bug29712_25 b/tests/lowalgos/extcc/bug29712_25 index c8bd0973ba..1503119687 100644 --- a/tests/lowalgos/extcc/bug29712_25 +++ b/tests/lowalgos/extcc/bug29712_25 @@ -17,8 +17,19 @@ circle c2 0 0 0 0 0 1 50 trim c1 c1 0 3 trim c2 c2 -8.3 -6.3 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c1 c2] full aDist1 -checkreal Distance $aDist1 $ExpDist 1.0e-7 0.0 +extrema c1 c2 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c2 c1] full aDist2 -checkreal Distance $aDist2 $ExpDist 1.0e-7 0.0 +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} + +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} diff --git a/tests/lowalgos/extcc/bug29712_29 b/tests/lowalgos/extcc/bug29712_29 index 0339082b9b..eeb9d4efa3 100644 --- a/tests/lowalgos/extcc/bug29712_29 +++ b/tests/lowalgos/extcc/bug29712_29 @@ -10,15 +10,25 @@ puts "" # However, they are bounded (trimmed) curves # and are shifted relatively to each other. -set ExpDist 150.0 circle c1 0 0 0 0 0 1 100 circle c2 0 0 0 0 0 1 50 trim c1 c1 0 3 trim c2 c2 3.1 5.1 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c1 c2] full aDist1 -checkreal Distance $aDist1 $ExpDist 1.0e-7 0.0 +extrema c1 c2 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c2 c1] full aDist2 -checkreal Distance $aDist2 $ExpDist 1.0e-7 0.0 +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} + +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} diff --git a/tests/lowalgos/extcc/bug29712_3 b/tests/lowalgos/extcc/bug29712_3 index e5424faea6..e996370645 100644 --- a/tests/lowalgos/extcc/bug29712_3 +++ b/tests/lowalgos/extcc/bug29712_3 @@ -17,9 +17,19 @@ line c2 3 4 0 1 0 0 trim c1 c1 0 1 trim c2 c2 0 1 -if { ![regexp {No solutions!} [extrema c1 c2] ] } { +extrema c1 c2 + +if { ![isdraw ext_1 ] } { puts "Error in Extrema-algorithm" } else { puts "Extrema-algorithm works properly" } +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} diff --git a/tests/lowalgos/extcc/bug29712_32 b/tests/lowalgos/extcc/bug29712_32 index bd554f5035..53a41faeb9 100644 --- a/tests/lowalgos/extcc/bug29712_32 +++ b/tests/lowalgos/extcc/bug29712_32 @@ -17,8 +17,19 @@ circle c2 0 0 0 0 0 1 50 trim c1 c1 0 pi trim c2 c2 -9.4 -7.4 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c1 c2] full aDist1 -checkreal Distance $aDist1 $ExpDist 1.0e-7 0.0 +extrema c1 c2 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c2 c1] full aDist2 -checkreal Distance $aDist2 $ExpDist 1.0e-7 0.0 +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} + +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} diff --git a/tests/lowalgos/extcc/bug29712_37 b/tests/lowalgos/extcc/bug29712_37 index ab063504aa..f9efb64981 100644 --- a/tests/lowalgos/extcc/bug29712_37 +++ b/tests/lowalgos/extcc/bug29712_37 @@ -18,8 +18,20 @@ circle c2 0 0 0 0 0 1 50 trim c1 c1 3 6.5 trim c2 c2 4 6 -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c1 c2] full aDist1 -checkreal Distance $aDist1 $ExpDist 1.0e-7 0.0 +extrema c1 c2 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} + +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { + puts "Error in Extrema-algorithm" +} else { + puts "Extrema-algorithm works properly" +} -regexp {Infinite number of extremas, distance = +([-0-9.+eE]+)} [extrema c2 c1] full aDist2 -checkreal Distance $aDist2 $ExpDist 1.0e-7 0.0 diff --git a/tests/lowalgos/extcc/bug29712_5 b/tests/lowalgos/extcc/bug29712_5 index b5794fadc3..c43d75dd96 100644 --- a/tests/lowalgos/extcc/bug29712_5 +++ b/tests/lowalgos/extcc/bug29712_5 @@ -16,14 +16,19 @@ line c2 5 0 0 0 0 1 trim c1 c1 -1.0e100 5 trim c2 c2 10 20 -if { ![regexp {No solutions!} [extrema c1 c2] ] } { +extrema c1 c2 + +if { ![isdraw ext_1 ] } { puts "Error in Extrema-algorithm" } else { puts "Extrema-algorithm works properly" } -if { ![regexp {No solutions!} [extrema c2 c1] ] } { +renamevar ext_1 e1 +extrema c2 c1 + +if { ![isdraw ext_1 ] } { puts "Error in Extrema-algorithm" } else { puts "Extrema-algorithm works properly" -} +} \ No newline at end of file -- 2.39.5