grid_generator 0.1.10 → 0.1.11
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/pyraminx/face.rb +102 -22
- data/lib/grid_generator/pyraminx/triangle_factory.rb +18 -14
- data/lib/grid_generator/rotator.rb +19 -0
- data/lib/grid_generator/transformation.rb +5 -0
- data/lib/grid_generator/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53cfa7a917357eed8d38db20a347c57cf2c8ac2a2dfe57a829fa7ba6eb8e7cf8
|
4
|
+
data.tar.gz: 837b371e56a485e84b9a1ab789286fb0ee4a8e66ff08209cacb1b113e54a8228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52a24b3bc799e624491112b526db58e9fcdc40bc34f8e3bae0d12339dbd13a724066b4a765b00d2a1087e66451ed0cf0ef9fe492b617e2fb658a2578f9c861b6
|
7
|
+
data.tar.gz: dd3ed5081f293a61691ab6fdcd123827db7715dbe6a330643ef7f24a433e8136560125d30ee6444746c1397684b428490ac6a8766756815b87f23d3f4c88a4c6
|
data/Gemfile.lock
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'triangle_factory'
|
2
|
+
require_relative '../rotator'
|
2
3
|
|
3
4
|
module GridGenerator
|
4
5
|
module Pyraminx
|
@@ -6,18 +7,34 @@ module GridGenerator
|
|
6
7
|
# * * *
|
7
8
|
# * * * * *
|
8
9
|
class Face
|
9
|
-
def initialize(x:, y:, units:, elements:)
|
10
|
+
def initialize(x:, y:, units:, elements:, rotation_angle: 0)
|
10
11
|
@x, @y = x, y
|
11
12
|
@units = units
|
12
13
|
@elements = elements.split('\n').map { |r| r.split(',') }
|
14
|
+
@rotation_angle = rotation_angle
|
13
15
|
end
|
14
16
|
|
15
|
-
attr_reader :x, :y, :units, :elements
|
17
|
+
attr_reader :x, :y, :units, :elements, :rotation_angle
|
16
18
|
|
17
19
|
def size
|
18
20
|
elements.size
|
19
21
|
end
|
20
22
|
|
23
|
+
def centre_point
|
24
|
+
Matrix.column_vector([
|
25
|
+
size * units * 0.5,
|
26
|
+
size * Math.sqrt(3) * 0.25 * units
|
27
|
+
])
|
28
|
+
end
|
29
|
+
|
30
|
+
def offset
|
31
|
+
Matrix.column_vector([x, y])
|
32
|
+
end
|
33
|
+
|
34
|
+
def rotator
|
35
|
+
@rotator ||= GridGenerator::Rotator.new(angle: rotation_angle, rotation_point: centre_point)
|
36
|
+
end
|
37
|
+
|
21
38
|
def start_x_for_row(r)
|
22
39
|
(size - 1 - r) * units / 2
|
23
40
|
end
|
@@ -30,62 +47,124 @@ module GridGenerator
|
|
30
47
|
Math.sqrt(3)/2 * (r + 1) * units
|
31
48
|
end
|
32
49
|
|
50
|
+
def vertical_start_point_for_row(r)
|
51
|
+
Matrix.column_vector([
|
52
|
+
start_x_for_row(r),
|
53
|
+
y_for_row(r),
|
54
|
+
])
|
55
|
+
end
|
56
|
+
|
57
|
+
def vertical_end_point_for_row(r)
|
58
|
+
Matrix.column_vector([
|
59
|
+
end_x_for_row(r),
|
60
|
+
y_for_row(r)
|
61
|
+
])
|
62
|
+
end
|
63
|
+
|
33
64
|
def vertical_lines
|
34
65
|
Array.new(size-1) do |i|
|
66
|
+
point_1 = vertical_start_point_for_row(i)
|
67
|
+
point_2 = vertical_end_point_for_row(i)
|
68
|
+
|
69
|
+
transformed_1 = rotator.rotate(point_1) + offset
|
70
|
+
transformed_2 = rotator.rotate(point_2) + offset
|
71
|
+
|
35
72
|
GridGenerator::BaseLine.new(
|
36
|
-
x1:
|
37
|
-
y1:
|
38
|
-
x2:
|
39
|
-
y2:
|
73
|
+
x1: transformed_1[0,0],
|
74
|
+
y1: transformed_1[1,0],
|
75
|
+
x2: transformed_2[0,0],
|
76
|
+
y2: transformed_2[1,0]
|
40
77
|
)
|
41
78
|
end
|
42
79
|
end
|
43
80
|
|
81
|
+
def diagonal_down_start_point_for_row(r)
|
82
|
+
Matrix.column_vector([
|
83
|
+
start_x_for_row(r),
|
84
|
+
y_for_row(r),
|
85
|
+
])
|
86
|
+
end
|
87
|
+
|
88
|
+
def diagonal_down_end_point_for_row(r)
|
89
|
+
Matrix.column_vector([
|
90
|
+
(size - 1 - r)*units,
|
91
|
+
y_for_row(size-1)
|
92
|
+
])
|
93
|
+
end
|
94
|
+
|
44
95
|
def diagonal_down_lines
|
45
96
|
Array.new(size-1) do |i|
|
97
|
+
point_1 = diagonal_down_start_point_for_row(i)
|
98
|
+
point_2 = diagonal_down_end_point_for_row(i)
|
99
|
+
|
100
|
+
transformed_1 = rotator.rotate(point_1) + offset
|
101
|
+
transformed_2 = rotator.rotate(point_2) + offset
|
102
|
+
|
46
103
|
GridGenerator::BaseLine.new(
|
47
|
-
x1:
|
48
|
-
y1:
|
49
|
-
x2:
|
50
|
-
y2:
|
104
|
+
x1: transformed_1[0,0],
|
105
|
+
y1: transformed_1[1,0],
|
106
|
+
x2: transformed_2[0,0],
|
107
|
+
y2: transformed_2[1,0]
|
51
108
|
)
|
52
109
|
end
|
53
110
|
end
|
54
111
|
|
112
|
+
def diagonal_up_start_point_for_row(r)
|
113
|
+
Matrix.column_vector([
|
114
|
+
(r+1)*units,
|
115
|
+
y_for_row(size-1),
|
116
|
+
])
|
117
|
+
end
|
118
|
+
|
119
|
+
def diagonal_up_end_point_for_row(r)
|
120
|
+
Matrix.column_vector([
|
121
|
+
end_x_for_row(r),
|
122
|
+
y_for_row(r)
|
123
|
+
])
|
124
|
+
end
|
125
|
+
|
55
126
|
def diagonal_up_lines
|
56
127
|
Array.new(size-1) do |i|
|
128
|
+
point_1 = diagonal_up_start_point_for_row(i)
|
129
|
+
point_2 = diagonal_up_end_point_for_row(i)
|
130
|
+
|
131
|
+
transformed_1 = rotator.rotate(point_1) + offset
|
132
|
+
transformed_2 = rotator.rotate(point_2) + offset
|
133
|
+
|
57
134
|
GridGenerator::BaseLine.new(
|
58
|
-
x1:
|
59
|
-
y1:
|
60
|
-
x2:
|
61
|
-
y2:
|
135
|
+
x1: transformed_1[0,0],
|
136
|
+
y1: transformed_1[1,0],
|
137
|
+
x2: transformed_2[0,0],
|
138
|
+
y2: transformed_2[1,0]
|
62
139
|
)
|
63
140
|
end
|
64
141
|
end
|
65
142
|
|
66
143
|
def top
|
67
144
|
Matrix.column_vector([
|
68
|
-
|
69
|
-
|
145
|
+
size * units / 2,
|
146
|
+
0
|
70
147
|
])
|
71
148
|
end
|
72
149
|
|
73
150
|
def bottom_left
|
74
151
|
Matrix.column_vector([
|
75
|
-
|
76
|
-
|
152
|
+
0,
|
153
|
+
size * Math.sqrt(3)/2 * units
|
77
154
|
])
|
78
155
|
end
|
79
156
|
|
80
157
|
def bottom_right
|
81
158
|
Matrix.column_vector([
|
82
|
-
|
83
|
-
|
159
|
+
size * units,
|
160
|
+
size * Math.sqrt(3)/2 * units
|
84
161
|
])
|
85
162
|
end
|
86
163
|
|
87
164
|
def points
|
88
|
-
[ top, bottom_left, bottom_right ]
|
165
|
+
[ top, bottom_left, bottom_right ].map do |point|
|
166
|
+
rotator.rotate(point) + offset
|
167
|
+
end
|
89
168
|
end
|
90
169
|
|
91
170
|
def points_string
|
@@ -102,7 +181,8 @@ module GridGenerator
|
|
102
181
|
col: col_num,
|
103
182
|
units: units,
|
104
183
|
size: size,
|
105
|
-
face: col
|
184
|
+
face: col,
|
185
|
+
rotator: rotator
|
106
186
|
).build unless col == '-'
|
107
187
|
end
|
108
188
|
end.flatten.compact
|
@@ -4,7 +4,7 @@ require_relative '../base_element'
|
|
4
4
|
module GridGenerator
|
5
5
|
module Pyraminx
|
6
6
|
class TriangleFactory
|
7
|
-
def initialize(x:, y:, row:, col:, units:, size:, face:)
|
7
|
+
def initialize(x:, y:, row:, col:, units:, size:, face:, rotator:)
|
8
8
|
@x, @y = x, y
|
9
9
|
@row = row
|
10
10
|
@col = col
|
@@ -13,9 +13,14 @@ module GridGenerator
|
|
13
13
|
face_attr = GridGenerator::FaceParser.new(face).parse
|
14
14
|
@colour = face_attr && face_attr[:colour]
|
15
15
|
@opacity = face_attr && face_attr[:opacity]
|
16
|
+
@rotator = rotator
|
16
17
|
end
|
17
18
|
|
18
|
-
attr_reader :x, :y, :row, :col, :units, :size, :colour, :opacity
|
19
|
+
attr_reader :x, :y, :row, :col, :units, :size, :colour, :opacity, :rotator
|
20
|
+
|
21
|
+
def offset
|
22
|
+
Matrix.column_vector([x, y])
|
23
|
+
end
|
19
24
|
|
20
25
|
# x + ((3 - 0) * 0.5 * units) + 0 * 0.5 * units # row = 0, col = 0
|
21
26
|
# x + ((3 - 1) * 0.5 * units) + 0 * 0.5 * units # row = 1, col = 0
|
@@ -24,7 +29,7 @@ module GridGenerator
|
|
24
29
|
# x + ((3 - 2) * 0.5 * units) + 2 * 0.5 * units # row = 2, col = 2
|
25
30
|
# x + ((3 - 2) * 0.5 * units) + 4 * 0.5 * units # row = 2, col = 4
|
26
31
|
def even_top_x
|
27
|
-
|
32
|
+
((size - row) * 0.5 * units) + col * 0.5 * units
|
28
33
|
end
|
29
34
|
|
30
35
|
# x + (0 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 0, col = 0
|
@@ -34,7 +39,7 @@ module GridGenerator
|
|
34
39
|
# x + (2 * -1 + (3 - 1)) * 0.5 * units + 2 * 0.5 * units # row = 2, col = 2
|
35
40
|
# x + (2 * -1 + (3 - 1)) * 0.5 * units + 4 * 0.5 * units# row = 2, col = 4
|
36
41
|
def even_bottom_left_x
|
37
|
-
|
42
|
+
(row * -1 + (size - 1)) * 0.5 * units + col * 0.5 * units
|
38
43
|
end
|
39
44
|
|
40
45
|
# x + (0 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 0, col = 0
|
@@ -44,21 +49,21 @@ module GridGenerator
|
|
44
49
|
# x + (2 * -1 + (3 + 1)) * 0.5 * units + 2 * 0.5 * units # row = 2, col = 2
|
45
50
|
# x + (2 * -1 + (3 + 1)) * 0.5 * units + 4 * 0.5 * units # row = 2, col = 4
|
46
51
|
def even_bottom_right_x
|
47
|
-
|
52
|
+
(row * -1 + (size + 1)) * 0.5 * units + col * 0.5 * units
|
48
53
|
end
|
49
54
|
|
50
55
|
# 0 * Math.sqrt(3)/2 * units # row = 0
|
51
56
|
# 1 * Math.sqrt(3)/2 * units # row = 1
|
52
57
|
# 2 * Math.sqrt(3)/2 * units # row = 2
|
53
58
|
def top_y
|
54
|
-
|
59
|
+
row * Math.sqrt(3)/2 * units
|
55
60
|
end
|
56
61
|
|
57
62
|
# (0 + 1) * Math.sqrt(3)/2 * units # row = 0
|
58
63
|
# (1 + 1) * Math.sqrt(3)/2 * units # row = 1
|
59
64
|
# (2 + 1) * Math.sqrt(3)/2 * units # row = 2
|
60
65
|
def bottom_y
|
61
|
-
|
66
|
+
(row + 1) * Math.sqrt(3)/2 * units
|
62
67
|
end
|
63
68
|
|
64
69
|
# (0 * -1 + 3) * 0.5 * units # row 0
|
@@ -67,7 +72,7 @@ module GridGenerator
|
|
67
72
|
# (2 * -1 + 3) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1
|
68
73
|
# (2 * -1 + 3) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
|
69
74
|
def odd_top_left_x
|
70
|
-
|
75
|
+
(row * -1 + size) * 0.5 * units + (col - 1) * 0.5 * units
|
71
76
|
end
|
72
77
|
|
73
78
|
# ((0 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 0, col = 1
|
@@ -75,7 +80,7 @@ module GridGenerator
|
|
75
80
|
# ((2 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1
|
76
81
|
# ((2 * -1) + 3 + 2) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
|
77
82
|
def odd_top_right_x
|
78
|
-
|
83
|
+
(row * -1 + size + 2) * 0.5 * units + (col - 1) * 0.5 * units
|
79
84
|
end
|
80
85
|
|
81
86
|
# (0 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 0, col = 1
|
@@ -83,7 +88,7 @@ module GridGenerator
|
|
83
88
|
# (2 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1
|
84
89
|
# (2 * -1 + 3 + 1) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
|
85
90
|
def odd_bottom_x
|
86
|
-
|
91
|
+
(row * -1 + size + 1) * 0.5 * units + (col - 1) * 0.5 * units
|
87
92
|
end
|
88
93
|
|
89
94
|
def even_points
|
@@ -103,10 +108,9 @@ module GridGenerator
|
|
103
108
|
end
|
104
109
|
|
105
110
|
def points
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
odd_points
|
111
|
+
all_points = col % 2 == 0 ? even_points : odd_points
|
112
|
+
all_points.map do |point|
|
113
|
+
rotator.rotate(point) + offset
|
110
114
|
end
|
111
115
|
end
|
112
116
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GridGenerator
|
2
|
+
class Rotator
|
3
|
+
def initialize(angle:, rotation_point:)
|
4
|
+
@angle = angle
|
5
|
+
@matrix = Matrix[
|
6
|
+
[Math.cos(angle), -1*Math.sin(angle)],
|
7
|
+
[Math.sin(angle), Math.cos(angle)]
|
8
|
+
]
|
9
|
+
@rotation_point = rotation_point
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :angle, :matrix, :rotation_point
|
13
|
+
|
14
|
+
def rotate(point)
|
15
|
+
# subtract rotation point to move point towards 0,0, rotate, then add to move back
|
16
|
+
(matrix * (point - rotation_point)) + rotation_point
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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.1.
|
4
|
+
version: 0.1.11
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: matrix
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/grid_generator/pyraminx/grid.rb
|
66
66
|
- lib/grid_generator/pyraminx/triangle_factory.rb
|
67
67
|
- lib/grid_generator/pyraminx/triangle_factory_v1.rb
|
68
|
+
- lib/grid_generator/rotator.rb
|
68
69
|
- lib/grid_generator/skewb/left_element_factory.rb
|
69
70
|
- lib/grid_generator/skewb/left_skewb_grid.rb
|
70
71
|
- lib/grid_generator/skewb/right_element_factory.rb
|
@@ -75,6 +76,7 @@ files:
|
|
75
76
|
- lib/grid_generator/square_one/element_factory.rb
|
76
77
|
- lib/grid_generator/square_one/face.rb
|
77
78
|
- lib/grid_generator/square_one_face_parser.rb
|
79
|
+
- lib/grid_generator/transformation.rb
|
78
80
|
- lib/grid_generator/version.rb
|
79
81
|
- sig/grid_generator.rbs
|
80
82
|
homepage: https://github.com/mrlhumphreys/grid_generator
|