32 return '0 ' + self.text |
32 return '0 ' + self.text |
33 else: |
33 else: |
34 return '0 // ' + self.text |
34 return '0 // ' + self.text |
35 |
35 |
36 class SubfileReference: |
36 class SubfileReference: |
37 def __init__(self, *, color, subfile_path, anchor, matrix): |
37 def __init__(self, *, colour, subfile_path, anchor, matrix): |
38 self.color, self.subfile_path, = color, subfile_path |
38 self.colour, self.subfile_path, = colour, subfile_path |
39 self.anchor, self.matrix = anchor, matrix |
39 self.anchor, self.matrix = anchor, matrix |
40 def __repr__(self): |
40 def __repr__(self): |
41 return str.format('linetypes.SubfileReference(' \ |
41 return str.format('linetypes.SubfileReference(' \ |
42 'color = {color!r}, ' \ |
42 'colour = {colour!r}, ' \ |
43 'subfile_path = {subfile_path!r}, ' \ |
43 'subfile_path = {subfile_path!r}, ' \ |
44 'anchor = {anchor!r}, ' \ |
44 'anchor = {anchor!r}, ' \ |
45 'matrix = {matrix!r})', **self.__dict__) |
45 'matrix = {matrix!r})', **self.__dict__) |
46 def textual_representation(self): |
46 def textual_representation(self): |
47 args = [ |
47 args = [ |
48 1, |
48 1, |
49 self.color, |
49 self.colour, |
50 *self.anchor.coordinates, |
50 *self.anchor.coordinates, |
51 *self.matrix.values, |
51 *self.matrix.values, |
52 self.subfile_path, |
52 self.subfile_path, |
53 ] |
53 ] |
54 return ' '.join(ldraw_str(arg) for arg in args) |
54 return ' '.join(ldraw_str(arg) for arg in args) |
55 |
55 |
56 class BasePolygon: |
56 class BasePolygon: |
57 def __init__(self, *, color, geometry): |
57 def __init__(self, *, colour, geometry): |
58 self.color, self.geometry = color, geometry |
58 self.colour, self.geometry = colour, geometry |
59 def __repr__(self): |
59 def __repr__(self): |
60 return str.format('linetypes.{typename}(' \ |
60 return str.format('linetypes.{typename}(' \ |
61 'color = {color!r}, ' \ |
61 'colour = {colour!r}, ' \ |
62 'geometry = {geometry!r})', |
62 'geometry = {geometry!r})', |
63 typename = type(self).__name__, |
63 typename = type(self).__name__, |
64 color = self.color, |
64 colour = self.colour, |
65 geometry = self.geometry, |
65 geometry = self.geometry, |
66 ) |
66 ) |
67 def base_textual_representation(self): |
67 def base_textual_representation(self): |
68 args = [self.color] |
68 args = [self.colour] |
69 for vertex in self.geometry.vertices: |
69 for vertex in self.geometry.vertices: |
70 args += vertex.coordinates |
70 args += vertex.coordinates |
71 return ' '.join(ldraw_str(arg) for arg in args) |
71 return ' '.join(ldraw_str(arg) for arg in args) |
72 |
72 |
73 class LineSegment(BasePolygon): |
73 class LineSegment(BasePolygon): |
81 class Quadrilateral(BasePolygon): |
81 class Quadrilateral(BasePolygon): |
82 def textual_representation(self): |
82 def textual_representation(self): |
83 return '4 ' + self.base_textual_representation() |
83 return '4 ' + self.base_textual_representation() |
84 |
84 |
85 class Contour(LineSegment): |
85 class Contour(LineSegment): |
86 def __init__(self, *, color, geometry, control_points): |
86 def __init__(self, *, colour, geometry, control_points): |
87 super().__init__(color = color, geometry = geometry) |
87 super().__init__(colour = colour, geometry = geometry) |
88 self.control_points = control_points |
88 self.control_points = control_points |
89 assert(len(self.control_points) == 2) |
89 assert(len(self.control_points) == 2) |
90 def __repr__(self): |
90 def __repr__(self): |
91 return str.format('linetypes.Contour(' \ |
91 return str.format('linetypes.Contour(' \ |
92 'color = {color!r}, ' \ |
92 'colour = {colour!r}, ' \ |
93 'geometry = {geometry!r}, ' \ |
93 'geometry = {geometry!r}, ' \ |
94 'control_points = {control_points!r})', **self.__dict__) |
94 'control_points = {control_points!r})', **self.__dict__) |
95 def textual_representation(self): |
95 def textual_representation(self): |
96 result = '5 ' + self.base_textual_representation() |
96 result = '5 ' + self.base_textual_representation() |
97 for control_point in self.control_points: |
97 for control_point in self.control_points: |