@@ -11,13 +11,17 @@ def scanHorizontal(image, rTool):
|
|||||||
for line in range(height):
|
for line in range(height):
|
||||||
for column in range(width):
|
for column in range(width):
|
||||||
|
|
||||||
|
if column > 0:
|
||||||
if image[line][column] == 1 and image[line][column - 1] != 1:
|
if image[line][column] == 1 and image[line][column - 1] != 1:
|
||||||
for px in range(2 * rTool + 1):
|
for px in range(2 * rTool + 1):
|
||||||
|
if column - rTool >= 0 and 0 <= line - rTool + px < height:
|
||||||
if image[line - rTool + px][column - rTool] == 0:
|
if image[line - rTool + px][column - rTool] == 0:
|
||||||
image[line - rTool + px][column - rTool] = 2
|
image[line - rTool + px][column - rTool] = 2
|
||||||
|
|
||||||
|
if column < width - 1:
|
||||||
if image[line][column] == 1 and image[line][column + 1] != 1:
|
if image[line][column] == 1 and image[line][column + 1] != 1:
|
||||||
for px in range(2 * rTool + 1):
|
for px in range(2 * rTool + 1):
|
||||||
|
if column + rTool < width and 0 <= line - rTool + px < height:
|
||||||
if image[line - rTool + px][column + rTool] == 0:
|
if image[line - rTool + px][column + rTool] == 0:
|
||||||
image[line - rTool + px][column + rTool] = 2
|
image[line - rTool + px][column + rTool] = 2
|
||||||
|
|
||||||
@@ -37,13 +41,17 @@ def scanVertical(image, rTool):
|
|||||||
for line in range(height):
|
for line in range(height):
|
||||||
for column in range(width):
|
for column in range(width):
|
||||||
|
|
||||||
|
if line > 0:
|
||||||
if image[line][column] == 1 and image[line - 1][column] != 1:
|
if image[line][column] == 1 and image[line - 1][column] != 1:
|
||||||
for px in range(2 * rTool + 1):
|
for px in range(2 * rTool + 1):
|
||||||
|
if line - rTool >= 0 and 0 <= column - rTool + px < width:
|
||||||
if image[line - rTool][column - rTool + px] == 0:
|
if image[line - rTool][column - rTool + px] == 0:
|
||||||
image[line - rTool][column - rTool + px] = 2
|
image[line - rTool][column - rTool + px] = 2
|
||||||
|
|
||||||
|
if line < height - 1:
|
||||||
if image[line][column] == 1 and image[line + 1][column] != 1:
|
if image[line][column] == 1 and image[line + 1][column] != 1:
|
||||||
for px in range(2 * rTool + 1):
|
for px in range(2 * rTool + 1):
|
||||||
|
if line + rTool < height and 0 <= column - rTool + px < width:
|
||||||
if image[line + rTool][column - rTool + px] == 0:
|
if image[line + rTool][column - rTool + px] == 0:
|
||||||
image[line + rTool][column - rTool + px] = 2
|
image[line + rTool][column - rTool + px] = 2
|
||||||
|
|
||||||
@@ -65,6 +73,7 @@ def twoRemoving(image, rTool):
|
|||||||
if image[line][column] == 1:
|
if image[line][column] == 1:
|
||||||
for pixelx in range(1, 2 * rTool):
|
for pixelx in range(1, 2 * rTool):
|
||||||
for pixely in range(1, 2*rTool):
|
for pixely in range(1, 2*rTool):
|
||||||
|
if 0 <= line - rTool + pixelx < height and 0 <= column - rTool + pixely < width:
|
||||||
if image[line - rTool + pixelx][column - rTool + pixely] == 2:
|
if image[line - rTool + pixelx][column - rTool + pixely] == 2:
|
||||||
image[line - rTool + pixelx][column - rTool + pixely] = 0
|
image[line - rTool + pixelx][column - rTool + pixely] = 0
|
||||||
|
|
||||||
|
|||||||
174
pcbdevice/tests/gcode/test_path.py
Normal file
174
pcbdevice/tests/gcode/test_path.py
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from pcbdevice.gcode.path import scanHorizontal, scanVertical, twoRemoving
|
||||||
|
|
||||||
|
|
||||||
|
class TestPath(TestCase):
|
||||||
|
|
||||||
|
#inputs
|
||||||
|
def imageTest(self):
|
||||||
|
return [[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 1, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0]]
|
||||||
|
|
||||||
|
def imageTestMulti(self):
|
||||||
|
return [[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 1, 0, 0, 1, 0, 0],
|
||||||
|
[0, 0, 0, 1, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 1, 0, 0]]
|
||||||
|
|
||||||
|
def imageTestHOut(self):
|
||||||
|
return [[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 1, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0]]
|
||||||
|
|
||||||
|
def imageTestVOut(self):
|
||||||
|
return [[0, 0, 0],
|
||||||
|
[0, 0, 0],
|
||||||
|
[0, 0, 0],
|
||||||
|
[0, 1, 0],
|
||||||
|
[0, 0, 0],
|
||||||
|
[0, 0, 0],
|
||||||
|
[0, 0, 0]]
|
||||||
|
|
||||||
|
def imageTest2(self):
|
||||||
|
return [[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 2, 2, 1, 2, 2, 0],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0]]
|
||||||
|
|
||||||
|
def imageTestMulti2(self):
|
||||||
|
return [[2, 2, 2, 2, 2, 2, 2],
|
||||||
|
[2, 2, 2, 2, 2, 2, 2],
|
||||||
|
[2, 1, 2, 2, 1, 2, 2],
|
||||||
|
[2, 2, 2, 1, 2, 2, 2],
|
||||||
|
[2, 2, 2, 2, 2, 2, 2],
|
||||||
|
[2, 2, 2, 2, 2, 2, 2],
|
||||||
|
[2, 2, 2, 2, 1, 2, 2]]
|
||||||
|
|
||||||
|
|
||||||
|
#horizontal results
|
||||||
|
def imageResultHr2(self):
|
||||||
|
return [[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 2, 0, 0, 0, 2, 0],
|
||||||
|
[0, 2, 0, 0, 0, 2, 0],
|
||||||
|
[0, 2, 0, 1, 0, 2, 0],
|
||||||
|
[0, 2, 0, 0, 0, 2, 0],
|
||||||
|
[0, 2, 0, 0, 0, 2, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0]]
|
||||||
|
|
||||||
|
def imageResultHr3(self):
|
||||||
|
return [[2, 0, 0, 0, 0, 0, 2],
|
||||||
|
[2, 0, 0, 0, 0, 0, 2],
|
||||||
|
[2, 0, 0, 0, 0, 0, 2],
|
||||||
|
[2, 0, 0, 1, 0, 0, 2],
|
||||||
|
[2, 0, 0, 0, 0, 0, 2],
|
||||||
|
[2, 0, 0, 0, 0, 0, 2],
|
||||||
|
[2, 0, 0, 0, 0, 0, 2]]
|
||||||
|
|
||||||
|
def imageResultHOut(self):
|
||||||
|
return [[0, 2, 0, 0, 0, 2, 0],
|
||||||
|
[0, 2, 0, 1, 0, 2, 0],
|
||||||
|
[0, 2, 0, 0, 0, 2, 0]]
|
||||||
|
|
||||||
|
def imageResultMultiH(self):
|
||||||
|
return [[0, 0, 2, 2, 0, 0, 2],
|
||||||
|
[0, 2, 2, 2, 0, 2, 2],
|
||||||
|
[0, 1, 2, 2, 1, 2, 2],
|
||||||
|
[0, 2, 2, 1, 0, 2, 2],
|
||||||
|
[0, 2, 2, 2, 0, 2, 2],
|
||||||
|
[0, 2, 2, 0, 0, 2, 2],
|
||||||
|
[0, 0, 2, 0, 1, 0, 2]]
|
||||||
|
|
||||||
|
|
||||||
|
#vertical results
|
||||||
|
def imageResultVr2(self):
|
||||||
|
return [[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 1, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0]]
|
||||||
|
|
||||||
|
def imageResultVr3(self):
|
||||||
|
return [[2, 2, 2, 2, 2, 2, 2],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 1, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[2, 2, 2, 2, 2, 2, 2]]
|
||||||
|
|
||||||
|
def imageResultVOut(self):
|
||||||
|
return [[0, 0, 0],
|
||||||
|
[2, 2, 2],
|
||||||
|
[0, 0, 0],
|
||||||
|
[0, 1, 0],
|
||||||
|
[0, 0, 0],
|
||||||
|
[2, 2, 2],
|
||||||
|
[0, 0, 0]]
|
||||||
|
|
||||||
|
def imageResultMultiV(self):
|
||||||
|
return [[2, 2, 2, 2, 2, 2, 2],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 1, 0, 0, 1, 0, 0],
|
||||||
|
[0, 0, 0, 1, 0, 0, 0],
|
||||||
|
[2, 2, 2, 2, 2, 2, 2],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 0, 0, 0, 1, 0, 0]]
|
||||||
|
|
||||||
|
#two results
|
||||||
|
|
||||||
|
def imageResult2(self):
|
||||||
|
return [[0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 2, 0, 0, 0, 2, 0],
|
||||||
|
[0, 2, 0, 1, 0, 2, 0],
|
||||||
|
[0, 2, 0, 0, 0, 2, 0],
|
||||||
|
[0, 2, 2, 2, 2, 2, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0]]
|
||||||
|
|
||||||
|
def imageResultMulti2(self):
|
||||||
|
return [[2, 2, 2, 2, 2, 2, 2],
|
||||||
|
[0, 0, 0, 0, 0, 0, 2],
|
||||||
|
[0, 1, 0, 0, 1, 0, 2],
|
||||||
|
[0, 0, 0, 1, 0, 0, 2],
|
||||||
|
[2, 2, 0, 0, 0, 2, 2],
|
||||||
|
[2, 2, 2, 0, 0, 0, 2],
|
||||||
|
[2, 2, 2, 0, 1, 0, 2]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_hori(self):
|
||||||
|
|
||||||
|
self.assertEqual(scanHorizontal(self.imageTest(), 2), self.imageResultHr2())
|
||||||
|
self.assertEqual(scanHorizontal(self.imageTest(), 3), self.imageResultHr3())
|
||||||
|
self.assertEqual(scanHorizontal(self.imageTestHOut(), 2), self.imageResultHOut())
|
||||||
|
self.assertEqual(scanHorizontal(self.imageTest(), 4), self.imageTest())
|
||||||
|
self.assertEqual(scanHorizontal(self.imageTestMulti(), 2), self.imageResultMultiH())
|
||||||
|
|
||||||
|
def test_vert(self):
|
||||||
|
|
||||||
|
self.assertEqual(scanVertical(self.imageTest(), 2), self.imageResultVr2())
|
||||||
|
self.assertEqual(scanVertical(self.imageTest(), 3), self.imageResultVr3())
|
||||||
|
self.assertEqual(scanVertical(self.imageTestVOut(), 2), self.imageResultVOut())
|
||||||
|
self.assertEqual(scanVertical(self.imageTest(), 4), self.imageTest())
|
||||||
|
self.assertEqual(scanVertical(self.imageTestMulti(), 2), self.imageResultMultiV())
|
||||||
|
|
||||||
|
def test_two(self):
|
||||||
|
|
||||||
|
self.assertEqual(twoRemoving(self.imageTest2(), 2), self.imageResult2())
|
||||||
|
self.assertEqual(twoRemoving(self.imageTest2(), 3), self.imageTest())
|
||||||
|
self.assertEqual(twoRemoving(self.imageTest2(), 7), self.imageTest())
|
||||||
|
self.assertEqual(twoRemoving(self.imageTestMulti2(), 2), self.imageResultMulti2())
|
||||||
Reference in New Issue
Block a user