From 52845b8c4cf0e777217dda047db6df31f7cc8838 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 24 Aug 2022 14:37:10 +0200 Subject: [PATCH] Surface: add unit test for blend curve --- src/Mod/Surface/CMakeLists.txt | 16 +++- src/Mod/Surface/Init.py | 2 + .../Surface/SurfaceTests/TestBlendCurve.py | 75 +++++++++++++++++++ src/Mod/Surface/SurfaceTests/__init__.py | 0 src/Mod/Surface/TestSurfaceApp.py | 24 ++++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/Mod/Surface/SurfaceTests/TestBlendCurve.py create mode 100644 src/Mod/Surface/SurfaceTests/__init__.py create mode 100644 src/Mod/Surface/TestSurfaceApp.py diff --git a/src/Mod/Surface/CMakeLists.txt b/src/Mod/Surface/CMakeLists.txt index ce0575e0f1..a11faa20c0 100644 --- a/src/Mod/Surface/CMakeLists.txt +++ b/src/Mod/Surface/CMakeLists.txt @@ -6,6 +6,12 @@ endif(BUILD_GUI) set(Surface_Scripts Init.py + TestSurfaceApp.py +) + +set(Surface_TestScripts + SurfaceTests/__init__.py + SurfaceTests/TestBlendCurve.py ) if(BUILD_GUI) @@ -13,13 +19,14 @@ if(BUILD_GUI) endif(BUILD_GUI) add_custom_target(SurfaceScripts ALL - SOURCES ${Surface_Scripts} + SOURCES ${Surface_Scripts} ${Surface_TestScripts} ) fc_target_copy_resource(SurfaceScripts ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/Mod/Surface ${Surface_Scripts} + ${Surface_TestScripts} ) install( @@ -28,3 +35,10 @@ install( DESTINATION Mod/Surface ) + +install( + FILES + ${Surface_TestScripts} + DESTINATION + Mod/Surface/SurfaceTests +) diff --git a/src/Mod/Surface/Init.py b/src/Mod/Surface/Init.py index 0fa131610a..605013d32d 100644 --- a/src/Mod/Surface/Init.py +++ b/src/Mod/Surface/Init.py @@ -1,2 +1,4 @@ # FreeCAD init script of the Surface module # (c) 2001 Juergen Riegel LGPL + +FreeCAD.__unit_test__ += ["TestSurfaceApp"] diff --git a/src/Mod/Surface/SurfaceTests/TestBlendCurve.py b/src/Mod/Surface/SurfaceTests/TestBlendCurve.py new file mode 100644 index 0000000000..0840ec8db8 --- /dev/null +++ b/src/Mod/Surface/SurfaceTests/TestBlendCurve.py @@ -0,0 +1,75 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2022 Werner Mayer * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "Surface unit tests" +__author__ = "Werner Mayer" +__url__ = "https://www.freecadweb.org" + +import sys +import unittest +from os.path import join + +import FreeCAD +from FreeCAD import Base +import Surface + +vec = Base.Vector + + +class TestBlendCurve(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + def assertAlmostCoincide(self, pt1, pt2, places=None, msg=None, delta=None): + self.assertAlmostEqual(pt1.x, pt2.x, places, msg, delta) + self.assertAlmostEqual(pt1.y, pt2.y, places, msg, delta) + self.assertAlmostEqual(pt1.z, pt2.z, places, msg, delta) + + def test_blend_curve(self): + # Create C0 BlendPoint at origin + b1 = Surface.BlendPoint() + # Create G1 BlendPoint + b2 = Surface.BlendPoint([vec(10,3,6), vec(2,5,6)]) + # BlendCurve between the two BlendPoints + bc = Surface.BlendCurve(b1, b2) + # Compute the interpolating BezierCurve + curve1 = bc.compute() + + # Create G2 BlendPoint at the end of previous BlendCurve + b1 = Surface.BlendPoint(curve1.toShape(), 1, 2) + # Create G1 BlendPoint + b2 = Surface.BlendPoint([vec(5,6,2), vec(2,5,6)]) + + bc = Surface.BlendCurve(b1, b2) + # Compute the interpolating BezierCurve + curve2 = bc.compute() + + d1 = curve1.getD2(1) + d2 = curve2.getD2(0) + + self.assertEqual(len(d1), len(d2)) + self.assertAlmostCoincide(d1[0], d2[0]) + self.assertAlmostCoincide(d1[1], d2[1]) + self.assertAlmostCoincide(d1[2], d2[2]) diff --git a/src/Mod/Surface/SurfaceTests/__init__.py b/src/Mod/Surface/SurfaceTests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Mod/Surface/TestSurfaceApp.py b/src/Mod/Surface/TestSurfaceApp.py new file mode 100644 index 0000000000..2b77c3fee5 --- /dev/null +++ b/src/Mod/Surface/TestSurfaceApp.py @@ -0,0 +1,24 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2022 Werner Mayer * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +# Unit test for the Surface module +from SurfaceTests.TestBlendCurve import TestBlendCurve