grid_generator 0.2.11 → 0.2.13
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64d15af10326ad444f4760ddbe17746cbfc05661e50e1fb5b81ce8f13b08d871
|
4
|
+
data.tar.gz: b3ba4a0c2b51159418ee98606b0d8ade3964741ab662458214c849c02ead5a5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a5212a5f5a42b696b9b2a3508aa9f0b0adcd7939dbaf556e4697d8a9eb3556a085372583138da04f601e7d5f3d66033ba6ae8cb143e95e0324dc11a96b3a872
|
7
|
+
data.tar.gz: fee3fdecb1114c47e7c94b3b2717d86d0d77e107dcf9c722c16e5f3654e89d93a093bd8cf92bb5f8e3c2939577150e90bd6217491d07245cae10735dfa3766bb
|
data/Gemfile.lock
CHANGED
@@ -18,6 +18,28 @@ module GridGenerator
|
|
18
18
|
Matrix.column_vector([x, y])
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
def self.intersection(ab,cd)
|
23
|
+
x1 = ab.a[0,0]
|
24
|
+
y1 = ab.a[1,0]
|
25
|
+
x2 = ab.b[0,0]
|
26
|
+
y2 = ab.b[1,0]
|
27
|
+
x3 = cd.a[0,0]
|
28
|
+
y3 = cd.a[1,0]
|
29
|
+
x4 = cd.b[0,0]
|
30
|
+
y4 = cd.b[1,0]
|
31
|
+
|
32
|
+
px_numerator = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)
|
33
|
+
px_denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
|
34
|
+
|
35
|
+
py_numerator = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)
|
36
|
+
py_denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
|
37
|
+
|
38
|
+
px = px_numerator.to_f / px_denominator
|
39
|
+
py = py_numerator.to_f / py_denominator
|
40
|
+
|
41
|
+
Matrix.column_vector([px, py])
|
42
|
+
end
|
21
43
|
end
|
22
44
|
end
|
23
45
|
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require_relative '../face_parser'
|
2
|
+
|
3
|
+
module GridGenerator
|
4
|
+
module Megaminx
|
5
|
+
class FaceElementFactory
|
6
|
+
def initialize(x:, y:, index:, face_points: , face_lines:, face:)
|
7
|
+
@x, @y = x, y
|
8
|
+
@index = index
|
9
|
+
@face_points = face_points
|
10
|
+
@face_lines = face_lines
|
11
|
+
face_attr = FaceParser.new(face).parse
|
12
|
+
@colour = face_attr && face_attr[:colour]
|
13
|
+
@opacity = face_attr && face_attr[:opacity]
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :x, :y, :index, :face_points, :face_lines, :colour, :opacity
|
17
|
+
|
18
|
+
def offset
|
19
|
+
Matrix.column_vector([x, y])
|
20
|
+
end
|
21
|
+
|
22
|
+
# front face points
|
23
|
+
# 0 top corner
|
24
|
+
# 1 right corner
|
25
|
+
# 2 bottom right corner
|
26
|
+
# 3 bottom left corner
|
27
|
+
# 4 left corner
|
28
|
+
|
29
|
+
# front face lines - parallel
|
30
|
+
# 0 - top right
|
31
|
+
# 1 - right
|
32
|
+
# 2 - down
|
33
|
+
# 3 - left
|
34
|
+
# 4 - top left right
|
35
|
+
|
36
|
+
def center_points
|
37
|
+
face_lines.each_with_index.map do |line, i|
|
38
|
+
a = line
|
39
|
+
b = face_lines[(i+1)%5]
|
40
|
+
GridGenerator::Helper.intersection(a, b)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def edge_points(i)
|
45
|
+
previous_line = face_linex[(i-1)%5]
|
46
|
+
this_line = face_lines[i]
|
47
|
+
next_line = face_lines[(i+1)%5]
|
48
|
+
|
49
|
+
previous_this_point = GridGenerator::Helper.intersection(previous_line, this_line)
|
50
|
+
this_next_point = GridGenerator::Helper.intersection(this_line, next_line)
|
51
|
+
|
52
|
+
[
|
53
|
+
previous_line.b,
|
54
|
+
next_line.a,
|
55
|
+
this_next_point,
|
56
|
+
previous_this_point
|
57
|
+
]
|
58
|
+
end
|
59
|
+
|
60
|
+
def corner_points(i)
|
61
|
+
line_a = face_lines[(i+3) % 5]
|
62
|
+
line_b = face_lines[(i+4) % 5]
|
63
|
+
intersection = GridGenerator::Helper.intersection(line_a, line_b)
|
64
|
+
|
65
|
+
[
|
66
|
+
face_points[i],
|
67
|
+
line_a.b,
|
68
|
+
line_b.a,
|
69
|
+
intersection
|
70
|
+
]
|
71
|
+
end
|
72
|
+
|
73
|
+
def points
|
74
|
+
all_points = if index == 0
|
75
|
+
center_points
|
76
|
+
else
|
77
|
+
if index % 2 == 0
|
78
|
+
edge_points(index / 2)
|
79
|
+
else
|
80
|
+
corner_points((index - 1) / 2)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
all_points.map { |p| p + offset }
|
85
|
+
end
|
86
|
+
|
87
|
+
def build
|
88
|
+
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -2,30 +2,20 @@ require 'matrix'
|
|
2
2
|
require_relative '../rotator'
|
3
3
|
require_relative '../helper'
|
4
4
|
require_relative '../line'
|
5
|
+
require_relative 'face_element_factory'
|
5
6
|
|
6
7
|
module GridGenerator
|
7
8
|
module Megaminx
|
8
9
|
class FaceProjection
|
9
10
|
# units 30 - pentagon 90 - megaminx - 150
|
10
11
|
# units * 5
|
11
|
-
|
12
|
-
# ***
|
13
|
-
# ***
|
14
|
-
#
|
15
|
-
# *** *** ***
|
16
|
-
# *** *** ***
|
17
|
-
# ***** ***** *****
|
18
|
-
#
|
19
|
-
# ***** *****
|
20
|
-
# *** ***
|
21
|
-
# *** ***
|
22
|
-
def initialize(x:, y:, units:, elements: [])
|
12
|
+
def initialize(x:, y:, units:, front_face_elements: "")
|
23
13
|
@x, @y = x, y
|
24
14
|
@units = units
|
25
|
-
@
|
15
|
+
@front_face_elements = front_face_elements.split(',')
|
26
16
|
end
|
27
17
|
|
28
|
-
attr_reader :x, :y, :units, :
|
18
|
+
attr_reader :x, :y, :units, :front_face_elements
|
29
19
|
|
30
20
|
def offset
|
31
21
|
@offset ||= Matrix.column_vector([x, y])
|
@@ -87,22 +77,26 @@ module GridGenerator
|
|
87
77
|
]
|
88
78
|
end
|
89
79
|
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
pentagon_points[2]
|
96
|
-
|
97
|
-
|
80
|
+
def front_face_lines_raw
|
81
|
+
(0..4).map do |i|
|
82
|
+
a = pentagon_points[i-1] # offset one so first line is top right
|
83
|
+
b = pentagon_points[(i)%5]
|
84
|
+
c = pentagon_points[(i+1)%5]
|
85
|
+
d = pentagon_points[(i+2)%5]
|
86
|
+
|
87
|
+
ab_intervals = GridGenerator::Helper.intervals(a,b,2)
|
88
|
+
cd_intervals = GridGenerator::Helper.intervals(c,d,2)
|
89
|
+
|
90
|
+
GridGenerator::Line.new(a: ab_intervals[-1], b: cd_intervals[0])
|
91
|
+
end
|
98
92
|
end
|
99
93
|
|
100
94
|
def top_right_face_lines_raw
|
101
95
|
(0..4).map do |i|
|
102
|
-
a = top_right_pentagon_points[i]
|
103
|
-
b = top_right_pentagon_points[(i
|
104
|
-
c = top_right_pentagon_points[(i+
|
105
|
-
d = top_right_pentagon_points[(i+
|
96
|
+
a = top_right_pentagon_points[i-1] # offset by one so first line is top right
|
97
|
+
b = top_right_pentagon_points[(i)%5]
|
98
|
+
c = top_right_pentagon_points[(i+1)%5]
|
99
|
+
d = top_right_pentagon_points[(i+2)%5]
|
106
100
|
|
107
101
|
ab_intervals = GridGenerator::Helper.intervals(a,b,2)
|
108
102
|
cd_intervals = GridGenerator::Helper.intervals(c,d,2)
|
@@ -126,26 +120,31 @@ module GridGenerator
|
|
126
120
|
|
127
121
|
# for svg
|
128
122
|
def right_face_lines
|
129
|
-
|
130
|
-
|
131
|
-
top_right_face_lines_raw.map do |l|
|
132
|
-
rotator.rotate(l) + offset
|
133
|
-
end
|
123
|
+
rotator = GridGenerator::Rotator.new(angle: Math::PI * 0.4, rotation_point: rotation_point)
|
124
|
+
top_right_face_lines_raw.map { |l| rotator.rotate(l) + offset }
|
134
125
|
end
|
135
126
|
|
136
127
|
# for svg
|
137
|
-
def
|
138
|
-
(0
|
139
|
-
|
140
|
-
|
141
|
-
c = pentagon_points[(i+2)%5]
|
142
|
-
d = pentagon_points[(i+3)%5]
|
128
|
+
def down_face_lines
|
129
|
+
rotator = GridGenerator::Rotator.new(angle: Math::PI * 0.8, rotation_point: rotation_point)
|
130
|
+
top_right_face_lines_raw.map { |l| rotator.rotate(l) + offset }
|
131
|
+
end
|
143
132
|
|
144
|
-
|
145
|
-
|
133
|
+
# for svg
|
134
|
+
def left_face_lines
|
135
|
+
rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.2, rotation_point: rotation_point)
|
136
|
+
top_right_face_lines_raw.map { |l| rotator.rotate(l) + offset }
|
137
|
+
end
|
146
138
|
|
147
|
-
|
148
|
-
|
139
|
+
# for svg
|
140
|
+
def top_left_face_lines
|
141
|
+
rotator = GridGenerator::Rotator.new(angle: Math::PI * 1.6, rotation_point: rotation_point)
|
142
|
+
top_right_face_lines_raw.map { |l| rotator.rotate(l) + offset }
|
143
|
+
end
|
144
|
+
|
145
|
+
# for svg
|
146
|
+
def front_face_lines
|
147
|
+
front_face_lines_raw.map { |l| l + offset }
|
149
148
|
end
|
150
149
|
|
151
150
|
# for svg
|
@@ -158,6 +157,19 @@ module GridGenerator
|
|
158
157
|
pentagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
159
158
|
end
|
160
159
|
|
160
|
+
# for svg
|
161
|
+
def front_face_element_shapes
|
162
|
+
front_face_elements.each_with_index.map do |element, i|
|
163
|
+
GridGenerator::Megaminx::FaceElementFactory.new(
|
164
|
+
x: x,
|
165
|
+
y: y,
|
166
|
+
index: i,
|
167
|
+
face_points: pentagon_points,
|
168
|
+
face_lines: front_face_lines_raw,
|
169
|
+
face: element
|
170
|
+
).build unless element == '-'
|
171
|
+
end.compact
|
172
|
+
end
|
161
173
|
end
|
162
174
|
end
|
163
175
|
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.
|
4
|
+
version: 0.2.13
|
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-
|
11
|
+
date: 2023-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: matrix
|
@@ -62,6 +62,7 @@ files:
|
|
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
|
65
|
+
- lib/grid_generator/megaminx/face_element_factory.rb
|
65
66
|
- lib/grid_generator/megaminx/face_projection.rb
|
66
67
|
- lib/grid_generator/megaminx/front_face.rb
|
67
68
|
- lib/grid_generator/pyraminx/face.rb
|