grid_generator 0.3.3 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22222fe473957054950f616c6000c02a60064192425785a6b59495733f89e8e7
4
- data.tar.gz: 940e4285e164e679d52a7f40afb6fc01d774505450b1a38e285baff76cc0cb02
3
+ metadata.gz: b10fb3da899b2d8a0b24adfd979503d79cb3e0fab6e3d789e9e2b7ca19bad30b
4
+ data.tar.gz: 1341aeb6ba35080f70011eee8433c8d49176688677a113d22fe4edb75cc07e03
5
5
  SHA512:
6
- metadata.gz: 222aa50cb0c31e3c80283758011b49dde53b442348d5e833dab5cb0b400f386e11814b91a538f009c6fab9331099cd7ae0f3e631fc3c80ff6b7b33fc811068dc
7
- data.tar.gz: cd2c7f75557ef04436dfa83327a3282fd1fcb5ebc65526c01d01a52f6af9f3fa35181699485f110ad5fe2ed289e184a862862d719772abaff4ba109f5f84072f
6
+ metadata.gz: fd32eb362a453be9e33a5d56dda8a2ea21131decb0366f8e0ebd72bd4cf414b77457186289e37952fbb69dd433ac3980d470ccb3f08be843862a98fb422d18f8
7
+ data.tar.gz: 5d8a1e79cc4a5675927fcf634ebfd22e9f8429a5f77f6a527b202227dd7105886ed7822dc7cd5c7ef708f68152557555325e9301c84b974a8575892e6d45fe1b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.3.3)
4
+ grid_generator (0.4.0)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -0,0 +1,169 @@
1
+ require_relative '../svg/style'
2
+ require_relative '../svg/path'
3
+ require_relative '../svg/move_command'
4
+ require_relative '../svg/line_command'
5
+ require_relative '../svg/quadratic_command'
6
+ require_relative '../svg/close_command'
7
+
8
+ module GridGenerator
9
+ module CurvyCopter
10
+ class TopElementFactory
11
+ def initialize(grid_x:, grid_y:, row_num:, col_num:, units:, colour:, opacity:)
12
+ @grid_x, @grid_y = grid_x, grid_y
13
+ @row_num, @col_num = row_num, col_num
14
+ @units = units
15
+ @colour, @opacity = colour, opacity
16
+ end
17
+
18
+ attr_reader :grid_x, :grid_y, :row_num, :col_num, :units, :colour, :opacity
19
+
20
+ def offset
21
+ Matrix.column_vector([grid_x, grid_y])
22
+ end
23
+
24
+ def anchors
25
+ @anchors ||= {
26
+ top_left_corner: Matrix.column_vector([3*units, 0]),
27
+ top_right_corner: Matrix.column_vector([6*units, 1.5*units]),
28
+ bottom_left_corner: Matrix.column_vector([0, 1.5*units]),
29
+ bottom_right_corner: Matrix.column_vector([3*units, 3*units]),
30
+
31
+ top_edge_left: Matrix.column_vector([4*units, 0.5*units]),
32
+ top_edge_right: Matrix.column_vector([5*units, units]),
33
+ right_edge_top: Matrix.column_vector([5*units, 2*units]),
34
+ right_edge_bottom: Matrix.column_vector([4*units, 2.5*units]),
35
+ bottom_edge_left: Matrix.column_vector([units, 2*units]),
36
+ bottom_edge_right: Matrix.column_vector([2*units, 2.5*units]),
37
+ left_edge_top: Matrix.column_vector([2*units, 0.5*units]),
38
+ left_edge_bottom: Matrix.column_vector([units, units]),
39
+
40
+ center: Matrix.column_vector([3*units, 1.5*units]),
41
+
42
+ top_edge_center: Matrix.column_vector([3.75*units, 1.125*units]),
43
+ right_edge_center: Matrix.column_vector([3.75*units, 1.875*units]),
44
+ bottom_edge_center: Matrix.column_vector([2.25*units, 1.875*units]),
45
+ left_edge_center: Matrix.column_vector([2.25*units, 1.125*units]),
46
+
47
+ top_left_corner_center: Matrix.column_vector([3*units, 0.75*units]),
48
+ top_right_corner_center: Matrix.column_vector([4.5*units, 1.5*units]),
49
+ bottom_left_corner_center: Matrix.column_vector([1.5*units, 1.5*units]),
50
+ bottom_right_corner_center: Matrix.column_vector([3*units, 2.25*units])
51
+ }
52
+ end
53
+
54
+ def commands
55
+ case [row_num, col_num]
56
+ when [0, 0] # Top Left Corner
57
+ [
58
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_left_corner]]),
59
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:top_edge_left]]),
60
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_left_corner_center], anchors[:left_edge_top]]),
61
+ GridGenerator::Svg::CloseCommand.new
62
+ ]
63
+ when [0, 1] # Top Middle Edge
64
+ [
65
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_edge_left]]),
66
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:top_edge_right]]),
67
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_edge_center], anchors[:center]]),
68
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_edge_center], anchors[:top_edge_left]]),
69
+ GridGenerator::Svg::CloseCommand.new
70
+ ]
71
+ when [0, 2] # Top Right Corner
72
+ [
73
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_edge_right]]),
74
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:top_right_corner]]),
75
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:right_edge_top]]),
76
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_right_corner_center], anchors[:top_edge_right]]),
77
+ GridGenerator::Svg::CloseCommand.new
78
+ ]
79
+ when [1, 0] # Top Left Middle
80
+ [
81
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_edge_left]]),
82
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_edge_center], anchors[:center]]),
83
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:left_edge_center], anchors[:left_edge_top]]),
84
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_left_corner_center], anchors[:top_edge_left]]),
85
+ GridGenerator::Svg::CloseCommand.new
86
+ ]
87
+ when [1, 1] # Top Right Middle
88
+ [
89
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_edge_right]]),
90
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_right_corner_center], anchors[:right_edge_top]]),
91
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:right_edge_center], anchors[:center]]),
92
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_edge_center], anchors[:top_edge_right]]),
93
+ GridGenerator::Svg::CloseCommand.new
94
+ ]
95
+ when [2, 0] # Middle Left Edge
96
+ [
97
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:left_edge_top]]),
98
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:left_edge_center], anchors[:center]]),
99
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:left_edge_center], anchors[:left_edge_bottom]]),
100
+ GridGenerator::Svg::CloseCommand.new
101
+ ]
102
+ when [2, 1] # Middle Right Edge
103
+ [
104
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:right_edge_top]]),
105
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:right_edge_bottom]]),
106
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:right_edge_center], anchors[:center]]),
107
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:right_edge_center], anchors[:right_edge_top]]),
108
+ GridGenerator::Svg::CloseCommand.new
109
+ ]
110
+ when [3, 0] # Bottom Left Middle
111
+ [
112
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:left_edge_bottom]]),
113
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:left_edge_center], anchors[:center]]),
114
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_edge_center], anchors[:bottom_edge_left]]),
115
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_left_corner_center], anchors[:left_edge_bottom]]),
116
+ GridGenerator::Svg::CloseCommand.new
117
+ ]
118
+ when [3, 1] # Bottom Right Middle
119
+ [
120
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:center]]),
121
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:right_edge_center], anchors[:right_edge_bottom]]),
122
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_right_corner_center], anchors[:bottom_edge_right]]),
123
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_edge_center], anchors[:center]]),
124
+ GridGenerator::Svg::CloseCommand.new
125
+ ]
126
+ when [4, 0] # Bottom Left Corner
127
+ [
128
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:left_edge_bottom]]),
129
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_left_corner_center], anchors[:bottom_edge_left]]),
130
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_left_corner]]),
131
+ GridGenerator::Svg::CloseCommand.new
132
+ ]
133
+ when [4, 1] # Bottom Middle Edge
134
+ [
135
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:center]]),
136
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_edge_center], anchors[:bottom_edge_right]]),
137
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_edge_left]]),
138
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_edge_center], anchors[:center]]),
139
+ GridGenerator::Svg::CloseCommand.new
140
+ ]
141
+ when [4, 2] # Bottom Right Corner
142
+ [
143
+ GridGenerator::Svg::MoveCommand.new(points: [anchors[:right_edge_bottom]]),
144
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_right_corner]]),
145
+ GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_edge_right]]),
146
+ GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_right_corner_center], anchors[:right_edge_bottom]]),
147
+ GridGenerator::Svg::CloseCommand.new
148
+ ]
149
+ else
150
+ []
151
+ end
152
+ end
153
+
154
+ def style
155
+ GridGenerator::Svg::Style.new(fill: colour, opacity: opacity)
156
+ end
157
+
158
+ def d
159
+ commands.map do |c|
160
+ (c + offset)
161
+ end
162
+ end
163
+
164
+ def build
165
+ GridGenerator::Svg::Path.new(d: d, style: style)
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../face_parser'
2
+ require_relative './top_element_factory'
3
+
4
+ module GridGenerator
5
+ module CurvyCopter
6
+ class TopGrid
7
+ def initialize(x:, y:, units: , elements: )
8
+ @x, @y = x, y
9
+ @units = units
10
+ @elements = case elements
11
+ when String
12
+ FaceParser.new(elements).parse
13
+ when Array
14
+ elements
15
+ else
16
+ raise ArgumentError, "elements must be array or string"
17
+ end
18
+ end
19
+
20
+ attr_reader :x, :y, :units, :elements
21
+
22
+ def to_svg
23
+ output = ''
24
+
25
+ element_shapes.each { |element| output += element.to_svg if element }
26
+
27
+ output
28
+ end
29
+
30
+ private
31
+
32
+ def build_element(row_num, col_num, data)
33
+ if data
34
+ TopElementFactory.new(
35
+ grid_x: x,
36
+ grid_y: y,
37
+ row_num: row_num,
38
+ col_num: col_num,
39
+ units: units,
40
+ colour: data[:colour],
41
+ opacity: data[:opacity]
42
+ ).build
43
+ else
44
+ nil
45
+ end
46
+ end
47
+
48
+ def element_shapes
49
+ elements.each_with_index.map do |row, row_num|
50
+ row.each_with_index.map do |col, col_num|
51
+ build_element(row_num, col_num, col)
52
+ end
53
+ end.flatten.compact
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ require_relative './path_command'
2
+
3
+ module GridGenerator
4
+ module Svg
5
+ class CloseCommand < GridGenerator::Svg::PathCommand
6
+ def type
7
+ 'Z'
8
+ end
9
+
10
+ def +(_offset)
11
+ self
12
+ end
13
+
14
+ def to_s
15
+ type
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,12 @@
1
+ require_relative './path_command'
2
+
3
+ module GridGenerator
4
+ module Svg
5
+ class LineCommand < GridGenerator::Svg::PathCommand
6
+ def type
7
+ 'L'
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ require_relative './path_command'
2
+
3
+ module GridGenerator
4
+ module Svg
5
+ class MoveCommand < GridGenerator::Svg::PathCommand
6
+ def type
7
+ 'M'
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,30 @@
1
+ module GridGenerator
2
+ module Svg
3
+ class Path
4
+ def initialize(d: , style:)
5
+ @d = case d
6
+ when String
7
+ d
8
+ when Array
9
+ d.map(&:to_s).join(' ')
10
+ else
11
+ raise ArgumentError, "d must be String or Array"
12
+ end
13
+ @style = case style
14
+ when GridGenerator::Svg::Style
15
+ style.to_s
16
+ when String
17
+ style
18
+ else
19
+ raise ArgumentError, "style must be String or Style"
20
+ end
21
+ end
22
+
23
+ attr_reader :d, :style
24
+
25
+ def to_svg
26
+ "<path d=\"#{d}\" style=\"#{style}\" />"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ module GridGenerator
2
+ module Svg
3
+ class PathCommand
4
+ def initialize(points: [])
5
+ @points = points
6
+ end
7
+
8
+ attr_reader :points
9
+
10
+ def type
11
+ 'M'
12
+ end
13
+
14
+ def +(offset)
15
+ if offset.class == Matrix
16
+ new_points = points.map { |p| p + offset }
17
+ self.class.new(points: new_points)
18
+ else
19
+ raise ArgumentError, "Offset must be Matrix"
20
+ end
21
+ end
22
+
23
+ def ==(other)
24
+ self.class == other.class && self.points == other.points
25
+ end
26
+
27
+ def to_s
28
+ [type, points_string].join(' ')
29
+ end
30
+
31
+ private
32
+
33
+ def points_string
34
+ points.map { |p| "#{p[0,0].round} #{p[1,0].round}" }.join(' ')
35
+ end
36
+ end
37
+ end
38
+ end
@@ -5,10 +5,19 @@ module GridGenerator
5
5
  @points = case points
