diff --git a/src/add/array.js b/src/add/array.js index c0f4f775..7d645a38 100644 --- a/src/add/array.js +++ b/src/add/array.js @@ -253,6 +253,7 @@ Math.bound = function(val, min, max) { }; Number.prototype.round = function(digits) { + if (digits === 0) return this.valueOf() | 0; const pow = Math.pow(10, digits || 3); return Math.round(this.valueOf() * pow) / pow; }; diff --git a/src/geo/base.js b/src/geo/base.js index dcace90e..4ce26fa8 100644 --- a/src/geo/base.js +++ b/src/geo/base.js @@ -134,7 +134,9 @@ function inRange(value, min, max) { } function round(v, zeros) { - let pow = Math.pow(10, zeros || round_decimal_precision); + const prec = zeros !== undefined ? zeros : round_decimal_precision; + if (prec === 0) return v | 0; + let pow = Math.pow(10, prec); return Math.round(v * pow) / pow; } diff --git a/src/kiri-mode/cam/export.js b/src/kiri-mode/cam/export.js index 98a33e57..ac6c29b6 100644 --- a/src/kiri-mode/cam/export.js +++ b/src/kiri-mode/cam/export.js @@ -131,7 +131,7 @@ CAM.export = function(print, online) { function add0(val, opt) { let s = val.toString(), d = s.indexOf("."); - if (d < 0) { + if (d < 0 && decimals > 0) { return opt ? s : s + '.0'; } else { return val.toFixed(decimals); @@ -170,7 +170,6 @@ CAM.export = function(print, online) { newpos.x = util.round(newpos.x, decimals); newpos.y = util.round(newpos.y, decimals); newpos.z = util.round(newpos.z, decimals); - // newpos.a = util.round(newpos.a || 0, decimals); // on tool change let changeTool = out.tool != pos.t; @@ -333,7 +332,7 @@ CAM.export = function(print, online) { if (map.Y) scale.y = map.Y; if (map.Z) scale.z = map.Z; if (map.DEC !== undefined) decimals = parseInt(map.DEC); - console.log('scaling axes', scale); + console.log('export scaling applied', map); } catch (e) { console.log('malformed scale directive', line); }