From 531e9143f427cb98e967ce76996fc1eea1561a8e Mon Sep 17 00:00:00 2001 From: jim Date: Sat, 1 Jan 2022 19:59:24 -0800 Subject: [PATCH 1/2] Correct typo in jitter dimension calculation --- src/Mod/Path/PathScripts/PathArray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Path/PathScripts/PathArray.py b/src/Mod/Path/PathScripts/PathArray.py index d8bc7093c6..e193f3d6f7 100644 --- a/src/Mod/Path/PathScripts/PathArray.py +++ b/src/Mod/Path/PathScripts/PathArray.py @@ -231,7 +231,7 @@ class PathArray: if self.jitterPercent == 0: pass elif random.randint(0,100) < self.jitterPercent: - pos.x = pos.x + random.uniform(-self.jitterMagnitude.x, self.jitterMagnitude.y) + pos.x = pos.x + random.uniform(-self.jitterMagnitude.x, self.jitterMagnitude.x) pos.y = pos.y + random.uniform(-self.jitterMagnitude.y, self.jitterMagnitude.y) pos.z = pos.z + random.uniform(-self.jitterMagnitude.z, self.jitterMagnitude.z) return pos From ba4f1b443bfd32afbf3ee4691105fa03f302c608 Mon Sep 17 00:00:00 2001 From: jim Date: Sun, 2 Jan 2022 07:38:56 -0800 Subject: [PATCH 2/2] allow user to specify a seed value for jitter pseudorandomness so that multiple operations/tools can follow the same sequence --- src/Mod/Path/PathScripts/PathArray.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Mod/Path/PathScripts/PathArray.py b/src/Mod/Path/PathScripts/PathArray.py index e193f3d6f7..7c150984c2 100644 --- a/src/Mod/Path/PathScripts/PathArray.py +++ b/src/Mod/Path/PathScripts/PathArray.py @@ -60,6 +60,8 @@ class ObjectArray: "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","Percent of copies to randomly offset")) obj.addProperty("App::PropertyVectorDistance", "JitterMagnitude", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","Maximum random offset of copies")) + obj.addProperty("App::PropertyInteger", "JitterSeed", + "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","Seed value for jitter randomness")) obj.addProperty("App::PropertyLink", "ToolController", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "The tool controller that will be used to calculate the path")) obj.addProperty("App::PropertyBool", "Active", @@ -88,6 +90,11 @@ class ObjectArray: angleMode = copiesMode = centreMode = 0 copiesXMode = copiesYMode = offsetMode = swapDirectionMode = 2 + if not hasattr(obj, "JitterSeed"): + obj.addProperty("App::PropertyInteger", "JitterSeed", + "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","Seed value for jitter randomness")) + obj.JitterSeed = 0 + obj.setEditorMode('Angle', angleMode) obj.setEditorMode('Copies', copiesMode) obj.setEditorMode('Centre', centreMode) @@ -97,6 +104,7 @@ class ObjectArray: obj.setEditorMode('SwapDirection', swapDirectionMode) obj.setEditorMode('JitterPercent', 0) obj.setEditorMode('JitterMagnitude', 0) + obj.setEditorMode('JitterSeed', 0) obj.setEditorMode('ToolController', 2) def onChanged(self, obj, prop): @@ -190,9 +198,12 @@ class ObjectArray: obj.Path = Path.Path() return + # use seed if specified, otherwise default to object name for consistency during recomputes + seed = obj.JitterSeed or obj.Name + pa = PathArray(obj.Base, obj.Type, obj.Copies, obj.Offset, obj.CopiesX, obj.CopiesY, obj.Angle, obj.Centre, obj.SwapDirection, - obj.JitterMagnitude, obj.JitterPercent, obj.Name) + obj.JitterMagnitude, obj.JitterPercent, seed) obj.Path = pa.getPath()