grid_generator 0.3.2 → 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: bac6da73c0f3f0fae6985d7c6e9b2f91f75ff82faaaf6d4a5299af71e0980e3c
4
- data.tar.gz: 53848371057b7cbb7743049bc992cdee7eb17fed5e26412fb3efe101710cf688
3
+ metadata.gz: b10fb3da899b2d8a0b24adfd979503d79cb3e0fab6e3d789e9e2b7ca19bad30b
4
+ data.tar.gz: 1341aeb6ba35080f70011eee8433c8d49176688677a113d22fe4edb75cc07e03
5
5
  SHA512:
6
- metadata.gz: b75fad2b601e6b0b027961e53b0562bd5a916309c12dd161a7471e1805746bf694e9908d3433c3e00bddef4e5e7fb1ad190c2d8063ac88ffa061a8641325d45a
7
- data.tar.gz: 0d4ee932026ea66b66ef3121bdf422bc56f1003c2acb4f4e461014eb20b80b1114c106965d0565a202dd767c9ca3eaf922909f1e0fc24ccd0220bb953afd8b88
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.2)
4
+ grid_generator (0.4.0)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  module GridGenerator
2
- class Line
2
+ class BaseLine
3
3
  COLOURS = {
4
4
  fill: "#d0d0d0",
5
5
  stroke: "#404040"
@@ -1,7 +1,7 @@
1
1
  require 'matrix'
2
2
  require_relative '../svg/polygon'
3
3
  require_relative '../svg/style'
4
- require_relative '../line'
4
+ require_relative '../base_line'
5
5
  require_relative '../face_parser'
6
6
  require_relative 'facing_square_factory'
7
7
 
@@ -92,7 +92,7 @@ module GridGenerator
92
92
  unit_y(i+1)
93
93
  ])
94
94
 
95
- GridGenerator::Line.new(a: a, b: b)
95
+ GridGenerator::BaseLine.new(a: a, b: b)
96
96
  end
97
97
  end
98
98
 
@@ -108,7 +108,7 @@ module GridGenerator
108
108
  max_y
109
109
  ])
110
110
 
111
- GridGenerator::Line.new(a: a, b: b)
111
+ GridGenerator::BaseLine.new(a: a, b: b)
112
112
  end
113
113
  end
114
114
 
@@ -2,7 +2,7 @@ require 'matrix'
2
2
  require_relative '../svg/polygon'
3
3
  require_relative '../svg/style'
4
4
  require_relative '../face_parser'
5
- require_relative '../line'
5
+ require_relative '../base_line'
6
6
  require_relative 'facing_square_factory'
7
7
 
8
8
  module GridGenerator
@@ -72,7 +72,7 @@ module GridGenerator
72
72
  unit_y(i+1)
73
73
  ])
74
74
 
75
- GridGenerator::Line.new(a: a, b: b)
75
+ GridGenerator::BaseLine.new(a: a, b: b)
76
76
  end
77
77
  end
78
78
 
@@ -88,7 +88,7 @@ module GridGenerator
88
88
  max_y
89
89
  ])
90
90
 
91
- GridGenerator::Line.new(a: a, b: b)
91
+ GridGenerator::BaseLine.new(a: a, b: b)
92
92
  end
93
93
  end
94
94
 
@@ -1,5 +1,5 @@
1
1
  require 'matrix'
2
- require_relative '../line'
2
+ require_relative '../base_line'
3
3
 
4
4
  module GridGenerator
5
5
  module Cubic
@@ -108,7 +108,7 @@ module GridGenerator
108
108
  row_line_end(i+1)[1,0]
109
109
  ])
110
110
 
111
- GridGenerator::Line.new(a: a, b: b)
111
+ GridGenerator::BaseLine.new(a: a, b: b)
112
112
  end
113
113
  end
114
114
 
@@ -124,7 +124,7 @@ module GridGenerator
124
124
  column_line_end(i+1)[1,0]
125
125
  ])
126
126
 
127
- GridGenerator::Line.new(a: a, b: b)
127
+ GridGenerator::BaseLine.new(a: a, b: b)
128
128
  end
129
129
  end
130
130
 
@@ -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
@@ -3,7 +3,7 @@ require_relative '../svg/polygon'
3
3
  require_relative '../svg/style'
4
4
  require_relative '../rotator'
