Пример #1
0
    def __init__(self, box1, box2, boxdists=[0,0]):

        self.box1 = box1
        self.box2 = box2

        connector_pt.__init__(self,
            [path.normsubpath([path.normline_pt(self.box1.center[0], self.box1.center[1],
                                                self.box2.center[0], self.box2.center[1])], closed=0)])

        self.omitends(box1, box2)
        self.shortenpath(boxdists)
Пример #2
0
    def __init__(self, box1, box2, relangle=45,
                 absbulge=None, relbulge=None, boxdists=[0,0]):

        # the deviation of arc from the straight line can be specified:
        # 1. By an angle between a straight line and the arc
        #    This angle is measured at the centers of the box.
        # 2. By the largest normal distance between line and arc: absbulge
        #    or, equivalently, by the bulge relative to the length of the
        #    straight line from center to center.
        # Only one can be used.

        self.box1 = box1
        self.box2 = box2

        tangent = (self.box2.center[0] - self.box1.center[0],
                   self.box2.center[1] - self.box1.center[1])
        distance = hypot(*tangent)
        tangent = tangent[0] / distance, tangent[1] / distance

        if relbulge is not None or absbulge is not None:
            # usage of bulge overrides the relangle parameter
            bulge = 0
            if absbulge is not None:
                bulge += absbulge
            if relbulge is not None:
                bulge += relbulge*distance
        else:
            # otherwise use relangle, which should be present
            bulge = 0.5 * distance * math.tan(0.5*radians(relangle))

        if abs(bulge) < normpath._epsilon:
            # fallback solution for too straight arcs
            connector_pt.__init__(self,
                [path.normsubpath([path.normline_pt(*(self.box1.center+self.box2.center))], closed=0)])
        else:
            radius = abs(0.5 * (bulge + 0.25 * distance**2 / bulge))
            centerdist = mathutils.sign(bulge) * (radius - abs(bulge))
            center = (0.5 * (self.box1.center[0] + self.box2.center[0]) + tangent[1]*centerdist,
                      0.5 * (self.box1.center[1] + self.box2.center[1]) - tangent[0]*centerdist)
            angle1 = atan2(self.box1.center[1] - center[1], self.box1.center[0] - center[0])
            angle2 = atan2(self.box2.center[1] - center[1], self.box2.center[0] - center[0])

            if bulge > 0:
                connectorpath = path.path(path.moveto_pt(*self.box1.center),
                                          path.arcn_pt(center[0], center[1], radius, degrees(angle1), degrees(angle2)))
                connector_pt.__init__(self, connectorpath.normpath().normsubpaths)
            else:
                connectorpath = path.path(path.moveto_pt(*self.box1.center),
                                          path.arc_pt(center[0], center[1], radius, degrees(angle1), degrees(angle2)))
                connector_pt.__init__(self, connectorpath.normpath().normsubpaths)

        self.omitends(box1, box2)
        self.shortenpath(boxdists)