]> OCCT Git - occt-copy.git/commitdiff
0029406: Foundation Classes - gp_Ax3 fails setting direction CR29406_1
authorisn <isn@opencascade.com>
Thu, 11 Jan 2018 16:03:03 +0000 (19:03 +0300)
committerisn <isn@opencascade.com>
Mon, 22 Jan 2018 11:02:43 +0000 (14:02 +0300)
Avoid exception in gp_Ax3::SetDirection(), SetAxis(): check if XDir of Ax3 is parallel to newly given direction.

src/QABugs/QABugs_20.cxx
src/gp/gp_Ax3.lxx
tests/bugs/fclasses/bug29406 [new file with mode: 0644]

index 7a5e33bee5b0180690747edfbea80561588f6b9b..584735d87c34a536c5ab0a23253025349c23b64e 100644 (file)
@@ -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 <BRepOffsetAPI_MakePipeShell.hxx>
 #include <GC_MakeArcOfCircle.hxx>
 #include <BRepAdaptor_CompCurve.hxx>
@@ -2836,5 +2875,7 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) {
                               "<result first point> <result last point>",
                               __FILE__, OCC29430, group);
 
+
+  theCommands.Add ("OCC29406", "OCC29406", __FILE__, OCC29406, group);
   return;
 }
index 2b4fe6d91ac28e45ef43d14ed2e9ae9356d3c45b..698e1c126ce71b060b235a4d11472d0bffe7ded8 100644 (file)
@@ -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 (file)
index 0000000..689ccfd
--- /dev/null
@@ -0,0 +1,10 @@
+puts "========"
+puts "OCC29406"
+puts "========"
+puts ""
+#########################################################
+##  Foundation Classes - gp_Ax3 fails setting direction
+#########################################################
+
+pload QAcommands
+OCC29406