From: isn Date: Thu, 11 Jan 2018 16:03:03 +0000 (+0300) Subject: 0029406: Foundation Classes - gp_Ax3 fails setting direction X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=af061f95c6a6e94dbdde77558332f25b870f95b8;p=occt-copy.git 0029406: Foundation Classes - gp_Ax3 fails setting direction Avoid exception in gp_Ax3::SetDirection(), SetAxis(): check if XDir of Ax3 is parallel to newly given direction. --- diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index 2f014583c4..4ad9d19e9d 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -2768,6 +2768,66 @@ static Standard_Integer OCC29371 (Draw_Interpretor& di, Standard_Integer n, cons return 0; } +static Standard_Integer OCC29406 (Draw_Interpretor&, Standard_Integer, const char**) +{ + gp_Ax3 anAx1, anAx2; + Standard_Boolean bDirect1 = anAx1.Direct(); + anAx1.SetDirection (gp::DX()); + if (bDirect1 != anAx1.Direct()) + { + std::cout << "Error: coordinate system is reversed\n"; + return 1; + } + // + Standard_Boolean bDirect2 = anAx2.Direct(); + anAx2.SetDirection (-gp::DX()); + if (bDirect2 != anAx2.Direct()) + { + std::cout << "Error: coordinate system is reversed\n"; + return 1; + } + // + gp_Ax3 anAx3, anAx4; + anAx3.ZReverse(); + anAx4.ZReverse(); + // + Standard_Boolean bDirect3 = anAx3.Direct(); + anAx3.SetDirection (gp::DX()); + if (bDirect3 != anAx3.Direct()) + { + std::cout << "Error: coordinate system is reversed\n"; + return 1; + } + // + Standard_Boolean bDirect4 = anAx4.Direct(); + anAx4.SetDirection (gp::DX()); + if (bDirect4 != anAx3.Direct()) + { + std::cout << "Error: coordinate system is reversed\n"; + return 1; + } + // + gp_Ax3 anAx5, anAx6; + gp_Ax1 anAx0_1 (gp::Origin(), gp::DX()); + Standard_Boolean bDirect5 = anAx5.Direct(); + anAx5.SetAxis (anAx0_1); + if (bDirect5 != anAx5.Direct()) + { + std::cout << "Error: coordinate system is reversed\n"; + return 1; + } + // + gp_Ax1 anAx0_2 (gp::Origin(), -gp::DX()); + Standard_Boolean bDirect6 = anAx6.Direct(); + anAx6.SetAxis (anAx0_1); + if (bDirect6 != anAx6.Direct()) + { + std::cout << "Error: coordinate system is reversed\n"; + return 1; + } + return 0; +} + void QABugs::Commands_20(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -2798,5 +2858,6 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) { theCommands.Add("OCC28131", "OCC28131 name: creates face problematic for offset", __FILE__, OCC28131, group); theCommands.Add("OCC29289", "OCC29289 : searching trigonometric root by Newton iterations", __FILE__, OCC29289, group); theCommands.Add ("OCC29371", "OCC29371", __FILE__, OCC29371, group); + theCommands.Add ("OCC29406", "OCC29406", __FILE__, OCC29406, group); return; } diff --git a/src/gp/gp_Ax3.lxx b/src/gp/gp_Ax3.lxx index 2b4fe6d91a..2b501f24f2 100644 --- a/src/gp/gp_Ax3.lxx +++ b/src/gp/gp_Ax3.lxx @@ -45,19 +45,49 @@ inline void gp_Ax3::ZReverse() inline void gp_Ax3::SetAxis(const gp_Ax1& A1) { Standard_Boolean direct = Direct(); - axis = A1; - vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction()); - if(direct) { vydir = axis.Direction().Crossed(vxdir); } - else { vydir = vxdir.Crossed(axis.Direction()); } + Standard_Real dot = A1.Direction().Dot(vxdir); + if(Abs(Abs(dot) - 1.) <= Precision::Angular()) + { + if(dot > 0) + { + vxdir = vydir; + vydir = axis.Direction(); + } + else + vxdir = axis.Direction(); + axis = A1; + } + else + { + axis = A1; + vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction()); + if(direct) { vydir = axis.Direction().Crossed(vxdir); } + else { vydir = vxdir.Crossed(axis.Direction()); } + } } inline void gp_Ax3::SetDirection(const gp_Dir& V) { - Standard_Boolean direct = Direct(); - axis.SetDirection (V); - vxdir = V.CrossCrossed (vxdir, V); - if (direct) { vydir = V.Crossed (vxdir); } - else { vydir = vxdir.Crossed (V); } + Standard_Boolean direct = Direct(); + Standard_Real dot = V.Dot(vxdir); + if(Abs(Abs(dot) - 1.) <= Precision::Angular()) + { + if(dot > 0) + { + vxdir = vydir; + vydir = axis.Direction(); + } + else + vxdir = axis.Direction(); + axis.SetDirection(V); + } + else + { + axis.SetDirection (V); + vxdir = V.CrossCrossed (vxdir, V); + if (direct) { vydir = V.Crossed (vxdir); } + else { vydir = vxdir.Crossed (V); } + } } inline void gp_Ax3::SetLocation(const gp_Pnt& P) diff --git a/tests/bugs/fclasses/bug29406 b/tests/bugs/fclasses/bug29406 new file mode 100644 index 0000000000..917bad3291 --- /dev/null +++ b/tests/bugs/fclasses/bug29406 @@ -0,0 +1,2 @@ +pload QAcommands +OCC29406