grid_generator 0.2.22 → 0.2.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1327abac79b922cc0a29266a8aa8cbf58e16c37650af0562a160afbfa699059
4
- data.tar.gz: fee34dc3995f296391beeca679aaa76c3a369cea551f455b265e392074778996
3
+ metadata.gz: 84401ca268f2dd6e73aa1cf880a9b534ca81291c5576f044e1494b5684aa0f26
4
+ data.tar.gz: 6c00e9248134a87f8751bd436a850e8467bfc65966c6ed7544640fc9b28130fa
5
5
  SHA512:
6
- metadata.gz: 9bd94d3336e91193a5fe43ea79f219b5fec06e61d7ab26b0508dcae04b96d023113c446adca8088f4ff0d2727c9d32ffa653d284f98f61b7a3110da1cccb12b2
7
- data.tar.gz: 055ad28e29b8dd6bdd6294cc953e8e1e3cdda3db30ea87118bb344839ff3df366a21707a0bcfae30680c64c2451457eb1dbab821675301446e701dcb4cd9692c
6
+ metadata.gz: 4ddbe0d8f15c45aa80ae209ed4e348d3d6c02a2c41a99cad2103a783267b487999034c1cc641c0ccbf6b30d97e3d34349f7165102713d7bdbbbc136ada17ec58
7
+ data.tar.gz: f7b7aac3f4daf48485de2f9d395c341bb40d84495e57825b468810b26b13e4f09d3d4928d46af2650d6fdff24db7b3325957ebae84e589a09e79b93d2d836dfc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.2.22)
4
+ grid_generator (0.2.23)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ module GridGenerator
9
9
  class FaceProjection
10
10
  # units 30 - pentagon 90 - megaminx - 150
11
11
  # units * 5
12
- def initialize(x:, y:, units:, front_face_elements: "", top_right_face_elements: "", right_face_elements: "", down_face_elements: "", left_face_elements: "", top_left_face_elements: "")
12
+ def initialize(x:, y:, units:, front_face_elements: "", top_right_face_elements: "", right_face_elements: "", down_face_elements: "", left_face_elements: "", top_left_face_elements: "", rotation_offset: 0)
13
13
  @x, @y = x, y
14
14
  @units = units
15
15
  @front_face_elements = front_face_elements.split(',')
@@ -18,14 +18,29 @@ module GridGenerator
18
18
  @down_face_elements = down_face_elements.split(',')
19
19
  @left_face_elements = left_face_elements.split(',')
20
20
  @top_left_face_elements = top_left_face_elements.split(',')
21
+ @rotation_offset = rotation_offset
21
22
  end
22
23
 
23
- attr_reader :x, :y, :units, :front_face_elements, :top_right_face_elements, :right_face_elements, :down_face_elements, :left_face_elements, :top_left_face_elements
24
+ attr_reader :x, :y, :units, :front_face_elements, :top_right_face_elements, :right_face_elements, :down_face_elements, :left_face_elements, :top_left_face_elements, :rotation_offset
25
+
26
+ def outside_face_elements
27
+ [
28
+ top_right_face_elements,
29
+ right_face_elements,
30
+ down_face_elements,
31
+ left_face_elements,
32
+ top_left_face_elements
33
+ ]
34
+ end
24
35
 
25
36
  def offset
26
37
  @offset ||= Matrix.column_vector([x, y])
27
38
  end
28
39
 
40
+ def offset_rotator
41
+ @offset_rotator ||= GridGenerator::Rotator.new(angle: rotation_offset, rotation_point: rotation_point)
42
+ end
43
+
29
44
  def decagon_radius
30
45
  5 * units
31
46
  end
@@ -82,24 +97,15 @@ module GridGenerator
82
97
  ]
83
98
  end
84
99
 
