示例#1
0
def _(expanding: ExpandingStitchRepeat, available: int) \
        -> Generator[KnitError, None, None]:
    yield from _verify_counts(to_fixed_repeat(expanding),
                              available - expanding.to_last.value)
    n = (available - expanding.to_last.value) // expanding.consumes
    yield from _exactly(n * expanding.consumes,
                        available - expanding.to_last.value, expanding)
示例#2
0
def _(pattern: Pattern, available: Optional[int] = None) -> Node:
    counted = infer_counts(to_fixed_repeat(pattern), available)
    assert isinstance(counted, RowRepeat)
    return replace(pattern,
                   rows=counted.rows,
                   consumes=counted.consumes,
                   produces=counted.produces)
示例#3
0
def _(row: Row, available: Optional[int] = None) -> Node:
    counted = infer_counts(to_fixed_repeat(row), available)
    assert isinstance(counted, FixedStitchRepeat)
    return replace(row,
                   stitches=counted.stitches,
                   consumes=counted.consumes,
                   produces=counted.produces)
示例#4
0
def _(row: Row, before: int) -> Node:
    fixed = _reverse(to_fixed_repeat(row), before)
    assert isinstance(fixed, FixedStitchRepeat)
    assert fixed.consumes == row.consumes
    assert fixed.produces == row.produces
    return replace(row,
                   stitches=fixed.stitches,
                   side=row.side.flip() if row.side else None)
示例#5
0
def _(rep: ExpandingStitchRepeat, available: Optional[int] = None) -> Node:
    if available is None:
        raise InterpretError("ambiguous use of expanding stitch repeat", rep)
    fixed = infer_counts(to_fixed_repeat(rep), available - rep.to_last.value)
    assert isinstance(fixed, FixedStitchRepeat)
    n = (available - rep.to_last.value) // fixed.consumes
    return replace(rep,
                   stitches=fixed.stitches,
                   consumes=fixed.consumes * n,
                   produces=fixed.produces * n)
示例#6
0
def _(pattern: Pattern) -> Generator[KnitError, None, None]:
    return _verify_make(to_fixed_repeat(pattern))
示例#7
0
def _(pattern: Pattern) -> str:
    return export_text(to_fixed_repeat(pattern))
示例#8
0
def _(rep: ExpandingStitchRepeat) -> str:
    stitches = export_text(to_fixed_repeat(rep))
    if rep.to_last.value == 0:
        return f"*{stitches}; rep from * to end"
    else:
        return f"*{stitches}; rep from * to last {rep.to_last.value}"
示例#9
0
def _(pattern: Pattern) -> Node:
    rolled = _roll_repeated_rows(to_fixed_repeat(pattern))
    assert isinstance(rolled, RowRepeat)
    return replace(pattern, rows=rolled.rows)
示例#10
0
def _(row: Row) -> Node:
    fixed = _combine_stitches(to_fixed_repeat(row))
    assert isinstance(fixed, FixedStitchRepeat)
    assert fixed.consumes == row.consumes
    assert fixed.produces == row.produces
    return replace(row, stitches=fixed.stitches)
示例#11
0
def _(pattern: Pattern, side: Side = Side.Right) -> Node:
    rep = _alternate_sides(to_fixed_repeat(pattern), side)
    assert isinstance(rep, RowRepeat)
    assert rep.consumes == pattern.consumes
    assert rep.produces == pattern.produces
    return replace(pattern, rows=rep.rows)
示例#12
0
def _(rep: ExpandingStitchRepeat, before: int) -> Node:
    fixed = _reverse(to_fixed_repeat(rep), before)
    assert isinstance(fixed, FixedStitchRepeat)
    return replace(rep, stitches=fixed.stitches, to_last=NaturalLit.of(before))
示例#13
0
def _(pattern: Pattern, unroll: bool = False) -> Node:
    flattened = _flatten(to_fixed_repeat(pattern), unroll)
    assert isinstance(flattened, RowRepeat)
    assert flattened.consumes == pattern.consumes
    assert flattened.produces == pattern.produces
    return replace(pattern, rows=flattened.rows)
示例#14
0
def _(row: Row, unroll: bool = False) -> Node:
    flattened = _flatten(to_fixed_repeat(row), unroll)
    assert isinstance(flattened, FixedStitchRepeat)
    assert flattened.consumes == row.consumes
    assert flattened.produces == row.produces
    return replace(row, stitches=flattened.stitches)
示例#15
0
def _(row: Row, available: int) -> Generator[KnitError, None, None]:
    yield from _verify_counts(to_fixed_repeat(row), available)
示例#16
0
def _(rep: ExpandingStitchRepeat) -> Node:
    fixed = _combine_stitches(to_fixed_repeat(rep))
    assert isinstance(fixed, FixedStitchRepeat)
    return replace(rep, stitches=fixed.stitches)
示例#17
0
def _(pattern: Pattern, available: int) -> Generator[KnitError, None, None]:
    yield from _verify_counts(to_fixed_repeat(pattern), available)
示例#18
0
def _(pattern: Pattern, acc: int = 0) -> int:
    return count_rows(to_fixed_repeat(pattern), acc)