From 9ec88feabc5616a265878c7be217925bdaaf2894 Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Thu, 12 Sep 2024 11:27:55 +0200 Subject: [PATCH] Draft: fix division by zero and count is zero for path arrays Fixes #16468. --- src/Mod/Draft/draftgeoutils/geo_arrays.py | 8 ++++++-- src/Mod/Draft/draftobjects/patharray.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Mod/Draft/draftgeoutils/geo_arrays.py b/src/Mod/Draft/draftgeoutils/geo_arrays.py index 13173fb015..dee2ba3d52 100644 --- a/src/Mod/Draft/draftgeoutils/geo_arrays.py +++ b/src/Mod/Draft/draftgeoutils/geo_arrays.py @@ -64,8 +64,9 @@ def get_init_values(path, count=6): edge = path.Shape.Edges[0] edge_length = edge.Length - step = edge_length / (count - 1) - inc = 360 / (count - 1) + n = (count - 1) if count > 1 else 1 + step = edge_length / n + inc = 360 / n return norm, edge, step, inc @@ -84,6 +85,9 @@ def get_n_params(edge, number, step, norm): def get_twisted_placements(path, count=15, rot_factor=0.25): """Get the placements of the twisted array elements.""" + if count < 1: + count = 1 + (norm, edge, step, inc) = get_init_values(path, count) diff --git a/src/Mod/Draft/draftobjects/patharray.py b/src/Mod/Draft/draftobjects/patharray.py index 7a67b19fa9..79466a5796 100644 --- a/src/Mod/Draft/draftobjects/patharray.py +++ b/src/Mod/Draft/draftobjects/patharray.py @@ -475,14 +475,19 @@ def placements_on_path(shapeRotation, pathwire, count, xlate, align, end = endOffset cdist = cdist - start - end - step = cdist / (count if (DraftGeomUtils.isReallyClosed(pathwire) and not (start or end)) else count - 1) + if count < 1: + count = 1 + n = count if (DraftGeomUtils.isReallyClosed(pathwire) and not (start or end)) else count - 1 + if n == 0: + n = 1 + step = cdist / n remains = 0 travel = start placements = [] - for i in range(0, count): + for i in range(count): # which edge in path should contain this shape? - for j in range(0, len(ends)): + for j in range(len(ends)): if travel <= ends[j]: iend = j remains = ends[iend] - travel