grid_generator 0.1.7 → 0.1.8
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 +112 -0
- data/lib/grid_generator/pyraminx/grid.rb +2 -2
- data/lib/grid_generator/pyraminx/triangle_factory.rb +91 -18
- data/lib/grid_generator/pyraminx/triangle_factory_v1.rb +45 -0
- data/lib/grid_generator/version.rb +1 -1
- data/lib/grid_generator.rb +3 -7
- 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: 8c0a572f9ff30e9a8a09dd3a25ff1da4d7407b62c96946c17173d6dc479dd11d
|
4
|
+
data.tar.gz: 82f11b79300e9aa6c0cdcf7752ef7ff86f1f3205ee049e5ae4bdd40617da4e6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0231572fba1c2911f88887eb6179c68a7c5d5df9b6d3d137b0f96cde999e219ef2925ec20506e28a9796c52f426ecbbf156239be4039b83ffb2ca2eb872e318
|
7
|
+
data.tar.gz: 88784bbaef6dd1a4266a9dc2a7e47a1cc872dbd239b28df10d4c2ba4bf56ca8081a78855fa2d519b4597f372edc1e32b3d4251eb9bbddc6fc929e433cbe29196
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
require_relative 'triangle_factory'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module Pyraminx
|
5
|
+
# *
|
6
|
+
# * * *
|
7
|
+
# * * * * *
|
8
|
+
class Face
|
9
|
+
def initialize(x:, y:, units:, elements:)
|
10
|
+
@x, @y = x, y
|
11
|
+
@units = units
|
12
|
+
@elements = elements.split('\n').map { |r| r.split(',') }
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :x, :y, :units, :elements
|
16
|
+
|
17
|
+
def size
|
18
|
+
elements.size
|
19
|
+
end
|
20
|
+
|
21
|
+
def start_x_for_row(r)
|
22
|
+
(size - 1 - r) * units / 2
|
23
|
+
end
|
24
|
+
|
25
|
+
def end_x_for_row(r)
|
26
|
+
(size + 1 + r) * units / 2
|
27
|
+
end
|
28
|
+
|
29
|
+
def y_for_row(r)
|
30
|
+
Math.sqrt(3)/2 * r * units
|
31
|
+
end
|
32
|
+
|
33
|
+
def vertical_lines
|
34
|
+
Array.new(size-1) do |i|
|
35
|
+
GridGenerator::BaseLine.new(
|
36
|
+
x1: x + start_x_for_row(i),
|
37
|
+
y1: y + y_for_row(i),
|
38
|
+
x2: x + end_x_for_row(i),
|
39
|
+
y2: y + y_for_row(i)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def diagonal_down_lines
|
45
|
+
Array.new(size-1) do |i|
|
46
|
+
GridGenerator::BaseLine.new(
|
47
|
+
x1: x + start_x_for_row(i),
|
48
|
+
y1: y + y_for_row(i),
|
49
|
+
x2: x + (size - 1 - i)*units,
|
50
|
+
y2: y + y_for_row(size)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def diagonal_up_lines
|
56
|
+
Array.new(size-1) do |i|
|
57
|
+
GridGenerator::BaseLine.new(
|
58
|
+
x1: x + (i+1)*units,
|
59
|
+
y1: y + y_for_row(size),
|
60
|
+
x2: x + end_x_for_row(i),
|
61
|
+
y2: y + y_for_row(i)
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def top
|
67
|
+
Matrix.column_vector([
|
68
|
+
x + units / 2,
|
69
|
+
y
|
70
|
+
])
|
71
|
+
end
|
72
|
+
|
73
|
+
def bottom_left
|
74
|
+
Matrix.column_vector([
|
75
|
+
x,
|
76
|
+
y + size * Math.sqrt(3)/2 * units
|
77
|
+
])
|
78
|
+
end
|
79
|
+
|
80
|
+
def bottom_right
|
81
|
+
Matrix.column_vector([
|
82
|
+
x + size * units,
|
83
|
+
y + size * Math.sqrt(3)/2 * units
|
84
|
+
])
|
85
|
+
end
|
86
|
+
|
87
|
+
def points
|
88
|
+
[ top, bottom_left, bottom_right ]
|
89
|
+
end
|
90
|
+
|
91
|
+
def points_string
|
92
|
+
points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
93
|
+
end
|
94
|
+
|
95
|
+
def element_shapes
|
96
|
+
elements.map.each_with_index do |row, row_num|
|
97
|
+
row.map.each_with_index do |col, col_num|
|
98
|
+
GridGenerator::Pyraminx::TriangleFactory.new(
|
99
|
+
x: x,
|
100
|
+
y: y,
|
101
|
+
row: row_num,
|
102
|
+
col: col_num,
|
103
|
+
units: units,
|
104
|
+
size: size,
|
105
|
+
face: col
|
106
|
+
).build unless col == '-'
|
107
|
+
end
|
108
|
+
end.flatten.compact
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative '../base_line'
|
2
|
-
require_relative '
|
2
|
+
require_relative 'triangle_factory_v1'
|
3
3
|
|
4
4
|
module GridGenerator
|
5
5
|
module Pyraminx
|
@@ -63,7 +63,7 @@ module GridGenerator
|
|
63
63
|
elements.map do |row|
|
64
64
|
row.map do |element|
|
65
65
|
if element
|
66
|
-
GridGenerator::Pyraminx::
|
66
|
+
GridGenerator::Pyraminx::TriangleFactoryV1.new(x: x, y: y, units: units, direction: element[:direction], colour: element[:colour], opacity: element[:opacity]).build
|
67
67
|
else
|
68
68
|
nil
|
69
69
|
end
|
@@ -1,44 +1,117 @@
|
|
1
|
+
require_relative '../face_parser'
|
1
2
|
require_relative '../base_element'
|
2
3
|
|
3
4
|
module GridGenerator
|
4
5
|
module Pyraminx
|
5
6
|
class TriangleFactory
|
6
|
-
def initialize(x:, y:,
|
7
|
+
def initialize(x:, y:, row:, col:, units:, size:, face:)
|
7
8
|
@x, @y = x, y
|
9
|
+
@row = row
|
10
|
+
@col = col
|
8
11
|
@units = units
|
9
|
-
@
|
10
|
-
|
11
|
-
@
|
12
|
+
@size = size
|
13
|
+
face_attr = GridGenerator::FaceParser.new(face).parse
|
14
|
+
@colour = face_attr && face_attr[:colour]
|
15
|
+
@opacity = face_attr && face_attr[:opacity]
|
12
16
|
end
|
13
17
|
|
14
|
-
attr_reader :x, :y, :units, :
|
18
|
+
attr_reader :x, :y, :row, :col, :units, :size, :colour, :opacity
|
15
19
|
|
16
|
-
|
20
|
+
# x + ((3 - 0) * 0.5 * units) + 0 * 0.5 * units # row = 0, col = 0
|
21
|
+
# x + ((3 - 1) * 0.5 * units) + 0 * 0.5 * units # row = 1, col = 0
|
22
|
+
# x + ((3 - 1) * 0.5 * units) + 2 * 0.5 * units # row = 1, col = 2
|
23
|
+
# x + ((3 - 2) * 0.5 * units) + 0 * 0.5 * units # row = 2, col = 0
|
24
|
+
# x + ((3 - 2) * 0.5 * units) + 2 * 0.5 * units # row = 2, col = 2
|
25
|
+
# x + ((3 - 2) * 0.5 * units) + 4 * 0.5 * units # row = 2, col = 4
|
26
|
+
def even_top_x
|
27
|
+
x + ((size - row) * 0.5 * units) + col * 0.5 * units
|
28
|
+
end
|
29
|
+
|
30
|
+
# x + (0 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 0, col = 0
|
31
|
+
# x + (1 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 1, col = 0
|
32
|
+
# x + (1 * -1 + (3 - 1)) * 0.5 * units + 2 * 0.5 * units # row = 1, col = 2
|
33
|
+
# x + (2 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 2, col = 0
|
34
|
+
# x + (2 * -1 + (3 - 1)) * 0.5 * units + 2 * 0.5 * units # row = 2, col = 2
|
35
|
+
# x + (2 * -1 + (3 - 1)) * 0.5 * units + 4 * 0.5 * units# row = 2, col = 4
|
36
|
+
def even_bottom_left_x
|
37
|
+
x + (row * -1 + (size - 1)) * 0.5 * units + col * 0.5 * units
|
38
|
+
end
|
39
|
+
|
40
|
+
# x + (0 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 0, col = 0
|
41
|
+
# x + (1 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 1, col = 0
|
42
|
+
# x + (1 * -1 + (3 + 1)) * 0.5 * units + 2 * 0.5 * units # row = 1, col = 2
|
43
|
+
# x + (2 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 2, col = 0
|
44
|
+
# x + (2 * -1 + (3 + 1)) * 0.5 * units + 2 * 0.5 * units # row = 2, col = 2
|
45
|
+
# x + (2 * -1 + (3 + 1)) * 0.5 * units + 4 * 0.5 * units # row = 2, col = 4
|
46
|
+
def even_bottom_right_x
|
47
|
+
x + (row * -1 + (size + 1)) * 0.5 * units + col * 0.5 * units
|
48
|
+
end
|
49
|
+
|
50
|
+
# 0 * Math.sqrt(3)/2 * units # row = 0
|
51
|
+
# 1 * Math.sqrt(3)/2 * units # row = 1
|
52
|
+
# 2 * Math.sqrt(3)/2 * units # row = 2
|
53
|
+
def top_y
|
54
|
+
y + row * Math.sqrt(3)/2 * units
|
55
|
+
end
|
56
|
+
|
57
|
+
# (0 + 1) * Math.sqrt(3)/2 * units # row = 0
|
58
|
+
# (1 + 1) * Math.sqrt(3)/2 * units # row = 1
|
59
|
+
# (2 + 1) * Math.sqrt(3)/2 * units # row = 2
|
60
|
+
def bottom_y
|
61
|
+
y + (row + 1) * Math.sqrt(3)/2 * units
|
62
|
+
end
|
63
|
+
|
64
|
+
# (0 * -1 + 3) * 0.5 * units # row 0
|
65
|
+
# (1 * -1 + 3) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1
|
66
|
+
# (1 * -1 + 3) * 0.5 * units + (3 - 1) * 0.5 * units # row 1, col = 3
|
67
|
+
# (2 * -1 + 3) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1
|
68
|
+
# (2 * -1 + 3) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
|
69
|
+
def odd_top_left_x
|
70
|
+
x + (row * -1 + size) * 0.5 * units + (col - 1) * 0.5 * units
|
71
|
+
end
|
72
|
+
|
73
|
+
# ((0 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 0, col = 1
|
74
|
+
# ((1 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1
|
75
|
+
# ((2 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1
|
76
|
+
# ((2 * -1) + 3 + 2) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
|
77
|
+
def odd_top_right_x
|
78
|
+
x + (row * -1 + size + 2) * 0.5 * units + (col - 1) * 0.5 * units
|
79
|
+
end
|
80
|
+
|
81
|
+
# (0 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 0, col = 1
|
82
|
+
# (1 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1
|
83
|
+
# (2 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1
|
84
|
+
# (2 * -1 + 3 + 1) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
|
85
|
+
def odd_bottom_x
|
86
|
+
x + (row * -1 + size + 1) * 0.5 * units + (col - 1) * 0.5 * units
|
87
|
+
end
|
88
|
+
|
89
|
+
def even_points
|
17
90
|
[
|
18
|
-
Matrix.column_vector([
|
19
|
-
Matrix.column_vector([
|
20
|
-
Matrix.column_vector([
|
91
|
+
Matrix.column_vector([even_top_x, top_y]),
|
92
|
+
Matrix.column_vector([even_bottom_right_x, bottom_y]),
|
93
|
+
Matrix.column_vector([even_bottom_left_x, bottom_y])
|
21
94
|
]
|
22
95
|
end
|
23
96
|
|
24
|
-
def
|
97
|
+
def odd_points
|
25
98
|
[
|
26
|
-
Matrix.column_vector([
|
27
|
-
Matrix.column_vector([
|
28
|
-
Matrix.column_vector([
|
99
|
+
Matrix.column_vector([odd_top_left_x, top_y]),
|
100
|
+
Matrix.column_vector([odd_top_right_x, top_y]),
|
101
|
+
Matrix.column_vector([odd_bottom_x, bottom_y])
|
29
102
|
]
|
30
103
|
end
|
31
104
|
|
32
105
|
def points
|
33
|
-
if
|
34
|
-
|
106
|
+
if col % 2 == 0
|
107
|
+
even_points
|
35
108
|
else
|
36
|
-
|
109
|
+
odd_points
|
37
110
|
end
|
38
111
|
end
|
39
|
-
|
112
|
+
|
40
113
|
def build
|
41
|
-
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
|
114
|
+
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) unless colour.nil?
|
42
115
|
end
|
43
116
|
end
|
44
117
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative '../base_element'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module Pyraminx
|
5
|
+
class TriangleFactoryV1
|
6
|
+
def initialize(x:, y:, units:, direction:, colour:, opacity:)
|
7
|
+
@x, @y = x, y
|
8
|
+
@units = units
|
9
|
+
@direction = direction
|
10
|
+
@colour = colour
|
11
|
+
@opacity = opacity
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :x, :y, :units, :direction, :colour, :opacity
|
15
|
+
|
16
|
+
def up_points
|
17
|
+
[
|
18
|
+
Matrix.column_vector([ x+units, y ]),
|
19
|
+
Matrix.column_vector([ x+2*units, y+units ]),
|
20
|
+
Matrix.column_vector([ x, y+units ])
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def down_points
|
25
|
+
[
|
26
|
+
Matrix.column_vector([ x+units, y+units ]),
|
27
|
+
Matrix.column_vector([ x+2*units, y ]),
|
28
|
+
Matrix.column_vector([ x, y ])
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
def points
|
33
|
+
if direction == :up
|
34
|
+
up_points
|
35
|
+
else
|
36
|
+
down_points
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def build
|
41
|
+
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/grid_generator.rb
CHANGED
@@ -17,7 +17,7 @@ require_relative 'grid_generator/arrows/vertical_arrow'
|
|
17
17
|
require_relative 'grid_generator/arrows/horizontal_arrow'
|
18
18
|
require_relative 'grid_generator/arrows/diagonal_down_arrow'
|
19
19
|
require_relative 'grid_generator/arrows/diagonal_up_arrow'
|
20
|
-
require_relative 'grid_generator/pyraminx/
|
20
|
+
require_relative 'grid_generator/pyraminx/face'
|
21
21
|
require_relative 'grid_generator/megaminx/face'
|
22
22
|
|
23
23
|
module GridGenerator
|
@@ -80,12 +80,8 @@ module GridGenerator
|
|
80
80
|
Arrows::DiagonalUpArrow.new(**args)
|
81
81
|
end
|
82
82
|
|
83
|
-
def self.
|
84
|
-
Pyraminx::
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.pyraminx_triangle(args)
|
88
|
-
Pyraminx::Triangle.new(**args)
|
83
|
+
def self.pyraminx_face(args)
|
84
|
+
Pyraminx::Face.new(**args)
|
89
85
|
end
|
90
86
|
|
91
87
|
def self.megaminx_face(args)
|
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.8
|
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-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: matrix
|
@@ -61,8 +61,10 @@ files:
|
|
61
61
|
- lib/grid_generator/megaminx/common.rb
|
62
62
|
- lib/grid_generator/megaminx/element_factory.rb
|
63
63
|
- lib/grid_generator/megaminx/face.rb
|
64
|
+
- lib/grid_generator/pyraminx/face.rb
|
64
65
|
- lib/grid_generator/pyraminx/grid.rb
|
65
66
|
- lib/grid_generator/pyraminx/triangle_factory.rb
|
67
|
+
- lib/grid_generator/pyraminx/triangle_factory_v1.rb
|
66
68
|
- lib/grid_generator/skewb/left_element_factory.rb
|
67
69
|
- lib/grid_generator/skewb/left_skewb_grid.rb
|
68
70
|
- lib/grid_generator/skewb/right_element_factory.rb
|