Exemplo n.º 1
0
 def test_bbox_nonintersection_is_empty(self):
     bbox1 = BoundingBox((0, 1), (2, 3))
     bbox2 = BoundingBox((2, 3), (1, 2))
     self.assertEqual(bbox1 & bbox2, BoundingBox())
Exemplo n.º 2
0
 def test_bbox_empty_equivalent_to_none(self):
     bbox = BoundingBox((0, 1), (2, 3))
     self.assertEqual(bbox + None, bbox + BoundingBox())
     self.assertEqual(bbox & None, bbox & BoundingBox())
     self.assertEqual(None + bbox, BoundingBox() + bbox)
     self.assertEqual(None & bbox, BoundingBox() & bbox)
Exemplo n.º 3
0
 def test_bbox_empty_is_zero_for_intersection(self):
     bbox = BoundingBox((0, 1), (2, 3))
     self.assertEqual(BoundingBox() & bbox, BoundingBox())
Exemplo n.º 4
0
 def test_bbox_empty_is_identity_for_addition(self):
     bbox = BoundingBox((0, 1), (2, 3))
     self.assertEqual(BoundingBox() + bbox, bbox)
Exemplo n.º 5
0
 def test_bbox_nonempty_is_true(self):
     self.assertTrue(bool(BoundingBox((0, 0), (0, 0))))
Exemplo n.º 6
0
 def test_bbox_empty_is_false(self):
     self.assertFalse(bool(BoundingBox()))
Exemplo n.º 7
0
    def effect(self):

        if len(self.options.ids) < 2:
            inkex.errormsg(_("This extension requires two selected paths."))
            return
        self.prepareSelectionList()

        # center at (0,0)
        bbox = self.patternNode.bounding_box()
        mat = [[1, 0, -bbox.center.x], [0, 1, -bbox.center.y]]
        if self.options.vertical:
            bbox = BoundingBox(-bbox.y, bbox.x)
            mat = (Transform([[0, -1, 0], [1, 0, 0]]) * Transform(mat)).matrix
        mat[1][2] += self.options.noffset
        self.patternNode.transform *= mat

        width = bbox.width
        dx = width + self.options.space

        # check if group and expand it
        patternList = []
        if self.options.grouppick and isinstance(self.patternNode, Group):
            mat = self.patternNode.transform
            for child in self.patternNode:
                child.transform *= mat
                patternList.append(child)
        else:
            patternList.append(self.patternNode)
        # inkex.debug(patternList)

        counter = 0
        for skelnode in self.skeletons.values():
            self.curSekeleton = skelnode.path.to_superpath()
            for comp in self.curSekeleton:
                self.skelcomp, self.lengths = linearize(comp)
                # !!!!>----> TODO: really test if path is closed! end point==start point is not enough!
                self.skelcompIsClosed = (self.skelcomp[0] == self.skelcomp[-1])

                length = sum(self.lengths)
                if self.options.stretch:
                    dx = width + self.options.space
                    n = int(
                        (length - self.options.toffset + self.options.space) /
                        dx)
                    if n > 0:
                        dx = (length - self.options.toffset) / n

                xoffset = self.skelcomp[0][
                    0] - bbox.x.minimum + self.options.toffset
                yoffset = self.skelcomp[0][
                    1] - bbox.y.center - self.options.noffset

                s = self.options.toffset
                while s <= length:
                    mat = self.localTransformAt(s, self.options.follow)
                    if self.options.pickmode == "rand":
                        clone = copy.deepcopy(patternList[random.randint(
                            0,
                            len(patternList) - 1)])

                    if self.options.pickmode == "seq":
                        clone = copy.deepcopy(patternList[counter])
                        counter = (counter + 1) % len(patternList)

                    # !!!--> should it be given an id?
                    # seems to work without this!?!
                    myid = patternList[random.randint(0,
                                                      len(patternList) -
                                                      1)].tag.split('}')[-1]
                    clone.set("id", self.svg.get_unique_id(myid))
                    self.gNode.append(clone)

                    clone.transform *= mat
                    s += dx

        self.patternNode.getparent().remove(self.patternNode)