From b19ae3d25fe7b977513362731ed1ff9220dacf69 Mon Sep 17 00:00:00 2001 From: gabrielle-ohlson Date: Mon, 28 Jun 2021 14:56:22 -0400 Subject: [PATCH] fix: split in neg dir was ' Tr-Rr' not 'Tr-Rl' --- .gitignore | 4 +++- extras/waste-section.js | 45 +++++++++++++++++++++++++++++++---------- knitout-to-kcode.js | 26 +++++++++++++++--------- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 984fd2f..92a5996 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ extras/*.knitout extras/*.kc extras/*.html extras/*.css -extras/test.js \ No newline at end of file +extras/test.js +in-k/ +out-kc/ \ No newline at end of file diff --git a/extras/waste-section.js b/extras/waste-section.js index 64447ad..68e039d 100644 --- a/extras/waste-section.js +++ b/extras/waste-section.js @@ -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(' '); @@ -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] === '-') { @@ -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] === '-') { @@ -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) { @@ -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) { @@ -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) { @@ -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`); @@ -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]; diff --git a/knitout-to-kcode.js b/knitout-to-kcode.js index 3309a93..723b694 100755 --- a/knitout-to-kcode.js +++ b/knitout-to-kcode.js @@ -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: @@ -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; @@ -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: @@ -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