Sha256: c9601b28deb491985c51def90bac847d2c9635c90438f3ee23a0e570c01796ce

Contents?: true

Size: 892 Bytes

Versions: 1

Compression:

Stored size: 892 Bytes

Contents

require 'bitmapped/commands/base_command'
require 'bitmapped/commands/commands_helper'
require 'bitmapped/exceptions'

module Bitmapped
  module Commands
    class HorizontalLineCommand < BaseCommand
      include CommandsHelper

      def command_id
        "H"
      end

      def process_command(bitmap, input)
        Validators::ValidateBitmapInitialised.parse_and_validate(bitmap)
        column, start, finish, color = Validators::ValidateSegmentInput.parse_and_validate(input)
        horizontal_command(bitmap, column, start, finish, color)
      end

      private
        def horizontal_command(bitmap, x, y, row, color)
          raise InvalidCoordinatesError unless (0 < row && row <= bitmap.rows)
          x, y = coordinates_to_array_indexes(bitmap, x, y)
          row = row - 1
          bitmap.pixels[row][x..y] = Array.new((x..y).size, color)
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitmapped-0.2.0 lib/bitmapped/commands/horizontal_line_command.rb