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.
This commit is contained in:
Ghostkeeper 2017-08-21 09:44:39 +02:00
parent e7c5854694
commit d8dd9c0d3a
No known key found for this signature in database
GPG Key ID: C5F96EE2BC0F7E75

View File

@ -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()