6
6
  when Array
7
7
  points.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
8
- else
8
+ when String
9
9
  points
10
+ else
11
+ raise ArgumentError, "points must be Array or String"
10
12
  end
11
- @style = style
13
+ @style = case style
14
+ when GridGenerator::Svg::Style
15
+ style.to_s
16
+ when String
17
+ style
18
+ else
19
+ raise ArgumentError, "style must be String or Style"
20
+ end
12
21
  end
13
22
 
14
23
  attr_reader :points, :style
@@ -0,0 +1,12 @@
1
+ require_relative './path_command'
2
+
3
+ module GridGenerator
4
+ module Svg
5
+ class QuadraticCommand < GridGenerator::Svg::PathCommand
6
+ def type
7
+ 'Q'
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -1,7 +1,7 @@
1
1
  module GridGenerator
2
2
  module Svg
3
3
  class Style
4
- def initialize(fill: , stroke: , stroke_width: 1, opacity: 1)
4
+ def initialize(fill: , stroke: '#404040', stroke_width: 1, opacity: 1)
5
5
  @fill = fill
6
6
  @stroke = stroke
7
7
  @stroke_width = stroke_width
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.3.3"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -12,6 +12,7 @@ require_relative 'grid_generator/cubic/square_factory'
12
12
  require_relative 'grid_generator/skewb/top_skewb_grid'
