cncjs-kt-ext
cncjs-kt-ext copied to clipboard
Division by 0 / NaN coordinates
Issue: Some combinations of input parameters can result in NaN
for X/Y travel coordinates during probing
Root Cause: Division-by-Zero may occur in this code segment:
let dx = (xmax - xmin) / parseInt((xmax - xmin) / this.delta)
let dy = (ymax - ymin) / parseInt((ymax - ymin) / this.delta)
Test: (#autolevel P1 X14 Y56)
Background:
- Default Margin is 2.5mm
- Default Delta is 10mm
- For probing-only mode
(xmax-xmin)
evaluates toX
- 5mm. IfX
< 15mmparseInt((xmax - xmin) / this.delta)
evaluates to 0 and dx will evaluate to NaN. Same for dy forY
values < 15mm
Proposed fix: Ensure parseInt(..)
-denominator is evaluating to >= 1, e.g.
let dx = (xmax - xmin) / max(parseInt((xmax - xmin) / this.delta), 1)
let dy = (ymax - ymin) / max(parseInt((ymax - ymin) / this.delta), 1)
Note: I have not checked for potential side-effects of the proposed fix!
Thanks for this great plugin!