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

0027774: Constructor GeomPlate_BuildAveragePlane crashes if two input normals are parallel to each other

Normalization has been avoided in case of impossibility.
This commit is contained in:
nbv 2016-08-15 15:57:11 +03:00 committed by bugmaster
parent b47bcd7ea7
commit 032881f4fb

View File

@ -108,7 +108,21 @@ myPts(Pts)
else if (NN == 2) else if (NN == 2)
{ {
BestVec = Normals(1) + Normals(2); BestVec = Normals(1) + Normals(2);
BestVec.Normalize(); const Standard_Real aSqMagn = BestVec.SquareMagnitude();
if(aSqMagn < Precision::SquareConfusion())
{
const Standard_Real aSq1 = Normals(1).SquareMagnitude(),
aSq2 = Normals(2).SquareMagnitude();
if(aSq1 > aSq2)
BestVec = Normals(1).Normalized();
else
BestVec = Normals(2).Normalized();
}
else
{
BestVec.Divide(sqrt(aSqMagn));
}
} }
else //the common case else //the common case
{ {
@ -131,11 +145,21 @@ myPts(Pts)
k = 1; k = 1;
for (i = 1; i <= NN-1; i++) for (i = 1; i <= NN-1; i++)
for (j = i+1; j <= NN; j++) for (j = i+1; j <= NN; j++, k++)
{ {
OptScal(k) = RealFirst();
Standard_Real Step = MaxAngle/Nint; Standard_Real Step = MaxAngle/Nint;
Vec = Normals(i) + Normals(j); Vec = Normals(i) + Normals(j);
Vec.Normalize();
const Standard_Real aSqMagn = Vec.SquareMagnitude();
if(aSqMagn < Precision::SquareConfusion())
{
continue;
}
Vec.Divide(sqrt(aSqMagn));
Cross1 = Normals(i) ^ Normals(j); Cross1 = Normals(i) ^ Normals(j);
Cross2 = Vec ^ Cross1; Cross2 = Vec ^ Cross1;
@ -144,7 +168,6 @@ myPts(Pts)
Vec1 = Vec.Rotated( Axe, -MaxAngle ); Vec1 = Vec.Rotated( Axe, -MaxAngle );
//Vec2 = Vec.Rotated( Axe, MaxAngle ); //Vec2 = Vec.Rotated( Axe, MaxAngle );
OptScal(k) = RealFirst();
for (n = 0; n <= 2*Nint; n++) for (n = 0; n <= 2*Nint; n++)
{ {
Vec1.Rotate( Axe, Step ); Vec1.Rotate( Axe, Step );
@ -161,7 +184,6 @@ myPts(Pts)
OptVec(k) = Vec1; OptVec(k) = Vec1;
} }
} }
k++;
} // for i, for j } // for i, for j
//Find maximum among all maximums //Find maximum among all maximums