From 165b52d9672d37f4bb738d9edb5c6cd0bd728a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20B=C3=A4hr?= Date: Sun, 26 Sep 2021 23:23:27 +0200 Subject: [PATCH] Speedup the double helical gear generation significantly It turned out that the "moving up" of the gear shape was responsible for the majority of processing time: it took 10x longer then the pipe creation and 100x longer then the mirroring. Now the moving is done of the helix and base face so that the other faces are generated directly where they should be, thus preventing a movement of all of them. In addition, as we don't have to transform the final shape, we don't have to use transformGeometry, but just change the placement via translate -- again much faster. --- freecad/gears/features.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/freecad/gears/features.py b/freecad/gears/features.py index ab19f03..33da1b7 100644 --- a/freecad/gears/features.py +++ b/freecad/gears/features.py @@ -1430,6 +1430,8 @@ def helicalextrusion(face, height, angle, double_helix=False): direction = bool(angle < 0) if double_helix: spine = Part.makeHelix(pitch, height / 2.0, radius, cone_angle, direction) + spine.translate(App.Vector(0, 0, height / 2.0)) + face = face.translated(App.Vector(0, 0, height / 2.0)) # don't transfrom our argument else: spine = Part.makeHelix(pitch, height, radius, cone_angle, direction) def make_pipe(path, profile): @@ -1450,24 +1452,18 @@ def helicalextrusion(face, height, angle, double_helix=False): top_face = Part.Face(top_wires) shell_faces.append(top_face) if double_helix: - origin = App.Vector(0, 0, 0) + origin = App.Vector(0, 0, height / 2.0) xy_normal = App.Vector(0, 0, 1) mirror_xy = lambda f: f.mirror(origin, xy_normal) bottom_faces = list(map(mirror_xy, shell_faces)) shell_faces.extend(bottom_faces) - matrix = App.Matrix() - matrix.move(App.Vector(0, 0, height / 2.0)) - move_up = lambda f: f.transformGeometry(matrix) - shell_faces = list(map(move_up, shell_faces)) + # TODO: why the heck is makeShell from this empty after mirroring? + # ... and why the heck does it work when making an intermediate compound??? + hacky_intermediate_compound = Part.makeCompound(shell_faces) + shell_faces = hacky_intermediate_compound.Faces else: shell_faces.append(face) # the bottom is what we extruded shell = Part.makeShell(shell_faces) - # TODO: why the heck is this shell empty if double_helix??? - if len(shell.Faces) == 0: - # ... and why the heck does it work when making an intermediate compound??? - hacky_intermediate_compound = Part.makeCompound(shell_faces) - shell = Part.makeShell(hacky_intermediate_compound.Faces) - App.Console.PrintMessage(f"shell.Faces from compound: {len(shell.Faces)}\n") #shell.sewShape() # fill gaps that may result from accumulated tolerances. Needed? #shell = shell.removeSplitter() # refine. Needed? return Part.makeSolid(shell)