Class: GridGenerator::CurvyCopter::ElementFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/grid_generator/curvy_copter/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/curvy_copter/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/curvy_copter/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/curvy_copter/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/curvy_copter/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/curvy_copter/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/curvy_copter/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/curvy_copter/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/curvy_copter/element_factory.rb', line 19

def units
  @units
end

Instance Method Details

#anchorsObject



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

def anchors
  {}
end

#buildObject



139
140
141
# File 'lib/grid_generator/curvy_copter/element_factory.rb', line 139

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/grid_generator/curvy_copter/element_factory.rb', line 29

def commands 
  case [row_num, col_num]
  when [0, 0] # Top Left Corner 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_left_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:top_edge_left]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_left_corner_center], anchors[:left_edge_top]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [0, 1] # Top Middle Edge
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_edge_left]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:top_edge_right]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_edge_center], anchors[:center]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_edge_center], anchors[:top_edge_left]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [0, 2] # Top Right Corner
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_edge_right]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:top_right_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:right_edge_top]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_right_corner_center], anchors[:top_edge_right]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [1, 0] # Top Left Middle
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_edge_left]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_edge_center], anchors[:center]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:left_edge_center], anchors[:left_edge_top]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_left_corner_center], anchors[:top_edge_left]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [1, 1] # Top Right Middle
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:top_edge_right]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_right_corner_center], anchors[:right_edge_top]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:right_edge_center], anchors[:center]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:top_edge_center], anchors[:top_edge_right]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [2, 0] # Middle Left Edge 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:left_edge_top]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:left_edge_center], anchors[:center]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:left_edge_center], anchors[:left_edge_bottom]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [2, 1] # Middle Right Edge
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:right_edge_top]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:right_edge_bottom]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:right_edge_center], anchors[:center]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:right_edge_center], anchors[:right_edge_top]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [3, 0] # Bottom Left Middle 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:left_edge_bottom]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:left_edge_center], anchors[:center]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_edge_center], anchors[:bottom_edge_left]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_left_corner_center], anchors[:left_edge_bottom]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [3, 1] # Bottom Right Middle
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:center]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:right_edge_center], anchors[:right_edge_bottom]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_right_corner_center], anchors[:bottom_edge_right]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_edge_center], anchors[:center]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [4, 0] # Bottom Left Corner 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:left_edge_bottom]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_left_corner_center], anchors[:bottom_edge_left]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_left_corner]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [4, 1] # Bottom Middle Edge 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:center]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_edge_center], anchors[:bottom_edge_right]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_edge_left]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_edge_center], anchors[:center]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  when [4, 2] # Bottom Right Corner 
    [
      GridGenerator::Svg::MoveCommand.new(points: [anchors[:right_edge_bottom]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_right_corner]]),
      GridGenerator::Svg::LineCommand.new(points: [anchors[:bottom_edge_right]]),
      GridGenerator::Svg::QuadraticCommand.new(points: [anchors[:bottom_right_corner_center], anchors[:right_edge_bottom]]),
      GridGenerator::Svg::CloseCommand.new
    ]
  else
    [] 
  end
end

#dObject



133
134
135
136
137
# File 'lib/grid_generator/curvy_copter/element_factory.rb', line 133

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

#offsetObject



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

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

#styleObject



129
130
131
# File 'lib/grid_generator/curvy_copter/element_factory.rb', line 129

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