Exemple #1
0
    def test_lines(self):
        """Test lines not aligned with axes for 8 slopes and directions"""
        row0, col0 = 1, 1

        dy, dx = 3, 5
        ref_coords = numpy.array(
            [(0, 0), (1, 1), (1, 2), (2, 3), (2, 4), (3, 5)])

        # Build lines for the 8 octants from this coordinantes
        lines = {  # name: (drow, dcol, ref_coords)
            '1st octant': (dy, dx, ref_coords),
            '2nd octant': (dx, dy, ref_coords[:, (1, 0)]),  # invert x and y
            '3rd octant': (dx, -dy, ref_coords[:, (1, 0)] * (1, -1)),
            '4th octant': (dy, -dx, ref_coords * (1, -1)),
            '5th octant': (-dy, -dx, ref_coords * (-1, -1)),
            '6th octant': (-dx, -dy, ref_coords[:, (1, 0)] * (-1, -1)),
            '7th octant': (-dx, dy, ref_coords[:, (1, 0)] * (-1, 1)),
            '8th octant': (-dy, dx, ref_coords * (-1, 1))
        }

        # Test with different starting points with positive and negative coords
        for row0, col0 in ((0, 0), (2, 3), (-4, 1), (-5, -6), (8, -7)):
            for name, (drow, dcol, ref_coords) in lines.items():
                row1 = row0 + drow
                col1 = col0 + dcol
                # Transpose from ((row0, col0), ...) to (rows, cols)
                ref_coords = numpy.transpose(ref_coords + (row0, col0))

                with self.subTest(msg=name,
                                  pt0=(row0, col0), pt1=(row1, col1)):
                    result = shapes.draw_line(row0, col0, row1, col1)
                    self.assertTrue(self.isEqual(name, result, ref_coords))
    def test_lines(self):
        """Test lines not aligned with axes for 8 slopes and directions"""
        row0, col0 = 1, 1

        dy, dx = 3, 5
        ref_coords = numpy.array([(0, 0), (1, 1), (1, 2), (2, 3), (2, 4),
                                  (3, 5)])

        # Build lines for the 8 octants from this coordinantes
        lines = {  # name: (drow, dcol, ref_coords)
            '1st octant': (dy, dx, ref_coords),
            '2nd octant': (dx, dy, ref_coords[:, (1, 0)]),  # invert x and y
            '3rd octant': (dx, -dy, ref_coords[:, (1, 0)] * (1, -1)),
            '4th octant': (dy, -dx, ref_coords * (1, -1)),
            '5th octant': (-dy, -dx, ref_coords * (-1, -1)),
            '6th octant': (-dx, -dy, ref_coords[:, (1, 0)] * (-1, -1)),
            '7th octant': (-dx, dy, ref_coords[:, (1, 0)] * (-1, 1)),
            '8th octant': (-dy, dx, ref_coords * (-1, 1))
        }

        # Test with different starting points with positive and negative coords
        for row0, col0 in ((0, 0), (2, 3), (-4, 1), (-5, -6), (8, -7)):
            for name, (drow, dcol, ref_coords) in lines.items():
                row1 = row0 + drow
                col1 = col0 + dcol
                # Transpose from ((row0, col0), ...) to (rows, cols)
                ref_coords = numpy.transpose(ref_coords + (row0, col0))

                with self.subTest(msg=name, pt0=(row0, col0),
                                  pt1=(row1, col1)):
                    result = shapes.draw_line(row0, col0, row1, col1)
                    self.assertTrue(self.isEqual(name, result, ref_coords))
    def test_aligned_lines(self):
        """Test drawing horizontal, vertical and diagonal lines"""

        lines = {  # test_name: (drow, dcol)
            'Horizontal line, col0 < col1': (0, 10),
            'Horizontal line, col0 > col1': (0, -10),
            'Vertical line, row0 < row1': (10, 0),
            'Vertical line, row0 > row1': (-10, 0),
            'Diagonal col0 < col1 and row0 < row1': (10, 10),
            'Diagonal col0 < col1 and row0 > row1': (-10, 10),
            'Diagonal col0 > col1 and row0 < row1': (10, -10),
            'Diagonal col0 > col1 and row0 > row1': (-10, -10),
        }
        row0, col0 = 1, 2  # Start point

        for test_name, (drow, dcol) in lines.items():
            row1 = row0 + drow
            col1 = col0 + dcol
            with self.subTest(msg=test_name, drow=drow, dcol=dcol):
                # Build reference coordinates from drow and dcol
                if drow == 0:
                    rows = row0 * numpy.ones(abs(dcol) + 1)
                else:
                    step = 1 if drow > 0 else -1
                    rows = row0 + numpy.arange(0, drow + step, step)

                if dcol == 0:
                    cols = col0 * numpy.ones(abs(drow) + 1)
                else:
                    step = 1 if dcol > 0 else -1
                    cols = col0 + numpy.arange(0, dcol + step, step)
                ref_coords = rows, cols

                result = shapes.draw_line(row0, col0, row1, col1)
                self.assertTrue(self.isEqual(test_name, result, ref_coords))