13
13
  require_relative 'grid_generator/skewb/left_skewb_grid'
14
14
  require_relative 'grid_generator/skewb/right_skewb_grid'
15
+ require_relative 'grid_generator/curvy_copter/top_grid'
15
16
  require_relative 'grid_generator/square_one/face'
16
17
  require_relative 'grid_generator/pyraminx/face'
17
18
  require_relative 'grid_generator/megaminx/face_projection'
@@ -56,6 +57,10 @@ module GridGenerator
56
57
  Skewb::RightSkewbGrid.new(**args)
57
58
  end
58
59
 
60
+ def self.curvy_copter_top_grid(args)
61
+ CurvyCopter::TopGrid.new(**args)
62
+ end
63
+
59
64
  def self.square_one_face(args)
60
65
  SquareOne::Face.new(**args)
61
66
  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.3.3
4
+ version: 0.4.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-29 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix
@@ -52,6 +52,8 @@ files:
52
52
  - lib/grid_generator/cubic/square_factory.rb
53
53
  - lib/grid_generator/cubic/top_grid.rb
54
54
  - lib/grid_generator/cubic/units_factory.rb
55
+ - lib/grid_generator/curvy_copter/top_element_factory.rb
56
+ - lib/grid_generator/curvy_copter/top_grid.rb
55
57
  - lib/grid_generator/face_parser.rb
56
58
  - lib/grid_generator/helper.rb
57
59
  - lib/grid_generator/megaminx/face_element_factory.rb
@@ -70,7 +72,13 @@ files:
70
72
  - lib/grid_generator/square_one/element_factory.rb
71
73
  - lib/grid_generator/square_one/face.rb
72
74
  - lib/grid_generator/square_one_face_parser.rb
75
+ - lib/grid_generator/svg/close_command.rb
76
+ - lib/grid_generator/svg/line_command.rb
77
+ - lib/grid_generator/svg/move_command.rb
78
+ - lib/grid_generator/svg/path.rb
79
+ - lib/grid_generator/svg/path_command.rb
73
80
  - lib/grid_generator/svg/polygon.rb
81
+ - lib/grid_generator/svg/quadratic_command.rb
74
82
  - lib/grid_generator/svg/style.rb
75
83
  - lib/grid_generator/version.rb
76
84
  - sig/grid_generator.rbs