grid_generator 0.2.24 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 812b6c5f247baa77cba970a91dd52c6b6663d1985563db1d21f173f44e391da1
4
- data.tar.gz: 1f0ac5ba29dc0983fe13acd9fb778047b4145cac67e19b39c1fe8a77135faefe
3
+ metadata.gz: d75cdb06a79ebb644afccc577353a18b2a7f999251ffffd6f1f7617b08c23745
4
+ data.tar.gz: fb3fc73597223fed891b6857250e217f9c4ca057e1795574b2ae1a9fd2ce1c41
5
5
  SHA512:
6
- metadata.gz: dd16fdc6510169001c957ac24342ed79cfc9d79fe96c98011f6270d6223a9a1dc08737dda987617068b4d30581abb519c8dba09cea83fffb438f4310a2e4847c
7
- data.tar.gz: e634b12f6070af21ea72cf5e7b6dc5fea167e0c511bdb03d1dfc3829145b80f1d87894ed09503c03270b4ad20fab6381e638b97fd81027990d89561ea2b1fa5c
6
+ metadata.gz: 06f2a4c827b2710abc6a379f6a45360a7caabafa4b0905f466e975968c0a622bb1f87296d7409b6225dabc7f807f126b4c93633af4b8a449830eb27703a5aee7
7
+ data.tar.gz: 1cb5b6a79655216376731edcd9724ceb9dd9cb5e6236df9cab39c8e048754a0aca33a17413a71d87aeb8985c48a74ad0500ac8f1035b2c7784a948db9b3f3976
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grid_generator (0.2.24)
4
+ grid_generator (0.3.0)
5
5
  matrix (~> 0.4.2)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ module GridGenerator
9
9
  'o' => '#ffb000',
10
10
  'gr' => '#808080',
11
11
  'br' => '#804000',
12
- 's' => '#8080ff',
12
+ 's' => '#8080ff', # change to sand colour
13
13
  'l' => '#80ff80',
14
14
  'p' => '#800080',
15
15
  'pi' => '#ff8080',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GridGenerator
4
- VERSION = "0.2.24"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -13,12 +13,7 @@ require_relative 'grid_generator/skewb/top_skewb_grid'
13
13
  require_relative 'grid_generator/skewb/left_skewb_grid'
14
14
  require_relative 'grid_generator/skewb/right_skewb_grid'
15
15
  require_relative 'grid_generator/square_one/face'
16
- require_relative 'grid_generator/arrows/vertical_arrow'
17
- require_relative 'grid_generator/arrows/horizontal_arrow'
18
- require_relative 'grid_generator/arrows/diagonal_down_arrow'
19
- require_relative 'grid_generator/arrows/diagonal_up_arrow'
20
16
  require_relative 'grid_generator/pyraminx/face'
21
- require_relative 'grid_generator/megaminx/face'
22
17
  require_relative 'grid_generator/megaminx/face_projection'
23
18
 
24
19
  module GridGenerator
@@ -65,30 +60,10 @@ module GridGenerator
65
60
  SquareOne::Face.new(**args)
66
61
  end
67
62
 
68
- def self.vertical_arrow(args)
69
- Arrows::VerticalArrow.new(**args)
70
- end
71
-
72
- def self.horizontal_arrow(args)
73
- Arrows::HorizontalArrow.new(**args)
74
- end
75
-
76
- def self.diagonal_down_arrow(args)
77
- Arrows::DiagonalDownArrow.new(**args)
78
- end
79
-
80
- def self.diagonal_up_arrow(args)
81
- Arrows::DiagonalUpArrow.new(**args)
82
- end
83
-
84
63
  def self.pyraminx_face(args)
85
64
  Pyraminx::Face.new(**args)
86
65
  end
87
66
 
88
- def self.megaminx_face(args)
89
- Megaminx::Face.new(**args)
90
- end
91
-
92
67
  def self.megaminx_face_projection(args)