5
5
  require_relative '../helper'
6
- require_relative '../line'
6
+ require_relative '../base_line'
7
7
  require_relative 'face_element_factory'
8
8
 
9
9
  module GridGenerator
@@ -120,7 +120,7 @@ module GridGenerator
120
120
  ab_intervals = GridGenerator::Helper.intervals(a,b,2)
121
121
  cd_intervals = GridGenerator::Helper.intervals(c,d,2)
122
122
 
123
- GridGenerator::Line.new(a: ab_intervals[-1], b: cd_intervals[0])
123
+ GridGenerator::BaseLine.new(a: ab_intervals[-1], b: cd_intervals[0])
124
124
  end
125
125
  end
126
126
 
@@ -134,7 +134,7 @@ module GridGenerator
134
134
  ab_intervals = GridGenerator::Helper.intervals(a,b,2)
135
135
  cd_intervals = GridGenerator::Helper.intervals(c,d,2)
136
136
 
137
- GridGenerator::Line.new(a: ab_intervals[-1], b: cd_intervals[0])
137
+ GridGenerator::BaseLine.new(a: ab_intervals[-1], b: cd_intervals[0])
138
138
  end
139
139
  end
140
140
 
@@ -164,7 +164,7 @@ module GridGenerator
164
164
  def connecting_lines
165
165
  pentagon_points.each_with_index.map do |p, i|
166
166
  d = decagon_points[i*2]
167
- offset_rotator.rotate(GridGenerator::Line.new(a: p, b: d)) + offset
167
+ offset_rotator.rotate(GridGenerator::BaseLine.new(a: p, b: d)) + offset
168
168
  end
169
169
  end
170
170
 
@@ -2,7 +2,7 @@ require_relative '../svg/polygon'
2
2
  require_relative '../svg/style'
3
3
  require_relative '../rotator'
4
4
  require_relative '../scaler'
5
- require_relative '../line'
5
+ require_relative '../base_line'
6
6
  require_relative 'triangle_factory'
7
7
 
8
8
  module GridGenerator
@@ -86,7 +86,7 @@ module GridGenerator
86
86
  transformed_1 = rotator.rotate(scaled_1) + offset
87
87
  transformed_2 = rotator.rotate(scaled_2) + offset
88
88
 
89
- GridGenerator::Line.new(a: transformed_1, b: transformed_2)
89
+ GridGenerator::BaseLine.new(a: transformed_1, b: transformed_2)
90
90
  end
91
91
  end
92
92
 
@@ -115,7 +115,7 @@ module GridGenerator
115
115
  transformed_1 = rotator.rotate(scaled_1) + offset
116
116
  transformed_2 = rotator.rotate(scaled_2) + offset
117
117
 
118
- GridGenerator::Line.new(a: transformed_1, b: transformed_2)
118
+ GridGenerator::BaseLine.new(a: transformed_1, b: transformed_2)
119
119
  end
120
120
  end
121
121
 
@@ -144,7 +144,7 @@ module GridGenerator
144
144
  transformed_1 = rotator.rotate(scaled_1) + offset
145
145
  transformed_2 = rotator.rotate(scaled_2) + offset
146
146
 
147
- GridGenerator::Line.new(a: transformed_1, b: transformed_2)
147
+ GridGenerator::BaseLine.new(a: transformed_1, b: transformed_2)
148
148
  end
149
149
  end
150
150
 
@@ -17,12 +17,12 @@ module GridGenerator
17
17
  case obj
18
18
  when Matrix
19
19
  (matrix * (obj - rotation_point)) + rotation_point
20
- when GridGenerator::Line
20
+ when GridGenerator::BaseLine
21
21
  new_a = rotate(obj.a)
22
22
  new_b = rotate(obj.b)
23
- GridGenerator::Line.new(a: new_a, b: new_b)
23
+ GridGenerator::BaseLine.new(a: new_a, b: new_b)
24
24
  else
25
- raise ArgumentError, "Object must be Matrix or Line"
25
+ raise ArgumentError, "Object must be Matrix or BaseLine"
26
26
  end
27
27
  end
28
28
  end
@@ -1,4 +1,4 @@
1
- require_relative '../line'
1
+ require_relative '../base_line'
2
2
  require_relative 'skewb_grid'
3
3
  require_relative 'left_element_factory'
4
4
 
