Skip to content

Commit

Permalink
Warn if pattern uses multiple yarn-in / yarn-out blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Gillespie committed Sep 25, 2023
1 parent 0a80382 commit 8babea9
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ <h2>Block Library:</h2>
</div>

<div id="message-box">
<div id="status-text"></div>
<div id="cycle-text"></div>
<div id="yarn-count-text"></div>
</div>


Expand Down Expand Up @@ -1181,9 +1182,9 @@ <h2>Block Library:</h2>
// probably will change keycode.
// Run topological sort.
if (!checkGlobalCellCorrectness()){
document.getElementById("status-text").innerHTML = "Warning: There is exists a cycle in yarn directions!";
document.getElementById("cycle-text").innerHTML = "Warning: There is exists a cycle in yarn directions!";
} else {
document.getElementById("status-text").innerHTML = "No cycles detected in yarn directions.";
document.getElementById("cycle-text").innerHTML = "No cycles detected in yarn directions.";
}
}

Expand Down Expand Up @@ -1940,16 +1941,16 @@ <h2>Block Library:</h2>
let cycleFree = (count == bodyLen);

if (cycleFree) {
document.getElementById("status-text").innerHTML = "No cycles detected in yarn directions.";
document.getElementById("cycle-text").innerHTML = "No cycles detected in yarn directions.";
} else {
document.getElementById("status-text").innerHTML = "Warning: There is exists a cycle in yarn directions!";
document.getElementById("cycle-text").innerHTML = "Warning: There is exists a cycle in yarn directions!";
}
return cycleFree;
}

/**
* allocateSpots(x0=1, y0=4)
* Computes a needle, frontHolder, backHolder, layer, direction, and yarnID for each cell, storing these in cell.schedulingData.
* Schedules a needle, frontHolder, backHolder, layer, direction, and yarnID for each cell, storing these in cell.schedulingData.
* Currently computes locations for knit, next-row, yarn-next-layer, loop-next-layer, cast-on, bind-off. */
function allocateSpots(x0=1, y0=4) {
// follow yarn through body
Expand All @@ -1962,6 +1963,7 @@ <h2>Block Library:</h2>

// set default schedulingData and look for yarn-in to start
let currCell = null;
let nYarnIn = 0, nYarnOut = 0;
for (let cellID = 0; cellID < body.cells.length; ++cellID) {
if (body.cells[cellID].schedulingData == null) {
body.cells[cellID].schedulingData = {
Expand All @@ -1985,12 +1987,21 @@ <h2>Block Library:</h2>
}
if (body.cells[cellID].template.name === "yarn-in") {
currCell = body.cells[cellID];
nYarnIn++;
} else if (body.cells[cellID].template.name === "yarn-out") {
nYarnOut++;
}
}
if (currCell == null) {
console.error("spot allocation failed: no yarn-in cell found");
return;
}
if (nYarnIn != 1 || nYarnOut != 1) {
document.getElementById("yarn-count-text").innerHTML = "Error: There are " + nYarnIn + " yarn-in blocks and " + nYarnOut + " yarn out blocks, when there should only be one of each";
return;
} else {
document.getElementById("yarn-count-text").innerHTML = "";
}

let exitFace = getYarnExitFace(currCell);
let currDirection = (exitFace === 2) ? -1 // TODO: remove magic indices
Expand Down

0 comments on commit 8babea9

Please sign in to comment.