fiber_pattern 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +41 -4
- data/lib/fiber_pattern/repeat.rb +31 -0
- data/lib/fiber_pattern/scaling.rb +38 -0
- data/lib/fiber_pattern/sizing.rb +13 -26
- data/lib/fiber_pattern/version.rb +3 -1
- data/lib/fiber_pattern.rb +2 -0
- metadata +10 -12
- data/CHANGELOG.md +0 -8
- data/CODE_OF_CONDUCT.md +0 -10
- data/Rakefile +0 -58
- data/mise.toml +0 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2975f472d7c4d0d21ffe8a6a6eb918d145b8cc37a7191e141c4aa167bd09e136
|
|
4
|
+
data.tar.gz: 723d930af45c9e963001a0c678e50db9da2fe75690c9297bbf524f898cb5bb32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 332c10d1d8a7cd0cf594ac22d597e0b6dc589155094157ecb7f7ca26552347ae1d8917ea63fcadce24158661ec668919a91b07cd2231e13f1f0a34532c2c2b42
|
|
7
|
+
data.tar.gz: de8c48b9c34681594201c7443e478bda797d432af8d2b3a1d66767cb94f4dfd84b44e30554c87b0b9d62743dd9cf236e04e11e26a7f90d4d5c87e858c9b243fd
|
data/README.md
CHANGED
|
@@ -83,6 +83,8 @@ Because:
|
|
|
83
83
|
|
|
84
84
|
# Pattern Stitch Repeats
|
|
85
85
|
|
|
86
|
+
Use `FiberPattern::Repeat` when a pattern requires stitch counts to align to a repeat.
|
|
87
|
+
|
|
86
88
|
Many patterns require stitch counts to be a **multiple of a repeat**.
|
|
87
89
|
|
|
88
90
|
Example: *multiple of 8 stitches*
|
|
@@ -90,7 +92,7 @@ Example: *multiple of 8 stitches*
|
|
|
90
92
|
```ruby
|
|
91
93
|
sizing = FiberPattern::Sizing.new(
|
|
92
94
|
gauge: gauge,
|
|
93
|
-
|
|
95
|
+
repeat: FiberPattern::Repeat.new(multiple: 8.stitches)
|
|
94
96
|
)
|
|
95
97
|
|
|
96
98
|
sizing.cast_on_for(38.inches)
|
|
@@ -117,8 +119,10 @@ multiple of 8 + 2
|
|
|
117
119
|
```ruby
|
|
118
120
|
sizing = FiberPattern::Sizing.new(
|
|
119
121
|
gauge: gauge,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
repeat: FiberPattern::Repeat.new(
|
|
123
|
+
multiple: 8.stitches,
|
|
124
|
+
offset: 2.stitches
|
|
125
|
+
)
|
|
122
126
|
)
|
|
123
127
|
|
|
124
128
|
sizing.cast_on_for(38.inches)
|
|
@@ -133,6 +137,38 @@ Calculation:
|
|
|
133
137
|
→ 178 stitches
|
|
134
138
|
```
|
|
135
139
|
|
|
140
|
+
# Gauge Scaling
|
|
141
|
+
|
|
142
|
+
You can also scale stitch and row counts from a pattern's gauge to a knitter's gauge.
|
|
143
|
+
|
|
144
|
+
```ruby
|
|
145
|
+
pattern_gauge = FiberGauge::Gauge.new(
|
|
146
|
+
stitches: 20.stitches,
|
|
147
|
+
rows: 28.rows,
|
|
148
|
+
width: 4.inches
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
knitter_gauge = FiberGauge::Gauge.new(
|
|
152
|
+
stitches: 18.stitches,
|
|
153
|
+
rows: 24.rows,
|
|
154
|
+
width: 4.inches
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
FiberPattern::Scaling.scale_stitches(
|
|
158
|
+
100.stitches,
|
|
159
|
+
pattern_gauge,
|
|
160
|
+
knitter_gauge
|
|
161
|
+
)
|
|
162
|
+
# => 90 stitches
|
|
163
|
+
|
|
164
|
+
FiberPattern::Scaling.scale_rows(
|
|
165
|
+
56.rows,
|
|
166
|
+
pattern_gauge,
|
|
167
|
+
knitter_gauge
|
|
168
|
+
)
|
|
169
|
+
# => 48 rows
|
|
170
|
+
```
|
|
171
|
+
|
|
136
172
|
# Example: Sweater Sizing
|
|
137
173
|
|
|
138
174
|
```ruby
|
|
@@ -144,7 +180,7 @@ gauge = FiberGauge::Gauge.new(
|
|
|
144
180
|
|
|
145
181
|
sizing = FiberPattern::Sizing.new(
|
|
146
182
|
gauge: gauge,
|
|
147
|
-
|
|
183
|
+
repeat: FiberPattern::Repeat.new(multiple: 8.stitches)
|
|
148
184
|
)
|
|
149
185
|
|
|
150
186
|
chest = 40.inches
|
|
@@ -160,6 +196,7 @@ cast_on = sizing.cast_on_for(chest)
|
|
|
160
196
|
* make **pattern math predictable**
|
|
161
197
|
* integrate with **typed fiber measurement units**
|
|
162
198
|
* support **repeat-based stitch patterns**
|
|
199
|
+
* help **scale instructions between gauges**
|
|
163
200
|
* stay **small and composable**
|
|
164
201
|
|
|
165
202
|
It forms part of a broader fiber tooling ecosystem:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FiberPattern
|
|
4
|
+
# Adjusts stitch counts to satisfy a repeat multiple and optional offset.
|
|
5
|
+
class Repeat
|
|
6
|
+
# @return [FiberUnits::Stitches] repeat multiple used for rounding
|
|
7
|
+
# @return [FiberUnits::Stitches] fixed offset applied before rounding
|
|
8
|
+
attr_reader :multiple, :offset
|
|
9
|
+
|
|
10
|
+
# @param multiple [FiberUnits::Stitches] repeat size required by the pattern
|
|
11
|
+
# @param offset [FiberUnits::Stitches] offset preserved when aligning to the repeat
|
|
12
|
+
def initialize(multiple:, offset: 0.stitches)
|
|
13
|
+
@multiple = multiple
|
|
14
|
+
@offset = offset
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Rounds a stitch count up to the next valid repeat-compatible value.
|
|
18
|
+
#
|
|
19
|
+
# @param stitches [FiberUnits::Stitches] stitch count to adjust
|
|
20
|
+
# @return [FiberUnits::Stitches] smallest valid count meeting the repeat constraints
|
|
21
|
+
def adjust(stitches)
|
|
22
|
+
m = multiple.value
|
|
23
|
+
o = offset.value
|
|
24
|
+
|
|
25
|
+
adjusted =
|
|
26
|
+
((stitches.value - o).to_f / m).ceil * m + o
|
|
27
|
+
|
|
28
|
+
adjusted.stitches
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FiberPattern
|
|
4
|
+
# Converts stitch and row counts from a pattern gauge to a knitter's gauge.
|
|
5
|
+
class Scaling
|
|
6
|
+
# Scales a stitch count to preserve width at a different stitches-per-inch rate.
|
|
7
|
+
#
|
|
8
|
+
# @param stitches [FiberUnits::Stitches] stitch count written for the pattern gauge
|
|
9
|
+
# @param pattern_gauge [FiberGauge::Gauge] gauge used by the source pattern
|
|
10
|
+
# @param knitter_gauge [FiberGauge::Gauge] gauge achieved by the knitter
|
|
11
|
+
# @return [FiberUnits::Stitches] adjusted stitch count for the knitter's gauge
|
|
12
|
+
def self.scale_stitches(stitches, pattern_gauge, knitter_gauge)
|
|
13
|
+
pattern_spi = pattern_gauge.spi
|
|
14
|
+
knitter_spi = knitter_gauge.spi
|
|
15
|
+
|
|
16
|
+
scaled =
|
|
17
|
+
(stitches.value * knitter_spi / pattern_spi).round
|
|
18
|
+
|
|
19
|
+
scaled.stitches
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Scales a row count to preserve length at a different rows-per-inch rate.
|
|
23
|
+
#
|
|
24
|
+
# @param rows [FiberUnits::Rows] row count written for the pattern gauge
|
|
25
|
+
# @param pattern_gauge [FiberGauge::Gauge] gauge used by the source pattern
|
|
26
|
+
# @param knitter_gauge [FiberGauge::Gauge] gauge achieved by the knitter
|
|
27
|
+
# @return [FiberUnits::Rows] adjusted row count for the knitter's gauge
|
|
28
|
+
def self.scale_rows(rows, pattern_gauge, knitter_gauge)
|
|
29
|
+
pattern_rpi = pattern_gauge.rpi
|
|
30
|
+
knitter_rpi = knitter_gauge.rpi
|
|
31
|
+
|
|
32
|
+
scaled =
|
|
33
|
+
(rows.value * knitter_rpi / pattern_rpi).round
|
|
34
|
+
|
|
35
|
+
scaled.rows
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/fiber_pattern/sizing.rb
CHANGED
|
@@ -6,46 +6,33 @@ module FiberPattern
|
|
|
6
6
|
# @return [Object] gauge object that responds to `required_stitches`
|
|
7
7
|
attr_reader :gauge
|
|
8
8
|
|
|
9
|
-
# @return [
|
|
10
|
-
attr_reader :
|
|
11
|
-
|
|
12
|
-
# @return [Object] optional offset to apply when rounding to stitch repeat
|
|
13
|
-
attr_reader :repeat_offset
|
|
9
|
+
# @return [FiberPattern::Repeat, nil] optional stitch repeat to round stitch counts to
|
|
10
|
+
attr_reader :repeat
|
|
14
11
|
|
|
15
12
|
# @param gauge [Object] gauge object used to derive stitch counts
|
|
16
|
-
# @param
|
|
17
|
-
|
|
18
|
-
def initialize(gauge:, stitch_repeat: nil, repeat_offset: 0.stitches)
|
|
13
|
+
# @param repeat [FiberPattern::Repeat, nil] optional stitch repeat to round stitch counts to
|
|
14
|
+
def initialize(gauge:, repeat: nil)
|
|
19
15
|
@gauge = gauge
|
|
20
|
-
@
|
|
21
|
-
@repeat_offset = repeat_offset
|
|
16
|
+
@repeat = repeat
|
|
22
17
|
end
|
|
23
18
|
|
|
24
|
-
#
|
|
19
|
+
# Calculates the number of stitches required to reach a given width, based on the provided gauge.
|
|
25
20
|
#
|
|
26
21
|
# @param width [Object] desired finished width in units accepted by the gauge
|
|
27
22
|
# @return [Integer] number of stitches required to reach the requested width
|
|
28
23
|
def cast_on_for(width)
|
|
29
24
|
stitches = gauge.required_stitches(width)
|
|
30
25
|
|
|
31
|
-
return stitches unless
|
|
26
|
+
return stitches unless repeat
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
repeat.adjust(stitches)
|
|
34
29
|
end
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def adjust_to_repeat(stitches)
|
|
42
|
-
repeat = stitch_repeat.value
|
|
43
|
-
offset = @repeat_offset.value
|
|
44
|
-
|
|
45
|
-
adjusted =
|
|
46
|
-
((stitches.value - offset).to_f / repeat).ceil * repeat + offset
|
|
47
|
-
|
|
48
|
-
adjusted.stitches
|
|
31
|
+
# Calculates the width of a given stitch count, based on the provided gauge.
|
|
32
|
+
# @param stitches [FiberUnits::Stitches] stitch count to calculate width for
|
|
33
|
+
# @return [Object] width in units accepted by the gauge
|
|
34
|
+
def width_for(stitches)
|
|
35
|
+
gauge.width_for_stitches(stitches)
|
|
49
36
|
end
|
|
50
37
|
end
|
|
51
38
|
end
|
data/lib/fiber_pattern.rb
CHANGED
|
@@ -4,6 +4,8 @@ require "fiber_units"
|
|
|
4
4
|
require "fiber_gauge"
|
|
5
5
|
require_relative "fiber_pattern/version"
|
|
6
6
|
require_relative "fiber_pattern/sizing"
|
|
7
|
+
require_relative "fiber_pattern/repeat"
|
|
8
|
+
require_relative "fiber_pattern/scaling"
|
|
7
9
|
|
|
8
10
|
# Utilities for generating fiber pattern measurements from gauge data.
|
|
9
11
|
module FiberPattern
|
metadata
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fiber_pattern
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Meagan Waller
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
@@ -45,23 +45,21 @@ executables: []
|
|
|
45
45
|
extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
|
47
47
|
files:
|
|
48
|
-
- CHANGELOG.md
|
|
49
|
-
- CODE_OF_CONDUCT.md
|
|
50
48
|
- LICENSE.txt
|
|
51
49
|
- README.md
|
|
52
|
-
- Rakefile
|
|
53
50
|
- lib/fiber_pattern.rb
|
|
51
|
+
- lib/fiber_pattern/repeat.rb
|
|
52
|
+
- lib/fiber_pattern/scaling.rb
|
|
54
53
|
- lib/fiber_pattern/sizing.rb
|
|
55
54
|
- lib/fiber_pattern/version.rb
|
|
56
|
-
- mise.toml
|
|
57
55
|
- sig/fiber_pattern.rbs
|
|
58
|
-
homepage: https://github.com/meaganewaller/fiber_pattern
|
|
56
|
+
homepage: https://github.com/meaganewaller/craftos/tree/main/gems/fiber_pattern
|
|
59
57
|
licenses:
|
|
60
58
|
- MIT
|
|
61
59
|
metadata:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
source_code_uri: https://github.com/meaganewaller/craftos/tree/main/gems/fiber_pattern
|
|
61
|
+
bug_tracker_uri: https://github.com/meaganewaller/craftos/issues
|
|
62
|
+
rubygems_mfa_required: 'true'
|
|
65
63
|
rdoc_options: []
|
|
66
64
|
require_paths:
|
|
67
65
|
- lib
|
|
@@ -69,14 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
69
67
|
requirements:
|
|
70
68
|
- - ">="
|
|
71
69
|
- !ruby/object:Gem::Version
|
|
72
|
-
version: 3.
|
|
70
|
+
version: '3.4'
|
|
73
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
72
|
requirements:
|
|
75
73
|
- - ">="
|
|
76
74
|
- !ruby/object:Gem::Version
|
|
77
75
|
version: '0'
|
|
78
76
|
requirements: []
|
|
79
|
-
rubygems_version:
|
|
77
|
+
rubygems_version: 3.6.9
|
|
80
78
|
specification_version: 4
|
|
81
79
|
summary: Pattern sizing and stitch math for knitting and crochet.
|
|
82
80
|
test_files: []
|
data/CHANGELOG.md
DELETED
data/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# Code of Conduct
|
|
2
|
-
|
|
3
|
-
"fiber_pattern" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
-
|
|
5
|
-
* Participants will be tolerant of opposing views.
|
|
6
|
-
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
-
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
-
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
-
|
|
10
|
-
If you have any concerns about behaviour within this project, please contact us at ["TODO: Write your email address"](mailto:"TODO: Write your email address").
|
data/Rakefile
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/gem_tasks"
|
|
4
|
-
require "rspec/core/rake_task"
|
|
5
|
-
require "yard"
|
|
6
|
-
require "yard/rake/yardoc_task"
|
|
7
|
-
require "standard/rake"
|
|
8
|
-
|
|
9
|
-
# YARD Documentation tasks
|
|
10
|
-
begin
|
|
11
|
-
namespace :doc do
|
|
12
|
-
desc "Generate YARD documentation"
|
|
13
|
-
YARD::Rake::YardocTask.new(:generate) do |t|
|
|
14
|
-
t.files = ["lib/**/*.rb", "-", "README.md"]
|
|
15
|
-
t.options = [
|
|
16
|
-
"--output-dir", "doc/yard",
|
|
17
|
-
"--markup", "markdown",
|
|
18
|
-
"--title", "YarnSkein - Yarn metadata and skein calculations",
|
|
19
|
-
"--readme", "README.md"
|
|
20
|
-
]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
desc "Regenerate documentation with cache reset"
|
|
24
|
-
task regenerate: ["doc:clean", "doc:generate"]
|
|
25
|
-
|
|
26
|
-
desc "Clean generated documentation"
|
|
27
|
-
task :clean do
|
|
28
|
-
rm_rf "doc/yard"
|
|
29
|
-
rm_rf ".yardoc"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
desc "Start YARD server for local documentation viewing"
|
|
33
|
-
task :serve do
|
|
34
|
-
sh "bundle exec yard server --reload --port 8808"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
desc "Validate YARD documentation coverage"
|
|
38
|
-
task :coverage do
|
|
39
|
-
sh "bundle exec yard stats --list-undoc"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
desc "Generate complete documentation with coverage report"
|
|
43
|
-
task complete: [:generate, :coverage]
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Add shorthand aliases
|
|
47
|
-
task yard: "doc:generate"
|
|
48
|
-
task yard_server: "doc:serve"
|
|
49
|
-
task yard_clean: "doc:clean"
|
|
50
|
-
rescue LoadError
|
|
51
|
-
# YARD is only available in development/test environments
|
|
52
|
-
# Silence this warning in production where it's not needed
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
task :default do
|
|
56
|
-
Rake::Task["standard"].invoke
|
|
57
|
-
Rake::Task["spec"].invoke
|
|
58
|
-
end
|
data/mise.toml
DELETED