Add files via upload

pull/13/head
tatarize 2018-09-21 12:26:48 -07:00 zatwierdzone przez GitHub
rodzic 674fac61c0
commit ca29755355
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 52 dodań i 2 usunięć

Wyświetl plik

@ -244,6 +244,38 @@ class EmbPattern:
that require an update"""
self.stitches.append([x, y, cmd])
def add_block(self, block, thread=None):
if thread is not None:
self.add_thread(thread)
self.add_command(COLOR_BREAK)
if block is None:
return
if isinstance(block, list) or isinstance(block, tuple):
if len(block) == 0:
return
v = block[0]
if isinstance(v, list) or isinstance(v, tuple):
for v in block:
x = v[0]
y = v[1]
try:
cmd = v[2]
except IndexError:
cmd = STITCH
self.add_stitch_absolute(cmd, x, y)
elif isinstance(v, complex):
for v in block:
x = v.real
y = v.imag
self.add_stitch_absolute(STITCH, x, y)
elif isinstance(v, int) or isinstance(v, float):
i = 0
ie = len(block)
while i < ie:
self.add_stitch_absolute(STITCH, block[i], block[i + 1])
i += 2
def add_stitchblock(self, stitchblock):
threadlist = self.threadlist
block = stitchblock[0]

Wyświetl plik

@ -1,6 +1,5 @@
from __future__ import print_function
# External dependencies:
import unittest
from pyembroidery import *
@ -81,4 +80,23 @@ class TestEmbpattern(unittest.TestCase):
self.assertEqual(csv_pattern.count_stitch_commands(STITCH), 5)
self.assertNotEqual(csv_pattern.stitches[-1][0], 0)
self.assertNotEqual(csv_pattern.stitches[-1][1], 0)
print("csv: ", csv_pattern.stitches)
print("csv: ", csv_pattern.stitches)
def position_equals(self, stitches, j, k):
self.assertEqual(stitches[j][0], stitches[k][0])
self.assertEqual(stitches[j][1], stitches[k][1])
def test_matrix(self):
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_command(MATRIX_ROTATE, 45)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "blue")
pattern.add_command(MATRIX_ROTATE, 45)
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "aqua")
pattern = pattern.get_normalized_pattern()
self.position_equals(pattern.stitches, 5, 6)
self.position_equals(pattern.stitches, 10, 11)
print(pattern.stitches)
write_svg(pattern, "file.svg")
self.assertIsNotNone(pattern.stitches)