grid_generator 0.3.1 → 0.3.2

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: f26be22e443d706a070b3610b275de01024997c550ed65d106afc6193e8fe0f3
4
- data.tar.gz: 41ee0e26215d6d6296907a735c93b0a832b9418fd2d1cdf0121404b3db6e8b7c
3
+ metadata.gz: bac6da73c0f3f0fae6985d7c6e9b2f91f75ff82faaaf6d4a5299af71e0980e3c
4
+ data.tar.gz: 53848371057b7cbb7743049bc992cdee7eb17fed5e26412fb3efe101710cf688
5
5
  SHA512:
6
- metadata.gz: 6eedfb3bdc00baa6eec0b8173afb35efdafb2e5583a354d128f9e078ddd26e768785bf0a8a3f095b830d8b9f4fc93c131c4191c7c33c779bceb826078a1bdda1
7
- data.tar.gz: f9029ee7f2f8c80e72e72a83f7792f5b941075f3d0e074ee8704b8c84cf3342a5c354e006b07c6e7c0e0b486c3702f8c2d89c526a319c0e9a0ce4b4a116355b6
6
+ metadata.gz: b75fad2b601e6b0b027961e53b0562bd5a916309c12dd161a7471e1805746bf694e9908d3433c3e00bddef4e5e7fb1ad190c2d8063ac88ffa061a8641325d45a
7
+ data.tar.gz: 0d4ee932026ea66b66ef3121bdf422bc56f1003c2acb4f4e461014eb20b80b1114c106965d0565a202dd767c9ca3eaf922909f1e0fc24ccd0220bb953afd8b88
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.3.1)
4
+ grid_generator (0.3.2)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -33,7 +33,7 @@ module GridGenerator
33
33
  end
34
34
 
35
35
  def to_svg
36
- "<polygon points=\"#{points_string}}\" style=\"fill:#{colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{opacity}\" />"
36
+ "<polygon points=\"#{points_string}\" style=\"fill:#{colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{opacity}\" />"
37
37
  end
38
38
  end
39
39
  end
@@ -1,4 +1,6 @@
1
1
  require 'matrix'
2
+ require_relative '../svg/polygon'
3
+ require_relative '../svg/style'
2
4
  require_relative '../line'
3
5
  require_relative '../face_parser'
4
6
  require_relative 'facing_square_factory'
@@ -128,34 +130,21 @@ module GridGenerator
128
130
  Matrix.column_vector([ x, max_y ])
129
131
  ]
130
132
  end
131
-
132
- def points_string
133
- points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
133
+
134
+ def base_shape_style
135
+ GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
134
136
  end
135
137
 
136
- def as_json
137
- {
138
- "points_string" => points_string,
139
- "rows" => rows,
140
- "columns" => columns,
141
- "element_shapes" => element_shapes.map(&:as_json)
142
- }
138
+ def base_shape
139
+ GridGenerator::Svg::Polygon.new(points: points, style: base_shape_style)
143
140
  end
144
141
 
145
142
  def to_svg
146
- output = "<polygon points=\"#{points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
147
-
148
- for row in rows do
149
- output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
150
- end
143
+ output = base_shape.to_svg
151
144
 
152
- for col in columns do
153
- output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
154
- end
155
-
156
- for shape in element_shapes do
157
- output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
158
- end
145
+ rows.each { |row| output += row.to_svg }
146
+ columns.each { |col| output += col.to_svg }
147
+ element_shapes.each { |shape| output += shape.to_svg }
159
148
 
160
149
  output
161
150
  end
@@ -1,4 +1,6 @@
1
1
  require 'matrix'
2
+ require_relative '../svg/polygon'
3
+ require_relative '../svg/style'
2
4
  require_relative '../face_parser'
3
5
  require_relative '../line'
4
6
  require_relative 'facing_square_factory'
@@ -108,34 +110,21 @@ module GridGenerator
108
110
  Matrix.column_vector([ x, max_y ])
109
111
  ]
110
112
  end
111
-
112
- def points_string
113
- points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
113
+
114
+ def base_shape_style
115
+ GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
114
116
  end
115
117
 
116
- def as_json
117
- {
118
- "points_string" => points_string,
119
- "rows" => rows,
120
- "columns" => columns,
121
- "element_shapes" => element_shapes.map(&:as_json)
122
- }
118
+ def base_shape
119
+ GridGenerator::Svg::Polygon.new(points: points, style: base_shape_style)
123
120
  end
124
121
 
