Esempio n. 1
0
    def test_bounds2slice(self):

        # test that if you ask to slice the matrix with the sheet's BoundingBox, you
        # get back the whole matrix
        sheet_bb = BoundingBox(points=((-0.5, -0.5), (0.5, 0.5)))
        ct = SheetCoordinateSystem(sheet_bb, 10)

        slice_ = Slice(sheet_bb, ct)
        true_slice = (0, 10, 0, 10
                      )  # inclusive left boundary, exclusive right boundary
        self.assertEqual(tuple(slice_.tolist()), true_slice)

        # for the following tests, the values have been all computed by hand and then
        # tested (by JC). The boundingbox and density tested have been chosen randomly,
        # then drawn to get the slice from it.

        # Test with 20 density.
        ct = SheetCoordinateSystem(sheet_bb, 20, 20)
        bb = BoundingBox(points=((-0.05, -0.20), (0.20, 0.05)))
        slice_ = Slice(bb, ct)

        true_slice = (9, 14, 9, 14)
        self.assertEqual(tuple(slice_.tolist()), true_slice)

        bb = BoundingBox(points=((-0.40, 0), (-0.30, 0.30)))
        slice_ = Slice(bb, ct)
        true_slice = (4, 10, 2, 4)
        self.assertEqual(tuple(slice_.tolist()), true_slice)

        bb = BoundingBox(points=((0.15, 0.10), (0.30, 0.30)))
        slice_ = Slice(bb, ct)
        true_slice = (4, 8, 13, 16)
        self.assertEqual(tuple(slice_.tolist()), true_slice)

        bb = BoundingBox(points=((-0.05, -0.45), (0.10, -0.25)))
        slice_ = Slice(bb, ct)
        true_slice = (15, 19, 9, 12)
        self.assertEqual(tuple(slice_.tolist()), true_slice)

        # test with 7 density sheet.

        bb = BoundingBox(points=((-0.5 + 2.0 / 7.0, 0.5 - 2.0 / 7.0),
                                 (-0.5 + 4.0 / 7.0, 0.5)))
        ct = SheetCoordinateSystem(sheet_bb, 7)

        slice_ = Slice(bb, ct)
        true_slice = (0, 2, 2, 4)
        self.assertEqual(tuple(slice_.tolist()), true_slice)

        #(4x4 matrix)
        ct = SheetCoordinateSystem(BoundingBox(radius=0.2),
                                   xdensity=10,
                                   ydensity=10)
        test_bounds = BoundingBox(radius=0.1)
        slice_ = Slice(test_bounds, ct)
        r1, r2, c1, c2 = slice_
        self.assertEqual((r1, r2, c1, c2), (1, 3, 1, 3))
Esempio n. 2
0
    def test_connection_field_like(self):
        # test a ConnectionField-like example
        sheet = Sheet(nominal_density=10,nominal_bounds=BoundingBox(radius=0.5))
        cf_bounds = BoundingBox(points=((0.3,0.3),(0.6,0.6)))

        slice_ = Slice(cf_bounds,sheet)
        slice_.crop_to_sheet(sheet)

        # check it's been cropped to fit onto sheet...
        self.assertEqual(slice_.tolist(),[0,2,8,10])

        # now check that it gives the correct bounds...
        cropped_bounds = slice_.compute_bounds(sheet)
        
        true_cropped_bounds = BoundingBox(points=((0.3,0.3),(0.5,0.5)))
        for a,b in zip(cropped_bounds.lbrt(),true_cropped_bounds.lbrt()):
            self.assertAlmostEqual(a,b)
Esempio n. 3
0
    def test_connection_field_like(self):
        # test a ConnectionField-like example
        sheet = Sheet(nominal_density=10,nominal_bounds=BoundingBox(radius=0.5))
        cf_bounds = BoundingBox(points=((0.3,0.3),(0.6,0.6)))

        slice_ = Slice(cf_bounds,sheet)
        slice_.crop_to_sheet(sheet)

        # check it's been cropped to fit onto sheet...
        self.assertEqual(slice_.tolist(),[0,2,8,10])

        # now check that it gives the correct bounds...
        cropped_bounds = slice_.compute_bounds(sheet)

        true_cropped_bounds = BoundingBox(points=((0.3,0.3),(0.5,0.5)))
        for a,b in zip(cropped_bounds.lbrt(),true_cropped_bounds.lbrt()):
            self.assertAlmostEqual(a,b)
Esempio n. 4
0
    def test_bounds2slice(self):
        
        # test that if you ask to slice the matrix with the sheet's BoundingBox, you
        # get back the whole matrix
        sheet_bb = BoundingBox(points=((-0.5,-0.5),(0.5,0.5)))
        ct = SheetCoordinateSystem(sheet_bb,10)
        
        slice_ = Slice(sheet_bb,ct)
        true_slice = (0,10,0,10) # inclusive left boundary, exclusive right boundary
        self.assertEqual(tuple(slice_.tolist()),true_slice) 

        # for the following tests, the values have been all computed by hand and then
        # tested (by JC). The boundingbox and density tested have been chosen randomly,
        # then drawn to get the slice from it.
       
        # Test with 20 density. 
        ct = SheetCoordinateSystem(sheet_bb,20,20)
        bb = BoundingBox(points=((-0.05,-0.20),(0.20,0.05)))
        slice_ = Slice(bb,ct)

        true_slice = (9,14,9,14) 
        self.assertEqual(tuple(slice_.tolist()),true_slice)

        bb = BoundingBox(points=((-0.40,0),(-0.30,0.30)))
        slice_ = Slice(bb,ct)
        true_slice = (4,10,2,4) 
        self.assertEqual(tuple(slice_.tolist()),true_slice)

        bb = BoundingBox(points=((0.15,0.10),(0.30,0.30)))
        slice_ = Slice(bb,ct)
        true_slice = (4,8,13,16) 
        self.assertEqual(tuple(slice_.tolist()),true_slice)

        bb = BoundingBox(points=((-0.05,-0.45),(0.10,-0.25)))
        slice_ = Slice(bb,ct)
        true_slice = (15,19,9,12) 
        self.assertEqual(tuple(slice_.tolist()),true_slice)
        
        # test with 7 density sheet.
        
        bb = BoundingBox(points=((-0.5+2.0/7.0,0.5-2.0/7.0),(-0.5+4.0/7.0,0.5)))
        ct = SheetCoordinateSystem(sheet_bb,7)
        
        slice_ = Slice(bb,ct)
        true_slice = (0,2,2,4) 
        self.assertEqual(tuple(slice_.tolist()),true_slice)

        #(4x4 matrix)
        ct = SheetCoordinateSystem(BoundingBox(radius=0.2),xdensity=10,ydensity=10)
        test_bounds = BoundingBox(radius=0.1)
        slice_=Slice(test_bounds,ct)
        r1,r2,c1,c2 = slice_
        self.assertEqual((r1,r2,c1,c2),(1,3,1,3))