Fix ignored last line

This commit is contained in:
Casper Lamboo 2018-03-06 12:41:00 +01:00
parent c4d8d1136a
commit 16e6e11e2f

View File

@ -55,6 +55,7 @@ export default function intersectionsToShapes(layerPoints, layerFaceIndexes, fac
if (startConnects[pointB]) { if (startConnects[pointB]) {
if (startConnects[pointB] === lineSegment) { if (startConnects[pointB] === lineSegment) {
delete startConnects[pointB]; delete startConnects[pointB];
lineSegment.push(pointB);
} else { } else {
lineSegment.push(...startConnects[pointB]); lineSegment.push(...startConnects[pointB]);
endConnects[lineSegment[lineSegment.length - 1]] = lineSegment; endConnects[lineSegment[lineSegment.length - 1]] = lineSegment;
@ -91,7 +92,10 @@ export default function intersectionsToShapes(layerPoints, layerFaceIndexes, fac
for (let pathIndex = 0; pathIndex < shape.length; pathIndex ++) { for (let pathIndex = 0; pathIndex < shape.length; pathIndex ++) {
const path = shape[pathIndex]; const path = shape[pathIndex];
if (almostEquals(path[0], path[path.length - 1])) continue; if (almostEquals(path[0], path[path.length - 1])) {
if (path.some(point => !almostEquals(point, path[0]))) lineShapesClosed.push(path);
continue;
}
let shapeStartPoint = path[0]; let shapeStartPoint = path[0];
for (const point of connectPoints) { for (const point of connectPoints) {
@ -114,7 +118,6 @@ export default function intersectionsToShapes(layerPoints, layerFaceIndexes, fac
if (shapeEndPoint) connectPoints.push({ point: shapeEndPoint, start: null, end: pathIndex }); if (shapeEndPoint) connectPoints.push({ point: shapeEndPoint, start: null, end: pathIndex });
} }
const lines = [];
while (connectPoints.length !== 0) { while (connectPoints.length !== 0) {
let { start, end } = connectPoints.pop(); let { start, end } = connectPoints.pop();
@ -126,26 +129,21 @@ export default function intersectionsToShapes(layerPoints, layerFaceIndexes, fac
line.push(...shape[newPoint.start]); line.push(...shape[newPoint.start]);
connectPoints.splice(connectPoints.indexOf(newPoint), 1); connectPoints.splice(connectPoints.indexOf(newPoint), 1);
if (newPoint.end === start) break; if (newPoint.end !== null && newPoint.end === start) break;
end = newPoint.end; end = newPoint.end;
start = newPoint.start; start = newPoint.start;
} }
lines.push(line);
}
if (openShape) { if (openShape) {
for (const line of lines) { if (almostEquals(line[0], line[line.length - 1])) {
const closed = almostEquals(line[0], line[line.length - 1]);
if (closed) {
lineShapesClosed.push(line); lineShapesClosed.push(line);
} else { } else {
lineShapesOpen.push(line); lineShapesOpen.push(line);
} }
}
} else { } else {
fillShapes.push(...lines); fillShapes.push(line);
}
} }
} }