125
122
  def to_svg
126
- output = "<polygon points=\"#{points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
127
-
128
- for row in rows do
129
- output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
130
- end
131
-
132
- for col in columns do
133
- output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
134
- end
135
-
136
- for shape in element_shapes do
137
- output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
138
- end
123
+ output = base_shape.to_svg
124
+
125
+ rows.each { |row| output += row.to_svg }
126
+ columns.each { |col| output += col.to_svg }
127
+ element_shapes.each { |shape| output += shape.to_svg }
139
128
 
140
129
  output
141
130
  end
@@ -153,34 +153,21 @@ module GridGenerator
153
153
  bottom_left
154
154
  ]
155
155
  end
156
-
157
- def points_string
158
- points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
156
+
157
+ def base_shape_style
158
+ GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
159
159
  end
160
160
 
161
- def as_json
162
- {
163
- "points_string" => points_string,
164
- "rows" => rows,
165
- "columns" => columns,
166
- "element_shapes" => element_shapes.map(&:as_json)
167
- }
161
+ def base_shape
162
+ GridGenerator::Svg::Polygon.new(points: points, style: base_shape_style)
168
163
  end
169
164
 
170
165
  def to_svg
171
- output = "<polygon points=\"#{points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
172
-
173
- for row in rows do
174
- output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
175
- end
166
+ output = base_shape.to_svg
176
167
 
177
- for col in columns do
178
- output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
179
- end
180
-
181
- for shape in element_shapes do
182
- output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
183
- end
168
+ rows.each { |row| output += row.to_svg }
169
+ columns.each { |col| output += col.to_svg }
170
+ element_shapes.each { |shape| output += shape.to_svg }
184
171
 
185
172
  output
186
173
  end
@@ -1,5 +1,10 @@
1
1
  module GridGenerator
2
2
  class Line
3
+ COLOURS = {
4
+ fill: "#d0d0d0",
5
+ stroke: "#404040"
6
+ }
7
+
3
8
  def initialize(a:, b:)
4
9
  @a, @b = a, b
5
10
  end
@@ -37,6 +42,10 @@ module GridGenerator
37
42
  def y2
38
43
  b[1,0]
39
44
  end
45
+
46
+ def to_svg
47
+ "<line x1=\"#{x1}\" y1=\"#{y1}\" x2=\"#{x2}\" y2=\"#{y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
48
+ end
40
49
  end
41
50
  end
42
51
 
@@ -1,4 +1,6 @@
1
1
  require 'matrix'
2
+ require_relative '../svg/polygon'
3
+ require_relative '../svg/style'
2
4
  require_relative '../rotator'
3
5
  require_relative '../helper'
4
6
  require_relative '../line'
@@ -149,13 +151,13 @@ module GridGenerator
149
151
  end
150
152
 
151
153
  # for svg
