0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 01:07:56 +01:00

Code refactoring.

This commit is contained in:
Wouter R 2016-01-06 20:35:19 +01:00
parent d48944e448
commit 5c07947fe5

View File

@ -112,50 +112,49 @@ function draw(_x, _y, _width) {
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(prevX, prevY); ctx.moveTo(prevX, prevY);
var lineWeight = null;
if (_width != undefined && _width < 0) { if (_width != undefined && _width < 0) {
if (settings['printer.bottomEnableTraveling']) { if (settings['printer.bottomEnableTraveling']) {
ctx.moveTo(_x, _y); ctx.moveTo(_x, _y);
} else { } else {
ctx.lineTo(_x, _y); lineWeight = 0.5;
ctx.lineWidth = 0.5;
ctx.stroke();
} }
} else { } else {
ctx.lineTo(_x, _y);
if (_width != undefined) { if (_width != undefined) {
ctx.lineWidth = _width; lineWeight = _width;
} else { } else {
if (drawVariableLineWeight) { if (drawVariableLineWeight) {
var dist = Math.sqrt(Math.pow((prevX - _x), 2) + Math.pow((prevY - _y), 2)); var dist = Math.sqrt(Math.pow((prevX - _x), 2) + Math.pow((prevY - _y), 2));
if (dist < 10) { if (dist < 10) {
lineweight += .25; lineWeight += .25;
} else if (dist < 20) { } else if (dist < 20) {
lineweight += .5; lineWeight += .5;
} else if (dist < 30) { } else if (dist < 30) {
lineweight += .75; lineWeight += .75;
} else if (dist < 50) { } else if (dist < 50) {
lineweight += 1; lineWeight += 1;
} else if (dist < 80) { } else if (dist < 80) {
lineweight += 1.5; lineWeight += 1.5;
} else if (dist < 120) { } else if (dist < 120) {
lineweight += 2.25; lineWeight += 2.25;
} else if (dist < 170) { } else if (dist < 170) {
lineweight += 3.5; lineWeight += 3.5;
} else { } else {
lineweight += 2; lineWeight += 2;
} }
lineweight = Math.min(lineweight, 30); lineWeight = Math.min(lineWeight, 30);
lineweight *= 0.90; lineWeight *= 0.90;
lineweight = Math.max(lineweight, 1.0); lineWeight = Math.max(lineWeight, 1.0);
} else { } else {
lineweight = 2; lineWeight = 2;
}
}
} }
ctx.lineWidth = lineweight; if (lineWeight != null) {
}
ctx.lineCap = 'round'; ctx.lineCap = 'round';
ctx.lineWidth = lineWeight;
ctx.lineTo(_x, _y);
ctx.stroke(); ctx.stroke();
} }
@ -338,18 +337,9 @@ function onCanvasMouseMove(e) {
y = e.layerY; y = e.layerY;
} }
if (prevPoint.x != -1 || prevPoint.y != -1) { var prevPresent = prevPoint.x != -1 || prevPoint.y != -1;
var dist = Math.sqrt(((prevPoint.x - x) * (prevPoint.x - x)) + ((prevPoint.y - y) * (prevPoint.y - y))); var dist = prevPresent ? Math.sqrt(Math.pow((prevPoint.x - x), 2) + Math.pow((prevPoint.y - y), 2)) : undefined;
if (dist > 5) { // replace by setting: doodle3d.simplify.minDistance if (!prevPresent || dist > 5) { // replace dist check by setting: doodle3d.simplify.minDistance
_points.push([x, y, false]);
adjustBounds(x, y);
adjustPreviewTransformation();
draw(x, y);
prevPoint.x = x;
prevPoint.y = y;
}
} else {
// this is called once, every time you start to draw a line
_points.push([x, y, false]); _points.push([x, y, false]);
adjustBounds(x, y); adjustBounds(x, y);
adjustPreviewTransformation(); adjustPreviewTransformation();
@ -439,19 +429,11 @@ function onCanvasTouchMove(e) {
//console.log("f:onCanvasTouchMove >> x,y = "+x+","+y+" , e: " , e); //console.log("f:onCanvasTouchMove >> x,y = "+x+","+y+" , e: " , e);
if (prevPoint.x != -1 || prevPoint.y != -1) { var prevPresent = prevPoint.x != -1 || prevPoint.y != -1;
var dist = Math.sqrt(Math.pow((prevPoint.x - x), 2) + Math.pow((prevPoint.y - y), 2)); var dist = prevPresent ? Math.sqrt(Math.pow((prevPoint.x - x), 2) + Math.pow((prevPoint.y - y), 2)) : undefined;
if (dist > 5) { if (!prevPresent || dist > 5) { // replace dist check by setting: doodle3d.simplify.minDistance
_points.push([x, y, false]); _points.push([x, y, false]);
adjustBounds(x, y) adjustBounds(x, y);
adjustPreviewTransformation();
draw(x, y);
prevPoint.x = x;
prevPoint.y = y;
}
} else {
_points.push([x, y, false]);
adjustBounds(x, y)
adjustPreviewTransformation(); adjustPreviewTransformation();
draw(x, y); draw(x, y);
prevPoint.x = x; prevPoint.x = x;