linetypes.py

Sun, 10 Dec 2017 15:45:50 +0200

author
Santeri Piippo
date
Sun, 10 Dec 2017 15:45:50 +0200
changeset 1
5411a25cfca7
parent 0
55b4c97d44c5
child 3
1dc58f44d556
permissions
-rw-r--r--

Parsing function complete

class EmptyLine:
    def __repr__(self):
        return 'linetypes.EmptyLine()'

class Comment:
    def __init__(self, text, style = 'old'):
        if style == 'old' and text.startswith('//'):
            self.text = text[3:].strip()
            self.style = 'new'
        else:
            self.text = text
            self.style = style
    def __repr__(self):
        return str.format('linetypes.Comment({text!r}, {style!r})',
            text = self.text,
            style = self.style,
        )

class SubfileReference:
    def __init__(self, *, color, subfile_path, anchor, matrix):
        self.color, self.subfile_path, = color, subfile_path
        self.anchor, self.matrix = anchor, matrix
    def __repr__(self):
        return str.format('linetypes.SubfileReference(' \
            'color = {color!r}, ' \
            'subfile_path = {subfile_path!r}, ' \
            'anchor = {anchor!r}, ' \
            'matrix = {matrix!r})', **self.__dict__)

class LineSegment:
    def __init__(self, *, color, geometry):
        self.color, self.geometry = color, geometry
    def __repr__(self):
        return str.format('linetypes.{typename}(' \
            'color = {color!r}, ' \
            'geometry = {geometry!r})',
            typename = type(self).__name__,
            color = self.color,
            geometry = self.geometry,
        )

class Triangle(LineSegment):
    pass

class Quadrilateral(LineSegment):
    pass

class Contour(LineSegment):
    def __init__(self, *, color, geometry, control_points):
        super().__init__(color = color, geometry = geometry)
        self.control_points = control_points
        assert(len(self.control_points) == 2)
    def __repr__(self):
        return str.format('linetypes.Contour(' \
            'color = {color!r}, ' \
            'geometry = {geometry!r}, ' \
            'control_points = {control_points!r})', **self.__dict__)

mercurial