Sha256: 4da96c2605cc9f66e151375c53072870738192947096306643617afec1fb858d

Contents?: true

Size: 1.36 KB

Versions: 56

Compression:

Stored size: 1.36 KB

Contents

module GridGenerator
  module Cubic
    class UnitsFactory
      def initialize(side:, type:, units:)
        raise ArgumentError "Unknown Side" unless [:top, :front, :right].include?(side)
        raise ArgumentError "Unknown Type" unless [:width, :height, :offset].include?(type)
        @side = side
        @type = type
        @units = units
      end

      attr_reader :side, :type, :units

      def top_unit
        case type
        when :width
          Matrix.column_vector([units, units/2])
        when :height
          Matrix.column_vector([-units, units/2])
        when :offset
          Matrix.column_vector([units,0])
        end
      end

      def front_unit
        case type
        when :width
          Matrix.column_vector([units, units/2])
        when :height
          Matrix.column_vector([0, units])
        when :offset
          Matrix.column_vector([0,0])
        end
      end

      def right_unit
        case type
        when :width
          Matrix.column_vector([units, (units*-0.5).to_i])
        when :height
          Matrix.column_vector([0, units])
        when :offset
          Matrix.column_vector([0,(units*0.5).to_i])
        end
      end

      def build
        case side
        when :top
          top_unit
        when :front
          front_unit
        when :right
          right_unit
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
grid_generator-0.2.6 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.5 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.4 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.3 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.2 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.1 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.0 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.12 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.11 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.10 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.9 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.8 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.7 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.6 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.5 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.1.4 lib/grid_generator/cubic/units_factory.rb