Class: GridGenerator::RexCube::ElementFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/grid_generator/rex_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.



12
13
14
15
16
17
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 12

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.



19
20
21
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 19

def col_num
  @col_num
end

#colourObject (readonly)

Returns the value of attribute colour.



19
20
21
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 19

def colour
  @colour
end

#grid_xObject (readonly)

Returns the value of attribute grid_x.



19
20
21
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 19

def grid_x
  @grid_x
end

#grid_yObject (readonly)

Returns the value of attribute grid_y.



19
20
21
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 19

def grid_y
  @grid_y
end

#opacityObject (readonly)

Returns the value of attribute opacity.



19
20
21
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 19

def opacity
  @opacity
end

#row_numObject (readonly)

Returns the value of attribute row_num.



19
20
21
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 19

def row_num
  @row_num
end

#unitsObject (readonly)

Returns the value of attribute units.



19
20
21
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 19

def units
  @units
end

Instance Method Details

#anchorsObject



25
26
27
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 25

def anchors
  {}
end

#buildObject



115
116
117
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 115

def build
  GridGenerator::Svg::Path.new(d: d, style: style)
end

#commandsObject



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 29

def commands 
  case [row_num, col_num]
  when [0, 0] # Top Edge 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_left_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:top_right_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_top]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:top_left_corner]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [1, 0] # Top Left Petal 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_left_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_top]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_left]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [1, 1] # Top Right Petal 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_right_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_right]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_top]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:top_right_corner]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [2, 0] # Left Edge 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_left_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_left]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_left_corner]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [2, 1] # Center 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:center_top]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_right]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_bottom]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_left]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [2, 2] # Right Edge 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_right_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_right_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_right]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:top_right_corner]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [3, 0] # Bottom Left Petal 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:center_left]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_bottom]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_left_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_left]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [3, 1] # Bottom Right Petal 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:center_right]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_right_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_bottom]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [4, 0] # Bottom Edge 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:center_bottom]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_right_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_left_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:center_bottom]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  else
    [] 
  end
end

#dObject



109
110
111
112
113
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 109

def d
  commands.map do |c| 
    (c + offset) 
  end
end

#offsetObject



21
22
23
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 21

def offset
  @offset ||= Matrix.column_vector([grid_x, grid_y])
end

#styleObject



105
106
107
# File 'lib/grid_generator/rex_cube/element_factory.rb', line 105

def style
  GridGenerator::Svg::Style.new(fill: colour, opacity: opacity)
end