grid_generator 0.3.1 → 0.3.3
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/Gemfile.lock +1 -1
- data/lib/grid_generator/base_element.rb +1 -1
- data/lib/grid_generator/{line.rb → base_line.rb} +10 -1
- data/lib/grid_generator/cubic/bordered_grid.rb +14 -25
- data/lib/grid_generator/cubic/facing_grid.rb +15 -26
- data/lib/grid_generator/cubic/grid.rb +12 -25
- data/lib/grid_generator/megaminx/face_projection.rb +34 -28
- data/lib/grid_generator/pyraminx/face.rb +19 -24
- data/lib/grid_generator/rotator.rb +3 -3
- data/lib/grid_generator/skewb/left_skewb_grid.rb +8 -33
- data/lib/grid_generator/skewb/right_skewb_grid.rb +8 -33
- data/lib/grid_generator/skewb/skewb_grid.rb +21 -9
- data/lib/grid_generator/skewb/top_skewb_grid.rb +8 -33
- data/lib/grid_generator/square_one/face.rb +4 -4
- data/lib/grid_generator/svg/polygon.rb +21 -0
- data/lib/grid_generator/svg/style.rb +18 -0
- data/lib/grid_generator/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22222fe473957054950f616c6000c02a60064192425785a6b59495733f89e8e7
|
4
|
+
data.tar.gz: 940e4285e164e679d52a7f40afb6fc01d774505450b1a38e285baff76cc0cb02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 222aa50cb0c31e3c80283758011b49dde53b442348d5e833dab5cb0b400f386e11814b91a538f009c6fab9331099cd7ae0f3e631fc3c80ff6b7b33fc811068dc
|
7
|
+
data.tar.gz: cd2c7f75557ef04436dfa83327a3282fd1fcb5ebc65526c01d01a52f6af9f3fa35181699485f110ad5fe2ed289e184a862862d719772abaff4ba109f5f84072f
|
data/Gemfile.lock
CHANGED
@@ -33,7 +33,7 @@ module GridGenerator
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def to_svg
|
36
|
-
"<polygon points=\"#{points_string}
|
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,5 +1,10 @@
|
|
1
1
|
module GridGenerator
|
2
|
-
class
|
2
|
+
class BaseLine
|
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,5 +1,7 @@
|
|
1
1
|
require 'matrix'
|
2
|
-
require_relative '../
|
2
|
+
require_relative '../svg/polygon'
|
3
|
+
require_relative '../svg/style'
|
4
|
+
require_relative '../base_line'
|
3
5
|
require_relative '../face_parser'
|
4
6
|
require_relative 'facing_square_factory'
|
5
7
|
|
@@ -90,7 +92,7 @@ module GridGenerator
|
|
90
92
|
unit_y(i+1)
|
91
93
|
])
|
92
94
|
|
93
|
-
GridGenerator::
|
95
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
@@ -106,7 +108,7 @@ module GridGenerator
|
|
106
108
|
max_y
|
107
109
|
])
|
108
110
|
|
109
|
-
GridGenerator::
|
111
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
@@ -128,34 +130,21 @@ module GridGenerator
|
|
128
130
|
Matrix.column_vector([ x, max_y ])
|
129
131
|
]
|
130
132
|
end
|
131
|
-
|
132
|
-
def
|
133
|
-
|
133
|
+
|
134
|
+
def base_shape_style
|
135
|
+
GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
|
134
136
|
end
|
135
137
|
|
136
|
-
def
|
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 =
|
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
|
-
|
153
|
-
|
154
|
-
|
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,6 +1,8 @@
|
|
1
1
|
require 'matrix'
|
2
|
+
require_relative '../svg/polygon'
|
3
|
+
require_relative '../svg/style'
|
2
4
|
require_relative '../face_parser'
|
3
|
-
require_relative '../
|
5
|
+
require_relative '../base_line'
|
4
6
|
require_relative 'facing_square_factory'
|
5
7
|
|
6
8
|
module GridGenerator
|
@@ -70,7 +72,7 @@ module GridGenerator
|
|
70
72
|
unit_y(i+1)
|
71
73
|
])
|
72
74
|
|
73
|
-
GridGenerator::
|
75
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
@@ -86,7 +88,7 @@ module GridGenerator
|
|
86
88
|
max_y
|
87
89
|
])
|
88
90
|
|
89
|
-
GridGenerator::
|
91
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
@@ -108,34 +110,21 @@ module GridGenerator
|
|
108
110
|
Matrix.column_vector([ x, max_y ])
|
109
111
|
]
|
110
112
|
end
|
111
|
-
|
112
|
-
def
|
113
|
-
|
113
|
+
|
114
|
+
def base_shape_style
|
115
|
+
GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
|
114
116
|
end
|
115
117
|
|
116
|
-
def
|
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 =
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'matrix'
|
2
|
-
require_relative '../
|
2
|
+
require_relative '../base_line'
|
3
3
|
|
4
4
|
module GridGenerator
|
5
5
|
module Cubic
|
@@ -108,7 +108,7 @@ module GridGenerator
|
|
108
108
|
row_line_end(i+1)[1,0]
|
109
109
|
])
|
110
110
|
|
111
|
-
GridGenerator::
|
111
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -124,7 +124,7 @@ module GridGenerator
|
|
124
124
|
column_line_end(i+1)[1,0]
|
125
125
|
])
|
126
126
|
|
127
|
-
GridGenerator::
|
127
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
@@ -153,34 +153,21 @@ module GridGenerator
|
|
153
153
|
bottom_left
|
154
154
|
]
|
155
155
|
end
|
156
|
-
|
157
|
-
def
|
158
|
-
|
156
|
+
|
157
|
+
def base_shape_style
|
158
|
+
GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
|
159
159
|
end
|
160
160
|
|
161
|
-
def
|
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 =
|
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
|
-
|
178
|
-
|
179
|
-
|
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,7 +1,9 @@
|
|
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
|
-
require_relative '../
|
6
|
+
require_relative '../base_line'
|
5
7
|
require_relative 'face_element_factory'
|
6
8
|
|
7
9
|
module GridGenerator
|
@@ -118,7 +120,7 @@ module GridGenerator
|
|
118
120
|
ab_intervals = GridGenerator::Helper.intervals(a,b,2)
|
119
121
|
cd_intervals = GridGenerator::Helper.intervals(c,d,2)
|
120
122
|
|
121
|
-
GridGenerator::
|
123
|
+
GridGenerator::BaseLine.new(a: ab_intervals[-1], b: cd_intervals[0])
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
@@ -132,7 +134,7 @@ module GridGenerator
|
|
132
134
|
ab_intervals = GridGenerator::Helper.intervals(a,b,2)
|
133
135
|
cd_intervals = GridGenerator::Helper.intervals(c,d,2)
|
134
136
|
|
135
|
-
GridGenerator::
|
137
|
+
GridGenerator::BaseLine.new(a: ab_intervals[-1], b: cd_intervals[0])
|
136
138
|
end
|
137
139
|
end
|
138
140
|
|
@@ -149,20 +151,20 @@ module GridGenerator
|
|
149
151
|
end
|
150
152
|
|
151
153
|
# for svg
|
152
|
-
def
|
153
|
-
decagon_points.map { |p| offset_rotator.rotate(p) + offset }
|
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
|
158
|
-
pentagon_points.map { |p| offset_rotator.rotate(p) + offset }
|
159
|
+
def pentagon_points_transformed
|
160
|
+
pentagon_points.map { |p| offset_rotator.rotate(p) + offset }
|
159
161
|
end
|
160
162
|
|
161
163
|
# for svg
|
162
164
|
def connecting_lines
|
163
165
|
pentagon_points.each_with_index.map do |p, i|
|
164
166
|
d = decagon_points[i*2]
|
165
|
-
offset_rotator.rotate(GridGenerator::
|
167
|
+
offset_rotator.rotate(GridGenerator::BaseLine.new(a: p, b: d)) + offset
|
166
168
|
end
|
167
169
|
end
|
168
170
|
|
@@ -210,32 +212,36 @@ module GridGenerator
|
|
210
212
|
end
|
211
213
|
end
|
212
214
|
|
213
|
-
def
|
214
|
-
|
215
|
-
|
215
|
+
def decagon_shape_style
|
216
|
+
GridGenerator::Svg::Style.new(fill: COLOURS[:fill], stroke: COLOURS[:stroke])
|
217
|
+
end
|
216
218
|
|
217
|
-
|
218
|
-
|
219
|
-
|
219
|
+
def decagon_shape
|
220
|
+
GridGenerator::Svg::Polygon.new(points: decagon_points_transformed, style: decagon_shape_style)
|
221
|
+
end
|
220
222
|
|
221
|
-
|
222
|
-
|
223
|
-
|
223
|
+
def pentagon_shape_style
|
224
|
+
GridGenerator::Svg::Style.new(fill: 'none', stroke: COLOURS[:stroke])
|
225
|
+
end
|
224
226
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
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
|
-
|
232
|
-
|
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
|
-
|
236
|
-
|
237
|
-
|
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 '
|
1
|
+
require_relative '../svg/polygon'
|
2
|
+
require_relative '../svg/style'
|
2
3
|
require_relative '../rotator'
|
3
4
|
require_relative '../scaler'
|
4
|
-
require_relative '../
|
5
|
+
require_relative '../base_line'
|
6
|
+
require_relative 'triangle_factory'
|
5
7
|
|
6
8
|
module GridGenerator
|
7
9
|
module Pyraminx
|
@@ -84,7 +86,7 @@ module GridGenerator
|
|
84
86
|
transformed_1 = rotator.rotate(scaled_1) + offset
|
85
87
|
transformed_2 = rotator.rotate(scaled_2) + offset
|
86
88
|
|
87
|
-
GridGenerator::
|
89
|
+
GridGenerator::BaseLine.new(a: transformed_1, b: transformed_2)
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
@@ -113,7 +115,7 @@ module GridGenerator
|
|
113
115
|
transformed_1 = rotator.rotate(scaled_1) + offset
|
114
116
|
transformed_2 = rotator.rotate(scaled_2) + offset
|
115
117
|
|
116
|
-
GridGenerator::
|
118
|
+
GridGenerator::BaseLine.new(a: transformed_1, b: transformed_2)
|
117
119
|
end
|
118
120
|
end
|
119
121
|
|
@@ -142,7 +144,7 @@ module GridGenerator
|
|
142
144
|
transformed_1 = rotator.rotate(scaled_1) + offset
|
143
145
|
transformed_2 = rotator.rotate(scaled_2) + offset
|
144
146
|
|
145
|
-
GridGenerator::
|
147
|
+
GridGenerator::BaseLine.new(a: transformed_1, b: transformed_2)
|
146
148
|
end
|
147
149
|
end
|
148
150
|
|
@@ -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
|
200
|
-
|
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
|
-
|
207
|
-
|
208
|
-
|
201
|
+
def base_shape
|
202
|
+
GridGenerator::Svg::Polygon.new(points: points, style: base_shape_style)
|
203
|
+
end
|
209
204
|
|
210
|
-
|
211
|
-
|
212
|
-
end
|
205
|
+
def to_svg
|
206
|
+
output = base_shape.to_svg
|
213
207
|
|
214
|
-
|
215
|
-
|
216
|
-
|
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
|
@@ -17,12 +17,12 @@ module GridGenerator
|
|
17
17
|
case obj
|
18
18
|
when Matrix
|
19
19
|
(matrix * (obj - rotation_point)) + rotation_point
|
20
|
-
when GridGenerator::
|
20
|
+
when GridGenerator::BaseLine
|
21
21
|
new_a = rotate(obj.a)
|
22
22
|
new_b = rotate(obj.b)
|
23
|
-
GridGenerator::
|
23
|
+
GridGenerator::BaseLine.new(a: new_a, b: new_b)
|
24
24
|
else
|
25
|
-
raise ArgumentError, "Object must be Matrix or
|
25
|
+
raise ArgumentError, "Object must be Matrix or BaseLine"
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -1,25 +1,20 @@
|
|
1
|
-
require_relative '../
|
1
|
+
require_relative '../base_line'
|
2
2
|
require_relative 'skewb_grid'
|
3
3
|
require_relative 'left_element_factory'
|
4
4
|
|
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
|
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
|
|
@@ -35,7 +30,7 @@ module GridGenerator
|
|
35
30
|
y + (3*i+1)*units
|
36
31
|
])
|
37
32
|
|
38
|
-
GridGenerator::
|
33
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
39
34
|
end
|
40
35
|
end
|
41
36
|
|
@@ -51,28 +46,8 @@ module GridGenerator
|
|
51
46
|
y + (-1*i+5)*units
|
52
47
|
])
|
53
48
|
|
54
|
-
GridGenerator::
|
55
|
-
end
|
56
|
-
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\" />"
|
49
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
63
50
|
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
51
|
end
|
77
52
|
end
|
78
53
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '../
|
1
|
+
require_relative '../base_line'
|
2
2
|
require_relative '../base_element'
|
3
3
|
require_relative 'skewb_grid.rb'
|
4
4
|
require_relative 'right_element_factory.rb'
|
@@ -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
|
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
|
|
@@ -36,7 +31,7 @@ module GridGenerator
|
|
36
31
|
y + (i+1)*units
|
37
32
|
])
|
38
33
|
|
39
|
-
GridGenerator::
|
34
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
@@ -52,28 +47,8 @@ module GridGenerator
|
|
52
47
|
y + (-3*i+5)*units
|
53
48
|
])
|
54
49
|
|
55
|
-
GridGenerator::
|
56
|
-
end
|
57
|
-
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\" />"
|
50
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
64
51
|
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
52
|
end
|
78
53
|
end
|
79
54
|
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
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '../
|
1
|
+
require_relative '../base_line'
|
2
2
|
require_relative '../base_element'
|
3
3
|
require_relative 'skewb_grid'
|
4
4
|
require_relative 'top_element_factory'
|
@@ -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
|
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
|
|
@@ -36,7 +31,7 @@ module GridGenerator
|
|
36
31
|
y + (2*i+1)*units
|
37
32
|
])
|
38
33
|
|
39
|
-
GridGenerator::
|
34
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
@@ -52,28 +47,8 @@ module GridGenerator
|
|
52
47
|
y + 3*units
|
53
48
|
])
|
54
49
|
|
55
|
-
GridGenerator::
|
56
|
-
end
|
57
|
-
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\" />"
|
50
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
64
51
|
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
52
|
end
|
78
53
|
end
|
79
54
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '../
|
1
|
+
require_relative '../base_line'
|
2
2
|
require_relative '../square_one_face_parser'
|
3
3
|
require_relative 'element_factory'
|
4
4
|
|
@@ -57,7 +57,7 @@ module GridGenerator
|
|
57
57
|
y+face_size
|
58
58
|
])
|
59
59
|
|
60
|
-
GridGenerator::
|
60
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
61
61
|
end
|
62
62
|
|
63
63
|
def back_axis
|
@@ -71,7 +71,7 @@ module GridGenerator
|
|
71
71
|
y+face_size
|
72
72
|
])
|
73
73
|
|
74
|
-
GridGenerator::
|
74
|
+
GridGenerator::BaseLine.new(a: a, b: b)
|
75
75
|
end
|
76
76
|
|
77
77
|
def element_shapes
|
@@ -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
|
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.
|
4
|
+
version: 0.3.3
|
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-
|
11
|
+
date: 2023-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: matrix
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- grid_generator.gemspec
|
42
42
|
- lib/grid_generator.rb
|
43
43
|
- lib/grid_generator/base_element.rb
|
44
|
+
- lib/grid_generator/base_line.rb
|
44
45
|
- lib/grid_generator/cubic/bordered_grid.rb
|
45
46
|
- lib/grid_generator/cubic/facing_grid.rb
|
46
47
|
- lib/grid_generator/cubic/facing_square_factory.rb
|
@@ -53,7 +54,6 @@ files:
|
|
53
54
|
- lib/grid_generator/cubic/units_factory.rb
|
54
55
|
- lib/grid_generator/face_parser.rb
|
55
56
|
- lib/grid_generator/helper.rb
|
56
|
-
- lib/grid_generator/line.rb
|
57
57
|
- lib/grid_generator/megaminx/face_element_factory.rb
|
58
58
|
- lib/grid_generator/megaminx/face_projection.rb
|
59
59
|
- lib/grid_generator/pyraminx/face.rb
|
@@ -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
|