summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embroider_input.py12
-rw-r--r--inkstitch/stitch_plan/stitch_plan.py13
2 files changed, 20 insertions, 5 deletions
diff --git a/embroider_input.py b/embroider_input.py
index e3a7b0c2..04d79d4f 100644
--- a/embroider_input.py
+++ b/embroider_input.py
@@ -37,12 +37,12 @@ def main(embroidery_file):
stop=stitch.flags & STOP,
trim=stitch.flags & TRIM)
- dimensions = stitch_plan.dimensions
+ extents = stitch_plan.extents
svg = etree.Element("svg", nsmap=inkex.NSS, attrib=
{
- "width": "%s" % dimensions[0],
- "height": "%s" % dimensions[1],
- "viewBox": "0 0 %s %s" % dimensions,
+ "width": str(extents[0] * 2),
+ "height": str(extents[1] * 2),
+ "viewBox": "0 0 %s %s" % (extents[0] * 2, extents[1] * 2),
})
render_stitch_plan(svg, stitch_plan)
@@ -51,6 +51,10 @@ def main(embroidery_file):
layer.set(INKSCAPE_LABEL, os.path.basename(embroidery_file))
layer.attrib.pop('id')
+ # Shift the design so that its origin is at the center of the canvas
+ # Note: this is NOT the same as centering the design in the canvas!
+ layer.set('transform', 'translate(%s,%s)' % (extents[0], extents[1]))
+
print etree.tostring(svg)
if __name__ == '__main__':
diff --git a/inkstitch/stitch_plan/stitch_plan.py b/inkstitch/stitch_plan/stitch_plan.py
index a7f39f70..fab87876 100644
--- a/inkstitch/stitch_plan/stitch_plan.py
+++ b/inkstitch/stitch_plan/stitch_plan.py
@@ -97,16 +97,27 @@ class StitchPlan(object):
return sum(block.num_stitches for block in self)
@property
- def dimensions(self):
+ def bounding_box(self):
color_block_bounding_boxes = [cb.bounding_box for cb in self]
minx = min(bb[0] for bb in color_block_bounding_boxes)
miny = min(bb[1] for bb in color_block_bounding_boxes)
maxx = max(bb[2] for bb in color_block_bounding_boxes)
maxy = max(bb[3] for bb in color_block_bounding_boxes)
+ return minx, miny, maxx, maxy
+
+ @property
+ def dimensions(self):
+ minx, miny, maxx, maxy = self.bounding_box
return (maxx - minx, maxy - miny)
@property
+ def extents(self):
+ minx, miny, maxx, maxy = self.bounding_box
+
+ return max(-minx, maxx), max(-miny, maxy)
+
+ @property
def dimensions_mm(self):
dimensions = self.dimensions
return (dimensions[0] / PIXELS_PER_MM, dimensions[1] / PIXELS_PER_MM)