@@ -28,7 +28,7 @@ def colinear(*points: complex) -> bool:
2828
2929
3030def force_int (p : complex ) -> complex :
31- "Force the coordinates of the complex number to line on the integer grid."
31+ "Force the coordinates of the complex number to lie on the integer grid."
3232 return complex (round (p .real ), round (p .imag ))
3333
3434
@@ -125,7 +125,10 @@ def fix_number(n: float) -> str:
125125 Otherwise round it to 2 digits."""
126126 if n .is_integer ():
127127 return str (int (n ))
128- return str (round (n , 2 ))
128+ n = round (n , 2 )
129+ if n .is_integer ():
130+ return str (int (n ))
131+ return str (n )
129132
130133
131134class XMLClass :
@@ -138,7 +141,7 @@ def mk_tag(*contents: str, **attrs: str) -> str:
138141 if isinstance (v , float ):
139142 v = fix_number (v )
140143 elif isinstance (v , str ):
141- v = re .sub (r"\d+(\.\d+)" ,
144+ v = re .sub (r"\b\ d+(\.\d+)\b " ,
142145 lambda m : fix_number (float (m .group ())), v )
143146 out += f'{ k .removesuffix ("_" ).replace ("__" , "-" )} ="{ v } " '
144147 out = out .rstrip () + ">" + "" .join (contents )
@@ -182,25 +185,14 @@ def find_dots(points: list[tuple[complex, complex]]) -> list[complex]:
182185
183186def bunch_o_lines (pairs : list [tuple [complex , complex ]], ** options ) -> str :
184187 "Collapse the pairs of points and return the smallest number of <polyline>s."
185- out = ""
186- scale = options ["scale" ]
187- w = options ["stroke_width" ]
188- c = options ["stroke" ]
189188 lines = []
190189 while pairs :
191190 group = take_next_group (pairs )
192191 merge_colinear (group )
193192 # make it a polyline
194193 pts = [group [0 ][0 ]] + [p [1 ] for p in group ]
195194 lines .append (pts )
196- for line in lines :
197- out += XML .polyline (
198- points = " " .join (
199- f"{ p .real * scale } ,{ p .imag * scale } " for p in line ),
200- stroke = c ,
201- stroke__width = w ,
202- )
203- return out
195+ return "" .join (polylinegon (line , ** options ) for line in lines )
204196
205197
206198def id_text (
0 commit comments