Sha256: d33b0370ec3fedd2ef5b0cb3af4b86aed3a73f9a269881b3f020d10e211a816c

Contents?: true

Size: 1.36 KB

Versions: 37

Compression:

Stored size: 1.36 KB

Contents

require_relative '../base_element'
require_relative 'common'

module GridGenerator
  module Megaminx
    class ElementFactory
      include GridGenerator::Megaminx::Common

      CENTER_INDEX = 0
      EDGE_INDEX = 1
      CORNER_INDEX = 2

      def initialize(x: , y:, row_index:, element_index:, units:, colour:, opacity:, rotation_offset: 0) 
        @x, @y = x, y
        @row_index = row_index
        @element_index = element_index
        @units = units
        @colour = colour
        @opacity = opacity
        @rotation_offset = rotation_offset
      end

      attr_reader :x, :y, :row_index, :element_index, :units, :colour, :opacity, :rotation_offset

      def points
        case row_index
        when CENTER_INDEX
          inner_corners  
        when EDGE_INDEX
          [
            outer_edges[element_index], 
            inner_corners[(element_index+1) % 5], 
            inner_corners[element_index], 
          ]
        when CORNER_INDEX
          [
            outer_corners[element_index], 
            outer_edges[element_index], 
            inner_corners[element_index], 
            outer_edges[(element_index-1) % 5], 
          ]
        else
          raise ArgumentError, "unknown row #{row_index}"
        end
      end

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

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
grid_generator-0.2.24 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.23 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.22 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.21 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.20 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.19 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.18 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.17 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.16 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.15 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.14 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.13 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.12 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.11 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.10 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.9 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.8 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.7 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.6 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.5 lib/grid_generator/megaminx/element_factory.rb