85
- def right_pentagon_points
86
- rotator = GridGenerator::Rotator.new(angle: Math::PI * 0.4, rotation_point: rotation_point)
87
- @right_pentagon_points ||= top_right_pentagon_points.map { |p| rotator.rotate(p) }
88
- end
89
-
90
- def down_pentagon_points
91
- rotator = GridGenerator::Rotator.new(angle: Math::PI * 0.8, rotation_point: rotation_point)
92
- @down_pentagon_points ||= top_right_pentagon_points.map { |p| rotator.rotate(p) }
93
- end
94
-
95
- def left_pentagon_points
96
- rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.2, rotation_point: rotation_point)
97
- @left_pentagon_points ||= top_right_pentagon_points.map { |p| rotator.rotate(p) }
98
- end
99
-
100
- def top_left_pentagon_points
101
- rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.6, rotation_point: rotation_point)
102
- @top_left_pentagon_points ||= top_right_pentagon_points.map { |p| rotator.rotate(p) }
100
+ def outside_pentagon_points
101
+ @outside_pentagon_points ||= (0..4).map do |i|
102
+ if i == 0
103
+ top_right_pentagon_points
104
+ else
105
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * i * 0.4, rotation_point: rotation_point)
106
+ top_right_pentagon_points.map { |p| rotator.rotate(p) }
107
+ end
108
+ end
103
109
  end
104
110
 
105
111
  def front_face_lines_raw
@@ -118,10 +124,10 @@ module GridGenerator
118
124
 
119
125
  def top_right_face_lines_raw
120
126
  @top_right_face_lines_raw ||= (0..4).map do |i|
121
- a = top_right_pentagon_points[i-1] # offset by one so first line is top right
122
- b = top_right_pentagon_points[(i)%5]
123
- c = top_right_pentagon_points[(i+1)%5]
124
- d = top_right_pentagon_points[(i+2)%5]
127
+ a = outside_pentagon_points[0][i-1] # offset by one so first line is top right
128
+ b = outside_pentagon_points[0][(i)%5]
129
+ c = outside_pentagon_points[0][(i+1)%5]
130
+ d = outside_pentagon_points[0][(i+2)%5]
125
131
 
126
132
  ab_intervals = GridGenerator::Helper.intervals(a,b,2)
127
133
  cd_intervals = GridGenerator::Helper.intervals(c,d,2)
@@ -130,24 +136,30 @@ module GridGenerator
130
136
  end
131
137
  end
132
138
 
133
- def right_face_lines_raw
134
- rotator = GridGenerator::Rotator.new(angle: Math::PI * 0.4, rotation_point: rotation_point)
135
- @right_face_lines_raw ||= top_right_face_lines_raw.map { |l| rotator.rotate(l) }
139
+ def outside_face_lines_raw
140
+ @outside_face_lines_raw ||= (0..4).map do |i|
141
+ if i == 0
142
+ top_right_face_lines_raw
143
+ else
144
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * i * 0.4, rotation_point: rotation_point)
145
+ top_right_face_lines_raw.map { |l| rotator.rotate(l) }
146
+ end
147
+ end
136
148
  end
137
149
 
138
- def down_face_lines_raw
139
- rotator = GridGenerator::Rotator.new(angle: Math::PI * 0.8, rotation_point: rotation_point)
140
- @down_face_lines_raw ||= top_right_face_lines_raw.map { |l| rotator.rotate(l) }
150
+ def top_left_face_lines_raw
151
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.6, rotation_point: rotation_point)
152
+ @top_left_face_lines_raw ||= outside_face_lines_raw[0].map { |l| rotator.rotate(l) }
141
153
  end
142
154
 
143
- def left_face_lines_raw
144
- rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.2, rotation_point: rotation_point)
145
- @left_face_lines_raw ||= top_right_face_lines_raw.map { |l| rotator.rotate(l) }
155
+ # for svg
156
+ def decagon_points_string
157
+ decagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
146
158
  end
147
159
 
148
- def top_left_face_lines_raw
149
- rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.6, rotation_point: rotation_point)
150
- @top_left_face_lines_raw ||= top_right_face_lines_raw.map { |l| rotator.rotate(l) }
160
+ # for svg
161
+ def pentagon_points_string
162
+ pentagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
151
163
  end
152
164
 
153
165
  # for svg
@@ -158,44 +170,16 @@ module GridGenerator
158
170
  end
159
171
  end
160
172
 
