grid_generator 0.1.11 → 0.2.0
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/helper.rb +8 -0
- data/lib/grid_generator/megaminx/face_projection.rb +106 -0
- data/lib/grid_generator/megaminx/front_face.rb +12 -0
- data/lib/grid_generator/pyraminx/face.rb +27 -10
- data/lib/grid_generator/pyraminx/triangle_factory.rb +5 -3
- data/lib/grid_generator/scaler.rb +18 -0
- data/lib/grid_generator/version.rb +1 -1
- data/lib/grid_generator.rb +4 -0
- metadata +6 -5
- data/lib/grid_generator/pyraminx/grid.rb +0 -84
- data/lib/grid_generator/pyraminx/triangle_factory_v1.rb +0 -45
- data/lib/grid_generator/transformation.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2668c9e2f64e3edc746fcc14a722c999fc4700a7835f472f3e661d6157c951d8
|
4
|
+
data.tar.gz: a9ee5d5b9ded2773be2bbb82caccc53258b0be5b9e01dba5e65cfcc74e53374a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 386ee6bc5bb324d0a986429f95e071df54c87dfaa58294007f54733256bb23c22b59d894e04c4e446b97536ad2e2d2a53edf3ad45f800c230996f022ed5f8bc2
|
7
|
+
data.tar.gz: 77d2e5859f4548e5c93c9d341ad947dfb6966940935edbc548b544070ef9e668818ea9019734e9597420870a58c07626c6e4dba55d0da0ad849b7bed62c8adde
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
require '../rotator'
|
3
|
+
require '../helper'
|
4
|
+
|
5
|
+
module GridGenerator
|
6
|
+
module Megaminx
|
7
|
+
class FaceProjection
|
8
|
+
# units 30 - pentagon 90 - megaminx - 150
|
9
|
+
# units * 5
|
10
|
+
# *****
|
11
|
+
# ***
|
12
|
+
# ***
|
13
|
+
#
|
14
|
+
# *** *** ***
|
15
|
+
# *** *** ***
|
16
|
+
# ***** ***** *****
|
17
|
+
#
|
18
|
+
# ***** *****
|
19
|
+
# *** ***
|
20
|
+
# *** ***
|
21
|
+
def initialize(x:, y:, units:, elements: [])
|
22
|
+
@x, @y = x, y
|
23
|
+
@units = units
|
24
|
+
@elements = elements
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :x, :y, :units, :elements
|
28
|
+
|
29
|
+
def offset
|
30
|
+
@offset ||= Matrix.column_vector([x, y])
|
31
|
+
end
|
32
|
+
|
33
|
+
def decagon_radius
|
34
|
+
5 * units
|
35
|
+
end
|
36
|
+
|
37
|
+
def decagon_top_point
|
38
|
+
Matrix.column_vector([
|
39
|
+
0,
|
40
|
+
decagon_radius
|
41
|
+
])
|
42
|
+
end
|
43
|
+
|
44
|
+
def rotation_point
|
45
|
+
Matrix.column_vector([
|
46
|
+
decagon_radius,
|
47
|
+
decagon_radius
|
48
|
+
])
|
49
|
+
end
|
50
|
+
|
51
|
+
def decagon_points
|
52
|
+
@decagon_points ||= (0..9).map do |i|
|
53
|
+
angle = 2.0 * Math::PI * i / 10.0
|
54
|
+
rotator = GridGenerator::Rotator.new(angle: angle, rotation_point: rotation_point)
|
55
|
+
rotator.rotate(top_point)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# also equal to pentagon radius
|
60
|
+
def decagon_side_length
|
61
|
+
@decagon_side_length ||= GridGenerator::Helper.distance(decagon_points[0], decagon_points[1])
|
62
|
+
end
|
63
|
+
|
64
|
+
def pentagon_top_point
|
65
|
+
@pentagon_top_point ||= Matrix.column_vector([
|
66
|
+
decagon_radius,
|
67
|
+
decagon_radius - decagon_side_length
|
68
|
+
])
|
69
|
+
end
|
70
|
+
|
71
|
+
def pentagon_points
|
72
|
+
@pentagon_points ||= (0..4).map do |i|
|
73
|
+
angle = 2.0 * Math::PI * i / 5.0
|
74
|
+
rotator = GridGenerator::Rotator.new(angle: angle, rotation_point: rotation_point)
|
75
|
+
rotator.rotate(top_point)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# for svg
|
80
|
+
def connecting_lines
|
81
|
+
@connecting_lines ||= pentagon_points.map_with_index do |p, i|
|
82
|
+
d = decagon_point[i*2]
|
83
|
+
offset_p = p + offset
|
84
|
+
offset_d = d + offset
|
85
|
+
GridGenerator::BaseLine.new(
|
86
|
+
x1: offset_p[0,0],
|
87
|
+
y1: offset_p[1,0],
|
88
|
+
x2: offset_d[0,0],
|
89
|
+
y2: offset_p[1,0]
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# for svg
|
95
|
+
def decagon_points_string
|
96
|
+
decagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
97
|
+
end
|
98
|
+
|
99
|
+
# for svg
|
100
|
+
def pentagon_points_string
|
101
|
+
pentagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative 'triangle_factory'
|
2
2
|
require_relative '../rotator'
|
3
|
+
require_relative '../scaler'
|
3
4
|
|
4
5
|
module GridGenerator
|
5
6
|
module Pyraminx
|
@@ -7,14 +8,15 @@ module GridGenerator
|
|
7
8
|
# * * *
|
8
9
|
# * * * * *
|
9
10
|
class Face
|
10
|
-
def initialize(x:, y:, units:, elements:, rotation_angle: 0)
|
11
|
+
def initialize(x:, y:, units:, elements:, vertical_scale: 1, rotation_angle: 0)
|
11
12
|
@x, @y = x, y
|
12
13
|
@units = units
|
13
14
|
@elements = elements.split('\n').map { |r| r.split(',') }
|
15
|
+
@vertical_scale = vertical_scale
|
14
16
|
@rotation_angle = rotation_angle
|
15
17
|
end
|
16
18
|
|
17
|
-
attr_reader :x, :y, :units, :elements, :rotation_angle
|
19
|
+
attr_reader :x, :y, :units, :elements, :vertical_scale, :rotation_angle
|
18
20
|
|
19
21
|
def size
|
20
22
|
elements.size
|
@@ -35,6 +37,10 @@ module GridGenerator
|
|
35
37
|
@rotator ||= GridGenerator::Rotator.new(angle: rotation_angle, rotation_point: centre_point)
|
36
38
|
end
|
37
39
|
|
40
|
+
def scaler
|
41
|
+
@scaler ||= GridGenerator::Scaler.new(horizontal_scale: 1, vertical_scale: vertical_scale)
|
42
|
+
end
|
43
|
+
|
38
44
|
def start_x_for_row(r)
|
39
45
|
(size - 1 - r) * units / 2
|
40
46
|
end
|
@@ -66,8 +72,11 @@ module GridGenerator
|
|
66
72
|
point_1 = vertical_start_point_for_row(i)
|
67
73
|
point_2 = vertical_end_point_for_row(i)
|
68
74
|
|
69
|
-
|
70
|
-
|
75
|
+
scaled_1 = scaler.scale(point_1)
|
76
|
+
scaled_2 = scaler.scale(point_2)
|
77
|
+
|
78
|
+
transformed_1 = rotator.rotate(scaled_1) + offset
|
79
|
+
transformed_2 = rotator.rotate(scaled_2) + offset
|
71
80
|
|
72
81
|
GridGenerator::BaseLine.new(
|
73
82
|
x1: transformed_1[0,0],
|
@@ -97,8 +106,11 @@ module GridGenerator
|
|
97
106
|
point_1 = diagonal_down_start_point_for_row(i)
|
98
107
|
point_2 = diagonal_down_end_point_for_row(i)
|
99
108
|
|
100
|
-
|
101
|
-
|
109
|
+
scaled_1 = scaler.scale(point_1)
|
110
|
+
scaled_2 = scaler.scale(point_2)
|
111
|
+
|
112
|
+
transformed_1 = rotator.rotate(scaled_1) + offset
|
113
|
+
transformed_2 = rotator.rotate(scaled_2) + offset
|
102
114
|
|
103
115
|
GridGenerator::BaseLine.new(
|
104
116
|
x1: transformed_1[0,0],
|
@@ -128,8 +140,11 @@ module GridGenerator
|
|
128
140
|
point_1 = diagonal_up_start_point_for_row(i)
|
129
141
|
point_2 = diagonal_up_end_point_for_row(i)
|
130
142
|
|
131
|
-
|
132
|
-
|
143
|
+
scaled_1 = scaler.scale(point_1)
|
144
|
+
scaled_2 = scaler.scale(point_2)
|
145
|
+
|
146
|
+
transformed_1 = rotator.rotate(scaled_1) + offset
|
147
|
+
transformed_2 = rotator.rotate(scaled_2) + offset
|
133
148
|
|
134
149
|
GridGenerator::BaseLine.new(
|
135
150
|
x1: transformed_1[0,0],
|
@@ -163,7 +178,8 @@ module GridGenerator
|
|
163
178
|
|
164
179
|
def points
|
165
180
|
[ top, bottom_left, bottom_right ].map do |point|
|
166
|
-
|
181
|
+
scaled = scaler.scale(point)
|
182
|
+
rotator.rotate(scaled) + offset
|
167
183
|
end
|
168
184
|
end
|
169
185
|
|
@@ -182,7 +198,8 @@ module GridGenerator
|
|
182
198
|
units: units,
|
183
199
|
size: size,
|
184
200
|
face: col,
|
185
|
-
rotator: rotator
|
201
|
+
rotator: rotator,
|
202
|
+
scaler: scaler
|
186
203
|
).build unless col == '-'
|
187
204
|
end
|
188
205
|
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:, rotator:)
|
7
|
+
def initialize(x:, y:, row:, col:, units:, size:, face:, rotator:, scaler:)
|
8
8
|
@x, @y = x, y
|
9
9
|
@row = row
|
10
10
|
@col = col
|
@@ -14,9 +14,10 @@ module GridGenerator
|
|
14
14
|
@colour = face_attr && face_attr[:colour]
|
15
15
|
@opacity = face_attr && face_attr[:opacity]
|
16
16
|
@rotator = rotator
|
17
|
+
@scaler = scaler
|
17
18
|
end
|
18
19
|
|
19
|
-
attr_reader :x, :y, :row, :col, :units, :size, :colour, :opacity, :rotator
|
20
|
+
attr_reader :x, :y, :row, :col, :units, :size, :colour, :opacity, :rotator, :scaler
|
20
21
|
|
21
22
|
def offset
|
22
23
|
Matrix.column_vector([x, y])
|
@@ -110,7 +111,8 @@ module GridGenerator
|
|
110
111
|
def points
|
111
112
|
all_points = col % 2 == 0 ? even_points : odd_points
|
112
113
|
all_points.map do |point|
|
113
|
-
|
114
|
+
scaled = scaler.scale(point)
|
115
|
+
rotator.rotate(scaled) + offset
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GridGenerator
|
2
|
+
class Scaler
|
3
|
+
def initialize(horizontal_scale: 1, vertical_scale: 1)
|
4
|
+
@horizontal_scale = horizontal_scale
|
5
|
+
@vertical_scale = vertical_scale
|
6
|
+
@matrix = Matrix[
|
7
|
+
[horizontal_scale,0],
|
8
|
+
[0,vertical_scale]
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :horizontal_scale, :vertical_scale, :matrix
|
13
|
+
|
14
|
+
def scale(point)
|
15
|
+
matrix * point
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/grid_generator.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: matrix
|
@@ -58,14 +58,16 @@ files:
|
|
58
58
|
- lib/grid_generator/cubic/top_grid.rb
|
59
59
|
- lib/grid_generator/cubic/units_factory.rb
|
60
60
|
- lib/grid_generator/face_parser.rb
|
61
|
+
- lib/grid_generator/helper.rb
|
61
62
|
- lib/grid_generator/megaminx/common.rb
|
62
63
|
- lib/grid_generator/megaminx/element_factory.rb
|
63
64
|
- lib/grid_generator/megaminx/face.rb
|
65
|
+
- lib/grid_generator/megaminx/face_projection.rb
|
66
|
+
- lib/grid_generator/megaminx/front_face.rb
|
64
67
|
- lib/grid_generator/pyraminx/face.rb
|
65
|
-
- lib/grid_generator/pyraminx/grid.rb
|
66
68
|
- lib/grid_generator/pyraminx/triangle_factory.rb
|
67
|
-
- lib/grid_generator/pyraminx/triangle_factory_v1.rb
|
68
69
|
- lib/grid_generator/rotator.rb
|
70
|
+
- lib/grid_generator/scaler.rb
|
69
71
|
- lib/grid_generator/skewb/left_element_factory.rb
|
70
72
|
- lib/grid_generator/skewb/left_skewb_grid.rb
|
71
73
|
- lib/grid_generator/skewb/right_element_factory.rb
|
@@ -76,7 +78,6 @@ files:
|
|
76
78
|
- lib/grid_generator/square_one/element_factory.rb
|
77
79
|
- lib/grid_generator/square_one/face.rb
|
78
80
|
- lib/grid_generator/square_one_face_parser.rb
|
79
|
-
- lib/grid_generator/transformation.rb
|
80
81
|
- lib/grid_generator/version.rb
|
81
82
|
- sig/grid_generator.rbs
|
82
83
|
homepage: https://github.com/mrlhumphreys/grid_generator
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require_relative '../base_line'
|
2
|
-
require_relative 'triangle_factory_v1'
|
3
|
-
|
4
|
-
module GridGenerator
|
5
|
-
module Pyraminx
|
6
|
-
class Grid
|
7
|
-
def initialize(x: ,y:, size: ,units: ,elements:)
|
8
|
-
@x, @y = x, y
|
9
|
-
@size = size
|
10
|
-
@units = units
|
11
|
-
@elements = elements
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :x, :y, :size, :units, :elements
|
15
|
-
|
16
|
-
def shape_points
|
17
|
-
[
|
18
|
-
[ x+size*units, y ],
|
19
|
-
[ x+2*size*units, y+size*units ],
|
20
|
-
[ x+size*units, y+2*size*units ],
|
21
|
-
[ x, y+size*units ]
|
22
|
-
]
|
23
|
-
end
|
24
|
-
|
25
|
-
def shape_points_string
|
26
|
-
shape_points.map { |x,y| [x,y].join(',') }.join(' ')
|
27
|
-
end
|
28
|
-
|
29
|
-
def vertical_line_points
|
30
|
-
Array.new((2*size)-1) do |i|
|
31
|
-
GridGenerator::BaseLine.new(
|
32
|
-
x1: x+((i+1)-size).abs*units,
|
33
|
-
y1: y+(i+1)*units,
|
34
|
-
x2: x+((((i+1)-size).abs*-1)+2*size)*units,
|
35
|
-
y2: y+(i+1)*units
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def diagonal_down_line_points
|
41
|
-
Array.new(size-1) do |i|
|
42
|
-
GridGenerator::BaseLine.new(
|
43
|
-
x1: x+((i-1).abs + 1)*units,
|
44
|
-
y1: y+(i+1)*units,
|
45
|
-
x2: x+((i-1).abs + 1 + size)*units,
|
46
|
-
y2: y+(i+1+size)*units
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def diagonal_up_line_points
|
52
|
-
Array.new(size-1) do |i|
|
53
|
-
GridGenerator::BaseLine.new(
|
54
|
-
x1: x+(i+1)*units,
|
55
|
-
y1: y+(i+1+size)*units,
|
56
|
-
x2: x+(i+1+size)*units,
|
57
|
-
y2: y+(i+1)*units
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def element_shapes
|
63
|
-
elements.map do |row|
|
64
|
-
row.map do |element|
|
65
|
-
if element
|
66
|
-
GridGenerator::Pyraminx::TriangleFactoryV1.new(x: x, y: y, units: units, direction: element[:direction], colour: element[:colour], opacity: element[:opacity]).build
|
67
|
-
else
|
68
|
-
nil
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end.flatten.compact
|
72
|
-
end
|
73
|
-
|
74
|
-
def as_json
|
75
|
-
{
|
76
|
-
"vertical_line_points" => vertical_line_points,
|
77
|
-
"diagonal_down_line_points" => diagonal_down_line_points,
|
78
|
-
"diagonal_up_line_points" => diagonal_up_line_points,
|
79
|
-
"element_shapes" => element_shapes.map(&:as_json)
|
80
|
-
}
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,45 +0,0 @@
|
|
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
|