Sha256: bb6d7c37377950a7c714082d2d861be4cecb33401ae9a5f672913500c7b9f24d

Contents?: true

Size: 1.17 KB

Versions: 54

Compression:

Stored size: 1.17 KB

Contents

require_relative '../base_element'
require_relative '../face_parser'
require_relative 'units_factory'

module GridGenerator
  module Cubic
    class SquareFactory
      def initialize(x:, y:, width_unit:, height_unit:, offset_unit:, face:)
        @x, @y = x, y
        @width_unit = width_unit
        @height_unit = height_unit
        @offset_unit = offset_unit
        face_attr = FaceParser.new(face).parse
        @colour = face_attr && face_attr[:colour]
        @opacity = face_attr && face_attr[:opacity]
      end
  
      attr_reader :x, :y, :width_unit, :height_unit, :offset_unit, :colour, :opacity

      def top_left
        Matrix.column_vector([x, y]) + offset_unit
      end
  
      def top_right
        top_left + width_unit
      end 
  
      def bottom_right
        top_left + width_unit + height_unit
      end 
  
      def bottom_left
        top_left + height_unit
      end

      def points
        [
          top_left,
          top_right,
          bottom_right,
          bottom_left,
        ]
      end
  
      def build
        GridGenerator::BaseElement.new(points: points, colour: colour, opacity: opacity) unless colour.nil?
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
grid_generator-0.6.7 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.6.6 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.6.5 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.6.4 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.6.3 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.6.2 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.6.1 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.6.0 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.5.3 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.5.2 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.5.1 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.5.0 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.4.5 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.4.4 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.4.3 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.4.2 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.4.1 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.4.0 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.3.3 lib/grid_generator/cubic/square_factory.rb
grid_generator-0.3.2 lib/grid_generator/cubic/square_factory.rb