Пример #1
0
    def test_multi_segment(self):
        '''
        what if we break it down into smaller segments?
        '''
        img = Image(10, 10)
        val = int(2**30)  # should work

        coords = np.linspace(-val, val, 100000)
        rev_coords = np.flipud(coords)

        diag = np.c_[coords, coords]
        bottom = np.c_[rev_coords, np.ones_like(coords) * val]
        side = np.c_[np.ones_like(coords) * -val, rev_coords, ]
        points = np.r_[diag, bottom, side]

        img.draw_polygon(points,
                         line_color='black',
                         fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)
        print arr
        print self.arr

        # this is expected to not be equal -- we've found a too-big value
        assert np.array_equal(arr, self.arr)
Пример #2
0
def test_polygon_clip():
    img = Image(100, 200)

    points = ((-20, 10), (20, 250), (120, 10), (50, 50))

    img.draw_polygon(points, fill_color='blue', line_color='red')
    img.save(outfile("test_image_polygon_clip.bmp"))
Пример #3
0
    def test_multi_segment(self):
        '''
        what if we break it down into smaller segments?
        '''
        img = Image(10, 10)
        val = int(2 ** 30)  # should work

        coords = np.linspace(-val, val, 100000)
        rev_coords = np.flipud(coords)

        diag = np.c_[coords, coords]
        bottom = np.c_[rev_coords, np.ones_like(coords) * val]
        side = np.c_[np.ones_like(coords) * -val, rev_coords, ]
        points = np.r_[diag, bottom, side]

        img.draw_polygon(points, line_color='black', fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)
        print arr
        print self.arr

        # this is expected to not be equal -- we've found a too-big value
        assert np.array_equal(arr, self.arr)
Пример #4
0
def test_Polygon1():
    img = Image(100, 200)

    points = ((10, 10), (20, 190), (90, 10), (50, 50))

    img.draw_polygon(points, 'red')
    img.save(outfile("test_image_poly1.bmp"))
Пример #5
0
def test_Polygon3():
    img = Image(100, 200)

    points = ((10, 10), (20, 190), (90, 10), (50, 50))

    img.draw_polygon(points, fill_color='blue', line_color='red', line_width=4)
    img.save(outfile("test_image_poly3.bmp"))
Пример #6
0
def test_Polygon2():
    img = Image(100, 200)

    points = ((10, 10), (20, 190), (90, 10), (50, 50))

    img.draw_polygon(points, fill_color='blue')

    img.save(outfile("test_image_poly2.bmp"))
Пример #7
0
    def test_inside(self):
        '''just to make sure the comparing is working'''
        img = Image(10, 10)

        # a triangle that divides the image
        points = ((-1, -1), (11, 11), (-1, 11))

        img.draw_polygon(points, line_color='black', fill_color=None,
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #8
0
    def test_outside(self):
        '''second value too large'''
        img = Image(10, 10)

        # a triangle that divides the image
        points = ((-1, -1), (100, 100), (-1, 100))

        img.draw_polygon(points, line_color='black', fill_color=None,
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #9
0
    def test_negative(self):
        '''negative coords value too large'''
        img = Image(10, 10)

        # a triangle that divides the image
        points = ((-100, -100), (10, 10), (-100, 10))

        img.draw_polygon(points, line_color='black', fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #10
0
    def test_outside(self):
        '''second value too large'''
        img = Image(10, 10)

        # a triangle that divides the image
        points = ((-1, -1), (100, 100), (-1, 100))

        img.draw_polygon(points,
                         line_color='black',
                         fill_color=None,
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #11
0
    def test_negative(self):
        '''negative coords value too large'''
        img = Image(10, 10)

        # a triangle that divides the image
        points = ((-100, -100), (10, 10), (-100, 10))

        img.draw_polygon(points,
                         line_color='black',
                         fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #12
0
    def test_inside(self):
        '''just to make sure the comparing is working'''
        img = Image(10, 10)

        # a triangle that divides the image
        points = ((-1, -1), (11, 11), (-1, 11))

        img.draw_polygon(points,
                         line_color='black',
                         fill_color=None,
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #13
0
    def test_huge(self):
        '''
        really big values, negative and positive, but not quite enough
        to overflow an integer
        '''
        img = Image(10, 10)
        val = int(2 ** 30)

        # a triangle that divides the image
        points = ((-val, -val), (val, val), (-val, val))

        img.draw_polygon(points, line_color='black', fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #14
0
    def test_large(self):
        '''
        large values, negative and positive
        just less than sqrt(max_int32)
        this seems to confirm that that's the limit
        '''
        img = Image(10, 10)
        val = int(2 ** 14)

        # a triangle that divides the image
        points = ((-val, -val), (val, val), (-val, val))

        img.draw_polygon(points, line_color='black', fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #15
0
    def test_huge(self):
        '''
        really big values, negative and positive, but not quite enough
        to overflow an integer
        '''
        img = Image(10, 10)
        val = int(2**30)

        # a triangle that divides the image
        points = ((-val, -val), (val, val), (-val, val))

        img.draw_polygon(points,
                         line_color='black',
                         fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #16
0
    def test_too_large(self):
        '''
        large values, negative and positive
        just more than sqrt(max_int32)
        this seems to confirm that that's the limit
        '''
        img = Image(10, 10)
        val = int(2 ** 15)

        # a triangle that divides the image
        points = ((-val, -val), (val, val), (-1, val))

        img.draw_polygon(points, line_color='black', fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        # this is expected to not be equal -- we've found a too-big value
        assert not np.array_equal(arr, self.arr)
Пример #17
0
    def test_overflow(self):
        '''
        Big enough to overflow an 32 bit int
        '''
        img = Image(10, 10)
        val = int(2 ** 33)

        # with pytest.raises(OverflowError):
        #     img.draw_line( (-val, -val), (val, val), 'white', line_width=2)

        # a triangle that divides the image
        points = ((-val, -val), (val, val), (-val, val))

        img.draw_polygon(points, line_color='black', fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        # This isn't expect to draw correctly
        assert not np.array_equal(arr, self.arr)
Пример #18
0
    def test_large(self):
        '''
        large values, negative and positive
        just less than sqrt(max_int32)
        this seems to confirm that that's the limit
        '''
        img = Image(10, 10)
        val = int(2**14)

        # a triangle that divides the image
        points = ((-val, -val), (val, val), (-val, val))

        img.draw_polygon(points,
                         line_color='black',
                         fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        assert np.array_equal(arr, self.arr)
Пример #19
0
    def test_too_large(self):
        '''
        large values, negative and positive
        just more than sqrt(max_int32)
        this seems to confirm that that's the limit
        '''
        img = Image(10, 10)
        val = int(2**15)

        # a triangle that divides the image
        points = ((-val, -val), (val, val), (-1, val))

        img.draw_polygon(points,
                         line_color='black',
                         fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        # this is expected to not be equal -- we've found a too-big value
        assert not np.array_equal(arr, self.arr)
Пример #20
0
    def test_overflow(self):
        '''
        Big enough to overflow an 32 bit int
        '''
        img = Image(10, 10)
        val = int(2**33)

        # with pytest.raises(OverflowError):
        #     img.draw_line( (-val, -val), (val, val), 'white', line_width=2)

        # a triangle that divides the image
        points = ((-val, -val), (val, val), (-val, val))

        img.draw_polygon(points,
                         line_color='black',
                         fill_color='red',
                         line_width=1)

        # save this one as an array
        arr = np.array(img)

        # This isn't expect to draw correctly
        assert not np.array_equal(arr, self.arr)