Sha256: 25ed6035db6e32cbd66c2257284ee6a34470a619944ce7900b3ff09d76a25b3a

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

require 'matrix'
require_relative '../base_element'

module GridGenerator
  module DinoCube 
    class ElementFactory
      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

      attr_reader :grid_x, :grid_y, :row_num, :col_num, :units, :colour, :opacity

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

      def points
        _points = case [row_num, col_num]
        when [0, 0] # top
          [
            anchors[:top_left_corner],
            anchors[:top_right_corner],
            anchors[:center]
          ]
        when [1, 0] # left 
          [
            anchors[:top_left_corner],
            anchors[:center],
            anchors[:bottom_left_corner]
          ]
        when [1, 1] # right 
          [
            anchors[:top_right_corner],
            anchors[:bottom_right_corner],
            anchors[:center]
          ]
        when [2, 0] # bottom 
          [
            anchors[:center],
            anchors[:bottom_right_corner],
            anchors[:bottom_left_corner]
          ]
        else
          []
        end
        _points.map { |p| p + offset }
      end

      def build
        GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
grid_generator-0.6.7 lib/grid_generator/dino_cube/element_factory.rb
grid_generator-0.6.6 lib/grid_generator/dino_cube/element_factory.rb
grid_generator-0.6.5 lib/grid_generator/dino_cube/element_factory.rb
grid_generator-0.6.4 lib/grid_generator/dino_cube/element_factory.rb
grid_generator-0.6.3 lib/grid_generator/dino_cube/element_factory.rb
grid_generator-0.6.2 lib/grid_generator/dino_cube/element_factory.rb
grid_generator-0.6.1 lib/grid_generator/dino_cube/element_factory.rb
grid_generator-0.6.0 lib/grid_generator/dino_cube/element_factory.rb
grid_generator-0.5.3 lib/grid_generator/dino_cube/element_factory.rb