Skip to content

Commit bd3089d

Browse files
authored
Merge pull request #89 from EmbroidePy/tatarize-issue_87_part2
Issue #87 Redux
2 parents c15f926 + f1487bc commit bd3089d

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

pyembroidery/EmbPattern.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,25 @@ def get_as_colorblocks(self):
327327
if colorblock_start != pos:
328328
thread = self.get_thread_or_filler(thread_index)
329329
thread_index += 1
330-
yield self.stitches[colorblock_start:pos-1], thread
330+
yield self.stitches[colorblock_start:pos], thread
331331
colorblock_start = pos + 1
332332
continue
333333
if command == COLOR_CHANGE:
334334
thread = self.get_thread_or_filler(thread_index)
335335
thread_index += 1
336-
yield self.stitches[colorblock_start:pos+1], thread
337-
colorblock_start = pos+1
336+
yield self.stitches[colorblock_start:pos + 1], thread
337+
colorblock_start = pos + 1
338338
continue
339339
if command == NEEDLE_SET and colorblock_start != pos:
340340
thread = self.get_thread_or_filler(thread_index)
341341
thread_index += 1
342-
yield self.stitches[colorblock_start:pos-1], thread
343-
colorblock_start = pos-1
342+
yield self.stitches[colorblock_start:pos], thread
343+
colorblock_start = pos
344344
continue
345345

346-
347346
if colorblock_start != len(self.stitches):
348347
thread = self.get_thread_or_filler(thread_index)
349-
yield (self.stitches[colorblock_start:], thread)
348+
yield self.stitches[colorblock_start:], thread
350349

351350
def get_as_stitches(self):
352351
"""pos, x, y, command, v1, v2, v3"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pyembroidery",
8-
version="1.4.15",
8+
version="1.4.16",
99
author="Tatarize",
1010
author_email="[email protected]",
1111
description="Embroidery IO library",

test/test_embpattern.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,12 @@ def test_issue_87(self):
289289
stitches_2 = [[4, 5], [6, 7]]
290290
pattern.add_block(stitches_1, 0xFF0000)
291291
pattern.add_block(stitches_2, 0x0000FF)
292-
self.assertEqual(len(list(pattern.get_as_colorblocks())), 2)
292+
blocks = list(pattern.get_as_colorblocks())
293+
for q in blocks:
294+
print(q)
295+
self.assertEqual(len(blocks), 2)
296+
self.assertEqual(len(blocks[0][0]), 2) # 0,1 and 2,3
297+
self.assertEqual(len(blocks[1][0]), 2) # 4,5 and 6,7
293298

294299
def test_issue_87_2(self):
295300
"""
@@ -312,6 +317,9 @@ def test_issue_87_2(self):
312317
self.assertEqual(blocks[1][1].color, 0xFF0000)
313318
self.assertEqual(blocks[2][1].color, 0x0000FF)
314319
self.assertEqual(len(blocks), 3)
320+
self.assertEqual(len(blocks[0][0]), 1)
321+
self.assertEqual(len(blocks[1][0]), 2)
322+
self.assertEqual(len(blocks[2][0]), 2)
315323

316324
for block in blocks:
317325
stitch_block = block[0]
@@ -335,6 +343,12 @@ def test_issue_87_2(self):
335343
self.assertEqual(blocks[1][1].color, 0xFF0000)
336344
self.assertEqual(blocks[2][1].color, 0x0000FF)
337345
self.assertEqual(len(blocks), 3)
346+
self.assertEqual(len(blocks[0][0]), 1)
347+
self.assertEqual(len(blocks[1][0]), 3)
348+
self.assertEqual(len(blocks[2][0]), 2) # Final color change is part of no block.
349+
pattern.color_change() # end block 3
350+
blocks = list(pattern.get_as_colorblocks())
351+
self.assertEqual(len(blocks[2][0]), 3) # Final block with colorchange.
338352

339353
def test_issue_87_3(self):
340354
"""
@@ -365,24 +379,27 @@ def test_issue_87_3(self):
365379

366380
pattern.needle_change() # start block 0
367381
pattern += stitches_1
368-
pattern += EmbThread(0xFF0000)
382+
pattern.add_thread(EmbThread(0xFF0000))
369383

370384
pattern.needle_change() # start block 1
371385
pattern += stitches_1
372-
pattern += EmbThread(0x0000FF)
386+
pattern.add_thread(EmbThread(0x0000FF))
373387

374388
pattern.needle_change() # start block 2
375-
pattern += EmbThread('random')
389+
pattern.add_thread(EmbThread('random'))
376390

377391
blocks = list(pattern.get_as_colorblocks())
378-
# for q in blocks:
379-
# print(q)
392+
for q in blocks:
393+
print(q)
380394
# Mask is required here since needle_set automatically appends extended data.
381395
self.assertEqual(blocks[0][0][0][2] & COMMAND_MASK, NEEDLE_SET) # Needle_set starts the block.
382396
self.assertEqual(blocks[1][0][0][2] & COMMAND_MASK, NEEDLE_SET) # Needle_set starts the block.
383397
self.assertEqual(blocks[0][1], 0xFF0000)
384398
self.assertEqual(blocks[1][1], 0x0000FF)
385399
self.assertEqual(len(blocks), 3)
400+
self.assertEqual(len(blocks[0][0]), 3)
401+
self.assertEqual(len(blocks[1][0]), 3)
402+
self.assertEqual(len(blocks[2][0]), 1)
386403

387404
def test_issue_87_4(self):
388405
"""
@@ -401,13 +418,15 @@ def test_issue_87_4(self):
401418
pattern.add_block(stitches_2, 0x0000FF)
402419
pattern += COLOR_BREAK
403420
blocks = list(pattern.get_as_colorblocks())
404-
# for q in blocks:
405-
# print(q)
406-
421+
for q in blocks:
422+
print(q)
423+
407424
for block in blocks:
408425
stitch_block = block[0]
409426
for stitch in stitch_block:
410427
self.assertNotEqual(stitch[2], COLOR_BREAK)
411428
self.assertEqual(blocks[0][1], 0xFF0000)
412429
self.assertEqual(blocks[1][1], 0x0000FF)
413-
self.assertEqual(len(list(pattern.get_as_colorblocks())), 2)
430+
self.assertEqual(len(blocks), 2)
431+
self.assertEqual(len(blocks[0][0]), 2)
432+
self.assertEqual(len(blocks[1][0]), 2)

0 commit comments

Comments
 (0)