comment optimize path code

This commit is contained in:
casperlamboo 2016-05-06 19:47:42 +02:00
parent 51412b5599
commit bf0f504c34

View File

@ -6,74 +6,74 @@ export default class {
} }
optimizePaths(start) { optimizePaths(start) {
if (this.brim !== undefined && this.brim.length > 0) { // if (this.brim !== undefined && this.brim.length > 0) {
this.brim = this.brim.optimizePath(start); // this.brim = this.brim.optimizePath(start);
start = this.brim.lastPoint(); // start = this.brim.lastPoint();
} // }
//
var parts = []; // var parts = [];
//
while (this.parts.length > 0) { // while (this.parts.length > 0) {
var closestDistance = Infinity; // var closestDistance = Infinity;
var closestPart; // var closestPart;
//
for (var i = 0; i < this.parts.length; i ++) { // for (var i = 0; i < this.parts.length; i ++) {
var part = this.parts[i]; // var part = this.parts[i];
if (part.shape.closed) { // if (part.shape.closed) {
var bounds = part.outerLine.bounds(); // var bounds = part.outerLine.bounds();
} // }
else { // else {
var bounds = part.shape.bounds(); // var bounds = part.shape.bounds();
} // }
//
var top = bounds.top - start.y; // var top = bounds.top - start.y;
var bottom = start.y - bounds.bottom; // var bottom = start.y - bounds.bottom;
var left = bounds.left - start.x; // var left = bounds.left - start.x;
var right = start.x - bounds.right; // var right = start.x - bounds.right;
//
var distance = Math.max(top, bottom, left, right); // var distance = Math.max(top, bottom, left, right);
//
if (distance < closestDistance) { // if (distance < closestDistance) {
closestDistance = distance; // closestDistance = distance;
closestPart = i; // closestPart = i;
} // }
} // }
//
var part = this.parts.splice(closestPart, 1)[0]; // var part = this.parts.splice(closestPart, 1)[0];
parts.push(part); // parts.push(part);
//
if (part.shape.closed) { // if (part.shape.closed) {
if (part.outerLine.length > 0) { // if (part.outerLine.length > 0) {
part.outerLine = part.outerLine.optimizePath(start); // part.outerLine = part.outerLine.optimizePath(start);
start = part.outerLine.lastPoint(); // start = part.outerLine.lastPoint();
} // }
//
for (var j = 0; j < part.innerLines.length; j ++) { // for (var j = 0; j < part.innerLines.length; j ++) {
var innerLine = part.innerLines[j]; // var innerLine = part.innerLines[j];
if (innerLine.length > 0) { // if (innerLine.length > 0) {
part.innerLines[j] = innerLine.optimizePath(start); // part.innerLines[j] = innerLine.optimizePath(start);
start = part.innerLines[j].lastPoint(); // start = part.innerLines[j].lastPoint();
} // }
} // }
//
if (part.fill.length > 0) { // if (part.fill.length > 0) {
part.fill = part.fill.optimizePath(start); // part.fill = part.fill.optimizePath(start);
start = part.fill.lastPoint(); // start = part.fill.lastPoint();
} // }
} // }
else { // else {
part.shape.optimizePath(start); // part.shape.optimizePath(start);
start = part.shape.lastPoint(); // start = part.shape.lastPoint();
} // }
//
} // }
//
this.parts = parts; // this.parts = parts;
//
if (this.support !== undefined && this.support.length > 0) { // if (this.support !== undefined && this.support.length > 0) {
this.support = this.support.optimizePath(start); // this.support = this.support.optimizePath(start);
start = this.support.lastPoint(); // start = this.support.lastPoint();
} // }
return start; return start;
} }