summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2017-12-31 22:38:15 -0500
committerLex Neva <github.com@lexneva.name>2017-12-31 22:38:15 -0500
commit75241f5f9ddb1e48744878e987136224f9526845 (patch)
tree0b484a56a67581cef747b8111e0122d11dffbbb5
parentfd4d19bf8dd04a978a6cad4d89949f3c08a1cd78 (diff)
trim unnecessary whitespace
-rw-r--r--embroider_simulate.py44
1 files changed, 39 insertions, 5 deletions
diff --git a/embroider_simulate.py b/embroider_simulate.py
index 6fdff57c..0bee6327 100644
--- a/embroider_simulate.py
+++ b/embroider_simulate.py
@@ -53,6 +53,7 @@ class EmbroiderySimulator(wx.Frame):
else:
return
+ self.trim_margins()
self.width, self.height = self.get_dimensions()
def adjust_speed(self, duration):
@@ -159,15 +160,48 @@ class EmbroiderySimulator(wx.Frame):
return segments
+ def all_coordinates(self):
+ for segment in self.segments:
+ start, end = segment[0]
+
+ yield start
+ yield end
+
+ def trim_margins(self):
+ """remove any unnecessary whitespace around the design"""
+
+ min_x = sys.maxint
+ min_y = sys.maxint
+
+ for x, y in self.all_coordinates():
+ min_x = min(min_x, x)
+ min_y = min(min_y, y)
+
+
+ new_segments = []
+
+ for segment in self.segments:
+ (start, end), color = segment
+
+ new_segment = (
+ (
+ (start[0] - min_x, start[1] - min_y),
+ (end[0] - min_x, end[1] - min_y),
+ ),
+ color
+ )
+
+ new_segments.append(new_segment)
+
+ self.segments = new_segments
+
def get_dimensions(self):
width = 0
height = 0
- for segment in self.segments:
- (start_x, start_y), (end_x, end_y) = segment[0]
-
- width = max(width, start_x, end_x)
- height = max(height, start_y, end_y)
+ for x, y in self.all_coordinates():
+ width = max(width, x)
+ height = max(height, y)
return width, height