Fix adaptive barrel refinement and ambiguous decimal-comma inputs
- adaptive: barrel links could attach to coarse leaves (up to 1 mm),
making the whole leaf equipotential and deleting the local spreading
resistance - via-field results read up to ~13% low. Barrel attachment
cells are now pinned into the keep-fine set before the quadtree is
built; the guard ring grades around them.
- skin/dialog: the decimal-comma rewrite turned '1,500' into 1.5, a
silent 1000x error in frequency, test current or cell size. Ambiguous
comma patterns (thousands separators, multiple commas, mixed with a
dot) now raise with a message; a real decimal comma ('1,5') still
parses.
- dialog: Selection.adaptive default now matches the documented
on-by-default; the adaptive accuracy claim is aligned to the measured
0.03% quoted in README and config.
This commit is contained in:
+18
-3
@@ -21,6 +21,7 @@ from __future__ import annotations
|
||||
|
||||
import cmath
|
||||
import math
|
||||
import re
|
||||
|
||||
MU0 = 4e-7 * math.pi
|
||||
|
||||
@@ -58,11 +59,25 @@ def resistance_factor(thickness_m: float, freq_hz: float,
|
||||
/ (rho_ohm_m / thickness_m))
|
||||
|
||||
|
||||
def normalize_decimal(text: str) -> str:
|
||||
"""Accept a European decimal comma ('1,5' -> '1.5'); reject
|
||||
thousands-separator commas ('1,500' would silently become 1.5,
|
||||
a 1000x error that propagates unnoticed into the result)."""
|
||||
if "," in text:
|
||||
if "." in text or text.count(",") > 1 \
|
||||
or re.search(r",\d{3}(?=\D|$)", text):
|
||||
raise ValueError(
|
||||
f"ambiguous comma in '{text}': use '.' as the decimal "
|
||||
"separator and no thousands separators")
|
||||
text = text.replace(",", ".")
|
||||
return text
|
||||
|
||||
|
||||
def parse_frequency(text: str) -> float:
|
||||
"""'0', '100k', '1.5M', '142500' -> Hz; empty -> 0 (DC).
|
||||
Raises ValueError on unparseable or negative input (a typo silently
|
||||
becoming DC would mislabel the result)."""
|
||||
t = text.strip().lower().replace(",", ".").removesuffix("hz").strip()
|
||||
Raises ValueError on unparseable, ambiguous or negative input (a
|
||||
typo silently becoming DC would mislabel the result)."""
|
||||
t = normalize_decimal(text.strip().lower()).removesuffix("hz").strip()
|
||||
if not t:
|
||||
return 0.0
|
||||
mult = 1.0
|
||||
|
||||
Reference in New Issue
Block a user