Conditions | 13 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like ed2d.assets.OBJ.__process_in_house() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | |||
64 | def __process_in_house(self, filename): |
||
65 | with open(filename, "r") as objfl: |
||
66 | |||
67 | for line in objfl: |
||
68 | |||
69 | value = line.split() |
||
70 | valueType = value[0] |
||
71 | |||
72 | if valueType not in ['f', 'v', 'vt', 'vn', 'g', 'usemtl']: |
||
73 | continue |
||
74 | |||
75 | value = value[1:] |
||
76 | |||
77 | # Check first and continue on early because of string splitting |
||
78 | if valueType == "f": |
||
79 | temp = [item.split("/") for item in value] |
||
80 | |||
81 | for i in range(3): |
||
82 | if temp[i][1] != '': |
||
83 | self.uvIndices[self.fnumber] = int(temp[i][1]) |
||
84 | self.vertexIndices[self.fnumber] = int(temp[i][0]) |
||
85 | self.normalIndices[self.fnumber] = int(temp[i][2]) |
||
86 | self.fnumber += 1 |
||
87 | |||
88 | continue |
||
89 | |||
90 | value = list(map(float, value)) |
||
91 | |||
92 | if valueType == "v": |
||
93 | v = [value[0], value[1], value[2]] |
||
94 | self.tempVertices[self.vnumber] = v |
||
95 | self.vnumber += 1 |
||
96 | |||
97 | elif valueType == "vt": |
||
98 | vt = [value[0], value[0]] |
||
99 | self.tempUVs[self.vtnumber] = vt |
||
100 | self.vtnumber += 1 |
||
101 | |||
102 | elif valueType == "vn": |
||
103 | n = [value[0], value[1], value[2]] |
||
104 | self.tempNormals[self.vnnumber] = n |
||
105 | self.vnnumber += 1 |
||
106 | |||
107 | elif valueType == "g": |
||
108 | g = value[0] |
||
109 | self.tempMaterials[self.matnumber] = g |
||
110 | self.matnumber += 1 |
||
111 | elif valueType == "usemtl": |
||
112 | gs = value[0] |
||
113 | # Need a way to generate which material per what face |
||
114 | # In a specific order |
||
115 | self.usedMaterials[sef.matnumber] = gs |
||
116 | |||
135 |