Exemple #4
0
    def test_aligned_lines(self):
        """Test drawing horizontal, vertical and diagonal lines"""

        lines = {  # test_name: (drow, dcol)
            'Horizontal line, col0 < col1': (0, 10),
            'Horizontal line, col0 > col1': (0, -10),
            'Vertical line, row0 < row1': (10, 0),
            'Vertical line, row0 > row1': (-10, 0),
            'Diagonal col0 < col1 and row0 < row1': (10, 10),
            'Diagonal col0 < col1 and row0 > row1': (-10, 10),
            'Diagonal col0 > col1 and row0 < row1': (10, -10),
            'Diagonal col0 > col1 and row0 > row1': (-10, -10),
        }
        row0, col0 = 1, 2  # Start point

        for test_name, (drow, dcol) in lines.items():
            row1 = row0 + drow
            col1 = col0 + dcol
            with self.subTest(msg=test_name, drow=drow, dcol=dcol):
                # Build reference coordinates from drow and dcol
                if drow == 0:
                    rows = row0 * numpy.ones(abs(dcol) + 1)
                else:
                    step = 1 if drow > 0 else -1
                    rows = row0 + numpy.arange(0, drow + step, step)

                if dcol == 0:
                    cols = col0 * numpy.ones(abs(drow) + 1)
                else:
                    step = 1 if dcol > 0 else -1
                    cols = col0 + numpy.arange(0, dcol + step, step)
                ref_coords = rows, cols

                result = shapes.draw_line(row0, col0, row1, col1)
                self.assertTrue(self.isEqual(test_name, result, ref_coords))
Exemple #5
0
    def updateLine(self, level, row0, col0, row1, col1, width, mask=True):
        """Mask/Unmask a line of the given mask level.

        :param int level: Mask level to update.
        :param int row0: Row of the starting point.
        :param int col0: Column of the starting point.
        :param int row1: Row of the end point.
        :param int col1: Column of the end point.
        :param int width: Width of the line in mask array unit.
        :param bool mask: True to mask (default), False to unmask.
        """
        rows, cols = shapes.draw_line(row0, col0, row1, col1, width)
        self.updatePoints(level, rows, cols, mask)
