grid_generator 0.2.23 → 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: 84401ca268f2dd6e73aa1cf880a9b534ca81291c5576f044e1494b5684aa0f26
4
- data.tar.gz: 6c00e9248134a87f8751bd436a850e8467bfc65966c6ed7544640fc9b28130fa
3
+ metadata.gz: 812b6c5f247baa77cba970a91dd52c6b6663d1985563db1d21f173f44e391da1
4
+ data.tar.gz: 1f0ac5ba29dc0983fe13acd9fb778047b4145cac67e19b39c1fe8a77135faefe
5
5
  SHA512:
6
- metadata.gz: 4ddbe0d8f15c45aa80ae209ed4e348d3d6c02a2c41a99cad2103a783267b487999034c1cc641c0ccbf6b30d97e3d34349f7165102713d7bdbbbc136ada17ec58
7
- data.tar.gz: f7b7aac3f4daf48485de2f9d395c341bb40d84495e57825b468810b26b13e4f09d3d4928d46af2650d6fdff24db7b3325957ebae84e589a09e79b93d2d836dfc
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.23)
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
@@ -99,12 +99,8 @@ module GridGenerator
99
99
 
100
100
  def outside_pentagon_points
101
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
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) }
108
104
  end
109
105
  end
110
106
 
@@ -138,12 +134,8 @@ module GridGenerator
138
134
 
139
135
  def outside_face_lines_raw
140
136
  @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
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) }
147
139
  end
148
140
  end
149
141
 
@@ -154,31 +146,31 @@ module GridGenerator
154
146
 
155
147
  # for svg
156
148
  def decagon_points_string
157
- decagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
149
+ decagon_points.map { |p| offset_rotator.rotate(p) + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
158
150
  end
159
151
 
160
152
  # for svg
161
153
  def pentagon_points_string
162
- pentagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
154
+ pentagon_points.map { |p| offset_rotator.rotate(p) + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
163
155
  end
164
156
 
165
157
  # for svg
166
158
  def connecting_lines
167
159
  pentagon_points.each_with_index.map do |p, i|
168
160
  d = decagon_points[i*2]
169
- GridGenerator::Line.new(a: p, b: d) + offset
161
+ offset_rotator.rotate(GridGenerator::Line.new(a: p, b: d)) + offset
170
162
  end
171
163
  end
172
164
 
173
165
  # for svg
174
166
  def front_face_lines
175
- front_face_lines_raw.map { |l| l + offset }
167
+ front_face_lines_raw.map { |l| offset_rotator.rotate(l) + offset }
176
168
  end
177
169
 
178
170
  # for svg
179
171
  def outside_face_lines
180
172
  outside_face_lines_raw.map do |face_lines|
181
- face_lines.map { |l| l + offset }
173
+ face_lines.map { |l| offset_rotator.rotate(l) + offset }
182
174
  end
183
175
  end
184
176
 
@@ -191,7 +183,8 @@ module GridGenerator
191
183
  index: i,
192
184
  face_points: pentagon_points,
193
185
  face_lines: front_face_lines_raw,
194
- face: element
186
+ face: element,
187
+ rotator: offset_rotator
195
188
  ).build unless element == '-'
196
189
  end.compact
197
190
  end
@@ -206,7 +199,8 @@ module GridGenerator
206
199
  index: element_index,
207
200
  face_points: outside_pentagon_points[face_index],
208
201
  face_lines: outside_face_lines_raw[face_index],
209
- face: element
202
+ face: element,
203
+ rotator: offset_rotator
210
204
  ).build unless element == '-'
211
205
  end.compact
212
206
  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.23"
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.23
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-07 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