@@ -122,61 +122,95 @@ def arc_on_two_points_and_slope(self,st,end,slope) :
122
122
a = (st - c ).cross (slope )
123
123
return Arc (st ,end ,c ,a )
124
124
125
+ def get_arg_comb (self ,s ,args ):
126
+ s = list (s )
127
+ args = {"x" :x ,"y" :y ,"a" :a ,"r" :r ,"i" :i ,"j" :j ,"l" :l }
128
+ for i in args :
129
+ if (args [i ] == None and i in s or
130
+ args [i ] != None and i not in s ) :
131
+ return False
132
+ return True
125
133
126
134
def get_arc_param (self ,x ,y ,a ,r ,i ,j ,l ) :
127
135
st = self .p
128
-
129
- if a == None and r == None and i == None and j == None and l == None :
136
+ c = None
137
+ # asume not enought params use slope.
138
+ if x != None or y != None :
130
139
# using two points and slope.
131
- if x == None and y == None : error ("To few parametersfor arc. Command: %s" % self .command )
132
140
end = P (x if x != None else self .p .x , y if y != None else self .p .y )
133
141
return self .arc_on_two_points_and_slope (self .p ,end ,self .slope )
142
+
143
+ if a != None :
144
+ if l != None :
145
+ r = l / a / 2
146
+ if r != None :
147
+ c = self .p + self .slope .ccw ()* r
148
+ if i != None or j != None :
149
+ c = P (i if i != None else self .p .x , j if j != None else self .p .y )
150
+ if c != None :
151
+ end = (self .p - c ).rotate (a ) + c
152
+ return self .arc_on_two_points_and_slope (self .p ,end ,self .slope )
153
+
154
+ if l != None :
155
+ if i != None or j != None :
156
+ c = P (i if i != None else self .p .x , j if j != None else self .p .y )
157
+ r = (self .p - c ).mag ()
158
+ if r != None :
159
+ a = l / r / 2
160
+ return get_arc_param (None , None , a , r , None , None , None )
161
+
162
+ error ("To few parametersfor arc. Command: %s" % self .command )
134
163
135
-
164
+
136
165
def draw_arc (self ,x ,y ,a ,r ,i ,j ,l ) :
137
166
st = self .p
138
167
arc = self .get_arc_param (x ,y ,a ,r ,i ,j ,l )
139
- warn (arc )
168
+ # warn(arc)
140
169
self .path .join (arc .to_csp ())
141
170
142
- def parse_command (self , a ) :
143
- if a .strip () == "" : return
144
- r = re . match ( "\s*([almhvALMHV])?\s*([alxyrijALXYRIJ\d\.\-\s]*)" , a )
145
- self . command = a
171
+ def parse_command (self , command ) :
172
+ if command .strip () == "" : return
173
+ self . command = command
174
+ r = re . match ( "\s*([almhvALMHV]?)\s*((\s*[alxyrijdALXYRIJD]\s*\-?[\d\.]+)*)\s*" , command )
146
175
if not r :
147
- error ("Cannot parse command: \" %s\" " % a )
148
- else :
149
- t ,params = r .groups ()
150
- if t == None or t == "" :
151
- t = self .last_command
152
- # parse the parameters
153
- x ,y ,a ,l ,r ,i ,j = None , None , None , None , None , None , None
154
- try :
155
- self .slope = self .path .slope (- 1 ,- 1 ,1 )
156
- except :
157
- self .slope = P (1. ,0. )
158
- for p in re .findall ("([alxyrijALXYRIJ])\s*(\-?\d*\.?\d*)" ,params ) :
159
- #warn(p)
160
- p = list (p )
161
- if p [0 ] == "A" : a = - float (p [1 ])/ 180 * pi
162
- elif p [0 ] == "a" : a = self .slope .angle () - float (p [1 ])/ 180 * pi
163
- else : p [1 ] = float (p [1 ])* self .options .units
164
- if p [0 ] == "x" : x = self .p .x + p [1 ]
165
- elif p [0 ] == "X" : x = p [1 ]
166
- elif p [0 ] == "y" : y = self .p .y - p [1 ]
167
- elif p [0 ] == "Y" : y = - p [1 ]
168
- elif p [0 ] == "i" : i = self .p .x + p [1 ]
169
- elif p [0 ] == "I" : I = p [1 ]
170
- elif p [0 ] == "j" : j = self .p .y - p [1 ]
171
- elif p [0 ] == "J" : J = - p [1 ]
172
- elif p [0 ] in ("r" ,"R" ) : r = - p [1 ]
173
- elif p [0 ] in ("l" ,"L" ) : l = p [1 ]
174
-
175
- # exec command
176
- if t in ("l" ,"L" ) : self .draw_line (x ,y ,a ,l )
177
- if t in ("a" ,"A" ) : self .draw_arc (x ,y ,a ,r ,i ,j ,l )
178
- if t in ("m" ,"M" ) : self .move_to (x ,y ,a ,l )
179
- self .last_command = t
176
+ error ("Cannot parse command: \" %s\" " % command )
177
+
178
+ r = re .match ("\s*([almhvALMHV])\s*([alxyrijdALXYRIJD].*)" , command )
179
+ if r :
180
+ warn (r .groups ())
181
+ t , command = r .groups ()
182
+ else :
183
+ t = self .last_command
184
+
185
+ # parse the parameters
186
+ x ,y ,a ,l ,r ,i ,j = None , None , None , None , None , None , None
187
+ try :
188
+ self .slope = self .path .slope (- 1 ,- 1 ,1 )
189
+ except :
190
+ self .slope = P (1. ,0. )
191
+ for p in re .findall ("([alxyrijALXYRIJ])\s*(\-?\d*\.?\d*)" , command ) :
192
+ #warn(p)
193
+ p = list (p )
194
+ if p [0 ] == "A" : a = - float (p [1 ])/ 180 * pi
195
+ elif p [0 ] == "a" : a = self .slope .angle () - float (p [1 ])/ 180 * pi
196
+ else : p [1 ] = float (p [1 ])* self .options .units
197
+ if p [0 ] == "x" : x = self .p .x + p [1 ]
198
+ elif p [0 ] == "X" : x = p [1 ]
199
+ elif p [0 ] == "y" : y = self .p .y - p [1 ]
200
+ elif p [0 ] == "Y" : y = - p [1 ]
201
+ elif p [0 ] == "i" : i = self .p .x + p [1 ]
202
+ elif p [0 ] == "I" : I = p [1 ]
203
+ elif p [0 ] == "j" : j = self .p .y - p [1 ]
204
+ elif p [0 ] == "J" : J = - p [1 ]
205
+ elif p [0 ] in ("r" ,"R" ) : r = p [1 ]
206
+ elif p [0 ] in ("d" ,"D" ) : r = p [1 ]/ 2
207
+ elif p [0 ] in ("l" ,"L" ) : l = p [1 ]
208
+
209
+ # exec command
210
+ if t in ("l" ,"L" ) : self .draw_line (x ,y ,a ,l )
211
+ if t in ("a" ,"A" ) : self .draw_arc (x ,y ,a ,r ,i ,j ,l )
212
+ if t in ("m" ,"M" ) : self .move_to (x ,y ,a ,l )
213
+ self .last_command = t
180
214
181
215
def effect (self ) :
182
216
if self .options .silent :
0 commit comments