cncjs-kt-ext icon indicating copy to clipboard operation
cncjs-kt-ext copied to clipboard

Division by 0 / NaN coordinates

Open Duffmann opened this issue 2 years ago • 0 comments

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 to X - 5mm. If X < 15mm parseInt((xmax - xmin) / this.delta) evaluates to 0 and dx will evaluate to NaN. Same for dy for Y 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!

Duffmann avatar Oct 30 '22 16:10 Duffmann