diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/extensions/print_pdf.py | 2 | ||||
| -rw-r--r-- | lib/stitch_plan/color_block.py | 9 | ||||
| -rw-r--r-- | lib/stitch_plan/stitch_plan.py | 8 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py index 97a806a7..16ca3a08 100644 --- a/lib/extensions/print_pdf.py +++ b/lib/extensions/print_pdf.py @@ -287,7 +287,7 @@ class Print(InkstitchExtension): 'num_trims': stitch_plan.num_trims, 'dimensions': stitch_plan.dimensions_mm, 'num_stitches': stitch_plan.num_stitches, - 'estimated_thread': '', # TODO + 'estimated_thread': stitch_plan.estimated_thread }, svg_overview=overview_svg, color_blocks=stitch_plan.color_blocks, diff --git a/lib/stitch_plan/color_block.py b/lib/stitch_plan/color_block.py index 10d199c2..cd7b9c6d 100644 --- a/lib/stitch_plan/color_block.py +++ b/lib/stitch_plan/color_block.py @@ -63,6 +63,15 @@ class ColorBlock(object): return len(self.stitches) @property + def estimated_thread(self): + previous_stitch = self.stitches[0] + length = 0 + for stitch in self.stitches[1:]: + length += (stitch - previous_stitch).length() + previous_stitch = stitch + return length + + @property def num_trims(self): """Number of trims in this color block.""" diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py index f6895197..a501391d 100644 --- a/lib/stitch_plan/stitch_plan.py +++ b/lib/stitch_plan/stitch_plan.py @@ -113,7 +113,8 @@ class StitchPlan(object): num_stops=self.num_stops, num_trims=self.num_trims, num_stitches=self.num_stitches, - bounding_box=self.bounding_box + bounding_box=self.bounding_box, + estimated_thread=self.estimated_thread ) @property @@ -148,6 +149,11 @@ class StitchPlan(object): return minx, miny, maxx, maxy @property + def estimated_thread(self): + thread_meter = sum(block.estimated_thread for block in self) / PIXELS_PER_MM / 1000 + return round(thread_meter, 2) + + @property def dimensions(self): minx, miny, maxx, maxy = self.bounding_box return (maxx - minx, maxy - miny) |