152
- def decagon_points_string
153
- decagon_points.map { |p| offset_rotator.rotate(p) + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
154
+ def decagon_points_transformed
155
+ decagon_points.map { |p| offset_rotator.rotate(p) + offset }
154
156
  end
155
157
 
156
158
  # for svg
157
- def pentagon_points_string
158
- pentagon_points.map { |p| offset_rotator.rotate(p) + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
159
+ def pentagon_points_transformed
160
+ pentagon_points.map { |p| offset_rotator.rotate(p) + offset }
159
161
  end
160
162
 
161
163
  # for svg
@@ -210,32 +212,36 @@ module GridGenerator
210
212
  end
211
213
  end
212
214
 
213
- def to_svg
214
- output = "<polygon points=\"#{ decagon_points_string }\" style=\"fill:#{ COLOURS[:fill] };stroke:#{ COLOURS[:stroke] };stroke-width:1\" />"
215
- output += "<polygon points=\"#{ pentagon_points_string }\" style=\"fill:none;stroke:#{ COLOURS[:stroke] };stroke-width:1\" />"
215
+ def decagon_shape_style
216
+ GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
217
+ end
216
218
 
217
- for line in connecting_lines do
218
- output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
219
- end
219
+ def decagon_shape
220
+ GridGenerator::Svg::Polygon.new(points: decagon_points_transformed, style: decagon_shape_style)
221
+ end
220
222
 
221
- for line in front_face_lines do
222
- output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
223
- end
223
+ def pentagon_shape_style
224
+ GridGenerator::Svg::Style.new(fill: 'none', stroke: COLOURS[:stroke])
225
+ end
224
226
 
225
- for face in outside_face_lines do
226
- for line in face do
227
- output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
228
- end
229
- end
227
+ def pentagon_shape
228
+ GridGenerator::Svg::Polygon.new(points: pentagon_points_transformed, style: pentagon_shape_style)
229
+ end
230
+
231
+ def to_svg
232
+ output = decagon_shape.to_svg
233
+ output += pentagon_shape.to_svg
234
+
235
+ connecting_lines.each { |line| output += line.to_svg }
230
236
 
231
- for shape in front_face_element_shapes do
232
- output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
237
+ front_face_lines.each { |line| output += line.to_svg }
238
+ outside_face_lines.each do |face|
239
+ face.each { |line| output += line.to_svg }
233
240
  end
234
241
 
235
- for face in outside_face_element_shapes do
236
- for shape in face do
237
- output += "<polygon points=\"#{shape.points_string}\" style=\"fill:#{shape.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{shape.opacity}\" />"
238
- end
242
+ front_face_element_shapes.each { |shape| output += shape.to_svg }
243
+ outside_face_element_shapes.each do |face|
244
+ face.each { |shape| output += shape.to_svg }
239
245
  end
240
246
 
241
247
  output
@@ -1,7 +1,9 @@
1
- require_relative 'triangle_factory'
1
+ require_relative '../svg/polygon'
2
+ require_relative '../svg/style'
2
3
  require_relative '../rotator'
3
4
  require_relative '../scaler'
4
5
  require_relative '../line'
6
+ require_relative 'triangle_factory'
5
7
 
6
8
  module GridGenerator
7
9
  module Pyraminx
@@ -174,10 +176,6 @@ module GridGenerator
174
176
  end
175
177
  end
176
178
 
177
- def points_string
178
- points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
179
- end
180
-
181
179
  def element_shapes
182
180
  elements.map.each_with_index do |row, row_num|
183
181
  row.map.each_with_index do |col, col_num|
@@ -196,24 +194,21 @@ module GridGenerator
196
194
  end.flatten.compact
197
195
  end
198
196
 
199
- def to_svg
200
- output = "<polygon points=\"#{ points_string }\" style=\"fill:#{ COLOURS[:fill] };stroke:#{ COLOURS[:stroke] };stroke-width:1\" />"
201
-
202
- for line in vertical_lines do
203
- output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
204
- end
197
+ def base_shape_style
198
+ GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
199
+ end
205
200
 
206
- for line in diagonal_up_lines do
207
- output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
208
- end
201
+ def base_shape
202
+ GridGenerator::Svg::Polygon.new(points: points, style: base_shape_style)
203
+ end
209
204
 
210
- for line in diagonal_down_lines do
211
- output += "<line x1=\"#{line.x1}\" y1=\"#{line.y1}\" x2=\"#{line.x2}\" y2=\"#{line.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
212
- end
205
+ def to_svg
206
+ output = base_shape.to_svg
213
207
 
214
- element_shapes.map do |shape|
215
- output += "<polygon points=\"#{ shape.points_string }\" style=\"fill:#{ shape.colour };stroke:#{ COLOURS[:stroke] };stroke-width:1;opacity:#{ shape.opacity }\" />"
216
- end
208
+ vertical_lines.each { |line| output += line.to_svg }
209
+ diagonal_up_lines.each { |line| output += line.to_svg }
210
+ diagonal_down_lines.each { |line| output += line.to_svg }
211
+ element_shapes.each { |shape| output += shape.to_svg }
217
212
 
218
213
  output
219
214
  end
@@ -5,21 +5,16 @@ require_relative 'left_element_factory'
5
5
  module GridGenerator
6
6
  module Skewb
7
7
  class LeftSkewbGrid < Skewb::SkewbGrid
8
- COLOURS = {
9
- fill: "#d0d0d0",
10
- stroke: "#404040"
11
- }
12
-
13
8
  def factory_class
14
9
  GridGenerator::Skewb::LeftElementFactory
15
10
  end
16
11
 
17
- def border_points
12
+ def points
18
13
  [
19
- [ x, y ],
20
- [ x + side_size*2*units, y + side_size*units ],
21
- [ x + side_size*2*units, y + side_size*3*units ],
22
- [ x, y + side_size*2*units ]
14
+ Matrix.column_vector([ x, y ]),
15
+ Matrix.column_vector([ x + side_size*2*units, y + side_size*units ]),
16
+ Matrix.column_vector([ x + side_size*2*units, y + side_size*3*units ]),
17
+ Matrix.column_vector([ x, y + side_size*2*units ])
23
18
  ]
24
19
  end
25
20
 
@@ -54,26 +49,6 @@ module GridGenerator
54
49
  GridGenerator::Line.new(a: a, b: b)
55
50
  end
56
51
  end
57
-
58
- def to_svg
59
- output = "<polygon points=\"#{border_points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
60
-
61
- rows.each do |row|
62
- output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
63
- end
64
-
65
- columns.each do |col|
66
- output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
67
- end
68
-
69
- element_shapes.each do |element|
70
- if element
71
- output += "<polygon points=\"#{element.points_string}\" style=\"fill:#{element.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{element.opacity}\" />"
72
- end
73
- end
74
-
75
- output
76
- end
77
52
  end
78
53
  end
79
54
  end
@@ -6,21 +6,16 @@ require_relative 'right_element_factory.rb'
6
6
  module GridGenerator
7
7
  module Skewb
8
8
  class RightSkewbGrid < Skewb::SkewbGrid
9
- COLOURS = {
10
- fill: "#d0d0d0",
11
- stroke: "#404040"
12
- }
13
-
14
9
  def factory_class
15
10
  GridGenerator::Skewb::RightElementFactory
16
11
  end
17
12
 
18
- def border_points
13
+ def points
19
14
  [
20
- [ x, y + side_size*units ],
21
- [ x + side_size*2*units, y ],
22
- [ x + side_size*2*units, y + side_size*2*units ],
23
- [ x, y + side_size*3*units ]
15
+ Matrix.column_vector([ x, y + side_size*units ]),
16
+ Matrix.column_vector([ x + side_size*2*units, y ]),
17
+ Matrix.column_vector([ x + side_size*2*units, y + side_size*2*units ]),
18
+ Matrix.column_vector([ x, y + side_size*3*units ])
24
19
  ]
25
20
  end
26
21
 
@@ -55,26 +50,6 @@ module GridGenerator
55
50
  GridGenerator::Line.new(a: a, b: b)
56
51
  end
57
52
  end
58
-
59
- def to_svg
60
- output = "<polygon points=\"#{border_points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
61
-
62
- rows.each do |row|
63
- output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
64
- end
65
-
66
- columns.each do |col|
67
- output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
68
- end
69
-
70
- element_shapes.each do |element|
71
- if element
72
- output += "<polygon points=\"#{element.points_string}\" style=\"fill:#{element.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{element.opacity}\" />"
73
- end
74
- end
75
-
76
- output
77
- end
78
53
  end
79
54
  end
80
55
  end
@@ -3,6 +3,11 @@ require_relative '../face_parser'
3
3
  module GridGenerator
4
4
  module Skewb
5
5
  class SkewbGrid
6
+ COLOURS = {
7
+ fill: "#d0d0d0",
8
+ stroke: "#404040"
9
+ }
10
+
6
11
  def initialize(x:, y:, units: , elements: )
7
12
  @x, @y = x, y
8
13
  @units = units
@@ -39,10 +44,6 @@ module GridGenerator
39
44
  end
40
45
  end
41
46
 
42
- def border_points_string
43
- border_points.map { |x| x.join(',') }.join(' ')
44
- end
45
-
46
47
  def element_shapes
47
48
  elements.each_with_index.map do |row, row_num|
48
49
  row.each_with_index.map do |col, col_num|
@@ -51,11 +52,22 @@ module GridGenerator
51
52
  end.flatten.compact
52
53
  end
53
54
 
54
- def as_json
55
- {
56
- "border_points_string" => border_points_string,
57
- "element_shapes" => element_shapes.map(&:as_json)
58
- }
55
+ def base_shape_style
56
+ GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
57
+ end
58
+
59
+ def base_shape
60
+ GridGenerator::Svg::Polygon.new(points: points, style: base_shape_style)
61
+ end
62
+
63
+ def to_svg
64
+ output = base_shape.to_svg
65
+
66
+ rows.each { |row| output += row.to_svg }
67
+ columns.each { |col| output += col.to_svg }
68
+ element_shapes.each { |element| output += element.to_svg if element }
69
+
70
+ output
59
71
  end
60
72
  end
61
73
  end
@@ -6,21 +6,16 @@ require_relative 'top_element_factory'
6
6
  module GridGenerator
7
7
  module Skewb
8
8
  class TopSkewbGrid < Skewb::SkewbGrid
9
- COLOURS = {
10
- fill: "#d0d0d0",
11
- stroke: "#404040"
12
- }
13
-
14
9
  def factory_class
15
10
  GridGenerator::Skewb::TopElementFactory
16
11
  end
17
12
 
18
- def border_points
13
+ def points
19
14
  [
20
- [ x + side_size*2*units, y ],
21
- [ x + side_size*4*units, y + side_size*units ],
22
- [ x + side_size*2*units, y + side_size*2*units ],
23
- [ x, y + side_size*units ]
15
+ Matrix.column_vector([ x + side_size*2*units, y ]),
16
+ Matrix.column_vector([ x + side_size*4*units, y + side_size*units ]),
17
+ Matrix.column_vector([ x + side_size*2*units, y + side_size*2*units ]),
18
+ Matrix.column_vector([ x, y + side_size*units ])
24
19
  ]
25
20
  end
26
21
 
@@ -55,26 +50,6 @@ module GridGenerator
55
50
  GridGenerator::Line.new(a: a, b: b)
56
51
  end
57
52
  end
58
-
59
- def to_svg
60
- output = "<polygon points=\"#{border_points_string}\" style=\"fill:#{COLOURS[:fill]};stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
61
-
62
- rows.each do |row|
63
- output += "<line x1=\"#{row.x1}\" y1=\"#{row.y1}\" x2=\"#{row.x2}\" y2=\"#{row.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
64
- end
65
-
66
- columns.each do |col|
67
- output += "<line x1=\"#{col.x1}\" y1=\"#{col.y1}\" x2=\"#{col.x2}\" y2=\"#{col.y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />"
68
- end
69
-
70
- element_shapes.each do |element|
71
- if element
72
- output += "<polygon points=\"#{element.points_string}\" style=\"fill:#{element.colour};stroke:#{COLOURS[:stroke]};stroke-width:1;opacity:#{element.opacity}\" />"
73
- end
74
- end
75
-
76
- output
77
- end
78
53
  end
79
54
  end
80
55
  end
@@ -98,7 +98,7 @@ module GridGenerator
98
98
  output = ""
99
99
  element_shapes.each do |element|
100
100
  if element.opacity == 0.4
101
- output += "<polygon points=\"#{ element.points_string }\" style=\"fill:#{ COLOURS[:fill] };stroke:#{ COLOURS[:stroke] };stroke-width:1;opacity:1;]\" />"
101
+ output += "<polygon points=\"#{ element.points_string }\" style=\"fill:#{ COLOURS[:fill] };stroke:#{ COLOURS[:stroke] };stroke-width:1;opacity:1;\" />"
102
102
  end
103
103
  output += "<polygon points=\"#{ element.points_string }\" style=\"fill:#{ element.colour };stroke:#{ COLOURS[:stroke] };stroke-width:1;opacity:#{ element.opacity };\" />"
104
104
  end
@@ -0,0 +1,21 @@
1
+ module GridGenerator
2
+ module Svg
3
+ class Polygon
4
+ def initialize(points: , style:)
5
+ @points = case points
6
+ when Array
7
+ points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
8
+ else
9
+ points
10
+ end
11
+ @style = style
12
+ end
13
+
14
+ attr_reader :points, :style
15
+
16
+ def to_svg
17
+ "<polygon points=\"#{points}\" style=\"#{style.to_s}\" />"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module GridGenerator
2
+ module Svg
3
+ class Style
4
+ def initialize(fill: , stroke: , stroke_width: 1, opacity: 1)
5
+ @fill = fill
6
+ @stroke = stroke
7
+ @stroke_width = stroke_width
8
+ @opacity = opacity
9
+ end
10
+
11
+ attr_reader :fill, :stroke, :stroke_width, :opacity
12
+
13
+ def to_s
14
+ "fill:#{fill};stroke:#{stroke};stroke-width:#{stroke_width};opacity:#{opacity};"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
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.3.1
4
+ version: 0.3.2
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-25 00:00:00.000000000 Z
11
+ date: 2023-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix
@@ -70,6 +70,8 @@ files:
70
70
  - lib/grid_generator/square_one/element_factory.rb
71
71
  - lib/grid_generator/square_one/face.rb
72
72
  - lib/grid_generator/square_one_face_parser.rb
73
+ - lib/grid_generator/svg/polygon.rb
74
+ - lib/grid_generator/svg/style.rb
73
75
  - lib/grid_generator/version.rb
74
76
  - sig/grid_generator.rbs
75
77
  homepage: https://github.com/mrlhumphreys/grid_generator