From 7bdbef9da526f872b1798e03ab81809147d2d492 Mon Sep 17 00:00:00 2001 From: isn Date: Thu, 11 Jan 2018 19:03:03 +0300 Subject: [PATCH] 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. --- src/QABugs/QABugs_20.cxx | 41 ++++++++++++++++++++++++++++++++++++ src/gp/gp_Ax3.lxx | 32 +++++++++++++++++++--------- tests/bugs/fclasses/bug29406 | 10 +++++++++ 3 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 tests/bugs/fclasses/bug29406 diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index 7a5e33bee5..584735d87c 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -2768,6 +2768,45 @@ static Standard_Integer OCC29371 (Draw_Interpretor& di, Standard_Integer n, cons return 0; } +static void CheckAx3Dir(gp_Ax3& theAx, const gp_Dir& theDir ) +{ + Standard_Boolean bDirect = theAx.Direct(); + theAx.SetDirection (theDir); + if (bDirect != theAx.Direct()) + std::cout << "Error: coordinate system is reversed\n"; + if (!theDir.IsEqual(theAx.Direction(), Precision::Angular())) + std::cout << "Error: main dir was not set properly\n"; +} + +static void CheckAx3Ax1(gp_Ax3& theAx, const gp_Ax1& theAx0 ) +{ + Standard_Boolean bDirect = theAx.Direct(); + theAx.SetAxis (theAx0); + if (bDirect != theAx.Direct()) + std::cout << "Error: coordinate system is reversed\n"; + if (!theAx0.Direction().IsEqual(theAx.Direction(), Precision::Angular())) + std::cout << "Error: main dir was not set properly\n"; +} + +static Standard_Integer OCC29406 (Draw_Interpretor&, Standard_Integer, const char**) +{ + gp_Ax3 anAx1, anAx2, anAx3, anAx4, anAx5, anAx6;; + anAx3.ZReverse(); + anAx4.ZReverse(); + // + CheckAx3Dir(anAx1, gp::DX()); + CheckAx3Dir(anAx2, -gp::DX()); + CheckAx3Dir(anAx3, gp::DX()); + CheckAx3Dir(anAx4, -gp::DX()); + // + gp_Ax1 anAx0_1 (gp::Origin(), gp::DX()); + gp_Ax1 anAx0_2 (gp::Origin(), -gp::DX()); + // + CheckAx3Ax1(anAx5, anAx0_1); + CheckAx3Ax1(anAx6, anAx0_2); + return 0; +} + #include #include #include @@ -2836,5 +2875,7 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) { " ", __FILE__, OCC29430, 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..698e1c126c 100644 --- a/src/gp/gp_Ax3.lxx +++ b/src/gp/gp_Ax3.lxx @@ -44,20 +44,32 @@ 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()); } + axis.SetLocation(A1.Location()); + SetDirection(A1.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_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 + { + Standard_Boolean direct = Direct(); + 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..689ccfd425 --- /dev/null +++ b/tests/bugs/fclasses/bug29406 @@ -0,0 +1,10 @@ +puts "========" +puts "OCC29406" +puts "========" +puts "" +######################################################### +## Foundation Classes - gp_Ax3 fails setting direction +######################################################### + +pload QAcommands +OCC29406 -- 2.39.5