Class: GridGenerator::RediCube::ElementFactory
- Inherits:
-
Object
- Object
- GridGenerator::RediCube::ElementFactory
- Defined in:
- lib/grid_generator/redi_cube/element_factory.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#col_num ⇒ Object
readonly
Returns the value of attribute col_num.
-
#colour ⇒ Object
readonly
Returns the value of attribute colour.
-
#grid_x ⇒ Object
readonly
Returns the value of attribute grid_x.
-
#grid_y ⇒ Object
readonly
Returns the value of attribute grid_y.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
-
#row_num ⇒ Object
readonly
Returns the value of attribute row_num.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(grid_x:, grid_y:, row_num:, col_num:, units:, colour:, opacity:) ⇒ ElementFactory
constructor
A new instance of ElementFactory.
- #offset ⇒ Object
- #points ⇒ Object
Constructor Details
#initialize(grid_x:, grid_y:, row_num:, col_num:, units:, colour:, opacity:) ⇒ ElementFactory
Returns a new instance of ElementFactory.
7 8 9 10 11 12 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 7 def initialize(grid_x:, grid_y:, row_num:, col_num:, units:, colour:, opacity:) @grid_x, @grid_y = grid_x, grid_y @row_num, @col_num = row_num, col_num @units = units @colour, @opacity = colour, opacity end |
Instance Attribute Details
#col_num ⇒ Object (readonly)
Returns the value of attribute col_num.
14 15 16 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 14 def col_num @col_num end |
#colour ⇒ Object (readonly)
Returns the value of attribute colour.
14 15 16 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 14 def colour @colour end |
#grid_x ⇒ Object (readonly)
Returns the value of attribute grid_x.
14 15 16 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 14 def grid_x @grid_x end |
#grid_y ⇒ Object (readonly)
Returns the value of attribute grid_y.
14 15 16 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 14 def grid_y @grid_y end |
#opacity ⇒ Object (readonly)
Returns the value of attribute opacity.
14 15 16 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 14 def opacity @opacity end |
#row_num ⇒ Object (readonly)
Returns the value of attribute row_num.
14 15 16 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 14 def row_num @row_num end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
14 15 16 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 14 def units @units end |
Instance Method Details
#build ⇒ Object
88 89 90 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 88 def build GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) end |
#offset ⇒ Object
16 17 18 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 16 def offset @offset ||= Matrix.column_vector([grid_x, grid_y]) end |
#points ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/grid_generator/redi_cube/element_factory.rb', line 20 def points _points = case [row_num, col_num] when [0, 0] # top left corner [ anchors[:top_left_corner_top_left], anchors[:top_left_corner_top_right], anchors[:top_left_corner_bottom_right], anchors[:top_left_corner_bottom_left] ] when [0, 1] # top edge [ anchors[:top_left_corner_top_right], anchors[:top_right_corner_top_left], anchors[:top_right_corner_bottom_left], anchors[:center], anchors[:top_left_corner_bottom_right] ] when [0, 2] # top right corner [ anchors[:top_right_corner_top_left], anchors[:top_right_corner_top_right], anchors[:top_right_corner_bottom_right], anchors[:top_right_corner_bottom_left], ] when [1, 0] # left edge [ anchors[:top_left_corner_bottom_left], anchors[:top_left_corner_bottom_right], anchors[:center], anchors[:bottom_left_corner_top_right], anchors[:bottom_left_corner_top_left] ] when [1, 1] # right edge [ anchors[:top_right_corner_bottom_left], anchors[:top_right_corner_bottom_right], anchors[:bottom_right_corner_top_right], anchors[:bottom_right_corner_top_left], anchors[:center] ] when [2, 0] # bottom left corner [ anchors[:bottom_left_corner_top_left], anchors[:bottom_left_corner_top_right], anchors[:bottom_left_corner_bottom_right], anchors[:bottom_left_corner_bottom_left] ] when [2, 1] # bottom edge [ anchors[:center], anchors[:bottom_right_corner_top_left], anchors[:bottom_right_corner_bottom_left], anchors[:bottom_left_corner_bottom_right], anchors[:bottom_left_corner_top_right] ] when [2, 2] # bottom right corner [ anchors[:bottom_right_corner_top_left], anchors[:bottom_right_corner_top_right], anchors[:bottom_right_corner_bottom_right], anchors[:bottom_right_corner_bottom_left], ] else [] end _points.map { |p| p + offset } end |