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.3.1 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.3.0 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.24 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.23 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.22 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.21 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.20 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.19 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.18 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.17 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.16 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.15 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.14 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.13 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.12 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.11 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.10 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.9 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.8 lib/grid_generator/cubic/units_factory.rb
grid_generator-0.2.7 lib/grid_generator/cubic/units_factory.rb