Skip to content

Commit

Permalink
fix: split in neg dir was ' Tr-Rr' not 'Tr-Rl'
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielle-ohlson committed Jun 28, 2021
1 parent a26d488 commit b19ae3d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ extras/*.knitout
extras/*.kc
extras/*.html
extras/*.css
extras/test.js
extras/test.js
in-k/
out-kc/
45 changes: 34 additions & 11 deletions extras/waste-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,12 @@ const steps = {
},
parse: async () => {
let wasteSection = [`x-roller-advance ${rollerAdvance}`, `x-stitch-number ${stitchNumber}`, `x-speed-number ${speedNumber}`];
let inWasteC = false, inDrawC = false, inCastonC = false;
let negCarriers = [];
let negCarriers = [], outCarriers = [];
if (file) {
lines = file.split('\n');
header = lines.splice(0, lines.findIndex(ln => ln.split(' ')[0] === 'in'));
let inCarrier = lines[0].split(' ')[1].charAt(0); //note: charAt is fine here since kniterate only has single-digit carriers //TODO: change if make waste-section.js for SWG too
lines.shift();
if (inCarrier === wasteCarrier) {
inWasteC = true;
}
if (inCarrier === drawCarrier) inDrawC = true;
if (castonStyle === 0 || inCarrier === castonCarrier) inCastonC = true;
inCarriers = [inCarrier];
lines.map((ln, idx) => {
let info = ln.trim().split(' ');
Expand All @@ -127,14 +121,13 @@ const steps = {
header = [';!knitout-2', `;;Machine: Kniterate`, `;;Carriers: 1 2 3 4 5 6`];
}
let otherCarriers = carriers.filter(c => c !== wasteCarrier && c !== drawCarrier && c !== castonCarrier);
let wasteDir = '-', drawDir = '+', castonDir = '+';
let wasteDir = '-', drawDir = '-', castonDir = '-';
if (inCarriers.includes(castonCarrier)) { //empty if !file, so will skip
for (let i = 0; i < lines.length; ++i) {
let info = lines[i].trim().split(' ');
if (info.length > 1 && !info[0].includes(';')) {
if (info[info.length - 1] === castonCarrier) {
if (info[1] === '+') {
if (castonCarrier !== wasteCarrier) negCarriers.push(castonCarrier);
castonDir = '-';
break;
} else if (info[1] === '-') {
Expand All @@ -154,7 +147,6 @@ const steps = {
if (info.length > 1 && !info[0].includes(';')) {
if (info[info.length - 1] === drawCarrier) {
if (info[1] === '+') {
if (drawCarrier !== wasteCarrier) negCarriers.push(drawCarrier);
drawDir = '-';
break;
} else if (info[1] === '-') {
Expand Down Expand Up @@ -188,6 +180,10 @@ const steps = {
}
}
}
if (drawDir === '-' && drawCarrier !== wasteCarrier) negCarriers.push(drawCarrier);
if (castonDir === '-' && castonCarrier !== wasteCarrier && castonCarrier !== drawCarrier) negCarriers.push(castonCarrier);
if (lines && otherCarriers.length) {
for (let c = 0; c < otherCarriers.length; ++c) {
for (let i = 0; i < lines.length; ++i) {
Expand Down Expand Up @@ -232,7 +228,7 @@ const steps = {
if (dir === '+') maxN = needle;
else break findMinMax;
}
} else { // break findMinMax; //remove
} else {
if (castonStyle !== 0 || removeComment(info[info.length - 1]) !== carrier) break findMinMax;
else {
for (let m = i; m < lines.length; ++m) {
Expand Down Expand Up @@ -340,6 +336,13 @@ const steps = {
wasteSection.push(`knit + f${n} ${wasteCarrier}`);
}
}
if (!inCarriers.includes(wasteCarrier) && wasteCarrier !== drawCarrier && wasteCarrier !== castonCarrier) {
if (wasteDir === '-') wasteSection.push(`out ${wasteCarrier}`); //*
else {
wasteSection.push(`miss + f${maxN + 4} ${wasteCarrier}`);
outCarriers.push(wasteCarrier);
}
}
// drop any extra needles if width < 20
if (toDrop.length) {
Expand All @@ -364,6 +367,13 @@ const steps = {
wasteSection.push(`knit - f${n} ${drawCarrier}`);
}
}
if (!inCarriers.includes(drawCarrier) && drawCarrier !== castonCarrier) {
if (drawDir === '-') wasteSection.push(`out ${drawCarrier}`); //*
else {
wasteSection.push(`miss + f${maxN + 4} ${drawCarrier}`);
outCarriers.push(drawCarrier);
}
}
if (castonStyle !== 0) {
wasteSection.push(`;cast-on`);
Expand All @@ -382,6 +392,19 @@ const steps = {
} else {
console.warn('//TODO: add support for other cast-on styles.');
}
if (!inCarriers.includes(castonCarrier)) {
if (castonDir === '-') wasteSection.push(`out ${castonCarrier}`); //*
else {
wasteSection.push(`miss + f${maxN + 4} ${castonCarrier}`);
outCarriers.push(castonCarrier);
}
}
}
if (outCarriers.length) {
for (let i = 0; i < outCarriers.length; ++i) {
wasteSection.push(`out ${outCarriers[i]}`);
}
}
lines = [...header, ...wasteSection, ...lines];
Expand Down
26 changes: 17 additions & 9 deletions knitout-to-kcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ const TYPE_TUCK_TUCK = {kcode:'Tu-Tu'};
const TYPE_XFER_FOUR_PASS = {front:'Xf', back:'Xf'}; //will actually get split in output
const TYPE_XFER_TWO_PASS = {front:'Xf', back:'Xf'}; //will actually get split in output

const TYPE_SPLIT_TO_BACK = {kcode: 'Tr-Rr'};
const TYPE_SPLIT_TO_FRONT = {kcode:'Rr-Tr'};
const TYPE_SPLIT_TO_BACK_NEG = {kcode: 'Tr-Rl'};
const TYPE_SPLIT_TO_BACK_POS = {kcode: 'Tr-Rr'};
const TYPE_SPLIT_TO_FRONT_NEG = {kcode:'Rl-Tr'};
const TYPE_SPLIT_TO_FRONT_POS = {kcode:'Rr-Tr'};

function merge_types(a,b) {
//same type, easy to merge:
Expand All @@ -159,11 +161,13 @@ function merge_types(a,b) {
if (a === TYPE_KNIT_x) {
if (b === TYPE_x_KNIT || b === TYPE_KNIT_KNIT) return TYPE_KNIT_KNIT;
else if (b === TYPE_x_TUCK || b === TYPE_KNIT_TUCK) return TYPE_KNIT_TUCK;
else if (b === TYPE_SPLIT_TO_BACK) return TYPE_SPLIT_TO_BACK;
else if (b === TYPE_SPLIT_TO_BACK_POS) return TYPE_SPLIT_TO_BACK_POS;
else if (b === TYPE_SPLIT_TO_BACK_NEG) return TYPE_SPLIT_TO_BACK_NEG;
} else if (a === TYPE_x_KNIT) {
if (b === TYPE_KNIT_x || b === TYPE_KNIT_KNIT) return TYPE_KNIT_KNIT;
else if (b === TYPE_TUCK_x || b === TYPE_TUCK_KNIT) return TYPE_TUCK_KNIT;
else if (b === TYPE_SPLIT_TO_FRONT) return TYPE_SPLIT_TO_FRONT;
else if (b === TYPE_SPLIT_TO_FRONT_POS) return TYPE_SPLIT_TO_FRONT_POS;
else if (b === TYPE_SPLIT_TO_FRONT_NEG) return TYPE_SPLIT_TO_FRONT_NEG;
} else if (a === TYPE_TUCK_x) {
if (b === TYPE_x_KNIT || b === TYPE_TUCK_KNIT) return TYPE_TUCK_KNIT;
else if (b === TYPE_x_TUCK || b === TYPE_TUCK_TUCK) return TYPE_TUCK_TUCK;
Expand All @@ -178,10 +182,14 @@ function merge_types(a,b) {
if (b === TYPE_TUCK_x || b === TYPE_x_KNIT) return TYPE_TUCK_KNIT;
} else if (a === TYPE_TUCK_TUCK) {
if (b === TYPE_TUCK_x || b === TYPE_x_TUCK) return TYPE_TUCK_TUCK;
} else if (a === TYPE_SPLIT_TO_BACK) {
if (b === TYPE_SPLIT_TO_BACK || b === TYPE_KNIT_x) return TYPE_SPLIT_TO_BACK;
} else if (a === TYPE_SPLIT_TO_FRONT) {
if (b === TYPE_SPLIT_TO_FRONT || b === TYPE_x_KNIT) return TYPE_SPLIT_TO_FRONT;
} else if (a === TYPE_SPLIT_TO_BACK_POS) {
if (b === TYPE_SPLIT_TO_BACK_POS || b === TYPE_KNIT_x) return TYPE_SPLIT_TO_BACK_POS;
} else if (a === TYPE_SPLIT_TO_BACK_NEG) {
if (b === TYPE_SPLIT_TO_BACK_NEG || b === TYPE_KNIT_x) return TYPE_SPLIT_TO_BACK_NEG;
} else if (a === TYPE_SPLIT_TO_FRONT_POS) {
if (b === TYPE_SPLIT_TO_FRONT_POS || b === TYPE_x_KNIT) return TYPE_SPLIT_TO_FRONT_POS;
} else if (a === TYPE_SPLIT_TO_FRONT_NEG) {
if (b === TYPE_SPLIT_TO_FRONT_NEG || b === TYPE_x_KNIT) return TYPE_SPLIT_TO_FRONT_NEG;
}

//return 'null' if no merge possible:
Expand Down Expand Up @@ -1041,7 +1049,7 @@ function knitoutToPasses(knitout, knitoutFile) {
//make sure that this is a valid operation, and fill in proper OP:
let type;
if (cs.length !== 0) { //split case
type = (n.isFront() ? TYPE_SPLIT_TO_BACK : TYPE_SPLIT_TO_FRONT);
type = (n.isFront() ? (d === '+' ? TYPE_SPLIT_TO_BACK_POS: TYPE_SPLIT_TO_BACK_NEG) : (d === '+' ? TYPE_SPLIT_TO_FRONT_POS : TYPE_SPLIT_TO_FRONT_NEG));
op = OP_SPLIT;
} else { //xfer case
d = ""; //xfer is directionless
Expand Down

0 comments on commit b19ae3d

Please sign in to comment.