Skip to content
Path.py 31.9 KiB
Newer Older
            return self._add_part(HorizontalSegment, length, radius)

    ##############################################

    def vertical_to(self, length, radius=None, absolute=False):
            return self._add_part(PathSegment, self.__vector_cls__(0, length), radius,
            return self._add_part(VerticalSegment, length, radius)

    ##############################################

    def absolute_horizontal_to(self, x, radius=None):
        return self._add_part(AbsoluteHorizontalSegment, x, radius)

    def absolute_vertical_to(self, y, radius=None):
        return self._add_part(AbsoluteVerticalSegment, y, radius)
    ##############################################
    def north_to(self, length, radius=None):
        return self._add_part(NorthSegment, length, radius)
    def south_to(self, length, radius=None):
        return self._add_part(SouthSegment, length, radius)
    def west_to(self, length, radius=None):
        return self._add_part(WestSegment, length, radius)
    def east_to(self, length, radius=None):
        return self._add_part(EastSegment, length, radius)
    def north_east_to(self, length, radius=None):
        return self._add_part(NorthEastSegment, length, radius)
    def south_east_to(self, length, radius=None):
        return self._add_part(SouthEastSegment, length, radius)
    def north_west_to(self, length, radius=None):
        return self._add_part(NorthWestSegment, length, radius)
    def south_west_to(self, length, radius=None):
        return self._add_part(SouthWestSegment, length, radius)

    ##############################################

    def line_to(self, point, radius=None, absolute=False):
        return self._add_part(PathSegment, point, radius, absolute=absolute)
    ##############################################

    def close(self, radius=None, close_radius=None):
        # Fixme: identify as close for SVG export <-- meaning ???
        closing = close_radius is not None
        segment = self._add_part(PathSegment, self._p0, radius, absolute=True, closing=closing)
        if closing:
            self.start_segment.close(close_radius)
        self._is_closed = True
        return segment

    ##############################################

    def quadratic_to(self, point1, point2, absolute=False):
        return self._add_part(QuadraticBezierSegment, point1, point2, absolute=absolute)

    ##############################################

    def cubic_to(self, point1, point2, point3, absolute=False):
        return self._add_part(CubicBezierSegment, point1, point2, point3, absolute=absolute)

    ##############################################

    def stringed_quadratic_to(self, point, absolute=False):
        return self._add_part(StringedQuadraticBezierSegment, point, absolute=absolute)

    ##############################################

    def stringed_cubic_to(self, point1, point2, absolute=False):
        return self._add_part(StringedCubicBezierSegment, point1, point2, absolute=absolute)

    ##############################################

    def arc_to(self, point, radius_x, radius_y, angle, large_arc, sweep, absolute=False):
        return self._add_part(ArcSegment, point, radius_x, radius_y, angle, large_arc, sweep,
                              absolute=absolute)

    ##############################################

    @classmethod
    def rounded_rectangle(cls, point, width, height, radius=None):

        path = cls(point)
        path.horizontal_to(width)
        path.vertical_to(height, radius=radius)
        path.horizontal_to(-width, radius=radius)
        path.close(radius=radius, close_radius=radius)

        return path

    ##############################################

    @classmethod
    def circle(cls, point, radius):

        diameter = 2*float(radius)
        path = cls(point)
        path.horizontal_to(diameter)
        path.vertical_to(diameter, radius=radius)
        path.horizontal_to(-diameter, radius=radius)
        path.close(radius=radius, close_radius=radius)

        return path