@@ -28,7 +28,7 @@ def colinear(*points: complex) -> bool:
28
28
29
29
30
30
def 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."
32
32
return complex (round (p .real ), round (p .imag ))
33
33
34
34
@@ -125,7 +125,10 @@ def fix_number(n: float) -> str:
125
125
Otherwise round it to 2 digits."""
126
126
if n .is_integer ():
127
127
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 )
129
132
130
133
131
134
class XMLClass :
@@ -138,7 +141,7 @@ def mk_tag(*contents: str, **attrs: str) -> str:
138
141
if isinstance (v , float ):
139
142
v = fix_number (v )
140
143
elif isinstance (v , str ):
141
- v = re .sub (r"\d+(\.\d+)" ,
144
+ v = re .sub (r"\b\ d+(\.\d+)\b " ,
142
145
lambda m : fix_number (float (m .group ())), v )
143
146
out += f'{ k .removesuffix ("_" ).replace ("__" , "-" )} ="{ v } " '
144
147
out = out .rstrip () + ">" + "" .join (contents )
@@ -182,25 +185,14 @@ def find_dots(points: list[tuple[complex, complex]]) -> list[complex]:
182
185
183
186
def bunch_o_lines (pairs : list [tuple [complex , complex ]], ** options ) -> str :
184
187
"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" ]
189
188
lines = []
190
189
while pairs :
191
190
group = take_next_group (pairs )
192
191
merge_colinear (group )
193
192
# make it a polyline
194
193
pts = [group [0 ][0 ]] + [p [1 ] for p in group ]
195
194
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 )
204
196
205
197
206
198
def id_text (
0 commit comments