Skip to content

Commit

Permalink
Add sleeve decrease function
Browse files Browse the repository at this point in the history
  • Loading branch information
terriko committed Feb 28, 2021
1 parent 8594aaf commit 522df2d
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions pyknit/pyknit.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def stitches_to_measurement(stitches: int) -> float:

def stitch_count(stitch_array: Set[str], legend: Set[str]) -> int:
if legend:
# Do calculations per stitch
# FIXME: Do calculations per stitch
return len(stitch_array)

# otherwise, assume every stitch has width=1
Expand Down Expand Up @@ -132,9 +132,11 @@ def print_chart(stitch_array: Set[str]) -> Image:


# Increase and decrease functions


def increase_evenly(
starting_count: int, increase_number: int, in_the_round: bool = False
):
) -> str:
""" A function to figure out even spacing for increases """

if not in_the_round:
Expand Down Expand Up @@ -187,9 +189,52 @@ def sleeve_decreases(
starting_count: int,
ending_count: int,
decrease_per_row: int = 2,
):
) -> str:
""" A function to figure out a nice even sleeve decrease. """

# TODO: This function is going to be pretty similar to the decrease_evenly()
# function. We may want to combine them later.

if starting_count <= ending_count:
print(
f"Error: No decreases needed, {starting_count} is already smaller than {ending_count}"
)

# How many times are we doing the decrease row?
number_of_decrease_rows = math.floor(
(starting_count - ending_count) / decrease_per_row
)
if ((starting_count - ending_count) % decrease_per_row) > 0:
# TODO: we could probably do this math for people if we wanted
print(
f"Warning: desired decrease doesn't work exactly with a {decrease_per_row} decrease"
)
print(
"Printing the closest alternative but you'll need to add decreases at the end"
)

# divide up the number of rows.
# This gives you a decrease on the first row but padding after the last
# TODO: make an option for padding both sides, padding neither?

interval = math.floor(
(number_of_rows - number_of_decrease_rows) / number_of_decrease_rows
)
remainder = (number_of_rows - number_of_decrease_rows) % number_of_decrease_rows

# If we had any remainder, pad out the early decreases
instruction_string = ""
if remainder > 0:
instruction_string += (
f"[decrease row, do {interval+1} rows in pattern] * {remainder} times, "
)
instruction_string += f"[decrease row, do {interval} rows in pattern] * {number_of_decrease_rows - remainder} times"

return instruction_string


import math


def main():
print(VERSION)
Expand Down

0 comments on commit 522df2d

Please sign in to comment.