Salome HOME
[Code coverage GeomAPI]: Unit test for Ax1, Ax2, Ax3
authorazv <azv@opencascade.com>
Wed, 19 Dec 2018 15:24:10 +0000 (18:24 +0300)
committerazv <azv@opencascade.com>
Wed, 19 Dec 2018 15:24:10 +0000 (18:24 +0300)
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Ax3.cpp
src/GeomAPI/Test/TestAx123.py [new file with mode: 0644]

index 88f8aefcbf47ab8b87730af011ce54d757524c48..13a4e7bc834985e8f8dce16e3988d802393bd10a 100644 (file)
@@ -160,6 +160,7 @@ INSTALL(TARGETS GeomAPI DESTINATION ${SHAPER_INSTALL_BIN})
 INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION ${SHAPER_INSTALL_SWIG})
 
 ADD_UNIT_TESTS(
+  TestAx123.py
   TestBox.py
   TestCone.py
   TestCylinder.py
index 5dd911edf7e10f1d508a43d38ecfbb4223da46bb..03c25422567f810993e3930adf49cd13e7939f80 100644 (file)
@@ -107,12 +107,12 @@ std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::to3D(double theX, double theY) const
 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const
 {
   gp_Pnt anOriginPnt = MY_AX3->Axis().Location();
-  gp_Vec aVec(anOriginPnt, gp_Pnt(0, 0, 0));
+  gp_Vec aVec(anOriginPnt, gp_Pnt(theX, theY, theZ));
 
   gp_Dir aXDir = MY_AX3->XDirection();
   gp_Dir aYDir = MY_AX3->YDirection();
 
   double aX = aVec.X() * aXDir.X() + aVec.Y() * aXDir.Y() + aVec.Z() * aXDir.Z();
-  double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Y();
+  double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Z();
   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
 }
diff --git a/src/GeomAPI/Test/TestAx123.py b/src/GeomAPI/Test/TestAx123.py
new file mode 100644 (file)
index 0000000..51b471e
--- /dev/null
@@ -0,0 +1,82 @@
+## Copyright (C) 2018-20xx  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+import math
+
+from GeomAPI import *
+
+TOLERANCE = 1.e-7
+
+origin = GeomAPI_Pnt(10, 0, 0)
+dir = GeomAPI_Dir(1, 0, 0)
+
+# Test GeomAPI_Ax1
+ax1 = GeomAPI_Ax1()
+ax1.setOrigin(origin)
+ax1.setDir(dir)
+assert(ax1.origin().distance(origin) < TOLERANCE)
+assert(math.fabs(ax1.dir().dot(dir) - 1.) < TOLERANCE)
+
+ax1.reverse()
+ax1 = ax1.reversed()
+assert(ax1.origin().distance(origin) < TOLERANCE)
+assert(math.fabs(ax1.dir().dot(dir) - 1.) < TOLERANCE)
+
+
+# Test GeomAPI_Ax2
+ax2 = GeomAPI_Ax2()
+ax2.setOrigin(origin)
+ax2.setDir(dir)
+assert(ax2.origin().distance(origin) < TOLERANCE)
+assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
+
+ax2 = GeomAPI_Ax2(origin, dir)
+assert(ax2.origin().distance(origin) < TOLERANCE)
+assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
+
+dx = GeomAPI_Dir(0, 1, 0)
+ax2 = GeomAPI_Ax2(origin, dir, dx)
+assert(ax2.origin().distance(origin) < TOLERANCE)
+assert(math.fabs(ax2.dir().dot(dir) - 1.) < TOLERANCE)
+
+
+# Test GeomAPI_Ax3
+dy = GeomAPI_Dir(0, 0, 1)
+ax3 = GeomAPI_Ax3()
+ax3.setOrigin(origin)
+ax3.setNormal(dy)
+ax3.setDirX(dir)
+ax3.setDirY(dx)
+assert(ax3.origin().distance(origin) < TOLERANCE)
+assert(math.fabs(ax3.normal().dot(dy) - 1.) < TOLERANCE)
+assert(math.fabs(ax3.dirX().dot(dir) - 1.) < TOLERANCE)
+assert(math.fabs(ax3.dirY().dot(dx) - 1.) < TOLERANCE)
+
+ax3 = GeomAPI_Ax3(origin, dx, dir)
+assert(ax3.origin().distance(origin) < TOLERANCE)
+assert(math.fabs(ax3.normal().dot(dir) - 1.) < TOLERANCE)
+assert(math.fabs(ax3.dirX().dot(dx) - 1.) < TOLERANCE)
+assert(math.fabs(ax3.dirY().dot(dy) - 1.) < TOLERANCE)
+
+p2d = GeomAPI_Pnt2d(1, 2)
+a2d = ax3.to2D(origin.x() + dx.x() * p2d.x() + dy.x() * p2d.y(),
+               origin.y() + dx.y() * p2d.x() + dy.y() * p2d.y(),
+               origin.z() + dx.z() * p2d.x() + dy.z() * p2d.y())
+assert(a2d.distance(p2d) < TOLERANCE)