diff --git a/src/sliceActions/helpers/GCode.js b/src/sliceActions/helpers/GCode.js index bb3fd2a..4cc6bf5 100644 --- a/src/sliceActions/helpers/GCode.js +++ b/src/sliceActions/helpers/GCode.js @@ -11,9 +11,6 @@ export const POSITION_Y = 'Y'; export const POSITION_Z = 'Z'; const PRECISION_INVERSE = 1 / PRECISION; -function toFixedTrimmed(value) { - return (Math.round(value * PRECISION_INVERSE) / PRECISION_INVERSE).toString(); -} export default class { constructor(layerHeight) { @@ -64,10 +61,10 @@ export default class { this._addGCode({ [MOVE]: 0, - [POSITION_X]: toFixedTrimmed(newNozzlePosition.x), - [POSITION_Y]: toFixedTrimmed(newNozzlePosition.y), - [POSITION_Z]: toFixedTrimmed(z), - [SPEED]: toFixedTrimmed(speed * 60) + [POSITION_X]: newNozzlePosition.x, + [POSITION_Y]: newNozzlePosition.y, + [POSITION_Z]: z, + [SPEED]: speed * 60 }); this._nozzlePosition = newNozzlePosition; @@ -84,11 +81,11 @@ export default class { this._addGCode({ [MOVE]: 1, - [POSITION_X]: toFixedTrimmed(newNozzlePosition.x), - [POSITION_Y]: toFixedTrimmed(newNozzlePosition.y), - [POSITION_Z]: toFixedTrimmed(z), - [SPEED]: toFixedTrimmed(speed * 60), - [EXTRUDER]: toFixedTrimmed(this._extruder) + [POSITION_X]: newNozzlePosition.x, + [POSITION_Y]: newNozzlePosition.y, + [POSITION_Z]: z, + [SPEED]: speed * 60, + [EXTRUDER]: this._extruder }); this._nozzlePosition = newNozzlePosition; @@ -105,8 +102,8 @@ export default class { this._addGCode({ [MOVE]: 0, - [EXTRUDER]: toFixedTrimmed(this._extruder), - [SPEED]: toFixedTrimmed(speed * 60) + [EXTRUDER]: this._extruder, + [SPEED]: speed * 60 }); } } @@ -123,8 +120,8 @@ export default class { this._addGCode({ [MOVE]: 0, - [EXTRUDER]: toFixedTrimmed(this._extruder - amount), - [SPEED]: toFixedTrimmed(speed * 60) + [EXTRUDER]: this._extruder - amount, + [SPEED]: speed * 60 }); } } diff --git a/src/sliceActions/slice.js b/src/sliceActions/slice.js index fcd13fc..b3eff9e 100644 --- a/src/sliceActions/slice.js +++ b/src/sliceActions/slice.js @@ -11,6 +11,7 @@ import optimizePaths from './optimizePaths.js'; import shapesToSlices from './shapesToSlices.js'; import slicesToGCode from './slicesToGCode.js'; import applyPrecision from './applyPrecision.js'; +import { PRECISION } from '../constants.js'; // // import removePrecision from './removePrecision.js'; export default function(settings, geometry, openObjectIndexes, constructLinePreview, onProgress) { @@ -68,6 +69,11 @@ export default function(settings, geometry, openObjectIndexes, constructLinePrev return gcode; } +const PRECISION_INVERSE = 1 / PRECISION; +function toFixedTrimmed(value) { + return (Math.round(value * PRECISION_INVERSE) / PRECISION_INVERSE).toString(); +} + function gcodeToString(gcode) { const currentValues = {}; return gcode.reduce((string, command) => { @@ -76,7 +82,7 @@ function gcodeToString(gcode) { } else { let first = true; for (const action in command) { - const value = command[action]; + const value = toFixedTrimmed(command[action]); const currentValue = currentValues[action]; if (first) { string += `${action}${value}`;