grid_generator 0.2.8 → 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: daf88e31a5aeab774e0a22adfdb485d9441053359add36bf45e1ac6c21c20fb2
4
- data.tar.gz: bcfed0e6b1f2ace7ca279fd65e5c01882277bb8cfb32af358cae075c72c514e3
3
+ metadata.gz: 9d34bf3e232b6ba728e1dfb968dc9f176932955a8ef93d9b796c5233f6ed495d
4
+ data.tar.gz: f135d7666604b09947e3be7465bdeb4831b8d1b0d49aca20ee4d17346fa53e61
5
5
  SHA512:
6
- metadata.gz: 8fa0e5d1bb6c3113ec548e1d1e2740c5cc0a2e7d873c16b91e42dc49ede201e212a2b275c19fb9c7f8f514abbed40d1e3d82700d38a46b92073eafdd70ae025e
7
- data.tar.gz: 9976ffeff14005e007578b23159b248780c338c09d62e61caec0faa7aa578e84ac582e52d97a7bd5b7f10df879393b258840e256237354c007f6584a42117887
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.8)
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
@@ -76,21 +77,45 @@ module GridGenerator
76
77
  end
77
78
  end
78
79
 
80
+ def top_right_pentagon_points
81
+ @top_right_pentagon_points ||= [
82
+ decagon_points[0],
83
+ decagon_points[1],
84
+ decagon_points[2],
85
+ pentagon_points[1],
86
+ pentagon_points[0]
87
+ ]
88
+ end
89
+
79
90
  # for svg
80
91
  def connecting_lines
81
92
  pentagon_points.each_with_index.map do |p, i|
82
93
  d = decagon_points[i*2]
83
- offset_p = p + offset
84
- offset_d = d + offset
85
- GridGenerator::BaseLine.new(
86
- x1: offset_p[0,0],
87
- y1: offset_p[1,0],
88
- x2: offset_d[0,0],
89
- y2: offset_d[1,0]
90
- )
94
+ line_start = p + offset
95
+ line_end = d + offset
96
+ GridGenerator::Line.new(a: line_start, b: line_end)
97
+ end
98
+ end
99
+
100
+ # for svg
101
+ def top_right_face_lines
102
+ (0..4).map do |i|
103
+ a = top_right_pentagon_points[i]
104
+ b = top_right_pentagon_points[(i+1)%5]
105
+ c = top_right_pentagon_points[(i+2)%5]
106
+ d = top_right_pentagon_points[(i+3)%5]
107
+
108
+ ab_intervals = GridGenerator::Helper.intervals(a,b,2)
109
+ cd_intervals = GridGenerator::Helper.intervals(c,d,2)
110
+
111
+ line_start = ab_intervals.last + offset
112
+ line_end = cd_intervals.first + offset
113
+
114
+ GridGenerator::Line.new(a: line_start, b: line_end)
91
115
  end
92
116
  end
93
117
 
118
+ # for svg
94
119
  def front_face_lines
95
120
  (0..4).map do |i|
96
121
  a = pentagon_points[i]
@@ -104,12 +129,7 @@ module GridGenerator
104
129
  line_start = ab_intervals.last + offset
105
130
  line_end = cd_intervals.first + offset
106
131
 
107
- GridGenerator::BaseLine.new(
108
- x1: line_start[0,0],
109
- y1: line_start[1,0],
110
- x2: line_end[0,0],
111
- y2: line_end[1,0]
112
- )
132
+ GridGenerator::Line.new(a: line_start, b: line_end)
113
133
  end
114
134
  end
115
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.8"
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.8
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