grid_generator 0.2.10 → 0.2.12

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: 9d34bf3e232b6ba728e1dfb968dc9f176932955a8ef93d9b796c5233f6ed495d
4
- data.tar.gz: f135d7666604b09947e3be7465bdeb4831b8d1b0d49aca20ee4d17346fa53e61
3
+ metadata.gz: d2e4ae2eb50929918c9de39208ddf4eaccaafdc56c53dc13774d398aa70f52e3
4
+ data.tar.gz: 5a7c155861ff0725f985660ef3727d18e834a42f770c8e030f73c8c145e1e88c
5
5
  SHA512:
6
- metadata.gz: 12f2aea851e3975e67ba4ed59451f6810f1f6c9b7cecee1cac673139b1fb3c76ae2b70b8bb0b37d9bee41fd198674308536c1ae74aa657a3de9f1055c1cec034
7
- data.tar.gz: dd555ce643c53dda16d03d49e6373f140cbedd6fcaccbf2a53447b72a68c781d144b6b78d4be362d7e830ce539b4b44d9a27d19b530a958f9af8f2f2d6287ec8
6
+ metadata.gz: 4adbf1a09e9839148113816c35920bad39d61128bb20f9dac8a30b0af6e8953cab5103cd7e682ea050a6a6de61ae9fecfb501bc1172b662b8642a749e8758d6b
7
+ data.tar.gz: a096f60c701cb163b94c79034961cefc8b3f6f65554dbd7f530fe4723878eae1377a1b32891c51ee9fd719697a391106b5916a2b7904df6ad101ac4953b0e4b1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.2.10)
4
+ grid_generator (0.2.12)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -12,6 +12,16 @@ module GridGenerator
12
12
  self.b == other.b
13
13
  end
14
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
+
15
25
  def x1
16
26
  a[0,0]
17
27
  end
@@ -87,18 +87,17 @@ module GridGenerator
87
87
  ]
88
88
  end
89
89
 
90
- # for svg
91
- def connecting_lines
92
- pentagon_points.each_with_index.map do |p, i|
93
- d = decagon_points[i*2]
94
- line_start = p + offset
95
- line_end = d + offset
96
- GridGenerator::Line.new(a: line_start, b: line_end)
97
- 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
+ ]
98
98
  end
99
-
100
- # for svg
101
- def top_right_face_lines
99
+
100
+ def top_right_face_lines_raw
102
101
  (0..4).map do |i|
103
102
  a = top_right_pentagon_points[i]
104
103
  b = top_right_pentagon_points[(i+1)%5]
@@ -108,13 +107,47 @@ module GridGenerator
108
107
  ab_intervals = GridGenerator::Helper.intervals(a,b,2)
109
108
  cd_intervals = GridGenerator::Helper.intervals(c,d,2)
110
109
 
111
- line_start = ab_intervals.last + offset
112
- line_end = cd_intervals.first + offset
110
+ GridGenerator::Line.new(a: ab_intervals[-1], b: cd_intervals[0])
111
+ end
112
+ end
113
113
 
114
- GridGenerator::Line.new(a: line_start, b: line_end)
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
115
119
  end
116
120
  end
117
121
 
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
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * 0.4, rotation_point: rotation_point)
130
+ top_right_face_lines_raw.map { |l| rotator.rotate(l) + offset }
131
+ end
132
+
133
+ # for svg
134
+ def down_face_lines
135
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * 0.8, rotation_point: rotation_point)
136
+ top_right_face_lines_raw.map { |l| rotator.rotate(l) + offset }
137
+ end
138
+
139
+ # for svg
140
+ def left_face_lines
141
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.2, rotation_point: rotation_point)
142
+ top_right_face_lines_raw.map { |l| rotator.rotate(l) + offset }
143
+ end
144
+
145
+ # for svg
146
+ def top_left_face_lines
147
+ rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.6, rotation_point: rotation_point)
148
+ top_right_face_lines_raw.map { |l| rotator.rotate(l) + offset }
149
+ end
150
+
118
151
  # for svg
119
152
  def front_face_lines
120
153
  (0..4).map do |i|
@@ -126,10 +159,7 @@ module GridGenerator
126
159
  ab_intervals = GridGenerator::Helper.intervals(a,b,2)
127
160
  cd_intervals = GridGenerator::Helper.intervals(c,d,2)
128
161
 
129
- line_start = ab_intervals.last + offset
130
- line_end = cd_intervals.first + offset
131
-
132
- GridGenerator::Line.new(a: line_start, b: line_end)
162
+ GridGenerator::Line.new(a: ab_intervals[-1], b: cd_intervals[0]) + offset
133
163
  end
134
164
  end
135
165
 
@@ -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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.2.10"
4
+ VERSION = "0.2.12"
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.10
4
+ version: 0.2.12
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