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.6.7 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.6.6 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.6.5 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.6.4 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.6.3 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.6.2 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.6.1 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.6.0 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.5.3 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.5.2 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.5.1 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.5.0 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.4.5 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.4.4 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.4.3 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.4.2 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.4.1 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.4.0 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.3.3 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.3.2 lib/grid_generator/cubic/units_factory.rb