From d8dd9c0d3af77cebf0c93433f59c95b33ecd50f4 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 21 Aug 2017 09:44:39 +0200 Subject: [PATCH] More efficient and elegant grid line creation Since the zero point is always in the centre, we can just re-use this loop to prevent code duplication and gain a minor speed increase. Contributes to issue CURA-4150. --- cura/BuildVolume.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 1530346967..6c18eb07ad 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -301,30 +301,23 @@ class BuildVolume(SceneNode): mb = MeshBuilder() for x in range(0, int(math.ceil(max_w)), MAJOR_GRID_SIZE): mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color) - for x in range(0, int(math.floor(min_w)), -MAJOR_GRID_SIZE): #Start from 0 in both cases, so you need to do this in two for loops. - mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color) + #Start from 0 in both cases, so you need to do this in two for loops. + mb.addLine(Vector(-x, min_h, min_d), Vector(-x, min_h, max_d), color = self._grid_color) for y in range(0, int(math.ceil(max_d)), MAJOR_GRID_SIZE): mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) - for y in range(0, int(math.floor(min_d)), -MAJOR_GRID_SIZE): - mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color) + mb.addLine(Vector(min_w, min_h, -y), Vector(max_w, min_h, -y), color = self._grid_color) #More fine grained grid. for x in range(0, int(math.ceil(max_w)), MINOR_GRID_SIZE): if x % MAJOR_GRID_SIZE == 0: #Don't overlap with the major grid. pass mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color) - for x in range(0, int(math.floor(min_w)), -MINOR_GRID_SIZE): - if x % MAJOR_GRID_SIZE == 0: - pass - mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color) + mb.addLine(Vector(-x, min_h, min_d), Vector(-x, min_h, max_d), color = self._grid_minor_color) for y in range(0, int(math.ceil(max_d)), MINOR_GRID_SIZE): if y % MAJOR_GRID_SIZE == 0: pass mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color) - for y in range(0, int(math.floor(min_d)), -MINOR_GRID_SIZE): - if y % MAJOR_GRID_SIZE == 0: - pass - mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color) + mb.addLine(Vector(min_w, min_h, -y), Vector(max_w, min_h, -y), color = self._grid_minor_color) self._grid_mesh = mb.build()