Class: GridGenerator::SquareOne::ElementFactory
- Inherits:
-
Object
- Object
- GridGenerator::SquareOne::ElementFactory
- Defined in:
- lib/grid_generator/square_one/element_factory.rb
Instance Attribute Summary collapse
-
#colour ⇒ Object
readonly
Returns the value of attribute colour.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
-
#shape ⇒ Object
readonly
Returns the value of attribute shape.
-
#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
- #base_points ⇒ Object
- #build ⇒ Object
- #face_size ⇒ Object
- #half_edge_width ⇒ Object
- #half_face_size ⇒ Object
-
#initialize(x:, y:, units:, shape:, offset:, colour:, opacity:) ⇒ ElementFactory
constructor
A new instance of ElementFactory.
- #offset_radians ⇒ Object
- #points ⇒ Object
- #rotation_matrix ⇒ Object
- #rotation_point ⇒ Object
Constructor Details
#initialize(x:, y:, units:, shape:, offset:, colour:, opacity:) ⇒ ElementFactory
Returns a new instance of ElementFactory.
7 8 9 10 11 12 13 14 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 7 def initialize(x: , y:, units:, shape:, offset:, colour:, opacity:) @x, @y = x, y @units = units @shape = shape @offset = offset @colour = colour @opacity = opacity end |
Instance Attribute Details
#colour ⇒ Object (readonly)
Returns the value of attribute colour.
16 17 18 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 16 def colour @colour end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
16 17 18 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 16 def offset @offset end |
#opacity ⇒ Object (readonly)
Returns the value of attribute opacity.
16 17 18 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 16 def opacity @opacity end |
#shape ⇒ Object (readonly)
Returns the value of attribute shape.
16 17 18 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 16 def shape @shape end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
16 17 18 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 16 def units @units end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
16 17 18 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 16 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
16 17 18 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 16 def y @y end |
Instance Method Details
#base_points ⇒ Object
18 19 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 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 18 def base_points case shape when :edge [ Matrix.column_vector([x+half_face_size-half_edge_width, y]), Matrix.column_vector([x+half_face_size+half_edge_width, y]), Matrix.column_vector([x+half_face_size, y+half_face_size]) ] when :corner [ Matrix.column_vector([x+half_face_size+half_edge_width, y]), Matrix.column_vector([x+face_size, y]), Matrix.column_vector([x+face_size, y+half_face_size-half_edge_width]), Matrix.column_vector([x+half_face_size, y+half_face_size]) ] when :middle [ Matrix.column_vector([x+half_face_size+half_edge_width, y]), Matrix.column_vector([x+face_size, y]), Matrix.column_vector([x+face_size, y+face_size]), Matrix.column_vector([x+half_face_size-half_edge_width, y+face_size]) ] when :middle_flipped @base_points ||= [ Matrix.column_vector([x+half_face_size-half_edge_width, y]), Matrix.column_vector([x+face_size, y]), Matrix.column_vector([x+face_size, y+face_size]), Matrix.column_vector([x+half_face_size+half_edge_width, y+face_size]) ] else raise ArgumentError, "unknown face shape: #{edge}" end end |
#build ⇒ Object
84 85 86 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 84 def build GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) end |
#face_size ⇒ Object
64 65 66 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 64 def face_size @face_size ||= 3 * units end |
#half_edge_width ⇒ Object
56 57 58 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 56 def half_edge_width @half_edge_width ||= half_face_size * Math.tan(Math::PI/12) end |
#half_face_size ⇒ Object
60 61 62 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 60 def half_face_size @half_face_size ||= face_size / 2 end |
#offset_radians ⇒ Object
52 53 54 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 52 def offset_radians offset*Math::PI/6 end |
#points ⇒ Object
80 81 82 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 80 def points base_points.map { |p| (rotation_matrix * (p - rotation_point)) + rotation_point } end |
#rotation_matrix ⇒ Object
72 73 74 75 76 77 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 72 def rotation_matrix @rotation_matrix ||= Matrix[ [Math.cos(offset_radians), -1*Math.sin(offset_radians)], [Math.sin(offset_radians), Math.cos(offset_radians)] ] end |
#rotation_point ⇒ Object
68 69 70 |
# File 'lib/grid_generator/square_one/element_factory.rb', line 68 def rotation_point Matrix.column_vector([x+half_face_size, y+half_face_size]) end |