textiles-lab / knitout-backend-kniterate

MIT License
16 stars 3 forks source link

need to review leftFloor / rightFloor #25

Open ixchow opened 3 years ago

ixchow commented 3 years ago

These variables enable what seems to be somewhat questionable behavior, need to review this code to understand what is being fixed and whether the fix is working.

gabrielle-ohlson commented 3 years ago

I added this as a fix for the following carrier placement issues:

  1. If more than 4 carriers are parked on a given side and carrierSpacing = 1, the carriers push/scrape against each other when moved.
  2. When a carrier is more than 8 spaces away from the edge-most needle on a given side (which happens quite easily when carrierSpacing = 2), it will frequently drop the edge stitches when picked up again to knit (due to too much slack and not enough security for the yarn).

My solution was to allow for x-carrier-spacing N to be equal to non-whole numbers in increments of 0.5, which tells the backend to alternate between: bumpAdd = Math.floor(N) and bumpAdd = Math.ceil(N) each time it bumps a carrier on a given side. So if x-carrier-spacing 1.5 is specified in the knitout, if (Math.abs(add) % 1 === 0.5) returns true, and the boolean leftFloor or rightFloor (depending on whether add < 0 [meaning we're dealing with carriers on the left side] or vice versa) is toggled between true (for that pass, the working carrier will be bumped 1 —> Math.floor(1.5)), and false (in the next pass, the working carrier will be bumped 2 —> Math.ceil(1.5)). But if N is a whole number, the carrierSpacing is consistently equal to that number.

I've found this to be really helpful for situations where I'm using 5 or 6 carriers and a pattern that causes a lot of carrier stacking, but it is still definitely a quick fix and could be replaced with something more clear and sophisticated.