16
16
version = sys .version_info [0 ]
17
17
18
18
19
+ class Doc :
20
+ def __init__ (self ):
21
+ self .DisplayName = "gCPy.Doc(DocDisplayName)"
22
+ self .FilePath = "gCPy.Doc(DocFilePath)"
23
+
24
+
19
25
class Line :
20
26
def __init__ (self , * args ):
21
27
"""Adds new line using two input points, or two input lists or 6 input doubles
@@ -24,19 +30,29 @@ def __init__(self, *args):
24
30
"""
25
31
if len (args ) == 2 :
26
32
if isinstance (args [0 ], Point ) and isinstance (args [1 ], Point ):
33
+ print "2 Point Instances"
27
34
self .X1 = args [0 ].X
28
35
self .Y1 = args [0 ].Y
29
- self .Z1 = args [0 ].X
30
- self .X2 = args [1 ].Z
36
+ self .Z1 = args [0 ].Z
37
+ self .X2 = args [1 ].X
31
38
self .Y2 = args [1 ].Y
32
39
self .Z2 = args [1 ].Z
33
- elif isinstance (args [0 ], list ) and isinstance (args [1 ], list ):
40
+ elif isinstance (args [0 ], list ) and isinstance (args [1 ], list ) and args [0 ][0 ] != '<Point>' and args [1 ][0 ] != '<Point>' :
41
+ print "2 List Instances"
34
42
self .X1 = args [0 ][0 ]
35
43
self .Y1 = args [0 ][1 ]
36
44
self .Z1 = args [0 ][2 ]
37
45
self .X2 = args [1 ][0 ]
38
46
self .Y2 = args [1 ][1 ]
39
47
self .Z2 = args [1 ][2 ]
48
+ elif isinstance (args [0 ], list ) and isinstance (args [1 ], list ) and args [0 ][0 ] == '<Point>' and args [1 ][0 ] == '<Point>' :
49
+ print "2 List Instances of type 2"
50
+ self .X1 = args [0 ][1 ]
51
+ self .Y1 = args [0 ][2 ]
52
+ self .Z1 = args [0 ][3 ]
53
+ self .X2 = args [1 ][1 ]
54
+ self .Y2 = args [1 ][2 ]
55
+ self .Z2 = args [1 ][3 ]
40
56
elif version == 2 :
41
57
if isinstance (args [0 ], basestring ) and isinstance (args [1 ], basestring ):
42
58
pointa = Point (args [0 ])
@@ -66,20 +82,7 @@ def __init__(self, *args):
66
82
self .Z2 = args [5 ]
67
83
68
84
def addLine (self ):
69
- return "gCPy.Line(" + str (self .X1 ) + ", " \
70
- + str (self .Y1 ) + ", " \
71
- + str (self .Z1 ) + ", " \
72
- + str (self .X2 ) + ", " \
73
- + str (self .Y2 ) + ", " \
74
- + str (self .Z2 ) + ")"
75
-
76
- def __repr__ (self ):
77
- return "gCPy.Line(" + str (self .X1 ) + ", " \
78
- + str (self .Y1 ) + ", " \
79
- + str (self .Z1 ) + ", " \
80
- + str (self .X2 ) + ", " \
81
- + str (self .Y2 ) + ", " \
82
- + str (self .Z2 ) + ")"
85
+ return ['<Line>' ,self .X1 , self .Y1 , self .Z1 , self .X2 , self .Y2 , self .Z2 , '<Line>' ]
83
86
84
87
def length (self ):
85
88
return ((self .X2 - self .X1 ) ** 2 + (self .Y2 - self .Y1 ) ** 2 + (self .Z2 - self .Z1 ) ** 2 ) ** 0.5
@@ -89,7 +92,11 @@ def pointOnLine(self, parameter=0.5):
89
92
(self .Y2 - self .Y1 ) * parameter + self .Y1 , \
90
93
(self .Z2 - self .Z1 ) * parameter + self .Z1 )
91
94
95
+ def __repr__ (self ):
96
+ return ['<Line>' ,self .X1 , self .Y1 , self .Z1 , self .X2 , self .Y2 , self .Z2 , '</Line>' ]
92
97
98
+ def __str__ (self ):
99
+ return str (['<Line>' ,self .X1 , self .Y1 , self .Z1 , self .X2 , self .Y2 , self .Z2 , '</Line>' ])
93
100
94
101
95
102
class Point :
@@ -113,15 +120,6 @@ def __init__(self, x=0., y=0., z=0.):
113
120
self .X = x [0 ]
114
121
self .Y = x [1 ]
115
122
self .Z = x [2 ]
116
- elif isinstance (x , basestring ):
117
- new_vars = []
118
- x = x .replace ("gCPy.Point(" , "" ).replace (")" , "" ).lstrip ().rstrip ()
119
- variables = x .split ("," )
120
- for i in variables :
121
- new_vars .append (float (i ))
122
- self .X = new_vars [0 ]
123
- self .Y = new_vars [1 ]
124
- self .Z = new_vars [2 ]
125
123
else :
126
124
self .X = x
127
125
self .Y = y
@@ -131,52 +129,17 @@ def __init__(self, x=0., y=0., z=0.):
131
129
self .X = x [0 ]
132
130
self .Y = x [1 ]
133
131
self .Z = x [2 ]
134
- elif isinstance (x , str ):
135
- new_vars = []
136
- x = x .replace ("gCPy.Point(" , "" ).replace (")" , "" ).lstrip ().rstrip ()
137
- variables = x .split ("," )
138
- for i in variables :
139
- new_vars .append (float (i ))
140
- self .X = new_vars [0 ]
141
- self .Y = new_vars [1 ]
142
- self .Z = new_vars [2 ]
143
132
else :
144
133
self .X = x
145
134
self .Y = y
146
135
self .Z = z
147
- self .addPoint = "gCPy. Point(" + str ( x ) + "," + str ( y ) + "," + str ( z ) + ")"
136
+ self .addPoint = [ '< Point>' , x , y , z , '</Point>' ]
148
137
149
138
def __repr__ (self ):
150
- return "gCPy. Point(" + str ( self .X ) + "," + str ( self .Y ) + "," + str ( self .Z ) + ")"
139
+ return [ '< Point>' , self .X , self .Y , self .Z , '</Point>' ]
151
140
152
141
def __str__ (self ):
153
- return "gCPy.Point(" + str (self .X ) + "," + str (self .Y ) + "," + str (self .Z ) + ")"
154
-
155
- class Surface :
156
- def __init__ (self , * args ):
157
- if len (args ) == 4 :
158
- if isinstance (args [0 ], Point ) and isinstance (args [1 ], Point ) and isinstance (args [2 ], Point ) and isinstance (args [3 ], Point ):
159
- self .P1 = args [0 ]
160
- self .P2 = args [1 ]
161
- self .P3 = args [2 ]
162
- self .P4 = args [3 ]
163
- self .addSurface = "gCPy.Surface(" + str (args [0 ].X ) + "," \
164
- + str (args [0 ].Y ) + "," \
165
- + str (args [0 ].Z ) + "," \
166
- + str (args [1 ].X ) + "," \
167
- + str (args [1 ].Y ) + "," \
168
- + str (args [1 ].Z ) + "," \
169
- + str (args [2 ].X ) + "," \
170
- + str (args [2 ].Y ) + "," \
171
- + str (args [2 ].Z ) + "," \
172
- + str (args [3 ].X ) + "," \
173
- + str (args [3 ].Y ) + "," \
174
- + str (args [3 ].Z ) + "," \
175
- + ")"
176
- elif len (args ) == 2 :
177
- pass
178
- else :
179
- print "you have to create surface from 4 points"
142
+ return str (['<Point>' , self .X , self .Y , self .Z , '</Point>' ])
180
143
181
144
182
145
########################### DEFINE METHODS ################################
@@ -197,18 +160,19 @@ def addLine(*args):
197
160
198
161
def addPoint (* args ):
199
162
"""
163
+
200
164
:param args:
201
165
:return:
202
166
"""
203
167
if len (args ) == 1 :
204
168
return Point (args [0 ])
205
169
elif len (args ) == 3 :
206
- return Point (args [0 ], args [1 ], args [2 ])
170
+ return Point (args [0 ], args [1 ], args [2 ]). addPoint
207
171
208
172
209
- def addSurface (* args ):
210
- return Surface (args [0 ], args [1 ], args [2 ], args [3 ]).addSurface
173
+ ##################################vars#################################
211
174
175
+ doc = Doc ();
212
176
213
177
if __name__ == '__main__' :
214
178
print __name__
0 commit comments