@@ -30,7 +30,7 @@ module GridGenerator
30
30
  y + (3*i+1)*units
31
31
  ])
32
32
 
33
- GridGenerator::Line.new(a: a, b: b)
33
+ GridGenerator::BaseLine.new(a: a, b: b)
34
34
  end
35
35
  end
36
36
 
@@ -46,7 +46,7 @@ module GridGenerator
46
46
  y + (-1*i+5)*units
47
47
  ])
48
48
 
49
- GridGenerator::Line.new(a: a, b: b)
49
+ GridGenerator::BaseLine.new(a: a, b: b)
50
50
  end
51
51
  end
52
52
  end
@@ -1,4 +1,4 @@
1
- require_relative '../line'
1
+ require_relative '../base_line'
2
2
  require_relative '../base_element'
3
3
  require_relative 'skewb_grid.rb'
4
4
  require_relative 'right_element_factory.rb'
@@ -31,7 +31,7 @@ module GridGenerator
31
31
  y + (i+1)*units
32
32
  ])
33
33
 
34
- GridGenerator::Line.new(a: a, b: b)
34
+ GridGenerator::BaseLine.new(a: a, b: b)
35
35
  end
36
36
  end
37
37
 
@@ -47,7 +47,7 @@ module GridGenerator
47
47
  y + (-3*i+5)*units
48
48
  ])
49
49
 
50
- GridGenerator::Line.new(a: a, b: b)
50
+ GridGenerator::BaseLine.new(a: a, b: b)
51
51
  end
52
52
  end
53
53
  end
@@ -1,4 +1,4 @@
1
- require_relative '../line'
1
+ require_relative '../base_line'
2
2
  require_relative '../base_element'
3
3
  require_relative 'skewb_grid'
4
4
  require_relative 'top_element_factory'
@@ -31,7 +31,7 @@ module GridGenerator
31
31
  y + (2*i+1)*units
32
32
  ])
33
33
 
34
- GridGenerator::Line.new(a: a, b: b)
34
+ GridGenerator::BaseLine.new(a: a, b: b)
35
35
  end
36
36
  end
37
37
 
@@ -47,7 +47,7 @@ module GridGenerator
47
47
  y + 3*units
48
48
  ])
49
49
 
50
- GridGenerator::Line.new(a: a, b: b)
50
+ GridGenerator::BaseLine.new(a: a, b: b)
51
51
  end
52
52
  end
53
53
  end
@@ -1,4 +1,4 @@
1
- require_relative '../line'
1
+ require_relative '../base_line'
2
2
  require_relative '../square_one_face_parser'
3
3
  require_relative 'element_factory'
4
4
 
@@ -57,7 +57,7 @@ module GridGenerator
57
57
  y+face_size
58
58
  ])
59
59
 
60
- GridGenerator::Line.new(a: a, b: b)
60
+ GridGenerator::BaseLine.new(a: a, b: b)
61
61
  end
62
62
 
63
63
  def back_axis
@@ -71,7 +71,7 @@ module GridGenerator
71
71
  y+face_size
72
72
  ])
73
73
 
74
- GridGenerator::Line.new(a: a, b: b)
74
+ GridGenerator::BaseLine.new(a: a, b: b)
75
75
  end
76
76
 
77
77
  def element_shapes
@@ -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.2"
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.2
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
@@ -41,6 +41,7 @@ files:
41
41
  - grid_generator.gemspec
42
42
  - lib/grid_generator.rb
43
43
  - lib/grid_generator/base_element.rb
44
+ - lib/grid_generator/base_line.rb
44
45
  - lib/grid_generator/cubic/bordered_grid.rb
45
46
  - lib/grid_generator/cubic/facing_grid.rb
46
47
  - lib/grid_generator/cubic/facing_square_factory.rb
@@ -51,9 +52,10 @@ files:
51
52
  - lib/grid_generator/cubic/square_factory.rb
52
53
  - lib/grid_generator/cubic/top_grid.rb
53
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
54
57
  - lib/grid_generator/face_parser.rb
55
58
  - lib/grid_generator/helper.rb
56
- - lib/grid_generator/line.rb
57
59
  - lib/grid_generator/megaminx/face_element_factory.rb
58
60
  - lib/grid_generator/megaminx/face_projection.rb
59
61
  - lib/grid_generator/pyraminx/face.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