grid_generator 0.5.1 → 0.5.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/grid_generator/dino_cube/element_factory.rb +57 -0
- data/lib/grid_generator/dino_cube/grid.rb +56 -0
- data/lib/grid_generator/dino_cube/left_element_factory.rb +17 -0
- data/lib/grid_generator/dino_cube/left_grid.rb +13 -0
- data/lib/grid_generator/dino_cube/right_element_factory.rb +17 -0
- data/lib/grid_generator/dino_cube/right_grid.rb +13 -0
- data/lib/grid_generator/dino_cube/top_element_factory.rb +17 -0
- data/lib/grid_generator/dino_cube/top_grid.rb +13 -0
- data/lib/grid_generator/version.rb +1 -1
- data/lib/grid_generator.rb +15 -0
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd51350c99559a869e29c7869469588cbbda4bb0336804b8f20c956451b3136c
|
4
|
+
data.tar.gz: 633dbd93675dea1a10b49ed0353bd172c734574672687bca120b1f3d9bce3250
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c81ffc2bcd159761c35e554b038d42a66c477c9030ca0a9d1b2aa944d03eb506a50a8df249a41b2c32a3557f324b4365844d7e7a9462739bf323fec0bce8593c
|
7
|
+
data.tar.gz: 3ef2e17855b8663c19a6ebc568a173c5c3b7dc30d70982d23c2335007047c7d82844e7511a96e90f8b16d0599c12248c16df25ff4923dde3497761aa5ccc9eef
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
require_relative '../base_element'
|
3
|
+
|
4
|
+
module GridGenerator
|
5
|
+
module DinoCube
|
6
|
+
class ElementFactory
|
7
|
+
def initialize(grid_x:, grid_y:, row_num:, col_num:, units:, colour:, opacity:)
|
8
|
+
@grid_x, @grid_y = grid_x, grid_y
|
9
|
+
@row_num, @col_num = row_num, col_num
|
10
|
+
@units = units
|
11
|
+
@colour, @opacity = colour, opacity
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :grid_x, :grid_y, :row_num, :col_num, :units, :colour, :opacity
|
15
|
+
|
16
|
+
def offset
|
17
|
+
@offset ||= Matrix.column_vector([grid_x, grid_y])
|
18
|
+
end
|
19
|
+
|
20
|
+
def points
|
21
|
+
_points = case [row_num, col_num]
|
22
|
+
when [0, 0] # top
|
23
|
+
[
|
24
|
+
anchors[:top_left_corner],
|
25
|
+
anchors[:top_right_corner],
|
26
|
+
anchors[:center]
|
27
|
+
]
|
28
|
+
when [1, 0] # left
|
29
|
+
[
|
30
|
+
anchors[:top_left_corner],
|
31
|
+
anchors[:center],
|
32
|
+
anchors[:bottom_left_corner]
|
33
|
+
]
|
34
|
+
when [0, 1] # right
|
35
|
+
[
|
36
|
+
anchors[:top_right_corner],
|
37
|
+
anchors[:bottom_right_corner],
|
38
|
+
anchors[:center]
|
39
|
+
]
|
40
|
+
when [1, 0] # bottom
|
41
|
+
[
|
42
|
+
anchors[:center],
|
43
|
+
anchors[:bottom_right_corner],
|
44
|
+
anchors[:bottom_left_corner]
|
45
|
+
]
|
46
|
+
else
|
47
|
+
[]
|
48
|
+
end
|
49
|
+
_points.map { |p| p + offset }
|
50
|
+
end
|
51
|
+
|
52
|
+
def build
|
53
|
+
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative '../face_parser'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module DinoCube
|
5
|
+
class Grid
|
6
|
+
def initialize(x:, y:, units: , elements: )
|
7
|
+
@x, @y = x, y
|
8
|
+
@units = units
|
9
|
+
@elements = case elements
|
10
|
+
when String
|
11
|
+
FaceParser.new(elements).parse
|
12
|
+
when Array
|
13
|
+
elements
|
14
|
+
else
|
15
|
+
raise ArgumentError, "elements must be array or string"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :x, :y, :units, :elements
|
20
|
+
|
21
|
+
def to_svg
|
22
|
+
output = ''
|
23
|
+
|
24
|
+
element_shapes.each { |element| output += element.to_svg if element }
|
25
|
+
|
26
|
+
output
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def build_element(row_num, col_num, data)
|
32
|
+
if data
|
33
|
+
element_factory_class.new(
|
34
|
+
grid_x: x,
|
35
|
+
grid_y: y,
|
36
|
+
row_num: row_num,
|
37
|
+
col_num: col_num,
|
38
|
+
units: units,
|
39
|
+
colour: data[:colour],
|
40
|
+
opacity: data[:opacity]
|
41
|
+
).build
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def element_shapes
|
48
|
+
elements.each_with_index.map do |row, row_num|
|
49
|
+
row.each_with_index.map do |col, col_num|
|
50
|
+
build_element(row_num, col_num, col)
|
51
|
+
end
|
52
|
+
end.flatten.compact
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative './element_factory'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module DinoCube
|
5
|
+
class LeftElementFactory < ElementFactory
|
6
|
+
def anchors
|
7
|
+
@anchors ||= {
|
8
|
+
top_left_corner: Matrix.column_vector([0, 0]),
|
9
|
+
top_right_corner: Matrix.column_vector([units, 0.5*units]),
|
10
|
+
bottom_left_corner: Matrix.column_vector([0, units]),
|
11
|
+
bottom_right_corner: Matrix.column_vector([units, 1.5*units]),
|
12
|
+
center: Matrix.column_vector([0.5*units, 0.75*units])
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative './element_factory'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module DinoCube
|
5
|
+
class RightElementFactory < ElementFactory
|
6
|
+
def anchors
|
7
|
+
@anchors ||= {
|
8
|
+
top_left_corner: Matrix.column_vector([0, 0.5*units]),
|
9
|
+
top_right_corner: Matrix.column_vector([units, 0]),
|
10
|
+
bottom_left_corner: Matrix.column_vector([0, 1.5*units]),
|
11
|
+
bottom_right_corner: Matrix.column_vector([units, units]),
|
12
|
+
center: Matrix.column_vector([0.5*units, 0.75*units])
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative './element_factory'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module DinoCube
|
5
|
+
class TopElementFactory < ElementFactory
|
6
|
+
def anchors
|
7
|
+
@anchors ||= {
|
8
|
+
top_left_corner: Matrix.column_vector([units, 0]),
|
9
|
+
top_right_corner: Matrix.column_vector([2*units, 0.5*units]),
|
10
|
+
bottom_left_corner: Matrix.column_vector([0, 0.5*units]),
|
11
|
+
bottom_right_corner: Matrix.column_vector([units, units]),
|
12
|
+
center: Matrix.column_vector([units, 0.5*units])
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/grid_generator.rb
CHANGED
@@ -15,6 +15,9 @@ require_relative 'grid_generator/skewb/right_skewb_grid'
|
|
15
15
|
require_relative 'grid_generator/curvy_copter/top_grid'
|
16
16
|
require_relative 'grid_generator/curvy_copter/left_grid'
|
17
17
|
require_relative 'grid_generator/curvy_copter/right_grid'
|
18
|
+
require_relative 'grid_generator/dino_cube/top_grid'
|
19
|
+
require_relative 'grid_generator/dino_cube/left_grid'
|
20
|
+
require_relative 'grid_generator/dino_cube/right_grid'
|
18
21
|
require_relative 'grid_generator/square_one/face'
|
19
22
|
require_relative 'grid_generator/pyraminx/face'
|
20
23
|
require_relative 'grid_generator/megaminx/face_projection'
|
@@ -71,6 +74,18 @@ module GridGenerator
|
|
71
74
|
CurvyCopter::RightGrid.new(**args)
|
72
75
|
end
|
73
76
|
|
77
|
+
def self.dino_cube_top_grid(args)
|
78
|
+
DinoCube::TopGrid.new(**args)
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.dino_cube_left_grid(args)
|
82
|
+
DinoCube::LeftGrid.new(**args)
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.dino_cube_right_grid(args)
|
86
|
+
DinoCube::RightGrid.new(**args)
|
87
|
+
end
|
88
|
+
|
74
89
|
def self.square_one_face(args)
|
75
90
|
SquareOne::Face.new(**args)
|
76
91
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grid_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Humphreys
|
@@ -60,6 +60,14 @@ files:
|
|
60
60
|
- lib/grid_generator/curvy_copter/right_grid.rb
|
61
61
|
- lib/grid_generator/curvy_copter/top_element_factory.rb
|
62
62
|
- lib/grid_generator/curvy_copter/top_grid.rb
|
63
|
+
- lib/grid_generator/dino_cube/element_factory.rb
|
64
|
+
- lib/grid_generator/dino_cube/grid.rb
|
65
|
+
- lib/grid_generator/dino_cube/left_element_factory.rb
|
66
|
+
- lib/grid_generator/dino_cube/left_grid.rb
|
67
|
+
- lib/grid_generator/dino_cube/right_element_factory.rb
|
68
|
+
- lib/grid_generator/dino_cube/right_grid.rb
|
69
|
+
- lib/grid_generator/dino_cube/top_element_factory.rb
|
70
|
+
- lib/grid_generator/dino_cube/top_grid.rb
|
63
71
|
- lib/grid_generator/face_parser.rb
|
64
72
|
- lib/grid_generator/helper.rb
|
65
73
|
- lib/grid_generator/megaminx/face_element_factory.rb
|