diff --git a/src/Mod/Path/PathScripts/PathUtils.py b/src/Mod/Path/PathScripts/PathUtils.py index 5152ae044a..8e5c1e0b42 100644 --- a/src/Mod/Path/PathScripts/PathUtils.py +++ b/src/Mod/Path/PathScripts/PathUtils.py @@ -788,8 +788,6 @@ class depth_params(object): def __init__(self, clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths=None, equalstep=False): '''self, clearance_height, safe_height, start_depth, step_down, z_finish_depth, final_depth, [user_depths=None], equalstep=False''' - if z_finish_step > step_down: - raise ValueError('z_finish_step must be less than step_down') self.__clearance_height = clearance_height self.__safe_height = safe_height @@ -801,6 +799,9 @@ class depth_params(object): self.data = self.__get_depths(equalstep=equalstep) self.index = 0 + if self.__z_finish_step > self.__step_down: + raise ValueError('z_finish_step must be less than step_down') + def __iter__(self): self.index = 0 return self diff --git a/src/Mod/Path/PathTests/TestPathDepthParams.py b/src/Mod/Path/PathTests/TestPathDepthParams.py index 3dfa419e7f..fed0779fc8 100644 --- a/src/Mod/Path/PathTests/TestPathDepthParams.py +++ b/src/Mod/Path/PathTests/TestPathDepthParams.py @@ -26,151 +26,188 @@ import unittest class depthTestCases(unittest.TestCase): def test00(self): - '''Stepping down to zero ''' - clearance_height= 15 - safe_height = 12 + """Stepping down to zero""" + args = { + "clearance_height": 15, + "safe_height": 12, + "start_depth": 10, + "step_down": 2, + "z_finish_step": 1, + "final_depth": 0, + "user_depths": None, + } - start_depth = 10 - step_down = 2 - z_finish_step = 1 - final_depth = 0 - user_depths = None + expected = [8, 6, 4, 2, 1, 0] - expected =[8,6,4,2,1,0] - - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) + self.assertListEqual(r, expected) def test10(self): - '''Stepping from zero to a negative depth ''' + """Stepping from zero to a negative depth""" - clearance_height= 10 - safe_height = 5 + args = { + "clearance_height": 10, + "safe_height": 5, + "start_depth": 0, + "step_down": 2, + "z_finish_step": 0, + "final_depth": -10, + "user_depths": None, + } - start_depth = 0 - step_down = 2 - z_finish_step = 0 - final_depth = -10 - user_depths = None + expected = [-2, -4, -6, -8, -10] - expected =[-2, -4, -6, -8, -10] - - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) + self.assertListEqual(r, expected) def test20(self): - '''Start and end are equal or start lower than finish ''' - clearance_height= 15 - safe_height = 12 + """Start and end are equal or start lower than finish""" - start_depth = 10 - step_down = 2 - z_finish_step = 0 - final_depth = 10 - user_depths = None + args = { + "clearance_height": 15, + "safe_height": 12, + "start_depth": 10, + "step_down": 2, + "z_finish_step": 0, + "final_depth": 10, + "user_depths": None, + } + expected = [10] - expected =[10] - - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) + self.assertListEqual(r, expected) - start_depth = 10 - final_depth = 15 + args["start_depth"] = 10 + args["final_depth"] = 15 - expected =[] + expected = [] - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) + self.assertListEqual(r, expected) def test30(self): - '''User Parameters passed in''' - clearance_height= 10 - safe_height = 5 + """User Parameters passed in""" + args = { + "clearance_height": 10, + "safe_height": 5, + "start_depth": 0, + "step_down": 2, + "z_finish_step": 0, + "final_depth": -10, + "user_depths": [2, 4, 8, 10, 11, 12], + } - start_depth = 0 - step_down = 2 - z_finish_step = 0 - final_depth = -10 - user_depths = [2, 4, 8, 10, 11, 12] + expected = [2, 4, 8, 10, 11, 12] - expected =[2, 4, 8, 10, 11, 12] - - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) + self.assertListEqual(r, expected) def test40(self): - '''z_finish_step passed in.''' - clearance_height= 10 - safe_height = 5 + """z_finish_step passed in.""" + args = { + "clearance_height": 10, + "safe_height": 5, + "start_depth": 0, + "step_down": 2, + "z_finish_step": 1, + "final_depth": -10, + "user_depths": None, + } - start_depth = 0 - step_down = 2 - z_finish_step = 1 - final_depth = -10 - user_depths = None + expected = [-2, -4, -6, -8, -9, -10] - expected =[-2, -4, -6, -8, -9, -10] - - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) - + self.assertListEqual(r, expected) def test50(self): - '''stepping down with equalstep=True''' - clearance_height= 10 - safe_height = 5 + """stepping down with equalstep=True""" + args = { + "clearance_height": 10, + "safe_height": 5, + "start_depth": 10, + "step_down": 3, + "z_finish_step": 0, + "final_depth": 0, + "user_depths": None, + "equalstep": True, + } - start_depth = 10 - step_down = 3 - z_finish_step = 0 - final_depth = 0 - user_depths = None + expected = [7.5, 5.0, 2.5, 0] - expected =[7.5, 5.0, 2.5, 0] - - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths, equalstep=True) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) - + self.assertListEqual(r, expected) def test60(self): - '''stepping down with equalstep=True and a finish depth''' - clearance_height= 10 - safe_height = 5 + """stepping down with equalstep=True and a finish depth""" + args = { + "clearance_height": 10, + "safe_height": 5, + "start_depth": 10, + "step_down": 3, + "z_finish_step": 1, + "final_depth": 0, + "user_depths": None, + } - start_depth = 10 - step_down = 3 - z_finish_step = 1 - final_depth = 0 - user_depths = None + expected = [7.0, 4.0, 1.0, 0] - expected =[7.0, 4.0, 1.0, 0] - - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths, equalstep=True) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) + self.assertListEqual(r, expected) def test70(self): - '''stepping down with stepdown greater than total depth''' - clearance_height= 10 - safe_height = 5 + """stepping down with stepdown greater than total depth""" + args = { + "clearance_height": 10, + "safe_height": 5, + "start_depth": 10, + "step_down": 20, + "z_finish_step": 1, + "final_depth": 0, + "user_depths": None, + } - start_depth = 10 - step_down = 20 - z_finish_step = 1 - final_depth = 0 - user_depths = None + expected = [1.0, 0] - expected =[1.0, 0] - - d = PathUtils.depth_params(clearance_height, safe_height, start_depth, step_down, z_finish_step, final_depth, user_depths) + d = PathUtils.depth_params(**args) r = [i for i in d] - self.assertListEqual (r, expected) + self.assertListEqual(r, expected) + def test80(self): + """Test handling of negative step-down, negative finish step, and relative size of step/finish""" + # negative steps should be converted to positive values + args = { + "clearance_height": 3, + "safe_height": 3, + "start_depth": 2, + "step_down": -1, + "z_finish_step": -1, + "final_depth": 0, + "user_depths": None, + } + + expected = [1.0, 0] + + d = PathUtils.depth_params(**args) + r = [i for i in d] + self.assertListEqual(r, expected) + + # a step_down less than the finish step is an error + args = { + "clearance_height": 3, + "safe_height": 3, + "start_depth": 2, + "step_down": 0.1, + "z_finish_step": 1, + "final_depth": 0, + "user_depths": None, + } + self.assertRaises(ValueError, PathUtils.depth_params, **args)