93
68
  Megaminx::FaceProjection.new(**args)
94
69
  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.24
4
+ version: 0.3.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-08 00:00:00.000000000 Z
11
+ date: 2023-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: matrix
@@ -40,11 +40,6 @@ files:
40
40
  - Rakefile
41
41
  - grid_generator.gemspec
42
42
  - lib/grid_generator.rb
43
- - lib/grid_generator/arrows/arrow.rb
44
- - lib/grid_generator/arrows/diagonal_down_arrow.rb
45
- - lib/grid_generator/arrows/diagonal_up_arrow.rb
46
- - lib/grid_generator/arrows/horizontal_arrow.rb
47
- - lib/grid_generator/arrows/vertical_arrow.rb
48
43
  - lib/grid_generator/base_element.rb
49
44
  - lib/grid_generator/cubic/bordered_grid.rb
50
45
  - lib/grid_generator/cubic/facing_grid.rb
@@ -59,12 +54,8 @@ files:
59
54
  - lib/grid_generator/face_parser.rb
60
55
  - lib/grid_generator/helper.rb
61
56
  - lib/grid_generator/line.rb
62
- - lib/grid_generator/megaminx/common.rb
63
- - lib/grid_generator/megaminx/element_factory.rb
64
- - lib/grid_generator/megaminx/face.rb
65
57
  - lib/grid_generator/megaminx/face_element_factory.rb
66
58
  - lib/grid_generator/megaminx/face_projection.rb
67
- - lib/grid_generator/megaminx/front_face.rb
68
59
  - lib/grid_generator/pyraminx/face.rb
69
60
  - lib/grid_generator/pyraminx/triangle_factory.rb
70
61
  - lib/grid_generator/rotator.rb
@@ -1,29 +0,0 @@
1
- module GridGenerator
2
- module Arrows
3
- class Arrow
4
- def initialize(x:, y:, length:, direction: :uni, colour: '#ffffff')
5
- @x, @y = x, y
6
- @length = length
7
- @direction = direction
8
- @colour = colour
9
- end
10
-
11
- attr_reader :x, :y, :length, :direction, :colour
12
-
13
- def points
14
- []
15
- end
16
-
17
- def points_string
18
- points.map { |p| p.join(',') }.join(' ')
19
- end
20
-
21
- def as_json
22
- {
23
- "points_string" => points_string,
24
- "colour" => colour
25
- }
26
- end
27
- end
28
- end
29
- end
@@ -1,65 +0,0 @@
1
- require_relative 'arrow'
2
-
3
- module GridGenerator
4
- module Arrows
5
- class DiagonalDownArrow < Arrow
6
- ARROW_SIDE = 12
7
- ARROW_OVERHANG = 4
8
-
9
- def arrow_start_point
10
- [
11
- [ x, y+ARROW_SIDE ],
12
- [ x, y ],
13
- [ x+ARROW_SIDE, y ]
14
- ]
15
- end
16
-
17
- def arrow_start_flat
18
- [
19
- [ x, y+ARROW_SIDE-(2*ARROW_OVERHANG) ],
20
- [ x+ARROW_SIDE-(2*ARROW_OVERHANG), y ]
21
- ]
22
- end
23
-
24
- def arrow_start_side
25
- [
26
- [ x+ARROW_SIDE-ARROW_OVERHANG, y+ARROW_OVERHANG ],
27
- [ x+(ARROW_SIDE-ARROW_OVERHANG)+length, y+length+ARROW_OVERHANG ]
28
- ]
29
- end
30
-
31
- def arrow_end_point
32
- [
33
- [ x+ARROW_SIDE+length, y+length ],
34
- [ x+ARROW_SIDE+length, y+ARROW_SIDE+length ],
35
- [ x+length, y+ARROW_SIDE+length ]
36
- ]
37
- end
38
-
39
- def arrow_end_flat
40
- [
41
- [ x+ARROW_SIDE+length, y+length+(2*ARROW_OVERHANG) ],
42
- [ x+length+(2*ARROW_OVERHANG), y+ARROW_SIDE+length ]
43
- ]
44
- end
45
-
46
- def arrow_end_side
47
- [
48
- [ x+length+ARROW_OVERHANG, y+ARROW_SIDE+length-ARROW_OVERHANG ],
49
- [ x+ARROW_OVERHANG, y+ARROW_SIDE-ARROW_OVERHANG ]
50
- ]
51
- end
52
-
53
- def points
54
- case direction
55
- when :forward
56
- arrow_start_flat + arrow_start_side + arrow_end_point + arrow_end_side
57
- when :backward
58
- arrow_start_point + arrow_start_side + arrow_end_flat + arrow_end_side
59
- else
60
- arrow_start_point + arrow_start_side + arrow_end_point + arrow_end_side
61
- end
62
- end
63
- end
64
- end
65
- end
@@ -1,66 +0,0 @@
1
- require_relative 'arrow'
2
-
3
- module GridGenerator
4
- module Arrows
5
- class DiagonalUpArrow < Arrow
6
- ARROW_SIDE = 12
7
- ARROW_OVERHANG = 4
8
-
9
- def arrow_start_point
10
- [
11
- [ x+ARROW_SIDE, y+length+ARROW_SIDE ],
12
- [ x, y+length+ARROW_SIDE ],
13
- [ x, y+length ]
14
- ]
15
- end
16
-
17
- def arrow_start_flat
18
- [
19
- [ x+ARROW_SIDE-(2*ARROW_OVERHANG), y+length+ARROW_SIDE ],
20
- [ x, y+length+(2*ARROW_OVERHANG) ]
21
- ]
22
- end
23
-
24
- def arrow_start_side
25
- [
26
- [ x+ARROW_OVERHANG, y+length+ARROW_OVERHANG ],
27
- [ x+length+ARROW_OVERHANG, y+ARROW_OVERHANG ]
28
- ]
29
- end
30
-
31
- def arrow_end_point
32
- [
33
- [ x+length, y ],
34
- [ x+length+ARROW_SIDE, y ],
35
- [ x+length+ARROW_SIDE, y+ARROW_SIDE ]
36
- ]
37
- end
38
-
39
- def arrow_end_flat
40
- [
41
- [ x+length+(2*ARROW_OVERHANG), y ],
42
- [ x+length+ARROW_SIDE, y+ARROW_SIDE-(2*ARROW_OVERHANG) ]
43
- ]
44
- end
45
-
46
- def arrow_end_side
47
- [
48
- [ x+length+ARROW_SIDE-ARROW_OVERHANG, y+ARROW_SIDE-ARROW_OVERHANG ],
49
- [ x+ARROW_SIDE-ARROW_OVERHANG, y+length+ARROW_SIDE-ARROW_OVERHANG ]
50
- ]
51
- end
52
-
53
- def points
54
- case direction
55
- when :forward
56
- arrow_start_flat + arrow_start_side + arrow_end_point + arrow_end_side
57
- when :backward
58
- arrow_start_point + arrow_start_side + arrow_end_flat + arrow_end_side
59
- else
60
- arrow_start_point + arrow_start_side + arrow_end_point + arrow_end_side
61
- end
62
- end
63
-
64
- end
65
- end
66
- end
@@ -1,66 +0,0 @@
1
- require_relative 'arrow'
2
-
3
- module GridGenerator
4
- module Arrows
5
- class HorizontalArrow < Arrow
6
- ARROW_WIDTH = 16
7
- ARROW_LENGTH = 8
8
- LINE_WIDTH = 6
9
-
10
- def arrow_start_point
11
- [
12
- [ x+ARROW_LENGTH, y+ARROW_WIDTH ],
13
- [ x, y+(ARROW_WIDTH/2) ],
14
- [ x+ARROW_LENGTH, y ]
15
- ]
16
- end
17
-
18
- def arrow_start_flat
19
- [
20
- [ x, y+(ARROW_WIDTH/2)+(LINE_WIDTH/2) ],
21
- [ x, y+(ARROW_WIDTH/2)-(LINE_WIDTH/2) ]
22
- ]
23
- end
24
-
25
- def arrow_start_side
26
- [
27
- [ x+ARROW_LENGTH, y+(ARROW_WIDTH/2)-(LINE_WIDTH/2) ],
28
- [ x+ARROW_LENGTH+length, y+(ARROW_WIDTH/2)-(LINE_WIDTH/2) ]
29
- ]
30
- end
31
-
32
- def arrow_end_point
33
- [
34
- [ x+ARROW_LENGTH+length, y ],
35
- [ x+(2*ARROW_LENGTH)+length, y+(ARROW_WIDTH/2) ],
36
- [ x+ARROW_LENGTH+length, y+ARROW_WIDTH ]
37
- ]
38
- end
39
-
40
- def arrow_end_flat
41
- [
42
- [ x+(2*ARROW_LENGTH)+length, y+(ARROW_WIDTH/2)-(LINE_WIDTH/2) ],
43
- [ x+(2*ARROW_LENGTH)+length, y+(ARROW_WIDTH/2)+(LINE_WIDTH/2) ]
44
- ]
45
- end
46
-
47
- def arrow_end_side
48
- [
49
- [ x+ARROW_LENGTH+length, y+(ARROW_WIDTH/2)+(LINE_WIDTH/2) ],
50
- [ x+ARROW_LENGTH, y+(ARROW_WIDTH/2)+(LINE_WIDTH/2) ]
51
- ]
52
- end
53
-
54
- def points
55
- case direction
56
- when :forward
57
- arrow_start_flat + arrow_start_side + arrow_end_point + arrow_end_side
58
- when :backward
59
- arrow_start_point + arrow_start_side + arrow_end_flat + arrow_end_side
60
- else
61
- arrow_start_point + arrow_start_side + arrow_end_point + arrow_end_side
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,66 +0,0 @@
1
- require_relative 'arrow'
2
-
3
- module GridGenerator
4
- module Arrows
5
- class VerticalArrow < Arrow
6
- ARROW_WIDTH = 16
7
- ARROW_LENGTH = 8
8
- LINE_WIDTH = 6
9
-
10
- def arrow_start_point
11
- [
12
- [ x, y+ARROW_LENGTH ],
13
- [ x+(ARROW_WIDTH/2), y ],
14
- [ x+ARROW_WIDTH, y+ARROW_LENGTH ]
15
- ]
16
- end
17
-
18
- def arrow_start_flat
19
- [
20
- [ x+(ARROW_WIDTH/2)-(LINE_WIDTH/2), y ],
21
- [ x+(ARROW_WIDTH/2)+(LINE_WIDTH/2), y ]
22
- ]
23
- end
24
-
25
- def arrow_start_side
26
- [
27
- [ x+(ARROW_WIDTH/2)+(LINE_WIDTH/2), y+ARROW_LENGTH ],
28
- [ x+(ARROW_WIDTH/2)+(LINE_WIDTH/2), y+ARROW_LENGTH+length ]
29
- ]
30
- end
31
-
32
- def arrow_end_point
33
- [
34
- [ x+ARROW_WIDTH, y+ARROW_LENGTH+length ],
35
- [ x+(ARROW_WIDTH/2), y+(ARROW_LENGTH*2)+length ],
36
- [ x, y+ARROW_LENGTH+length ]
37
- ]
38
- end
39
-
40
- def arrow_end_flat
41
- [
42
- [ x+(ARROW_WIDTH/2)+(LINE_WIDTH/2), y+(2*ARROW_LENGTH)+length ],
43
- [ x+(ARROW_WIDTH/2)-(LINE_WIDTH/2), y+(2*ARROW_LENGTH)+length ]
44
- ]
45
- end
46
-
47
- def arrow_end_side
48
- [
49
- [ x+(ARROW_WIDTH/2)-(LINE_WIDTH/2), y+ARROW_LENGTH+length ],
50
- [ x+(ARROW_WIDTH/2)-(LINE_WIDTH/2), y+ARROW_LENGTH ]
51
- ]
52
- end
53
-
54
- def points
55
- case direction
56
- when :forward
57
- arrow_start_flat + arrow_start_side + arrow_end_point + arrow_end_side
58
- when :backward
59
- arrow_start_point + arrow_start_side + arrow_end_flat + arrow_end_side
60
- else
61
- arrow_start_point + arrow_start_side + arrow_end_point + arrow_end_side
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,95 +0,0 @@
1
- require 'matrix'
2
-
3
- module GridGenerator
4
- module Megaminx
5
- module Common
6
- ROTATION_STEP = 2 * Math::PI / 5
7
-
8
- ROTATION_MATRIX = Proc.new do |theta|
9
- Matrix[
10
- [Math.cos(theta), -1*Math.sin(theta)],
11
- [Math.sin(theta), Math.cos(theta)]
12
- ]
13
- end
14
-
15
- ROTATION_MATRICES = Array.new(5) do |i|
16
- ROTATION_MATRIX.call(ROTATION_STEP * i)
17
- end
18
-
19
- def rotation_offset_matrix
20
- @rotation_offset_matrix ||= ROTATION_MATRIX.call(rotation_offset)
21
- end
22
-
23
- def rotation_point
24
- @rotation_point ||= Matrix.column_vector([x+2*units, y+2*units])
25
- end
26
-
27
- def rotate(matrix, point)
28
- (matrix * (point - rotation_point)) + rotation_point
29
- end
30
-
31
- # line
32
-
33
- def intersection(a,b,c,d)
34
- x1 = a[0,0]
35
- y1 = a[1,0]
36
- x2 = b[0,0]
37
- y2 = b[1,0]
38
- x3 = c[0,0]
39
- y3 = c[1,0]
40
- x4 = d[0,0]
41
- y4 = d[1,0]
42
-
43
- px_numerator = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)
44
- px_denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
45
-
46
- py_numerator = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)
47
- py_denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
48
-
49
- px = px_numerator / px_denominator
50
- py = py_numerator / py_denominator
51
-
52
- Matrix.column_vector([px, py])
53
- end
54
-
55
- # points
56
-
57
- def top_outer_corner
58
- @top_outer_corner ||= rotate(rotation_offset_matrix, Matrix.column_vector([x+2*units,y]))
59
- end
60
-
61
- def top_outer_edge
62
- point_a, point_b = outer_corners.first(2)
63
- @top_outer_edge = (point_a + point_b) / 2
64
- end
65
-
66
- def top_inner_corner
67
- intersection(outer_edges[4], outer_edges[1], outer_edges[3], outer_edges[0])
68
- end
69
-
70
- def outer_corners
71
- @outer_corners ||= ROTATION_MATRICES.map do |matrix|
72
- rotate(matrix, top_outer_corner)
73
- end
74
- end
75
-
76
- def outer_edges
77
- @outer_edges ||= ROTATION_MATRICES.map do |matrix|
78
- rotate(matrix, top_outer_edge)
79
- end
80
- end
81
-
82
- def inner_corners
83
- @inner_corners ||= ROTATION_MATRICES.map do |matrix|
84
- rotate(matrix, top_inner_corner)
85
- end
86
- end
87
-
88
- def outer_edges_ordered_by_evens_then_odds
89
- evens = outer_edges.select.with_index { |_,i| i % 2 == 0 }
90
- odds = outer_edges.select.with_index { |_,i| i % 2 == 1 }
91
- evens + odds
92
- end
93
- end
94
- end
95
- end
@@ -1,52 +0,0 @@
1
- require_relative '../base_element'
2
- require_relative 'common'
3
-
4
- module GridGenerator
5
- module Megaminx
6
- class ElementFactory
7
- include GridGenerator::Megaminx::Common
8
-
9
- CENTER_INDEX = 0
10
- EDGE_INDEX = 1
11
- CORNER_INDEX = 2
12
-
13
- def initialize(x: , y:, row_index:, element_index:, units:, colour:, opacity:, rotation_offset: 0)
14
- @x, @y = x, y
15
- @row_index = row_index
16
- @element_index = element_index
17
- @units = units
18
- @colour = colour
19
- @opacity = opacity
20
- @rotation_offset = rotation_offset
21
- end
22
-
23
- attr_reader :x, :y, :row_index, :element_index, :units, :colour, :opacity, :rotation_offset
24
-
25
- def points
26
- case row_index
27
- when CENTER_INDEX
28
- inner_corners
29
- when EDGE_INDEX
30
- [
31
- outer_edges[element_index],
32
- inner_corners[(element_index+1) % 5],
33
- inner_corners[element_index],
34
- ]
35
- when CORNER_INDEX
36
- [
37
- outer_corners[element_index],
38
- outer_edges[element_index],
39
- inner_corners[element_index],
40
- outer_edges[(element_index-1) % 5],
41
- ]
42
- else
43
- raise ArgumentError, "unknown row #{row_index}"
44
- end
45
- end
46
-
47
- def build
48
- GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
49
- end
50
- end
51
- end
52
- end
@@ -1,79 +0,0 @@
1
- require_relative '../face_parser'
2
- require_relative 'common'
3
- require_relative 'element_factory'
4
-
5
- module GridGenerator
6
- module Megaminx
7
- class Face
8
- include GridGenerator::Megaminx::Common
9
-
10
- def initialize(x:, y: , units: , elements: , rotation_offset: 0, label: nil)
11
- @x, @y = x, y
12
- @units = units
13
- @elements = FaceParser.new(elements).parse
14
- @rotation_offset = rotation_offset
15
- @label = label
16
- end
17
-
18
- attr_reader :x, :y, :units, :elements, :rotation_offset, :label
19
-
20
- # outline
21
-
22
- def outline_string
23
- outer_corners.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
24
- end
25
-
26
- def inner_string
27
- inner_corners.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
28
- end
29
-
30
- def inline_string
31
- outer_edges_ordered_by_evens_then_odds.map { |p| "#{p[0,0].round},#{p[1,0].round}" }.join(' ')
32
- end
33
-
34
- # elements
35
-
36
- def element_shapes
37
- elements.each_with_index.map do |row, row_index|
38
- row.each_with_index.map do |element, element_index|
39
- GridGenerator::Megaminx::ElementFactory.new(
40
- x: x,
41
- y: y,
42
- row_index: row_index,
43
- element_index: element_index,
44
- units: units,
45
- colour: element[:colour],
46
- opacity: element[:opacity],
47
- rotation_offset: rotation_offset
48
- ).build if element
49
- end
50
- end.flatten.compact
51
- end
52
-
53
- # label methods
54
-
55
- def label_position
56
- x = rotation_point[0,0] - units*0.3
57
- y = rotation_point[1,0] + units*0.4
58
- {
59
- x: x.round,
60
- y: y.round
61
- }
62
- end
63
-
64
- def label_size
65
- units
66
- end
67
-
68
- def as_json
69
- {
70
- "outline_string" => outline_string,
71
- "inline_string" => inline_string,
72
- "element_shapes" => element_shapes.as_json,
73
- "label_position" => label_position,
74
- "label_size" => label_size
75
- }
76
- end
77
- end
78
- end
79
- end
@@ -1,12 +0,0 @@
1
- class GridGenerator
2
- module Megaminx
3
- class FrontFace
4
- def (x:, y:, units:, elements:)
5
- @x, @y = x, y
6
- @units = units
7
- @elements = elements
8
- end
9
-
10
- end
11
- end
12
- end