Class: GridGenerator::Pyraminx::TriangleFactory
- Inherits:
-
Object
- Object
- GridGenerator::Pyraminx::TriangleFactory
- Defined in:
- lib/grid_generator/pyraminx/triangle_factory.rb
Instance Attribute Summary collapse
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#colour ⇒ Object
readonly
Returns the value of attribute colour.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
-
#rotator ⇒ Object
readonly
Returns the value of attribute rotator.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#scaler ⇒ Object
readonly
Returns the value of attribute scaler.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#bottom_y ⇒ Object
(0 + 1) * Math.sqrt(3)/2 * units # row = 0 (1 + 1) * Math.sqrt(3)/2 * units # row = 1 (2 + 1) * Math.sqrt(3)/2 * units # row = 2.
- #build ⇒ Object
-
#even_bottom_left_x ⇒ Object
x + (0 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 0, col = 0 x + (1 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 1, col = 0 x + (1 * -1 + (3 - 1)) * 0.5 * units + 2 * 0.5 * units # row = 1, col = 2 x + (2 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 2, col = 0 x + (2 * -1 + (3 - 1)) * 0.5 * units + 2 * 0.5 * units # row = 2, col = 2 x + (2 * -1 + (3 - 1)) * 0.5 * units + 4 * 0.5 * units# row = 2, col = 4.
-
#even_bottom_right_x ⇒ Object
x + (0 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 0, col = 0 x + (1 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 1, col = 0 x + (1 * -1 + (3 + 1)) * 0.5 * units + 2 * 0.5 * units # row = 1, col = 2 x + (2 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 2, col = 0 x + (2 * -1 + (3 + 1)) * 0.5 * units + 2 * 0.5 * units # row = 2, col = 2 x + (2 * -1 + (3 + 1)) * 0.5 * units + 4 * 0.5 * units # row = 2, col = 4.
- #even_points ⇒ Object
-
#even_top_x ⇒ Object
x + ((3 - 0) * 0.5 * units) + 0 * 0.5 * units # row = 0, col = 0 x + ((3 - 1) * 0.5 * units) + 0 * 0.5 * units # row = 1, col = 0 x + ((3 - 1) * 0.5 * units) + 2 * 0.5 * units # row = 1, col = 2 x + ((3 - 2) * 0.5 * units) + 0 * 0.5 * units # row = 2, col = 0 x + ((3 - 2) * 0.5 * units) + 2 * 0.5 * units # row = 2, col = 2 x + ((3 - 2) * 0.5 * units) + 4 * 0.5 * units # row = 2, col = 4.
-
#initialize(x:, y:, row:, col:, units:, size:, face:, rotator:, scaler:) ⇒ TriangleFactory
constructor
A new instance of TriangleFactory.
-
#odd_bottom_x ⇒ Object
(0 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 0, col = 1 (1 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1 (2 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1 (2 * -1 + 3 + 1) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3.
- #odd_points ⇒ Object
-
#odd_top_left_x ⇒ Object
(0 * -1 + 3) * 0.5 * units # row 0 (1 * -1 + 3) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1 (1 * -1 + 3) * 0.5 * units + (3 - 1) * 0.5 * units # row 1, col = 3 (2 * -1 + 3) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1 (2 * -1 + 3) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3.
-
#odd_top_right_x ⇒ Object
((0 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 0, col = 1 ((1 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1 ((2 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1 ((2 * -1) + 3 + 2) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3.
- #offset ⇒ Object
- #points ⇒ Object
-
#top_y ⇒ Object
0 * Math.sqrt(3)/2 * units # row = 0 1 * Math.sqrt(3)/2 * units # row = 1 2 * Math.sqrt(3)/2 * units # row = 2.
Constructor Details
#initialize(x:, y:, row:, col:, units:, size:, face:, rotator:, scaler:) ⇒ TriangleFactory
Returns a new instance of TriangleFactory.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 7 def initialize(x:, y:, row:, col:, units:, size:, face:, rotator:, scaler:) @x, @y = x, y @row = row @col = col @units = units @size = size face_attr = GridGenerator::FaceParser.new(face).parse @colour = face_attr && face_attr[:colour] @opacity = face_attr && face_attr[:opacity] @rotator = rotator @scaler = scaler end |
Instance Attribute Details
#col ⇒ Object (readonly)
Returns the value of attribute col.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def col @col end |
#colour ⇒ Object (readonly)
Returns the value of attribute colour.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def colour @colour end |
#opacity ⇒ Object (readonly)
Returns the value of attribute opacity.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def opacity @opacity end |
#rotator ⇒ Object (readonly)
Returns the value of attribute rotator.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def rotator @rotator end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def row @row end |
#scaler ⇒ Object (readonly)
Returns the value of attribute scaler.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def scaler @scaler end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def size @size end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def units @units end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
20 21 22 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 20 def y @y end |
Instance Method Details
#bottom_y ⇒ Object
(0 + 1) * Math.sqrt(3)/2 * units # row = 0
(1 + 1) * Math.sqrt(3)/2 * units # row = 1
(2 + 1) * Math.sqrt(3)/2 * units # row = 2
66 67 68 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 66 def bottom_y (row + 1) * Math.sqrt(3)/2 * units end |
#build ⇒ Object
119 120 121 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 119 def build GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) unless colour.nil? end |
#even_bottom_left_x ⇒ Object
x + (0 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 0, col = 0 x + (1 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 1, col = 0 x + (1 * -1 + (3 - 1)) * 0.5 * units + 2 * 0.5 * units # row = 1, col = 2 x + (2 * -1 + (3 - 1)) * 0.5 * units + 0 * 0.5 * units # row = 2, col = 0 x + (2 * -1 + (3 - 1)) * 0.5 * units + 2 * 0.5 * units # row = 2, col = 2 x + (2 * -1 + (3 - 1)) * 0.5 * units + 4 * 0.5 * units# row = 2, col = 4
42 43 44 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 42 def even_bottom_left_x (row * -1 + (size - 1)) * 0.5 * units + col * 0.5 * units end |
#even_bottom_right_x ⇒ Object
x + (0 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 0, col = 0
x + (1 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 1, col = 0
x + (1 * -1 + (3 + 1)) * 0.5 * units + 2 * 0.5 * units # row = 1, col = 2
x + (2 * -1 + (3 + 1)) * 0.5 * units + 0 * 0.5 * units # row = 2, col = 0
x + (2 * -1 + (3 + 1)) * 0.5 * units + 2 * 0.5 * units # row = 2, col = 2
x + (2 * -1 + (3 + 1)) * 0.5 * units + 4 * 0.5 * units # row = 2, col = 4
52 53 54 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 52 def even_bottom_right_x (row * -1 + (size + 1)) * 0.5 * units + col * 0.5 * units end |
#even_points ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 95 def even_points [ Matrix.column_vector([even_top_x, top_y]), Matrix.column_vector([even_bottom_right_x, bottom_y]), Matrix.column_vector([even_bottom_left_x, bottom_y]) ] end |
#even_top_x ⇒ Object
x + ((3 - 0) * 0.5 * units) + 0 * 0.5 * units # row = 0, col = 0
x + ((3 - 1) * 0.5 * units) + 0 * 0.5 * units # row = 1, col = 0
x + ((3 - 1) * 0.5 * units) + 2 * 0.5 * units # row = 1, col = 2
x + ((3 - 2) * 0.5 * units) + 0 * 0.5 * units # row = 2, col = 0
x + ((3 - 2) * 0.5 * units) + 2 * 0.5 * units # row = 2, col = 2
x + ((3 - 2) * 0.5 * units) + 4 * 0.5 * units # row = 2, col = 4
32 33 34 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 32 def even_top_x ((size - row) * 0.5 * units) + col * 0.5 * units end |
#odd_bottom_x ⇒ Object
(0 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 0, col = 1
(1 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1
(2 * -1 + 3 + 1) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1
(2 * -1 + 3 + 1) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
91 92 93 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 91 def odd_bottom_x (row * -1 + size + 1) * 0.5 * units + (col - 1) * 0.5 * units end |
#odd_points ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 103 def odd_points [ Matrix.column_vector([odd_top_left_x, top_y]), Matrix.column_vector([odd_top_right_x, top_y]), Matrix.column_vector([odd_bottom_x, bottom_y]) ] end |
#odd_top_left_x ⇒ Object
(0 * -1 + 3) * 0.5 * units # row 0
(1 * -1 + 3) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1
(1 * -1 + 3) * 0.5 * units + (3 - 1) * 0.5 * units # row 1, col = 3
(2 * -1 + 3) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1
(2 * -1 + 3) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
75 76 77 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 75 def odd_top_left_x (row * -1 + size) * 0.5 * units + (col - 1) * 0.5 * units end |
#odd_top_right_x ⇒ Object
((0 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 0, col = 1 ((1 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 1, col = 1 ((2 * -1) + 3 + 2) * 0.5 * units + (1 - 1) * 0.5 * units # row 2, col = 1 ((2 * -1) + 3 + 2) * 0.5 * units + (3 - 1) * 0.5 * units # row 2, col = 3
83 84 85 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 83 def odd_top_right_x (row * -1 + size + 2) * 0.5 * units + (col - 1) * 0.5 * units end |
#offset ⇒ Object
22 23 24 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 22 def offset Matrix.column_vector([x, y]) end |
#points ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 111 def points all_points = col % 2 == 0 ? even_points : odd_points all_points.map do |point| scaled = scaler.scale(point) rotator.rotate(scaled) + offset end end |
#top_y ⇒ Object
0 * Math.sqrt(3)/2 * units # row = 0
1 * Math.sqrt(3)/2 * units # row = 1
2 * Math.sqrt(3)/2 * units # row = 2
59 60 61 |
# File 'lib/grid_generator/pyraminx/triangle_factory.rb', line 59 def top_y row * Math.sqrt(3)/2 * units end |