grid_generator 0.2.9 → 0.2.11

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: 4b4decfd16c0f0358a935123fed5fb0a190d2379d14a37b83e2f0c958d41a624
4
+ data.tar.gz: 50883416a3a299e9ea384b14777eef77d1767ffb22ff11b7449fb1d79f6c8bae
5
5
  SHA512:
6
- metadata.gz: bc79e92443cc6d6eb1d7215ea519fdfeb93d12f7532b061e2d5f3fb3ca605d7961546d3e02a8687cbcb1a538036b54ecb42a133875b5a849df38f2f6ff203bc3
7
- data.tar.gz: cc9b3660c6b3cb0a8043ecae38fcc91982989eddb09a664cb56ae0b980e327444929412bc239acc26d326c6ed2668acc8d69f97ed01589521418da4bb75fce92
6
+ metadata.gz: 4a35b02c742ec97e40f5b674232ab528b00fe7ee401ae47340b1bc0539e29cd3c75e2bfa31349dc9a66a3b6e51da3d59209f3aebbf1d06423b168aea0343e083
7
+ data.tar.gz: 12e781e8a1d8c0b125b4395a0bdf20b29636a632f2a4b288226f718a6ddac223756db2a06a078797f2dbaf0ec786673c126da1e4fdea780cb29acc6bd3f28f13
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.11)
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,42 @@
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 +(offset)
16
+ if offset.class == Matrix
17
+ new_a = a + offset
18
+ new_b = b + offset
19
+ self.class.new(a: new_a, b: new_b)
20
+ else
21
+ raise ArgumentError, "Offset must be Matrix"
22
+ end
23
+ end
24
+
25
+ def x1
26
+ a[0,0]
27
+ end
28
+
29
+ def y1
30
+ a[1,0]
31
+ end
32
+
33
+ def x2
34
+ b[0,0]
35
+ end
36
+
37
+ def y2
38
+ b[1,0]
39
+ end
40
+ end
41
+ end
42
+
@@ -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
@@ -86,23 +87,17 @@ module GridGenerator
86
87
  ]
87
88
  end
88
89
 
89
- # for svg
90
- def connecting_lines
91
- pentagon_points.each_with_index.map do |p, i|
92
- 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
- )
101
- end
90
+ def right_pentagon_points
91
+ @right_pentagon_points ||= [
92
+ decagon_points[2],
93
+ decagon_points[3],
94
+ decagon_points[4],
95
+ pentagon_points[2],
96
+ pentagon_points[1]
97
+ ]
102
98
  end
103
-
104
- # for svg
105
- def top_right_face_lines
99
+
100
+ def top_right_face_lines_raw
106
101
  (0..4).map do |i|
107
102
  a = top_right_pentagon_points[i]
108
103
  b = top_right_pentagon_points[(i+1)%5]
@@ -112,15 +107,29 @@ module GridGenerator
112
107
  ab_intervals = GridGenerator::Helper.intervals(a,b,2)
113
108
  cd_intervals = GridGenerator::Helper.intervals(c,d,2)
114
109
 
115
- line_start = ab_intervals.last + offset
116
- line_end = cd_intervals.first + offset
110
+ GridGenerator::Line.new(a: ab_intervals[-1], b: cd_intervals[0])
111
+ end
112
+ end
113
+
114
+ # for svg
115
+ def connecting_lines
116
+ pentagon_points.each_with_index.map do |p, i|
117
+ d = decagon_points[i*2]
118
+ GridGenerator::Line.new(a: p, b: d) + offset
119
+ end
120
+ end
117
121
 
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
- )
122
+ # for svg
123
+ def top_right_face_lines
124
+ top_right_face_lines_raw.map { |l| l + offset }
125
+ end
126
+
127
+ # for svg
128
+ def right_face_lines
129
+ angle = Math::PI * 0.4
130
+ rotator = GridGenerator::Rotator.new(angle: angle, rotation_point: rotation_point)
131
+ top_right_face_lines_raw.map do |l|
132
+ rotator.rotate(l) + offset
124
133
  end
125
134
  end
126
135
 
@@ -135,15 +144,7 @@ module GridGenerator
135
144
  ab_intervals = GridGenerator::Helper.intervals(a,b,2)
136
145
  cd_intervals = GridGenerator::Helper.intervals(c,d,2)
137
146
 
138
- line_start = ab_intervals.last + offset
139
- line_end = cd_intervals.first + offset
140
-
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
- )
147
+ GridGenerator::Line.new(a: ab_intervals[-1], b: cd_intervals[0]) + offset
147
148
  end
148
149
  end
149
150
 
@@ -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
 
@@ -11,9 +11,18 @@ module GridGenerator
11
11
 
12
12
  attr_reader :angle, :matrix, :rotation_point
13
13
 
14
- def rotate(point)
15
- # subtract rotation point to move point towards 0,0, rotate, then add to move back
16
- (matrix * (point - rotation_point)) + rotation_point
14
+ # subtract rotation point to move point towards 0,0, rotate, then add to move back
15
+ def rotate(obj)
16
+ case obj
17
+ when Matrix
18
+ (matrix * (obj - rotation_point)) + rotation_point
19
+ when GridGenerator::Line
20
+ new_a = rotate(obj.a)
21
+ new_b = rotate(obj.b)
22
+ GridGenerator::Line.new(a: new_a, b: new_b)
23
+ else
24
+ raise ArgumentError, "Object must be Matrix or Line"
25
+ end
17
26
  end
18
27
  end
19
28
  end
@@ -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.11"
5
5
  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.2.9
4
+ version: 0.2.11
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-04 00:00:00.000000000 Z
11
+ date: 2023-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix
@@ -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