From 95cffaf502b0a9d2016ae6d8234bc2d6789305c4 Mon Sep 17 00:00:00 2001 From: Russell Johnson <47639332+Russ4262@users.noreply.github.com> Date: Sat, 19 Mar 2022 22:20:29 -0500 Subject: [PATCH] Path: Simplify changes per developer conversations Also update TestPathDepthParams.py to reflect simplification of changes. Remove some comments. Employ `sorted()` function per MLampert suggestion --- src/Mod/Path/PathScripts/PathUtils.py | 62 ++----------------- src/Mod/Path/PathTests/TestPathDepthParams.py | 50 +-------------- 2 files changed, 9 insertions(+), 103 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathUtils.py b/src/Mod/Path/PathScripts/PathUtils.py index 6c29871bdb..7914c0a54c 100644 --- a/src/Mod/Path/PathScripts/PathUtils.py +++ b/src/Mod/Path/PathScripts/PathUtils.py @@ -609,11 +609,7 @@ class depth_params(object): self.__step_down = math.fabs(step_down) self.__z_finish_step = math.fabs(z_finish_step) self.__final_depth = final_depth - self.__user_depths = ( - None - if user_depths is None - else self.__filter_roughly_equal_depths(user_depths) - ) + self.__user_depths = user_depths self.data = self.__get_depths(equalstep=equalstep) self.index = 0 @@ -737,60 +733,14 @@ class depth_params(object): to be removed, so as to eliminate an effective step-down depth with the removal of repetitive roughly-equal values.""" - depthcopy = depths.copy() #make a copy so we don't touch original - depthcopy.reverse() # reverse it low to high - keep = [depthcopy[0]] # initialize keep list with first element - for depth in depthcopy[1:]: # iterate the list from second element on - if not PathGeom.isRoughly(depth, keep[-1]): #Compare each to the last kept item - keep.append(depth) # if different, add to keep + depthcopy = sorted(depths) # make a copy and sort low to high + keep = [depthcopy[0]] + for depth in depthcopy[1:]: + if not PathGeom.isRoughly(depth, keep[-1]): + keep.append(depth) keep.reverse() # reverse results back high to low return keep - # if len(depths) == 2: - # if PathGeom.isRoughly(depths[0], depths[1]): - # return [depths[1]] - # return depths - - # # print("raw depths: {}".format(depths)) - - # uniqueDepths = depths - # lastDepth = None - # maxLoops = 0 - # while maxLoops < 10: - # # print("\nStart scan... uniqueDepths: {}".format(uniqueDepths)) - # stop = True - # keep = [] - # # Filter out unique values from consecutive pairs - # for i in range(0, len(uniqueDepths) - 1): - # dep1 = uniqueDepths[i] - # dep2 = uniqueDepths[i + 1] - # # print("comparing: {} and {}".format(dep1, dep2)) - # # print("lastDepth: {}".format(lastDepth)) - - # if PathGeom.isRoughly(dep1, dep2): - # if PathGeom.isRoughly(lastDepth, dep2): - # keep.pop() - # keep.append(dep2) - # # Cycle again if a roughly-equal pair is found - # stop = False - # else: - # if lastDepth is None: - # keep.append(dep1) - # else: - # if not PathGeom.isRoughly(lastDepth, dep1): - # keep.append(dep1) - # keep.append(dep2) - - # lastDepth = dep2 - # # Efor - # uniqueDepths = keep - # maxLoops += 1 - # if stop: - # break - - # # print("uniqueDepths: {}".format(uniqueDepths)) - # return uniqueDepths - def __equal_steps(self, start, stop, max_size): """returns a list of depths beginning with the bottom (included), ending with the top (not included). diff --git a/src/Mod/Path/PathTests/TestPathDepthParams.py b/src/Mod/Path/PathTests/TestPathDepthParams.py index e334dbe18c..a8ccd95579 100644 --- a/src/Mod/Path/PathTests/TestPathDepthParams.py +++ b/src/Mod/Path/PathTests/TestPathDepthParams.py @@ -252,60 +252,16 @@ class depthTestCases(unittest.TestCase): r, expected, "Expected {}, but result of {}".format(expected, r) ) - def test011(self): - """two custom user depths roughly equal to final depth""" args = { "clearance_height": 20.0, "safe_height": 15.0, - "start_depth": 9.0, - "step_down": 3.0, + "start_depth": 10.0, + "step_down": 9.9999999, "z_finish_step": 0.0, "final_depth": 0.0, - "user_depths": [0.00000001, 0.0], + "user_depths": None, } - expected = [0] - - d = PathUtils.depth_params(**args) - r = [i for i in d] - self.assertListEqual( - r, expected, "Expected {}, but result of {}".format(expected, r) - ) - - def test012(self): - """four custom user depths with two roughly equal included""" - args = { - "clearance_height": 20.0, - "safe_height": 15.0, - "start_depth": 9.0, - "step_down": 3.0, - "z_finish_step": 0.0, - "final_depth": 0.0, - "user_depths": [6.0, 3.00000001, 3.0, 0.0], - } - - expected = [6.0, 3.0, 0.0] - - d = PathUtils.depth_params(**args) - r = [i for i in d] - self.assertListEqual( - r, expected, "Expected {}, but result of {}".format(expected, r) - ) - - def test013(self): - """five custom user depths with three roughly equal included""" - args = { - "clearance_height": 20.0, - "safe_height": 15.0, - "start_depth": 9.0, - "step_down": 3.0, - "z_finish_step": 0.0, - "final_depth": 0.0, - "user_depths": [6.0, 3.00000002, 3.00000001, 3.0, 0.0], - } - - expected = [6.0, 3.0, 0.0] - d = PathUtils.depth_params(**args) r = [i for i in d] self.assertListEqual(