holder: fix decimal -D overrides being truncated to int
_filter_params() had a stale short-circuit:
v = float(v) if p.step and p.step != int(p.step) else int(float(v))
For auto-extracted params (the new majority of PARAMS), `p.step is None`,
which is falsy. The conditional took the `int(float(v))` branch and
truncated values like 0.2 -> 0, 0.7 -> 0, 1.5 -> 1. The /holder render
silently dropped every clearance, tolerance, and offset to zero, so
the holder pieces in "both" mode (and a handful of other configurations)
came out merged at their edges. /scad never hit the bug because it
doesn't pass -D overrides — the SCAD defaults applied unchanged.
Fix: always coerce through float, then narrow back to int only when
the result has no fractional part. Verified /holder render with all
defaults now produces the exact same STL bytes as /scad with the
bundled source (md5 match).
This commit is contained in:
@@ -305,10 +305,11 @@ def _filter_params(params: dict) -> dict:
|
|||||||
continue
|
continue
|
||||||
p = known[k]
|
p = known[k]
|
||||||
if p.kind == "number":
|
if p.kind == "number":
|
||||||
v = float(v) if p.step and p.step != int(p.step) else int(float(v))
|
# Always coerce through float — earlier logic short-circuited to
|
||||||
# keep ints for integer-step params
|
# int(float(v)) when step was None (most auto-extracted params),
|
||||||
if isinstance(p.default, int) and float(v).is_integer():
|
# truncating decimals like box_clearance=0.2 → 0.
|
||||||
v = int(v)
|
fv = float(v)
|
||||||
|
v = int(fv) if fv.is_integer() else fv
|
||||||
elif p.kind == "bool":
|
elif p.kind == "bool":
|
||||||
v = bool(v)
|
v = bool(v)
|
||||||
elif p.kind == "select":
|
elif p.kind == "select":
|
||||||
|
|||||||
Reference in New Issue
Block a user