From ae52e604b039583ee0e6083f47f18470a566d356 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 19 Dec 2018 18:24:10 +0300 Subject: [PATCH] [Code coverage GeomAPI]: Unit test for Ax1, Ax2, Ax3 --- src/GeomAPI/CMakeLists.txt | 1 + src/GeomAPI/GeomAPI_Ax3.cpp | 4 +- src/GeomAPI/Test/TestAx123.py | 82 +++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/GeomAPI/Test/TestAx123.py diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 88f8aefcb..13a4e7bc8 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -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 diff --git a/src/GeomAPI/GeomAPI_Ax3.cpp b/src/GeomAPI/GeomAPI_Ax3.cpp index 5dd911edf..03c254225 100644 --- a/src/GeomAPI/GeomAPI_Ax3.cpp +++ b/src/GeomAPI/GeomAPI_Ax3.cpp @@ -107,12 +107,12 @@ std::shared_ptr GeomAPI_Ax3::to3D(double theX, double theY) const std::shared_ptr 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(new GeomAPI_Pnt2d(aX, aY)); } diff --git a/src/GeomAPI/Test/TestAx123.py b/src/GeomAPI/Test/TestAx123.py new file mode 100644 index 000000000..51b471e33 --- /dev/null +++ b/src/GeomAPI/Test/TestAx123.py @@ -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 +## + +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) -- 2.30.2