Exemplo n.º 1
0
 def test_bbox(self):
     """Creating bounding boxes"""
     self.assertEqual(tuple(BoundingBox(1, 3)), ((1, 1), (3, 3)))
     self.assertEqual(tuple(BoundingBox((1, 2), 3)), ((1, 2), (3, 3)))
     self.assertEqual(tuple(BoundingBox(1, (3, 4))), ((1, 1), (3, 4)))
     self.assertEqual(tuple(BoundingBox((1, 2), (3, 4))), ((1, 2), (3, 4)))
     self.assertEqual(repr(BoundingBox((1, 2), (3, 4))),
                      'BoundingBox((1, 2),(3, 4))')
Exemplo n.º 2
0
 def test_bbox_anchor_top_bottom(self):
     """Bunding box anchoring (top to bottom)"""
     bbox = BoundingBox((10, 20), (-1, 1))
     self.assertEqual([
         bbox.get_anchor('l', 't', 'tb'),
         bbox.get_anchor('l', 'm', 'tb'),
         bbox.get_anchor('l', 'b', 'tb'),
         bbox.get_anchor('l', 't', 'bt'),
         bbox.get_anchor('l', 'm', 'bt'),
         bbox.get_anchor('l', 'b', 'bt'),
     ], [-1, 0.0, 1, 1, -0.0, -1])
Exemplo n.º 3
0
 def test_bbox_anchor_left_right(self):
     """Bunding box anchoring (left to right)"""
     bbox = BoundingBox((-1, 1), (10, 20))
     self.assertEqual([
         bbox.get_anchor('l', 't', 'lr'),
         bbox.get_anchor('m', 't', 'lr'),
         bbox.get_anchor('r', 't', 'lr'),
         bbox.get_anchor('l', 't', 'rl'),
         bbox.get_anchor('m', 't', 'rl'),
         bbox.get_anchor('r', 't', 'rl'),
     ], [-1, 0.0, 1, 1, -0.0, -1])
Exemplo n.º 4
0
    def test_selected_bbox(self):
        """Can we get a bounding box from the selected items"""
        doc = svg_file(self.data_file('svg', 'multilayered-test.svg'))
        doc.selected.set('path3904', 'path3902')
        from inkex.transforms import BoundingBox
        x, y, w, h = 199.544, 156.412, 377.489, 199.972  # from inkscape --query-all
        expected_3904 = BoundingBox((x, x + w), (y, y + h))
        x, y, w, h = 145.358, 478.373, 439.135, 419.142  # from inkscape --query-all
        expected_3902 = BoundingBox((x, x + w), (y, y + h))
        expected = list(expected_3902 + expected_3904)

        for x, y in zip(expected, doc.selection.bounding_box()):
            self.assertDeepAlmostEqual(tuple(x), tuple(y), delta=1e-3)
Exemplo n.º 5
0
 def test_bbox_sum(self):
     """Test adding bboxes together"""
     self.assertEqual(
         tuple(
             BoundingBox((0, 10), (0, 10)) +
             BoundingBox((-10, 0), (-10, 0))), ((-10, 10), (-10, 10)))
     ret = sum([
         BoundingBox((-5, 0), (0, 0)),
         BoundingBox((0, 5), (0, 0)),
         BoundingBox((0, 0), (-5, 0)),
         BoundingBox((0, 0), (0, 5))
     ], None)
     self.assertEqual(tuple(ret), ((-5, 5), (-5, 5)))
     self.assertEqual(tuple(BoundingBox(-10, 2) + ret), ((-10, 5), (-5, 5)))
     self.assertEqual(tuple(ret + BoundingBox(1, -10)), ((-5, 5), (-10, 5)))
Exemplo n.º 6
0
 def test_bbox_anchor_custom(self):
     """Bounding box anchoring custom angle"""
     bbox = BoundingBox((10, 10), (5, 5))
     self.assertEqual([
         bbox.get_anchor('l', 't', 0),
         bbox.get_anchor('l', 't', 90),
         bbox.get_anchor('l', 't', 180),
         bbox.get_anchor('l', 't', 270),
         bbox.get_anchor('l', 't', 45),
     ], [10, -5, -10, 5, 3.5355339059327378])
Exemplo n.º 7
0
 def test_bbox_anchor_radial(self):
     """Bounding box anchoring radial in/out"""
     bbox = BoundingBox((10, 10), (5, 5))
     self.assertRaises(ValueError, bbox.get_anchor, 'm', 'm', 'ro')
     selbox = BoundingBox((100, 100), (100, 100))
     self.assertEqual(int(bbox.get_anchor('m', 'm', 'ro', selbox)), 130)
Exemplo n.º 8
0
 def test_bbox_scale(self):
     """Bounding Boxes can be scaled"""
     self.assertEqual(tuple(BoundingBox(1, 3) * 2), ((2, 2), (6, 6)))
Exemplo n.º 9
0
 def test_bbox_neg(self):
     self.assertEqual(tuple(-BoundingBox(-10, 2)), ((10, 10), (-2, -2)))
     self.assertEqual(tuple(-BoundingBox((-10, 15), (2, 10))),
                      ((-15, 10), (-10, -2)))
Exemplo n.º 10
0
def boxunion(b1, b2):
    """list(BoundingBox(b1) + BoundingBox(b2))"""
    bbox = BoundingBox(b1[:2], b1[2:]) + BoundingBox(b2[:2], b2[2:])
    return bbox.x.minimum, bbox.x.maximum, bbox.y.minimum, bbox.y.maximum