161
- # for svg
162
- def top_right_face_lines
163
- top_right_face_lines_raw.map { |l| l + offset }
164
- end
165
-
166
- # for svg
167
- def right_face_lines
168
- right_face_lines_raw.map { |l| l + offset }
169
- end
170
-
171
- # for svg
172
- def down_face_lines
173
- down_face_lines_raw.map { |l| l + offset }
174
- end
175
-
176
- # for svg
177
- def left_face_lines
178
- left_face_lines_raw.map { |l| l + offset }
179
- end
180
-
181
- # for svg
182
- def top_left_face_lines
183
- top_left_face_lines_raw.map { |l| l + offset }
184
- end
185
-
186
173
  # for svg
187
174
  def front_face_lines
188
175
  front_face_lines_raw.map { |l| l + offset }
189
176
  end
190
177
 
191
178
  # for svg
192
- def decagon_points_string
193
- decagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
194
- end
195
-
196
- # for svg
197
- def pentagon_points_string
198
- pentagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
179
+ def outside_face_lines
180
+ outside_face_lines_raw.map do |face_lines|
181
+ face_lines.map { |l| l + offset }
182
+ end
199
183
  end
200
184
 
201
185
  # for svg
@@ -213,69 +197,19 @@ module GridGenerator
213
197
  end
214
198
 
215
199
  # for svg
216
- def top_right_face_element_shapes
217
- top_right_face_elements.each_with_index.map do |element, i|
218
- GridGenerator::Megaminx::FaceElementFactory.new(
219
- x: x,
220
- y: y,
221
- index: i,
222
- face_points: top_right_pentagon_points,
223
- face_lines: top_right_face_lines_raw,
224
- face: element
225
- ).build unless element == '-'
226
- end.compact
227
- end
228
-
229
- def right_face_element_shapes
230
- right_face_elements.each_with_index.map do |element, i|
231
- GridGenerator::Megaminx::FaceElementFactory.new(
232
- x: x,
233
- y: y,
234
- index: i,
235
- face_points: right_pentagon_points,
236
- face_lines: right_face_lines_raw,
237
- face: element
238
- ).build unless element == '-'
239
- end.compact
240
- end
241
-
242
- def down_face_element_shapes
243
- down_face_elements.each_with_index.map do |element, i|
244
- GridGenerator::Megaminx::FaceElementFactory.new(
245
- x: x,
246
- y: y,
247
- index: i,
248
- face_points: down_pentagon_points,
249
- face_lines: down_face_lines_raw,
250
- face: element
251
- ).build unless element == '-'
252
- end.compact
253
- end
254
-
255
- def left_face_element_shapes
256
- left_face_elements.each_with_index.map do |element, i|
257
- GridGenerator::Megaminx::FaceElementFactory.new(
258
- x: x,
259
- y: y,
260
- index: i,
261
- face_points: left_pentagon_points,
262
- face_lines: left_face_lines_raw,
263
- face: element
264
- ).build unless element == '-'
265
- end.compact
266
- end
267
-
268
- def top_left_face_element_shapes
269
- top_left_face_elements.each_with_index.map do |element, i|
270
- GridGenerator::Megaminx::FaceElementFactory.new(
271
- x: x,
272
- y: y,
273
- index: i,
274
- face_points: top_left_pentagon_points,
275
- face_lines: top_left_face_lines_raw,
276
- face: element
277
- ).build unless element == '-'
278
- end.compact
200
+ def outside_face_element_shapes
201
+ outside_face_elements.each_with_index.map do |face_elements, face_index|
202
+ face_elements.each_with_index.map do |element, element_index|
203
+ GridGenerator::Megaminx::FaceElementFactory.new(
204
+ x: x,
205
+ y: y,
206
+ index: element_index,
207
+ face_points: outside_pentagon_points[face_index],
208
+ face_lines: outside_face_lines_raw[face_index],
209
+ face: element
210
+ ).build unless element == '-'
211
+ end.compact
212
+ end
279
213
  end
280
214
  end
281
215
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.2.22"
4
+ VERSION = "0.2.23"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grid_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.22
4
+ version: 0.2.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Humphreys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-06 00:00:00.000000000 Z
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix