grid_generator 0.2.9 → 0.2.10

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: c33e9c431f4c4150d7c1c5290b62fe5affad86f9bc8bff8270af5ba6afcb0be0
4
- data.tar.gz: 612becd6432cb6009d7d23aecd834a7b4d7cd0f5bca2623a81ac31bda0d83885
3
+ metadata.gz: 9d34bf3e232b6ba728e1dfb968dc9f176932955a8ef93d9b796c5233f6ed495d
4
+ data.tar.gz: f135d7666604b09947e3be7465bdeb4831b8d1b0d49aca20ee4d17346fa53e61
5
5
  SHA512:
6
- metadata.gz: bc79e92443cc6d6eb1d7215ea519fdfeb93d12f7532b061e2d5f3fb3ca605d7961546d3e02a8687cbcb1a538036b54ecb42a133875b5a849df38f2f6ff203bc3
7
- data.tar.gz: cc9b3660c6b3cb0a8043ecae38fcc91982989eddb09a664cb56ae0b980e327444929412bc239acc26d326c6ed2668acc8d69f97ed01589521418da4bb75fce92
6
+ metadata.gz: 12f2aea851e3975e67ba4ed59451f6810f1f6c9b7cecee1cac673139b1fb3c76ae2b70b8bb0b37d9bee41fd198674308536c1ae74aa657a3de9f1055c1cec034
7
+ data.tar.gz: dd555ce643c53dda16d03d49e6373f140cbedd6fcaccbf2a53447b72a68c781d144b6b78d4be362d7e830ce539b4b44d9a27d19b530a958f9af8f2f2d6287ec8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.2.9)
4
+ grid_generator (0.2.10)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -1,3 +1,5 @@
1
+ require 'matrix'
2
+ require_relative '../line'
1
3
  require_relative '../face_parser'
2
4
  require_relative 'facing_square_factory'
3
5
 
@@ -73,23 +75,33 @@ module GridGenerator
73
75
 
74
76
  def rows
75
77
  Array.new(height) do |i|
76
- GridGenerator::BaseLine.new(
77
- x1: x,
78
- y1: unit_y(i+1),
79
- x2: max_x,
80
- y2: unit_y(i+1)
81
- )
78
+ a = Matrix.column_vector([
79
+ x,
80
+ unit_y(i+1),
81
+ ])
82
+
83
+ b = Matrix.column_vector([
84
+ max_x,
85
+ unit_y(i+1)
86
+ ])
87
+
88
+ GridGenerator::Line.new(a: a, b: b)
82
89
  end
83
90
  end
84
91
 
85
92
  def columns
86
93
  Array.new(width) do |i|
87
- GridGenerator::BaseLine.new(
88
- x1: unit_x(i+1),
89
- y1: y,
90
- x2: unit_x(i+1),
91
- y2: max_y
92
- )
94
+ a = Matrix.column_vector([
95
+ unit_x(i+1),
96
+ y,
97
+ ])
98
+
99
+ b = Matrix.column_vector([
100
+ unit_x(i+1),
101
+ max_y
102
+ ])
103
+
104
+ GridGenerator::Line.new(a: a, b: b)
93
105
  end
94
106
  end
95
107
 
@@ -1,5 +1,6 @@
1
+ require 'matrix'
1
2
  require_relative '../face_parser'
2
- require_relative '../base_line'
3
+ require_relative '../line'
3
4
  require_relative 'facing_square_factory'
4
5
 
5
6
  module GridGenerator
@@ -54,23 +55,33 @@ module GridGenerator
54
55
 
55
56
  def rows
56
57
  Array.new(height) do |i|
57
- GridGenerator::BaseLine.new(
58
- x1: x,
59
- y1: unit_y(i+1),
60
- x2: max_x,
61
- y2: unit_y(i+1)
62
- )
58
+ a = Matrix.column_vector([
59
+ x,
60
+ unit_y(i+1),
61
+ ])
62
+
63
+ b = Matrix.column_vector([
64
+ max_x,
65
+ unit_y(i+1)
66
+ ])
67
+
68
+ GridGenerator::Line.new(a: a, b: b)
63
69
  end
64
70
  end
65
71
 
66
72
  def columns
67
73
  Array.new(width) do |i|
68
- GridGenerator::BaseLine.new(
69
- x1: unit_x(i+1),
70
- y1: y,
71
- x2: unit_x(i+1),
72
- y2: max_y
73
- )
74
+ a = Matrix.column_vector([
75
+ unit_x(i+1),
76
+ y,
77
+ ])
78
+
79
+ b = Matrix.column_vector([
80
+ unit_x(i+1),
81
+ max_y
82
+ ])
83
+
84
+ GridGenerator::Line.new(a: a, b: b)
74
85
  end
75
86
  end
76
87
 
@@ -1,5 +1,5 @@
1
1
  require 'matrix'
2
- require_relative '../base_line'
2
+ require_relative '../line'
3
3
 
4
4
  module GridGenerator
5
5
  module Cubic
@@ -93,23 +93,33 @@ module GridGenerator
93
93
 
94
94
  def rows
95
95
  Array.new(height) do |i|
96
- GridGenerator::BaseLine.new(
97
- x1: row_line_start(i+1)[0,0],
98
- y1: row_line_start(i+1)[1,0],
99
- x2: row_line_end(i+1)[0,0],
100
- y2: row_line_end(i+1)[1,0]
101
- )
96
+ a = Matrix.column_vector([
97
+ row_line_start(i+1)[0,0],
98
+ row_line_start(i+1)[1,0],
99
+ ])
100
+
101
+ b = Matrix.column_vector([
102
+ row_line_end(i+1)[0,0],
103
+ row_line_end(i+1)[1,0]
104
+ ])
105
+
106
+ GridGenerator::Line.new(a: a, b: b)
102
107
  end
103
108
  end
104
109
 
105
110
  def columns
106
111
  Array.new(width) do |i|
107
- GridGenerator::BaseLine.new(
108
- x1: column_line_start(i+1)[0,0],
109
- y1: column_line_start(i+1)[1,0],
110
- x2: column_line_end(i+1)[0,0],
111
- y2: column_line_end(i+1)[1,0]
112
- )
112
+ a = Matrix.column_vector([
113
+ column_line_start(i+1)[0,0],
114
+ column_line_start(i+1)[1,0],
115
+ ])
116
+
117
+ b = Matrix.column_vector([
118
+ column_line_end(i+1)[0,0],
119
+ column_line_end(i+1)[1,0]
120
+ ])
121
+
122
+ GridGenerator::Line.new(a: a, b: b)
113
123
  end
114
124
  end
115
125
 
@@ -0,0 +1,32 @@
1
+ module GridGenerator
2
+ class Line
3
+ def initialize(a:, b:)
4
+ @a, @b = a, b
5
+ end
6
+
7
+ attr_reader :a, :b
8
+
9
+ def ==(other)
10
+ self.class == other.class &&
11
+ self.a == other.a &&
12
+ self.b == other.b
13
+ end
14
+
15
+ def x1
16
+ a[0,0]
17
+ end
18
+
19
+ def y1
20
+ a[1,0]
21
+ end
22
+
23
+ def x2
24
+ b[0,0]
25
+ end
26
+
27
+ def y2
28
+ b[1,0]
29
+ end
30
+ end
31
+ end
32
+
@@ -1,6 +1,7 @@
1
1
  require 'matrix'
2
2
  require_relative '../rotator'
3
3
  require_relative '../helper'
4
+ require_relative '../line'
4
5
 
5
6
  module GridGenerator
6
7
  module Megaminx
@@ -90,14 +91,9 @@ module GridGenerator
90
91
  def connecting_lines
91
92
  pentagon_points.each_with_index.map do |p, i|
92
93
  d = decagon_points[i*2]
93
- offset_p = p + offset
94
- offset_d = d + offset
95
- GridGenerator::BaseLine.new(
96
- x1: offset_p[0,0],
97
- y1: offset_p[1,0],
98
- x2: offset_d[0,0],
99
- y2: offset_d[1,0]
100
- )
94
+ line_start = p + offset
95
+ line_end = d + offset
96
+ GridGenerator::Line.new(a: line_start, b: line_end)
101
97
  end
102
98
  end
103
99
 
@@ -115,12 +111,7 @@ module GridGenerator
115
111
  line_start = ab_intervals.last + offset
116
112
  line_end = cd_intervals.first + offset
117
113
 
118
- GridGenerator::BaseLine.new(
119
- x1: line_start[0,0],
120
- y1: line_start[1,0],
121
- x2: line_end[0,0],
122
- y2: line_end[1,0]
123
- )
114
+ GridGenerator::Line.new(a: line_start, b: line_end)
124
115
  end
125
116
  end
126
117
 
@@ -138,12 +129,7 @@ module GridGenerator
138
129
  line_start = ab_intervals.last + offset
139
130
  line_end = cd_intervals.first + offset
140
131
 
141
- GridGenerator::BaseLine.new(
142
- x1: line_start[0,0],
143
- y1: line_start[1,0],
144
- x2: line_end[0,0],
145
- y2: line_end[1,0]
146
- )
132
+ GridGenerator::Line.new(a: line_start, b: line_end)
147
133
  end
148
134
  end
149
135
 
@@ -1,6 +1,7 @@
1
1
  require_relative 'triangle_factory'
2
2
  require_relative '../rotator'
3
3
  require_relative '../scaler'
4
+ require_relative '../line'
4
5
 
5
6
  module GridGenerator
6
7
  module Pyraminx
@@ -78,12 +79,7 @@ module GridGenerator
78
79
  transformed_1 = rotator.rotate(scaled_1) + offset
79
80
  transformed_2 = rotator.rotate(scaled_2) + offset
80
81
 
81
- GridGenerator::BaseLine.new(
82
- x1: transformed_1[0,0],
83
- y1: transformed_1[1,0],
84
- x2: transformed_2[0,0],
85
- y2: transformed_2[1,0]
86
- )
82
+ GridGenerator::Line.new(a: transformed_1, b: transformed_2)
87
83
  end
88
84
  end
89
85
 
@@ -112,12 +108,7 @@ module GridGenerator
112
108
  transformed_1 = rotator.rotate(scaled_1) + offset
113
109
  transformed_2 = rotator.rotate(scaled_2) + offset
114
110
 
115
- GridGenerator::BaseLine.new(
116
- x1: transformed_1[0,0],
117
- y1: transformed_1[1,0],
118
- x2: transformed_2[0,0],
119
- y2: transformed_2[1,0]
120
- )
111
+ GridGenerator::Line.new(a: transformed_1, b: transformed_2)
121
112
  end
122
113
  end
123
114
 
@@ -146,12 +137,7 @@ module GridGenerator
146
137
  transformed_1 = rotator.rotate(scaled_1) + offset
147
138
  transformed_2 = rotator.rotate(scaled_2) + offset
148
139
 
149
- GridGenerator::BaseLine.new(
150
- x1: transformed_1[0,0],
151
- y1: transformed_1[1,0],
152
- x2: transformed_2[0,0],
153
- y2: transformed_2[1,0]
154
- )
140
+ GridGenerator::Line.new(a: transformed_1, b: transformed_2)
155
141
  end
156
142
  end
157
143
 
@@ -1,4 +1,4 @@
1
- require_relative '../base_line'
1
+ require_relative '../line'
2
2
  require_relative 'skewb_grid'
3
3
  require_relative 'left_element_factory'
4
4
 
@@ -20,23 +20,33 @@ module GridGenerator
20
20
 
21
21
  def rows
22
22
  Array.new(side_size) do |i|
23
- GridGenerator::BaseLine.new(
24
- x1: x + (2*i)*units,
25
- y1: y + (3*i+2)*units,
26
- x2: x + (2*i+2)*units,
27
- y2: y + (3*i+1)*units
28
- )
23
+ a = Matrix.column_vector([
24
+ x + (2*i)*units,
25
+ y + (3*i+2)*units,
26
+ ])
27
+
28
+ b = Matrix.column_vector([
29
+ x + (2*i+2)*units,
30
+ y + (3*i+1)*units
31
+ ])
32
+
33
+ GridGenerator::Line.new(a: a, b: b)
29
34
  end
30
35
  end
31
36
 
32
37
  def columns
33
38
  Array.new(side_size) do |i|
34
- GridGenerator::BaseLine.new(
35
- x1: x + (2*i)*units,
36
- y1: y + (-1*i+2)*units,
37
- x2: x + (i+1)*2*units,
38
- y2: y + (-1*i+5)*units
39
- )
39
+ a = Matrix.column_vector([
40
+ x + (2*i)*units,
41
+ y + (-1*i+2)*units,
42
+ ])
43
+
44
+ b = Matrix.column_vector([
45
+ x + (i+1)*2*units,
46
+ y + (-1*i+5)*units
47
+ ])
48
+
49
+ GridGenerator::Line.new(a: a, b: b)
40
50
  end
41
51
  end
42
52
  end
@@ -1,3 +1,4 @@
1
+ require_relative '../line'
1
2
  require_relative '../base_element'
2
3
  require_relative 'skewb_grid.rb'
3
4
  require_relative 'right_element_factory.rb'
@@ -20,23 +21,33 @@ module GridGenerator
20
21
 
21
22
  def rows
22
23
  Array.new(side_size) do |i|
23
- GridGenerator::BaseLine.new(
24
- x1: x + (2*i)*units,
25
- y1: y + (i+4)*units,
26
- x2: x + (2*i+2)*units,
27
- y2: y + (i+1)*units
28
- )
24
+ a = Matrix.column_vector([
25
+ x + (2*i)*units,
26
+ y + (i+4)*units,
27
+ ])
28
+
29
+ b = Matrix.column_vector([
30
+ x + (2*i+2)*units,
31
+ y + (i+1)*units
32
+ ])
33
+
34
+ GridGenerator::Line.new(a: a, b: b)
29
35
  end
30
36
  end
31
37
 
32
38
  def columns
33
39
  Array.new(side_size) do |i|
34
- GridGenerator::BaseLine.new(
35
- x1: x + (2*i)*units,
36
- y1: y + (-3*i+4)*units,
37
- x2: x + (i+1)*2*units,
38
- y2: y + (-3*i+5)*units
39
- )
40
+ a = Matrix.column_vector([
41
+ x + (2*i)*units,
42
+ y + (-3*i+4)*units,
43
+ ])
44
+
45
+ b = Matrix.column_vector([
46
+ x + (i+1)*2*units,
47
+ y + (-3*i+5)*units
48
+ ])
49
+
50
+ GridGenerator::Line.new(a: a, b: b)
40
51
  end
41
52
  end
42
53
  end
@@ -1,3 +1,4 @@
1
+ require_relative '../line'
1
2
  require_relative '../base_element'
2
3
  require_relative 'skewb_grid'
3
4
  require_relative 'top_element_factory'
@@ -20,23 +21,33 @@ module GridGenerator
20
21
 
21
22
  def rows
22
23
  Array.new(side_size) do |i|
23
- GridGenerator::BaseLine.new(
24
- x1: x + 2*units,
25
- y1: y + (2*i+1)*units,
26
- x2: x + 6*units,
27
- y2: y + (2*i+1)*units
28
- )
24
+ a = Matrix.column_vector([
25
+ x + 2*units,
26
+ y + (2*i+1)*units,
27
+ ])
28
+
29
+ b = Matrix.column_vector([
30
+ x + 6*units,
31
+ y + (2*i+1)*units
32
+ ])
33
+
34
+ GridGenerator::Line.new(a: a, b: b)
29
35
  end
30
36
  end
31
37
 
32
38
  def columns
33
39
  Array.new(side_size) do |i|
