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.4 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.3 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.2 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.1 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.2.0 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.12 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.11 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.10 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.9 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.8 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.7 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.6 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.5 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.4 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.3 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.2 lib/grid_generator/megaminx/element_factory.rb
grid_generator-0.1.1 lib/grid_generator/megaminx/element_factory.rb