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