Answers the list with rounded units (and all of the other items in the argument list) are a Unit instance. >>> uRound(Em(2.3)) 2em >>> uRound(4.2) 4pt >>> uRound(2, 2.4, pt(14.4), (20.9, pt(19.8))) [2pt, 2pt, 14pt, [21pt, 20pt]] >>> uRound(pt(1.3), pt(2.4), pt(3.5))
(u, *args)
| 306 | return hasattr(u, 'v') and hasattr(u, 'g') and hasattr(u, 'base') |
| 307 | |
| 308 | def uRound(u, *args): |
| 309 | """Answers the list with rounded units (and all of the other items in the |
| 310 | argument list) are a Unit instance. |
| 311 | |
| 312 | >>> uRound(Em(2.3)) |
| 313 | 2em |
| 314 | >>> uRound(4.2) |
| 315 | 4pt |
| 316 | >>> uRound(2, 2.4, pt(14.4), (20.9, pt(19.8))) |
| 317 | [2pt, 2pt, 14pt, [21pt, 20pt]] |
| 318 | >>> uRound(pt(1.3), pt(2.4), pt(3.5)) |
| 319 | [1pt, 2pt, 4pt] |
| 320 | >>> uRound(pt(1.000001), pt(2.44444449), 3, pt(mm(4))) |
| 321 | [1pt, 2pt, 3pt, 11pt] |
| 322 | """ |
| 323 | if args: |
| 324 | if isinstance(u, (list, tuple)): |
| 325 | u = list(u) |
| 326 | else: |
| 327 | u = [u] |
| 328 | for arg in args: |
| 329 | u.append(arg) |
| 330 | if isUnit(u): |
| 331 | u = u.rounded |
| 332 | elif isinstance(u, (int, float)): |
| 333 | u = pt(u).rounded |
| 334 | elif isinstance(u, (list, tuple)): |
| 335 | ruu = [] |
| 336 | for uu in u: |
| 337 | ruu.append(uRound(uu)) # Can be nested tuples. |
| 338 | u = ruu |
| 339 | return u |
| 340 | |
| 341 | def classOf(u): |
| 342 | """Answers the class of the Unit instance. Otherwise answer None. |