grid_generator 0.2.22 → 0.2.24

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: 812b6c5f247baa77cba970a91dd52c6b6663d1985563db1d21f173f44e391da1
4
+ data.tar.gz: 1f0ac5ba29dc0983fe13acd9fb778047b4145cac67e19b39c1fe8a77135faefe
5
5
  SHA512:
6
- metadata.gz: 9bd94d3336e91193a5fe43ea79f219b5fec06e61d7ab26b0508dcae04b96d023113c446adca8088f4ff0d2727c9d32ffa653d284f98f61b7a3110da1cccb12b2
7
- data.tar.gz: 055ad28e29b8dd6bdd6294cc953e8e1e3cdda3db30ea87118bb344839ff3df366a21707a0bcfae30680c64c2451457eb1dbab821675301446e701dcb4cd9692c
6
+ metadata.gz: dd16fdc6510169001c957ac24342ed79cfc9d79fe96c98011f6270d6223a9a1dc08737dda987617068b4d30581abb519c8dba09cea83fffb438f4310a2e4847c
7
+ data.tar.gz: e634b12f6070af21ea72cf5e7b6dc5fea167e0c511bdb03d1dfc3829145b80f1d87894ed09503c03270b4ad20fab6381e638b97fd81027990d89561ea2b1fa5c
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.24)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -3,7 +3,7 @@ require_relative '../face_parser'
3
3
  module GridGenerator
4
4
  module Megaminx
5
5
  class FaceElementFactory
6
- def initialize(x:, y:, index:, face_points: , face_lines:, face:)
6
+ def initialize(x:, y:, index:, face_points: , face_lines:, face:, rotator: )
7
7
  @x, @y = x, y
8
8
  @index = index
9
9
  @face_points = face_points
@@ -11,9 +11,10 @@ module GridGenerator
11
11
  face_attr = FaceParser.new(face).parse
12
12
  @colour = face_attr && face_attr[:colour]
13
13
  @opacity = face_attr && face_attr[:opacity]
14
+ @rotator = rotator
14
15
  end
15
16
 
16
- attr_reader :x, :y, :index, :face_points, :face_lines, :colour, :opacity
17
+ attr_reader :x, :y, :index, :face_points, :face_lines, :colour, :opacity, :rotator
17
18
 
18
19
  def offset
19
20
  Matrix.column_vector([x, y])
@@ -81,7 +82,7 @@ module GridGenerator
81
82
  end
82
83
  end
83
84
 
84
- all_points.map { |p| p + offset }
85
+ all_points.map { |p| rotator.rotate(p) + offset }
85
86
  end
86
87
 
87
88
  def build
@@ -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,11 @@ 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
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * i * 0.4, rotation_point: rotation_point)
103
+ top_right_pentagon_points.map { |p| rotator.rotate(p) }
104
+ end
103
105
  end
104
106
 
105
107
  def front_face_lines_raw
@@ -118,10 +120,10 @@ module GridGenerator
118
120
 
119
121
  def top_right_face_lines_raw
120
122
  @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]
123
+ a = outside_pentagon_points[0][i-1] # offset by one so first line is top right
124
+ b = outside_pentagon_points[0][(i)%5]
125
+ c = outside_pentagon_points[0][(i+1)%5]
126
+ d = outside_pentagon_points[0][(i+2)%5]
125
127
 
126
128
  ab_intervals = GridGenerator::Helper.intervals(a,b,2)
127
129
  cd_intervals = GridGenerator::Helper.intervals(c,d,2)
@@ -130,72 +132,46 @@ module GridGenerator
130
132
  end
131
133
  end
132
134
 
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) }
136
- end
137
-
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) }
141
- end
142
-
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) }
135
+ def outside_face_lines_raw
136
+ @outside_face_lines_raw ||= (0..4).map do |i|
137
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * i * 0.4, rotation_point: rotation_point)
138
+ top_right_face_lines_raw.map { |l| rotator.rotate(l) }
139
+ end
146
140
  end
147
141
 
148
142
  def top_left_face_lines_raw
149
143
  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) }
144
+ @top_left_face_lines_raw ||= outside_face_lines_raw[0].map { |l| rotator.rotate(l) }
151
145
  end
152
146
 
153
147
  # for svg
154
- def connecting_lines
155
- pentagon_points.each_with_index.map do |p, i|
156
- d = decagon_points[i*2]
157
- GridGenerator::Line.new(a: p, b: d) + offset
158
- end
159
- end
160
-
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 }
148
+ def decagon_points_string
149
+ decagon_points.map { |p| offset_rotator.rotate(p) + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
174
150
  end
175
151
 
176
152
  # for svg
177
- def left_face_lines
178
- left_face_lines_raw.map { |l| l + offset }
153
+ def pentagon_points_string
154
+ pentagon_points.map { |p| offset_rotator.rotate(p) + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
179
155
  end
180
156
 
181
157
  # for svg
182
- def top_left_face_lines
183
- top_left_face_lines_raw.map { |l| l + offset }
158
+ def connecting_lines
159
+ pentagon_points.each_with_index.map do |p, i|
160
+ d = decagon_points[i*2]
161
+ offset_rotator.rotate(GridGenerator::Line.new(a: p, b: d)) + offset
162
+ end
184
163
  end
185
164
 
186
165
  # for svg
187
166
  def front_face_lines
188
- front_face_lines_raw.map { |l| l + offset }
189
- end
190
-
191
- # 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(' ')
167
+ front_face_lines_raw.map { |l| offset_rotator.rotate(l) + offset }
194
168
  end
195
169
 
196
170
  # 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(' ')
171
+ def outside_face_lines
172
+ outside_face_lines_raw.map do |face_lines|
173
+ face_lines.map { |l| offset_rotator.rotate(l) + offset }
174
+ end
199
175
  end
200
176
 
201
177
  # for svg
@@ -207,75 +183,27 @@ module GridGenerator
207
183
  index: i,
208
184
  face_points: pentagon_points,
209
185
  face_lines: front_face_lines_raw,
210
- face: element
186
+ face: element,
187
+ rotator: offset_rotator
211
188
  ).build unless element == '-'
212
189
  end.compact
213
190
  end
214
191
 
215
192
  # 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
193
+ def outside_face_element_shapes
194
+ outside_face_elements.each_with_index.map do |face_elements, face_index|
195
+ face_elements.each_with_index.map do |element, element_index|
196
+ GridGenerator::Megaminx::FaceElementFactory.new(
197
+ x: x,
198
+ y: y,
199
+ index: element_index,
200
+ face_points: outside_pentagon_points[face_index],
201
+ face_lines: outside_face_lines_raw[face_index],
202
+ face: element,
203
+ rotator: offset_rotator
204
+ ).build unless element == '-'
205
+ end.compact
206
+ end
279
207
  end
280
208
  end
281
209
  end
@@ -13,6 +13,7 @@ module GridGenerator
13
13
 
14
14
  # subtract rotation point to move point towards 0,0, rotate, then add to move back
15
15
  def rotate(obj)
16
+ return obj if angle == 0
16
17
  case obj
17
18
  when Matrix
18
19
  (matrix * (obj - rotation_point)) + rotation_point
@@ -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.24"
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.24
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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix