Class: GridGenerator::RediCube::ElementFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/grid_generator/redi_cube/element_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_numObject (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

#colourObject (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_xObject (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_yObject (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

#opacityObject (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_numObject (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

#unitsObject (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

#buildObject



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

#offsetObject



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

#pointsObject



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