Check spacing parameter.
(spacing, verbose=None)
| 1443 | |
| 1444 | @verbose |
| 1445 | def _check_spacing(spacing, verbose=None): |
| 1446 | """Check spacing parameter.""" |
| 1447 | # check to make sure our parameters are good, parse 'spacing' |
| 1448 | types = 'a string with values "ico#", "oct#", "all", or an int >= 2' |
| 1449 | space_err = f'"spacing" must be {types}, got type {type(spacing)} ({repr(spacing)})' |
| 1450 | |
| 1451 | if isinstance(spacing, str): |
| 1452 | if spacing == "all": |
| 1453 | stype = "all" |
| 1454 | sval = "" |
| 1455 | elif isinstance(spacing, str) and spacing[:3] in ("ico", "oct"): |
| 1456 | stype = spacing[:3] |
| 1457 | sval = spacing[3:] |
| 1458 | try: |
| 1459 | sval = int(sval) |
| 1460 | except Exception: |
| 1461 | raise ValueError( |
| 1462 | f"{stype} subdivision must be an integer, got {repr(sval)}" |
| 1463 | ) |
| 1464 | lim = 0 if stype == "ico" else 1 |
| 1465 | if sval < lim: |
| 1466 | raise ValueError(f"{stype} subdivision must be >= {lim}, got {sval}") |
| 1467 | else: |
| 1468 | raise ValueError(space_err) |
| 1469 | else: |
| 1470 | stype = "spacing" |
| 1471 | sval = _ensure_int(spacing, "spacing", types) |
| 1472 | if sval < 2: |
| 1473 | raise ValueError(f"spacing must be >= 2, got {sval}.") |
| 1474 | if stype == "all": |
| 1475 | logger.info("Include all vertices") |
| 1476 | ico_surf = None |
| 1477 | src_type_str = "all" |
| 1478 | else: |
| 1479 | src_type_str = f"{stype} = {sval}" |
| 1480 | if stype == "ico": |
| 1481 | logger.info(f"Icosahedron subdivision grade {sval}") |
| 1482 | ico_surf = _get_ico_surface(sval) |
| 1483 | elif stype == "oct": |
| 1484 | logger.info(f"Octahedron subdivision grade {sval}") |
| 1485 | ico_surf = _tessellate_sphere_surf(sval) |
| 1486 | else: |
| 1487 | assert stype == "spacing" |
| 1488 | logger.info(f"Approximate spacing {sval} mm") |
| 1489 | ico_surf = sval |
| 1490 | return stype, sval, ico_surf, src_type_str |
| 1491 | |
| 1492 | |
| 1493 | @verbose |
no test coverage detected