move casting to string in slice.js

This commit is contained in:
casperlamboo 2018-02-01 18:13:55 +01:00
parent 6a63077b55
commit bc06f703ac
2 changed files with 20 additions and 17 deletions

View File

@ -11,9 +11,6 @@ export const POSITION_Y = 'Y';
export const POSITION_Z = 'Z'; export const POSITION_Z = 'Z';
const PRECISION_INVERSE = 1 / PRECISION; const PRECISION_INVERSE = 1 / PRECISION;
function toFixedTrimmed(value) {
return (Math.round(value * PRECISION_INVERSE) / PRECISION_INVERSE).toString();
}
export default class { export default class {
constructor(layerHeight) { constructor(layerHeight) {
@ -64,10 +61,10 @@ export default class {
this._addGCode({ this._addGCode({
[MOVE]: 0, [MOVE]: 0,
[POSITION_X]: toFixedTrimmed(newNozzlePosition.x), [POSITION_X]: newNozzlePosition.x,
[POSITION_Y]: toFixedTrimmed(newNozzlePosition.y), [POSITION_Y]: newNozzlePosition.y,
[POSITION_Z]: toFixedTrimmed(z), [POSITION_Z]: z,
[SPEED]: toFixedTrimmed(speed * 60) [SPEED]: speed * 60
}); });
this._nozzlePosition = newNozzlePosition; this._nozzlePosition = newNozzlePosition;
@ -84,11 +81,11 @@ export default class {
this._addGCode({ this._addGCode({
[MOVE]: 1, [MOVE]: 1,
[POSITION_X]: toFixedTrimmed(newNozzlePosition.x), [POSITION_X]: newNozzlePosition.x,
[POSITION_Y]: toFixedTrimmed(newNozzlePosition.y), [POSITION_Y]: newNozzlePosition.y,
[POSITION_Z]: toFixedTrimmed(z), [POSITION_Z]: z,
[SPEED]: toFixedTrimmed(speed * 60), [SPEED]: speed * 60,
[EXTRUDER]: toFixedTrimmed(this._extruder) [EXTRUDER]: this._extruder
}); });
this._nozzlePosition = newNozzlePosition; this._nozzlePosition = newNozzlePosition;
@ -105,8 +102,8 @@ export default class {
this._addGCode({ this._addGCode({
[MOVE]: 0, [MOVE]: 0,
[EXTRUDER]: toFixedTrimmed(this._extruder), [EXTRUDER]: this._extruder,
[SPEED]: toFixedTrimmed(speed * 60) [SPEED]: speed * 60
}); });
} }
} }
@ -123,8 +120,8 @@ export default class {
this._addGCode({ this._addGCode({
[MOVE]: 0, [MOVE]: 0,
[EXTRUDER]: toFixedTrimmed(this._extruder - amount), [EXTRUDER]: this._extruder - amount,
[SPEED]: toFixedTrimmed(speed * 60) [SPEED]: speed * 60
}); });
} }
} }

View File

@ -11,6 +11,7 @@ import optimizePaths from './optimizePaths.js';
import shapesToSlices from './shapesToSlices.js'; import shapesToSlices from './shapesToSlices.js';
import slicesToGCode from './slicesToGCode.js'; import slicesToGCode from './slicesToGCode.js';
import applyPrecision from './applyPrecision.js'; import applyPrecision from './applyPrecision.js';
import { PRECISION } from '../constants.js';
// // import removePrecision from './removePrecision.js'; // // import removePrecision from './removePrecision.js';
export default function(settings, geometry, openObjectIndexes, constructLinePreview, onProgress) { export default function(settings, geometry, openObjectIndexes, constructLinePreview, onProgress) {
@ -68,6 +69,11 @@ export default function(settings, geometry, openObjectIndexes, constructLinePrev
return gcode; return gcode;
} }
const PRECISION_INVERSE = 1 / PRECISION;
function toFixedTrimmed(value) {
return (Math.round(value * PRECISION_INVERSE) / PRECISION_INVERSE).toString();
}
function gcodeToString(gcode) { function gcodeToString(gcode) {
const currentValues = {}; const currentValues = {};
return gcode.reduce((string, command) => { return gcode.reduce((string, command) => {
@ -76,7 +82,7 @@ function gcodeToString(gcode) {
} else { } else {
let first = true; let first = true;
for (const action in command) { for (const action in command) {
const value = command[action]; const value = toFixedTrimmed(command[action]);
const currentValue = currentValues[action]; const currentValue = currentValues[action];
if (first) { if (first) {
string += `${action}${value}`; string += `${action}${value}`;