Exemple #6
0
    def updateLine(self, level, row0, col0, row1, col1, width, mask=True):
        """Mask/Unmask a line of the given mask level.

        :param int level: Mask level to update.
        :param int row0: Row of the starting point.
        :param int col0: Column of the starting point.
        :param int row1: Row of the end point.
        :param int col1: Column of the end point.
        :param int width: Width of the line in mask array unit.
        :param bool mask: True to mask (default), False to unmask.
        """
        rows, cols = shapes.draw_line(row0, col0, row1, col1, width)
        self.updatePoints(level, rows, cols, mask)
    def test_width(self):
        """Test of line width"""

        lines = { # test_name: row0, col0, row1, col1, width, ref
            'horizontal w=2':
                (0, 0, 0, 1, 2, ((0, 1, 0, 1),
                                 (0, 0, 1, 1))),
            'horizontal w=3':
                (0, 0, 0, 1, 3, ((-1, 0, 1, -1, 0, 1),
                                 (0, 0, 0, 1, 1, 1))),
            'vertical w=2':
                (0, 0, 1, 0, 2, ((0, 0, 1, 1),
                                 (0, 1, 0, 1))),
            'vertical w=3':
                (0, 0, 1, 0, 3, ((0, 0, 0, 1, 1, 1),
                                 (-1, 0, 1, -1, 0, 1))),
            'diagonal w=3':
                (0, 0, 1, 1, 3, ((-1, 0, 1, 0, 1, 2),
                                 (0, 0, 0, 1, 1, 1))),
            '1st octant w=3':
                (0, 0, 1, 2, 3,
                 numpy.array(((-1, 0), (0, 0), (1, 0),
                              (0, 1), (1, 1), (2, 1),
                              (0, 2), (1, 2), (2, 2))).T),
            '2nd octant w=3':
                (0, 0, 2, 1, 3,
                 numpy.array(((0, -1), (0, 0), (0, 1),
                              (1, 0), (1, 1), (1, 2),
                              (2, 0), (2, 1), (2, 2))).T),
        }

        for test_name, (row0, col0, row1, col1, width, ref) in lines.items():
            with self.subTest(msg=test_name,
                              pt0=(row0, col0),
                              pt1=(row1, col1),
                              width=width):
                result = shapes.draw_line(row0, col0, row1, col1, width)
                self.assertTrue(self.isEqual(test_name, result, ref))
Exemple #8
0
    def test_width(self):
        """Test of line width"""

        lines = {  # test_name: row0, col0, row1, col1, width, ref
            'horizontal w=2':
                (0, 0, 0, 1, 2, ((0, 1, 0, 1),
                                 (0, 0, 1, 1))),
            'horizontal w=3':
                (0, 0, 0, 1, 3, ((-1, 0, 1, -1, 0, 1),
                                 (0, 0, 0, 1, 1, 1))),
            'vertical w=2':
                (0, 0, 1, 0, 2, ((0, 0, 1, 1),
                                 (0, 1, 0, 1))),
            'vertical w=3':
                (0, 0, 1, 0, 3, ((0, 0, 0, 1, 1, 1),
                                 (-1, 0, 1, -1, 0, 1))),
            'diagonal w=3':
                (0, 0, 1, 1, 3, ((-1, 0, 1, 0, 1, 2),
                                 (0, 0, 0, 1, 1, 1))),
            '1st octant w=3':
                (0, 0, 1, 2, 3,
                 numpy.array(((-1, 0), (0, 0), (1, 0),
                              (0, 1), (1, 1), (2, 1),
                              (0, 2), (1, 2), (2, 2))).T),
            '2nd octant w=3':
                (0, 0, 2, 1, 3,
                 numpy.array(((0, -1), (0, 0), (0, 1),
                              (1, 0), (1, 1), (1, 2),
                              (2, 0), (2, 1), (2, 2))).T),
        }

        for test_name, (row0, col0, row1, col1, width, ref) in lines.items():
            with self.subTest(msg=test_name,
                              pt0=(row0, col0), pt1=(row1, col1), width=width):
                result = shapes.draw_line(row0, col0, row1, col1, width)
                self.assertTrue(self.isEqual(test_name, result, ref))
 def test_noline(self):
     """Test pt0 == pt1"""
     for width in range(4):
         with self.subTest(width=width):
             result = shapes.draw_line(1, 2, 1, 2, width)
             self.assertTrue(numpy.all(numpy.equal(result, [(1, ), (2, )])))
Exemple #10
0
 def test_noline(self):
     """Test pt0 == pt1"""
     for width in range(4):
         with self.subTest(width=width):
             result = shapes.draw_line(1, 2, 1, 2, width)
             self.assertTrue(numpy.all(numpy.equal(result, [(1,), (2,)])))