grid_generator 0.1.12 → 0.2.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/grid_generator/helper.rb +8 -0
- data/lib/grid_generator/megaminx/face_projection.rb +106 -0
- data/lib/grid_generator/megaminx/front_face.rb +12 -0
- data/lib/grid_generator/version.rb +1 -1
- data/lib/grid_generator.rb +4 -0
- metadata +5 -4
- data/lib/grid_generator/pyraminx/grid.rb +0 -84
- data/lib/grid_generator/pyraminx/triangle_factory_v1.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2668c9e2f64e3edc746fcc14a722c999fc4700a7835f472f3e661d6157c951d8
|
4
|
+
data.tar.gz: a9ee5d5b9ded2773be2bbb82caccc53258b0be5b9e01dba5e65cfcc74e53374a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 386ee6bc5bb324d0a986429f95e071df54c87dfaa58294007f54733256bb23c22b59d894e04c4e446b97536ad2e2d2a53edf3ad45f800c230996f022ed5f8bc2
|
7
|
+
data.tar.gz: 77d2e5859f4548e5c93c9d341ad947dfb6966940935edbc548b544070ef9e668818ea9019734e9597420870a58c07626c6e4dba55d0da0ad849b7bed62c8adde
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
require '../rotator'
|
3
|
+
require '../helper'
|
4
|
+
|
5
|
+
module GridGenerator
|
6
|
+
module Megaminx
|
7
|
+
class FaceProjection
|
8
|
+
# units 30 - pentagon 90 - megaminx - 150
|
9
|
+
# units * 5
|
10
|
+
# *****
|
11
|
+
# ***
|
12
|
+
# ***
|
13
|
+
#
|
14
|
+
# *** *** ***
|
15
|
+
# *** *** ***
|
16
|
+
# ***** ***** *****
|
17
|
+
#
|
18
|
+
# ***** *****
|
19
|
+
# *** ***
|
20
|
+
# *** ***
|
21
|
+
def initialize(x:, y:, units:, elements: [])
|
22
|
+
@x, @y = x, y
|
23
|
+
@units = units
|
24
|
+
@elements = elements
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :x, :y, :units, :elements
|
28
|
+
|
29
|
+
def offset
|
30
|
+
@offset ||= Matrix.column_vector([x, y])
|
31
|
+
end
|
32
|
+
|
33
|
+
def decagon_radius
|
34
|
+
5 * units
|
35
|
+
end
|
36
|
+
|
37
|
+
def decagon_top_point
|
38
|
+
Matrix.column_vector([
|
39
|
+
0,
|
40
|
+
decagon_radius
|
41
|
+
])
|
42
|
+
end
|
43
|
+
|
44
|
+
def rotation_point
|
45
|
+
Matrix.column_vector([
|
46
|
+
decagon_radius,
|
47
|
+
decagon_radius
|
48
|
+
])
|
49
|
+
end
|
50
|
+
|
51
|
+
def decagon_points
|
52
|
+
@decagon_points ||= (0..9).map do |i|
|
53
|
+
angle = 2.0 * Math::PI * i / 10.0
|
54
|
+
rotator = GridGenerator::Rotator.new(angle: angle, rotation_point: rotation_point)
|
55
|
+
rotator.rotate(top_point)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# also equal to pentagon radius
|
60
|
+
def decagon_side_length
|
61
|
+
@decagon_side_length ||= GridGenerator::Helper.distance(decagon_points[0], decagon_points[1])
|
62
|
+
end
|
63
|
+
|
64
|
+
def pentagon_top_point
|
65
|
+
@pentagon_top_point ||= Matrix.column_vector([
|
66
|
+
decagon_radius,
|
67
|
+
decagon_radius - decagon_side_length
|
68
|
+
])
|
69
|
+
end
|
70
|
+
|
71
|
+
def pentagon_points
|
72
|
+
@pentagon_points ||= (0..4).map do |i|
|
73
|
+
angle = 2.0 * Math::PI * i / 5.0
|
74
|
+
rotator = GridGenerator::Rotator.new(angle: angle, rotation_point: rotation_point)
|
75
|
+
rotator.rotate(top_point)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# for svg
|
80
|
+
def connecting_lines
|
81
|
+
@connecting_lines ||= pentagon_points.map_with_index do |p, i|
|
82
|
+
d = decagon_point[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_p[1,0]
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# for svg
|
95
|
+
def decagon_points_string
|
96
|
+
decagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
97
|
+
end
|
98
|
+
|
99
|
+
# for svg
|
100
|
+
def pentagon_points_string
|
101
|
+
pentagon_points.map { |p| p + offset }.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
data/lib/grid_generator.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: matrix
|
@@ -58,13 +58,14 @@ files:
|
|
58
58
|
- lib/grid_generator/cubic/top_grid.rb
|
59
59
|
- lib/grid_generator/cubic/units_factory.rb
|
60
60
|
- lib/grid_generator/face_parser.rb
|
61
|
+
- lib/grid_generator/helper.rb
|
61
62
|
- lib/grid_generator/megaminx/common.rb
|
62
63
|
- lib/grid_generator/megaminx/element_factory.rb
|
63
64
|
- lib/grid_generator/megaminx/face.rb
|
65
|
+
- lib/grid_generator/megaminx/face_projection.rb
|
66
|
+
- lib/grid_generator/megaminx/front_face.rb
|
64
67
|
- lib/grid_generator/pyraminx/face.rb
|
65
|
-
- lib/grid_generator/pyraminx/grid.rb
|
66
68
|
- lib/grid_generator/pyraminx/triangle_factory.rb
|
67
|
-
- lib/grid_generator/pyraminx/triangle_factory_v1.rb
|
68
69
|
- lib/grid_generator/rotator.rb
|
69
70
|
- lib/grid_generator/scaler.rb
|
70
71
|
- lib/grid_generator/skewb/left_element_factory.rb
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require_relative '../base_line'
|
2
|
-
require_relative 'triangle_factory_v1'
|
3
|
-
|
4
|
-
module GridGenerator
|
5
|
-
module Pyraminx
|
6
|
-
class Grid
|
7
|
-
def initialize(x: ,y:, size: ,units: ,elements:)
|
8
|
-
@x, @y = x, y
|
9
|
-
@size = size
|
10
|
-
@units = units
|
11
|
-
@elements = elements
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :x, :y, :size, :units, :elements
|
15
|
-
|
16
|
-
def shape_points
|
17
|
-
[
|
18
|
-
[ x+size*units, y ],
|
19
|
-
[ x+2*size*units, y+size*units ],
|
20
|
-
[ x+size*units, y+2*size*units ],
|
21
|
-
[ x, y+size*units ]
|
22
|
-
]
|
23
|
-
end
|
24
|
-
|
25
|
-
def shape_points_string
|
26
|
-
shape_points.map { |x,y| [x,y].join(',') }.join(' ')
|
27
|
-
end
|
28
|
-
|
29
|
-
def vertical_line_points
|
30
|
-
Array.new((2*size)-1) do |i|
|
31
|
-
GridGenerator::BaseLine.new(
|
32
|
-
x1: x+((i+1)-size).abs*units,
|
33
|
-
y1: y+(i+1)*units,
|
34
|
-
x2: x+((((i+1)-size).abs*-1)+2*size)*units,
|
35
|
-
y2: y+(i+1)*units
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def diagonal_down_line_points
|
41
|
-
Array.new(size-1) do |i|
|
42
|
-
GridGenerator::BaseLine.new(
|
43
|
-
x1: x+((i-1).abs + 1)*units,
|
44
|
-
y1: y+(i+1)*units,
|
45
|
-
x2: x+((i-1).abs + 1 + size)*units,
|
46
|
-
y2: y+(i+1+size)*units
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def diagonal_up_line_points
|
52
|
-
Array.new(size-1) do |i|
|
53
|
-
GridGenerator::BaseLine.new(
|
54
|
-
x1: x+(i+1)*units,
|
55
|
-
y1: y+(i+1+size)*units,
|
56
|
-
x2: x+(i+1+size)*units,
|
57
|
-
y2: y+(i+1)*units
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def element_shapes
|
63
|
-
elements.map do |row|
|
64
|
-
row.map do |element|
|
65
|
-
if element
|
66
|
-
GridGenerator::Pyraminx::TriangleFactoryV1.new(x: x, y: y, units: units, direction: element[:direction], colour: element[:colour], opacity: element[:opacity]).build
|
67
|
-
else
|
68
|
-
nil
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end.flatten.compact
|
72
|
-
end
|
73
|
-
|
74
|
-
def as_json
|
75
|
-
{
|
76
|
-
"vertical_line_points" => vertical_line_points,
|
77
|
-
"diagonal_down_line_points" => diagonal_down_line_points,
|
78
|
-
"diagonal_up_line_points" => diagonal_up_line_points,
|
79
|
-
"element_shapes" => element_shapes.map(&:as_json)
|
80
|
-
}
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require_relative '../base_element'
|
2
|
-
|
3
|
-
module GridGenerator
|
4
|
-
module Pyraminx
|
5
|
-
class TriangleFactoryV1
|
6
|
-
def initialize(x:, y:, units:, direction:, colour:, opacity:)
|
7
|
-
@x, @y = x, y
|
8
|
-
@units = units
|
9
|
-
@direction = direction
|
10
|
-
@colour = colour
|
11
|
-
@opacity = opacity
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :x, :y, :units, :direction, :colour, :opacity
|
15
|
-
|
16
|
-
def up_points
|
17
|
-
[
|
18
|
-
Matrix.column_vector([ x+units, y ]),
|
19
|
-
Matrix.column_vector([ x+2*units, y+units ]),
|
20
|
-
Matrix.column_vector([ x, y+units ])
|
21
|
-
]
|
22
|
-
end
|
23
|
-
|
24
|
-
def down_points
|
25
|
-
[
|
26
|
-
Matrix.column_vector([ x+units, y+units ]),
|
27
|
-
Matrix.column_vector([ x+2*units, y ]),
|
28
|
-
Matrix.column_vector([ x, y ])
|
29
|
-
]
|
30
|
-
end
|
31
|
-
|
32
|
-
def points
|
33
|
-
if direction == :up
|
34
|
-
up_points
|
35
|
-
else
|
36
|
-
down_points
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def build
|
41
|
-
GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|