34
- GridGenerator::BaseLine.new(
35
- x1: x + (4*i+2)*units,
36
- y1: y + units,
37
- x2: x + (4*i+2)*units,
38
- y2: y + 3*units
39
- )
40
+ a = Matrix.column_vector([
41
+ x + (4*i+2)*units,
42
+ y + units,
43
+ ])
44
+
45
+ b = Matrix.column_vector([
46
+ x + (4*i+2)*units,
47
+ y + 3*units
48
+ ])
49
+
50
+ GridGenerator::Line.new(a: a, b: b)
40
51
  end
41
52
  end
42
53
  end
@@ -1,4 +1,4 @@
1
- require_relative '../base_line'
1
+ require_relative '../line'
2
2
  require_relative '../square_one_face_parser'
3
3
  require_relative 'element_factory'
4
4
 
@@ -42,21 +42,31 @@ module GridGenerator
42
42
  end
43
43
 
44
44
  def forward_axis
45
- GridGenerator::BaseLine.new(
46
- x1: x+half_face_size+half_edge_width,
47
- y1: y,
48
- x2: x+half_face_size-half_edge_width,
49
- y2: y+face_size
50
- )
45
+ a = Matrix.column_vector([
46
+ x+half_face_size+half_edge_width,
47
+ y,
48
+ ])
49
+
50
+ b = Matrix.column_vector([
51
+ x+half_face_size-half_edge_width,
52
+ y+face_size
53
+ ])
54
+
55
+ GridGenerator::Line.new(a: a, b: b)
51
56
  end
52
57
 
53
58
  def back_axis
54
- GridGenerator::BaseLine.new(
55
- x1: x+half_face_size-half_edge_width,
56
- y1: y,
57
- x2: x+half_face_size+half_edge_width,
58
- y2: y+face_size
59
- )
59
+ a = Matrix.column_vector([
60
+ x+half_face_size-half_edge_width,
61
+ y,
62
+ ])
63
+
64
+ b = Matrix.column_vector([
65
+ x+half_face_size+half_edge_width,
66
+ y+face_size
67
+ ])
68
+
69
+ GridGenerator::Line.new(a: a, b: b)
60
70
  end
61
71
 
62
72
  def element_shapes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.2.9"
4
+ VERSION = "0.2.10"
5
5
  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.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Humphreys
@@ -46,7 +46,6 @@ files:
46
46
  - lib/grid_generator/arrows/horizontal_arrow.rb
47
47
  - lib/grid_generator/arrows/vertical_arrow.rb
48
48
  - lib/grid_generator/base_element.rb
49
- - lib/grid_generator/base_line.rb
50
49
  - lib/grid_generator/cubic/bordered_grid.rb
51
50
  - lib/grid_generator/cubic/facing_grid.rb
52
51
  - lib/grid_generator/cubic/facing_square_factory.rb
@@ -59,6 +58,7 @@ files:
59
58
  - lib/grid_generator/cubic/units_factory.rb
60
59
  - lib/grid_generator/face_parser.rb
61
60
  - lib/grid_generator/helper.rb
61
+ - lib/grid_generator/line.rb
62
62
  - lib/grid_generator/megaminx/common.rb
63
63
  - lib/grid_generator/megaminx/element_factory.rb
64
64
  - lib/grid_generator/megaminx/face.rb
@@ -1,26 +0,0 @@
1
- module GridGenerator
2
- class BaseLine
3
- def initialize(x1:, y1:, x2:, y2:)
4
- @x1, @y1 = x1, y1
5
- @x2, @y2 = x2, y2
6
- end
7
-
8
- attr_reader :x1, :y1, :x2, :y2
9
-
10
- def ==(other)
11
- self.x1 == other.x1 &&
12
- self.y1 == other.y1 &&
13
- self.x2 == other.x2 &&
14
- self.y2 == other.y2
15
- end
16
-
17
- def as_json
18
- {
19
- "x1" => x1,
20
- "y1" => y1,
21
- "x2" => x2,
22
- "y2" => y2
23
- }
24
- end
25
- end
26
- end