Conditions | 6 |
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:
1 | |||
6 | def __init__(self, fileName): |
||
7 | ''' Wavefront .obj file parser.''' |
||
8 | fcount = 0 |
||
9 | vcount = 0 |
||
10 | vtcount = 0 |
||
11 | vncount = 0 |
||
12 | |||
13 | # Load the file |
||
14 | objfile = open(fileName, "r") |
||
15 | |||
16 | # Do a head count |
||
17 | for line in objfile: |
||
18 | value = line[:2] |
||
19 | if value == 'f ': |
||
20 | fcount += 1 |
||
21 | elif value == 'v ': |
||
22 | vcount += 1 |
||
23 | elif value == 'vt': |
||
24 | vtcount += 1 |
||
25 | elif value == 'vn': |
||
26 | vncount += 1 |
||
27 | |||
28 | fcount *= 3 |
||
29 | vcount *= 3 |
||
30 | vtcount *= 3 |
||
31 | vncount *= 3 |
||
32 | |||
33 | self.tempVertices = [None] * vcount |
||
34 | self.tempNormals = [None] * vncount |
||
35 | |||
36 | self.tempUVs = [None] * fcount |
||
37 | |||
38 | self.vertexIndices = [None] * fcount |
||
39 | self.normalIndices = [None] * fcount |
||
40 | self.uvIndices = [None] * fcount |
||
41 | |||
42 | self.finalVertices = [None] * fcount |
||
43 | self.finalNormals = [None] * fcount |
||
44 | self.finalUVs = [None] * fcount |
||
45 | |||
46 | self.fnumber = 0 |
||
47 | self.vnumber = 0 |
||
48 | self.vtnumber = 0 |
||
49 | self.vnnumber = 0 |
||
50 | |||
51 | # Process the data |
||
52 | self.__process_in_house(objfile) |
||
53 | # Finalize |
||
54 | self.get_final_data() |
||
55 | |||
56 | # Close the file |
||
57 | objfile.close() |
||
58 | |||
120 |