grid_generator 0.5.1 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31583359c1ea7dce72378e20739d6c6bb267b5b2c5db7fdde794c54be81744ef
4
- data.tar.gz: a0a0c371171902cb6e4524f711c322ab07b427b2e31b819778d8e6900786c6a0
3
+ metadata.gz: 11c0a7be05f3d64ebbf4a9280d08523a43ba8fb1e0591a865a8cc7cfdd9cd017
4
+ data.tar.gz: 6312025ad36904f7ad8ffe078d74a1ea08dca518f1082ed7711b51fdf052972f
5
5
  SHA512:
6
- metadata.gz: 4fd90a1c4c847d9f5f9c914dd01a1060e0597dd2c0f6fb61ea305925de6c9a28b67703a40f7975c032a10b9f2af29fb5ecb0708cd2eaefbd7cc94f8ffe71b12f
7
- data.tar.gz: 0ed77d4f77bfe5944b3f14e65dd717c50fc8d366838dadebcc285f794b0f196a57e3d8693af9c7a41f57ea0c255204d50105f8bec39e364563f2706f9a1633f9
6
+ metadata.gz: 6397a82b5bb9a173b95ca5ba30ecdfdaf5d5573b70a82e51694019fc59e54bab5d2d02fed4da30f64ea9e20d03f0a46ee666ac6f5f1da370d953790f0b1c596b
7
+ data.tar.gz: f0f1a7576c2e202e80a7e0979ba2ea919412261bc9cc79bda8374e77cc30a40d47a3cfbfa42dab359028d75b6398538ae5afc2f55bf2f00efa9a7a7c6377b3db
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.5.1)
4
+ grid_generator (0.5.3)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -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 [1, 1] # right
35
+ [
36
+ anchors[:top_right_corner],
37
+ anchors[:bottom_right_corner],
38
+ anchors[:center]
39
+ ]
40
+ when [2, 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,13 @@
1
+ require_relative '../face_parser'
2
+ require_relative './grid'
3
+ require_relative './left_element_factory'
4
+
5
+ module GridGenerator
6
+ module DinoCube
7
+ class LeftGrid < Grid
8
+ def element_factory_class
9
+ LeftElementFactory
10
+ end
11
+ end
12
+ end
13
+ 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,13 @@
1
+ require_relative '../face_parser'
2
+ require_relative './grid'
3
+ require_relative './right_element_factory'
4
+
5
+ module GridGenerator
6
+ module DinoCube
7
+ class RightGrid < Grid
8
+ def element_factory_class
9
+ RightElementFactory
10
+ end
11
+ end
12
+ end
13
+ 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
@@ -0,0 +1,13 @@
1
+ require_relative '../face_parser'
2
+ require_relative './grid'
3
+ require_relative './top_element_factory'
4
+
5
+ module GridGenerator
6
+ module DinoCube
7
+ class TopGrid < Grid
8
+ def element_factory_class
9
+ TopElementFactory
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.3"
5
5
  end
@@ -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.1
4
+ version: 0.5.3
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